Page 1 of 1
Increase size of existing swap file
Posted: Sat Jun 08, 2013 2:10 am
by Physics_Dude
First of all I need to mention that my Pi is running off a mechanical HDD, not an SD card. So from this it is understandable that a larger swap file would be beneficial when the internal ram fills up.
The existing 100MB swap file at /var/swap is doing a good job, but I am in need of a bit more. Perhaps a Gig or two.
Does anyone have a few words on how I can go about doing this without causing to much trouble on the system?
Re: Increase size of existing swap file
Posted: Sat Jun 08, 2013 5:26 am
by rpdom
Change the size in /etc/dphys-swapfile:
man dphys-swapfile for details.
Re: Increase size of existing swap file
Posted: Sat Jun 08, 2013 8:28 am
by Physics_Dude
Code: Select all
$ free -m
total used free shared buffers cached
Mem: 485 141 344 0 10 63
-/+ buffers/cache: 66 419
Swap: 1023 0 1023
Thanks!

Re: Increase size of existing swap file
Posted: Wed Feb 05, 2014 11:14 am
by Zeno
I think it should be CONF_SWAPSIZE
AFAIK CONF_SWAPFILE is for the swap location
Re: Increase size of existing swap file
Posted: Thu Feb 01, 2018 7:59 pm
by alexanderre
exactly what I was looking for, thanks, guys

Re: Increase size of existing swap file
Posted: Thu Feb 01, 2018 9:29 pm
by n67
This is a good necro.
I've been wondering exactly this for awhile now - and may well have started a new thread about it had I not seen this one. Well done!
BTW, is there any way to make it use the new settings (after editing the config file) other than rebooting? I try to avoid rebooting if possible.
Re: Increase size of existing swap file
Posted: Tue Mar 06, 2018 6:43 am
by jostle
@n67
You just need to run
to update the settings changes.
Have Fun ...
Re: Increase size of existing swap file
Posted: Sun Apr 01, 2018 1:24 pm
by richlion2
Hello,
I just found this thread, as I need to inscrease my swap space. I am a bit confused, I am on a RPI 3 B+ with all the updates and when I run "top" is shows swap size is 1000 KiB. So the value in the file /etc/dphys-swapfile is in what if it is 100? I edited the file :
/etc/dphys-swapfile and changed from 100 to 200 and now "top" is showing 2048 MiB.
Thanks,
Richard
Re: Increase size of existing swap file
Posted: Sun Apr 01, 2018 2:43 pm
by jahboater
I use
Code: Select all
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
"setup" doesn't work for me.
And "free -h" is a quicker way of checking things than top.
Re: Increase size of existing swap file
Posted: Sat Oct 12, 2019 11:09 pm
by BenRandomNameHere
Very greatful of this post! I was getting quite upset at random input lag on my shiny new RPi4B, and this appears to have solved it!
and without a reboot!
and I got to learn about top and free!

Re: Increase size of existing swap file
Posted: Sun Oct 13, 2019 10:03 am
by jahboater
I since found you can do that in one step:
Code: Select all
sudo /etc/init.d/dphys-swapfile restart
Re: Increase size of existing swap file
Posted: Mon Dec 23, 2019 1:17 am
by Nowayno
Hello all,
I've been searching how to increase swap size from 100 to 1024/2048 but operation is not successful so I decided to write ,I will explain what I've been doing if something is not right please correct me. Thanks in advance
Sudo nano /etc/dphys-swapfile [enter] different black screen opens
I edit CONF_SWAPFILE=100 to CONF_SWAPFILE=1024
After that
I opened new terminal and
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
I do this command line above
Next step is free -m and it still says swap 100 , so I am confused.
Please help me since I'm new raspberry Pi 3b+ user
Regards
Re: Increase size of existing swap file
Posted: Mon Dec 23, 2019 5:36 am
by DougieLawson
sudo dphys-swapfile swapoff
sudo dphys-swapfile swapon
Re: Increase size of existing swap file
Posted: Mon Dec 23, 2019 5:37 am
by GlowInTheDark
Or just reboot.
Keep it simple.
Re: Increase size of existing swap file
Posted: Mon Jun 29, 2020 6:55 pm
by godofr
The correct sequence of steps is this (note the bold):
[20:23:11(root@surcopi)~]
# free -h
total used free shared buff/cache available
Mem: 704Mi 325Mi 36Mi 34Mi 342Mi 281Mi
Swap: 99Mi 0B 99Mi
[20:23:14(root@surcopi)~]
# dphys-swapfile swapoff
[20:24:50(root@surcopi)~]
# free -h
total used free shared buff/cache available
Mem: 704Mi 324Mi 36Mi 34Mi 342Mi 281Mi
Swap: 0B 0B 0B
[20:24:53(root@surcopi)~]
# nano /etc/dphys-swapfile
# /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=100
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
[20:24:59(root@surcopi)~]
# dphys-swapfile setup
want /var/swap=1024MByte, checking existing: deleting wrong size file (104857600), generating swapfile ... of 1024MBytes
[20:25:15(root@surcopi)~]
# dphys-swapfile swapon
[20:25:31(root@surcopi)~]
# free -h
total used free shared buff/cache available
Mem: 704Mi 325Mi 32Mi 34Mi 345Mi 280Mi
Swap: 1,0Gi 0B 1,0Gi
[20:25:45(root@surcopi)~]
#
This has worked for me, without having to restart.
Regards.