dennisdunbar
Posts: 20
Joined: Sun Aug 26, 2012 9:56 am
Location: Washington, DC

How to expand Virtual Memory on RPi B3 +?

Mon Apr 23, 2018 11:59 am

I just set up for first RPi B3+ using Stretch.

I am seeing virtual memory at 203MB.

I would like it to be 1024 MB.

I edited the file at /etc/init.d/dphys-swapfile

CONF_SWAPSIZE=1024

I reboot and I still get 203.

If I stop and start using
/etc/init.d/dphys-swapfile stop
and
/etc/init.d/dphys-swapfile start

It get it to 1203 MB until the next restart.

How to make the expanded size stick?
Many many many RPi, RPi B, RPi 3, RPi B+, RPi 3 B+ and one Zero running 20-30 websites, Word Press, FreePBX, PiAware, PrivateEyePi.

Ernst
Posts: 594
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: How to expand Virtual Memory on RPi B3 +?

Mon Apr 23, 2018 3:24 pm

I normally edit /etc/dphys-swapfile and do a reboot.

Code: Select all

# /etc/dphys-swapfile - user settings for dphys-swapfile package
# author Neil Franklin, last modification 2010.05.05
# copyright ETH Zuerich Physics Departement
#   use under either modified/non-advertising BSD or GPL license

# this file is sourced with . so full normal sh syntax applies

# the default settings are added as commented out CONF_*=* lines


# where we want the swapfile to be, this is the default
#CONF_SWAPFILE=/var/swap

# set size to absolute value, leaving empty (default) then uses computed value
#   you most likely don't want this, unless you have an special disk situation
CONF_SWAPSIZE=200

# set size to computed value, this times RAM size, dynamically adapts,
#   guarantees that there is enough swap without wasting disk space on excess
#CONF_SWAPFACTOR=2

# restrict size (computed and absolute!) to maximally this limit
#   can be set to empty for no limit, but beware of filled partitions!
#   this is/was a (outdated?) 32bit kernel limit (in MBytes), do not overrun it
#   but is also sensible on 64bit to prevent filling /var or even / partition
#CONF_MAXSWAP=2048
My first computer was an ICT1500, my first "personal" computer was the Science of Cambridge Mk14, followed by a TRS-80 Model I later

n67
Posts: 718
Joined: Mon Oct 30, 2017 4:55 pm

Re: How to expand Virtual Memory on RPi B3 +?

Mon Apr 23, 2018 3:44 pm

Yes. It seems OP just edited the wrong file.

The right file to edit is /etc/dphys-swapfile.

But this leads to a question: Now that we live in the world of systemd, why are there any files at all in /etc/init.d? Is that just a relic of the old init system? Are the files just there to trap the unwary?
"L'enfer, c'est les autres"

gkaiseril
Posts: 429
Joined: Mon Aug 08, 2016 9:27 pm
Location: Chicago, IL

Re: How to expand Virtual Memory on RPi B3 +?

Mon Apr 23, 2018 6:41 pm

The Raspbian OS is backward compatible to the R Pi 1A, so any new OS must retain compatibility with that model. So in this case it could be wise to update both places if the OP is still using the R Pi 1A.

n67
Posts: 718
Joined: Mon Oct 30, 2017 4:55 pm

Re: How to expand Virtual Memory on RPi B3 +?

Mon Apr 23, 2018 6:48 pm

gkaiseril wrote:
Mon Apr 23, 2018 6:41 pm
The Raspbian OS is backward compatible to the R Pi 1A, so any new OS must retain compatibility with that model. So in this case it could be wise to update both places if the OP is still using the R Pi 1A.
The 1A doesn't use systemd?
"L'enfer, c'est les autres"

mfa298
Posts: 1235
Joined: Tue Apr 22, 2014 11:18 am

Re: How to expand Virtual Memory on RPi B3 +?

Mon Apr 23, 2018 6:59 pm

gkaiseril wrote:
Mon Apr 23, 2018 6:41 pm
The Raspbian OS is backward compatible to the R Pi 1A, so any new OS must retain compatibility with that model. So in this case it could be wise to update both places if the OP is still using the R Pi 1A.
systemd is an OS update (moving away from the old sysvinit) rather than a hardware change so I'm not sure that comment makes sense. With stretch all models of Pi will use systemd by default. Software won't always be backwards compatible (and shouldn't be otherwise you end up with a mess like WinME).

I think not all things have migrated from sysvinit (/etc/init.d) to systemd so systemd will pull in some stuff from /etc/init

gkaiseril
Posts: 429
Joined: Mon Aug 08, 2016 9:27 pm
Location: Chicago, IL

Re: How to expand Virtual Memory on RPi B3 +?

Mon Apr 23, 2018 7:32 pm

That is up to the RPF to make that decision. Their decision is right now to keep that compatability since one of their goals is to provide an affordible computer to teach stidents worldwide including third world countries where even a $35.00 is an expensive purchase for many.

User avatar
rpdom
Posts: 12647
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: How to expand Virtual Memory on RPi B3 +?

Mon Apr 23, 2018 7:44 pm

gkaiseril wrote:
Mon Apr 23, 2018 7:32 pm
That is up to the RPF to make that decision. Their decision is right now to keep that compatability since one of their goals is to provide an affordible computer to teach stidents worldwide including third world countries where even a $35.00 is an expensive purchase for many.
It is nothing to do with the RPF. It is a decision by Debian on maintaining compatibility with old sysvinit based programs.

The hardware has nothing to do with it. It's not even just a Pi issue.

MaxK1
Posts: 1047
Joined: Sun Aug 26, 2012 11:34 pm

Re: How to expand Virtual Memory on RPi B3 +?

Tue Apr 24, 2018 10:38 am

Just a comment: If you NEED that much swap space, you are probably in very deep weeds. You are likely in deep weeds if you even approach 203Mb... Are you sure you haven't allocated too much memory for the GPU?
You are in a maze of twisty little passages, all alike.
When General Failure and Major Disaster get together, Private Parts usually suffers.

dennisdunbar
Posts: 20
Joined: Sun Aug 26, 2012 9:56 am
Location: Washington, DC

Re: How to expand Virtual Memory on RPi B3 +?

Tue Apr 24, 2018 11:14 am

n67 wrote:
Mon Apr 23, 2018 3:44 pm
Yes. It seems OP just edited the wrong file.

The right file to edit is /etc/dphys-swapfile.

But this leads to a question: Now that we live in the world of systemd, why are there any files at all in /etc/init.d? Is that just a relic of the old init system? Are the files just there to trap the unwary?

Edited /etc/dphys-swapfile., NO GO.
Many many many RPi, RPi B, RPi 3, RPi B+, RPi 3 B+ and one Zero running 20-30 websites, Word Press, FreePBX, PiAware, PrivateEyePi.

User avatar
DougieLawson
Posts: 33308
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to expand Virtual Memory on RPi B3 +?

Tue Apr 24, 2018 11:17 am

After you edit the file you need to run the sudo dphys-swapfile program to implement your changes.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

dennisdunbar
Posts: 20
Joined: Sun Aug 26, 2012 9:56 am
Location: Washington, DC

Re: How to expand Virtual Memory on RPi B3 +?

Tue Apr 24, 2018 11:29 am

MaxK1 wrote:
Tue Apr 24, 2018 10:38 am
Just a comment: If you NEED that much swap space, you are probably in very deep weeds. You are likely in deep weeds if you even approach 203Mb... Are you sure you haven't allocated too much memory for the GPU?
Not in weeds, GPU space fine, WHY NOT, THE SPACE IS THERE!
Many many many RPi, RPi B, RPi 3, RPi B+, RPi 3 B+ and one Zero running 20-30 websites, Word Press, FreePBX, PiAware, PrivateEyePi.

User avatar
rpdom
Posts: 12647
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: How to expand Virtual Memory on RPi B3 +?

Tue Apr 24, 2018 12:09 pm

dennisdunbar wrote:
Tue Apr 24, 2018 11:29 am
WHY NOT, THE SPACE IS THERE!
If you are needing to use virtual memory (swap space) on a Pi (or almost any other server really), you need to reconsider things. Are you using the right hardware? Is your application being too memory hungry?

Using virtual memory on a Pi is even worse than using it on a normal server with spinning rust storage. It will be incredibly slow and if you are using it on an SD card it can wear out the card very quickly.

ejolson
Posts: 1722
Joined: Tue Mar 18, 2014 11:47 am

Re: How to expand Virtual Memory on RPi B3 +?

Wed Apr 25, 2018 5:37 am

rpdom wrote:
Tue Apr 24, 2018 12:09 pm
If you are needing to use virtual memory (swap space) on a Pi (or almost any other server really), you need to reconsider things. Are you using the right hardware? Is your application being too memory hungry?
I think you need more than 200MB swap just to compile a new version of gcc.

Swap rate and swap size, while related, are not the same. I remember Linux swap working much better on the 1.2.x and 2.0.x series kernels than it does these days. However, that memory may not be accurate. It is interesting the way Linux user land reinvents the wheel with systemd and others and then keeps using the old wheels as well. If I did the same with my car it would be impossible to drive and likely destroy the road if I tried.

jahboater
Posts: 2782
Joined: Wed Feb 04, 2015 6:38 pm

Re: How to expand Virtual Memory on RPi B3 +?

Wed Apr 25, 2018 5:56 am

ejolson wrote:
Wed Apr 25, 2018 5:37 am
rpdom wrote:
Tue Apr 24, 2018 12:09 pm
If you are needing to use virtual memory (swap space) on a Pi (or almost any other server really), you need to reconsider things. Are you using the right hardware? Is your application being too memory hungry?
I think you need more than 200MB swap just to compile a new version of gcc.
The main point here is that the swap is needed for a few minutes only during the 4.5 hour build, but it enables the build to complete.
Reducing the memory usage (with "make" say instead of "make -j4") would slow the build down a lot by only using one core. ( "make -j4" runs four compilations at the same time utilizing all four cores on the Pi).

So using swap reduces the build time by roughly a factor of four - cant be bad!

My build script just has this in it:-

Code: Select all

#
#  For the Pi or any computer with less than 2GB of memory
#
if [ -f /etc/dphys-swapfile ]; then
  sudo sed -i 's/^CONF_SWAPSIZE=[0-9]*$/CONF_SWAPSIZE=1024/' /etc/dphys-swapfile
  sudo /etc/init.d/dphys-swapfile stop
  sudo /etc/init.d/dphys-swapfile start
fi
For interest, the other (really slow) way of adding swap is:-

Code: Select all

sudo dd if=/dev/zero of=/swapfile1GB bs=1G count=1
sudo chmod 0600 /swapfile1GB
sudo mkswap /swapfile1GB
sudo swapon /swapfile1GB

dennisdunbar
Posts: 20
Joined: Sun Aug 26, 2012 9:56 am
Location: Washington, DC

Re: How to expand Virtual Memory on RPi B3 +?

Wed Apr 25, 2018 7:52 am

DougieLawson wrote:
Tue Apr 24, 2018 11:17 am
After you edit the file you need to run the sudo dphys-swapfile program to implement your changes.
Tried that, here is what I got:

[email protected]:~# dphys-swapfile
Usage: /sbin/dphys-swapfile {setup|swapon|swapoff|uninstall}
[email protected]:~# dphys-swapfile setup
want /var/swap=1024MByte, checking existing: keeping it
[email protected]:~# dphys-swapfile swapon
After reboot, no go, still 203.
Many many many RPi, RPi B, RPi 3, RPi B+, RPi 3 B+ and one Zero running 20-30 websites, Word Press, FreePBX, PiAware, PrivateEyePi.

jahboater
Posts: 2782
Joined: Wed Feb 04, 2015 6:38 pm

Re: How to expand Virtual Memory on RPi B3 +?

Wed Apr 25, 2018 8:07 am

Please read my previous post which has a script entry that does the edit and restarts swap.
You need:-

sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start

dennisdunbar
Posts: 20
Joined: Sun Aug 26, 2012 9:56 am
Location: Washington, DC

Re: How to expand Virtual Memory on RPi B3 +?

Wed Apr 25, 2018 11:32 am

jahboater wrote:
Wed Apr 25, 2018 8:07 am
Please read my previous post which has a script entry that does the edit and restarts swap.
You need:-

sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start

Did that NO GO.
Many many many RPi, RPi B, RPi 3, RPi B+, RPi 3 B+ and one Zero running 20-30 websites, Word Press, FreePBX, PiAware, PrivateEyePi.

jahboater
Posts: 2782
Joined: Wed Feb 04, 2015 6:38 pm

Re: How to expand Virtual Memory on RPi B3 +?

Wed Apr 25, 2018 11:48 am

Well four suggestions,

1) have you got enough disk space?
2) have you correctly updated /etc/dphys-swapfile ?
Perhaps post it here.
3) check to see if /var/swap is the correct size
Use: ls -lh /var/swap
4) use "free -h" to show your swap

It works fine for me everytime on any Pi model.
The change is immediate, you do not have to reboot.

dennisdunbar
Posts: 20
Joined: Sun Aug 26, 2012 9:56 am
Location: Washington, DC

Re: How to expand Virtual Memory on RPi B3 +?

Wed Apr 25, 2018 11:57 am

jahboater wrote:
Wed Apr 25, 2018 11:48 am
Well two suggestions,

1) have you got enough disk space?
2) have you correctly updated /etc/dphys-swapfile ?
Perhaps post it here.
3) check to see if /var/swap is the correct size

It works fine for me on any Pi model.
Yes it always worked, I have 5 or 6 other here running no problem.

Like I said this is my first Stretch and my first Pi B3+
I have the memory,
I'll post the info in a bit
Many many many RPi, RPi B, RPi 3, RPi B+, RPi 3 B+ and one Zero running 20-30 websites, Word Press, FreePBX, PiAware, PrivateEyePi.

jahboater
Posts: 2782
Joined: Wed Feb 04, 2015 6:38 pm

Re: How to expand Virtual Memory on RPi B3 +?

Wed Apr 25, 2018 11:58 am

It works on stretch too!

Perhaps your sd card is faulty or old

User avatar
PeterO
Posts: 4211
Joined: Sun Jul 22, 2012 4:14 pm

Re: How to expand Virtual Memory on RPi B3 +?

Wed Apr 25, 2018 12:32 pm

dennisdunbar wrote:
Wed Apr 25, 2018 11:32 am
jahboater wrote:
Wed Apr 25, 2018 8:07 am
Please read my previous post which has a script entry that does the edit and restarts swap.
You need:-

sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start

Did that NO GO.
Did you do all of if though ...

Code: Select all

if [ -f /etc/dphys-swapfile ]; then
  sudo sed -i 's/^CONF_SWAPSIZE=[0-9]*$/CONF_SWAPSIZE=1024/' /etc/dphys-swapfile
  sudo /etc/init.d/dphys-swapfile stop
  sudo /etc/init.d/dphys-swapfile start
fi
What is in the file "/etc/dphys-swapfile" on your machine ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

dennisdunbar
Posts: 20
Joined: Sun Aug 26, 2012 9:56 am
Location: Washington, DC

Re: How to expand Virtual Memory on RPi B3 +?

Thu Apr 26, 2018 1:40 am

What is in the file "/etc/dphys-swapfile" on your machine ?

PeterO
[/quote]



#CONF_SWAPFILE=/var/swap

# set size to absolute value, leaving empty (default) then uses computed value
# you most likely don't want this, unless you have an special disk situation

CONF_SWAPSIZE=1024

# set size to computed value, this times RAM size, dynamically adapts,
# guarantees that there is enough swap without wasting disk space on excess
#CONF_SWAPFACTOR=2

# restrict size (computed and absolute!) to maximally this limit
# can be set to empty for no limit, but beware of filled partitions!
# this is/was a (outdated?) 32bit kernel limit (in MBytes), do not overrun it
# but is also sensible on 64bit to prevent filling /var or even / partition
#CONF_MAXSWAP=2048
Many many many RPi, RPi B, RPi 3, RPi B+, RPi 3 B+ and one Zero running 20-30 websites, Word Press, FreePBX, PiAware, PrivateEyePi.

dennisdunbar
Posts: 20
Joined: Sun Aug 26, 2012 9:56 am
Location: Washington, DC

Re: How to expand Virtual Memory on RPi B3 +?

Thu Apr 26, 2018 1:43 am

jahboater wrote:
Wed Apr 25, 2018 11:48 am
Well four suggestions,

1) have you got enough disk space?
2) have you correctly updated /etc/dphys-swapfile ?
Perhaps post it here.
3) check to see if /var/swap is the correct size
Use: ls -lh /var/swap
4) use "free -h" to show your swap

It works fine for me everytime on any Pi model.
The change is immediate, you do not have to reboot.
Has for me previously,

ls -lh /var/swap
-rw------- 1 root root 1.0G Apr 22 19:06 /var/swap
Many many many RPi, RPi B, RPi 3, RPi B+, RPi 3 B+ and one Zero running 20-30 websites, Word Press, FreePBX, PiAware, PrivateEyePi.

dennisdunbar
Posts: 20
Joined: Sun Aug 26, 2012 9:56 am
Location: Washington, DC

Re: How to expand Virtual Memory on RPi B3 +?

Thu Apr 26, 2018 1:51 am

jahboater wrote:
Wed Apr 25, 2018 11:48 am
Well four suggestions,

1) have you got enough disk space?
2) have you correctly updated /etc/dphys-swapfile ?
Perhaps post it here.
3) check to see if /var/swap is the correct size
Use: ls -lh /var/swap
4) use "free -h" to show your swap

It works fine for me everytime on any Pi model.
The change is immediate, you do not have to reboot.
ls -lh /var/swap
-rw------- 1 root root 1.0G Apr 22 19:06 /var/swap
free -h
total used free shared buff/cache available
Mem: 748M 163M 174M 17M 410M 512M
Swap: 203M 0B 203M
Many many many RPi, RPi B, RPi 3, RPi B+, RPi 3 B+ and one Zero running 20-30 websites, Word Press, FreePBX, PiAware, PrivateEyePi.

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 14 guests