Physics_Dude
Posts: 4
Joined: Fri Sep 28, 2012 3:19 pm

Increase size of existing swap file

Sat Jun 08, 2013 2:10 am

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?

User avatar
rpdom
Posts: 19281
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Increase size of existing swap file

Sat Jun 08, 2013 5:26 am

Change the size in /etc/dphys-swapfile:

Code: Select all

CONF_SWAPFILE=100
man dphys-swapfile for details.

Physics_Dude
Posts: 4
Joined: Fri Sep 28, 2012 3:19 pm

Re: Increase size of existing swap file

Sat Jun 08, 2013 8:28 am

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! :mrgreen:

Zeno
Posts: 3
Joined: Tue Jan 14, 2014 4:56 pm

Re: Increase size of existing swap file

Wed Feb 05, 2014 11:14 am

I think it should be CONF_SWAPSIZE
AFAIK CONF_SWAPFILE is for the swap location

User avatar
alexanderre
Posts: 19
Joined: Fri Mar 04, 2016 4:51 pm
Location: Kyiv, Ukraine
Contact: Facebook

Re: Increase size of existing swap file

Thu Feb 01, 2018 7:59 pm

exactly what I was looking for, thanks, guys :)

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

Re: Increase size of existing swap file

Thu Feb 01, 2018 9:29 pm

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.
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

User avatar
jostle
Posts: 16
Joined: Tue Mar 06, 2018 6:26 am

Re: Increase size of existing swap file

Tue Mar 06, 2018 6:43 am

@n67

You just need to run

Code: Select all

sudo dphys-swapfile setup
to update the settings changes.

Have Fun ...
Have Fun ...

User avatar
richlion2
Posts: 100
Joined: Thu Mar 29, 2018 7:14 am

Re: Increase size of existing swap file

Sun Apr 01, 2018 1:24 pm

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
“It’s nice to be important, but it’s more important to be nice.” ;)

User avatar
jahboater
Posts: 7542
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: Increase size of existing swap file

Sun Apr 01, 2018 2:43 pm

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.

BenRandomNameHere
Posts: 15
Joined: Fri Sep 20, 2019 2:59 pm

Re: Increase size of existing swap file

Sat Oct 12, 2019 11:09 pm

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! :D

User avatar
jahboater
Posts: 7542
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: Increase size of existing swap file

Sun Oct 13, 2019 10:03 am

I since found you can do that in one step:

Code: Select all

sudo /etc/init.d/dphys-swapfile restart

Nowayno
Posts: 1
Joined: Tue Nov 19, 2019 11:41 pm

Re: Increase size of existing swap file

Mon Dec 23, 2019 1:17 am

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

User avatar
DougieLawson
Posts: 41899
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Increase size of existing swap file

Mon Dec 23, 2019 5:36 am

sudo dphys-swapfile swapoff
sudo dphys-swapfile swapon
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

GlowInTheDark
Posts: 2097
Joined: Sat Nov 09, 2019 12:14 pm

Re: Increase size of existing swap file

Mon Dec 23, 2019 5:37 am

Or just reboot.

Keep it simple.
Poster of inconvenient truths.

Back from a short, unplanned vacation. Did you miss me?

godofr
Posts: 1
Joined: Mon Jun 29, 2020 6:48 pm

Re: Increase size of existing swap file

Mon Jun 29, 2020 6:55 pm

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.

Return to “Beginners”