Raspberry PI: How to Increase swapfile

  1. Confirm the current swap file status
    ==========================
pi@raspberrypi ~ $ swapon -s
Filename                                Type            Size    Used    Priority
/var/swap                               file            102396  0       -1
  1. Stop dphys-swapfile
    ==========================
pi@raspberrypi ~ $ sudo /etc/init.d/dphys-swapfile stop
Stopping dphys-swapfile swapfile setup ..., done.
  1. Modify dphys-swapfile conf File
    ==========================

Change the value of CONF_SWAPSIZE (in MB) (e.g. 1GB)

pi@raspberrypi ~ $ sudo vi /etc/dphys-swapfile
CONF_SWAPSIZE=1024
  1. Start dphys-swapfile
    ===========================
pi@raspberrypi ~ $ sudo /etc/init.d/dphys-swapfile start
Starting dphys-swapfile swapfile setup ...
want /var/swap=1024MByte, checking existing: deleting wrong size file (104857600), generating swapfile ... of 1024MBytes
done.
  1. Confirm the increased swap file
    ===========================
pi@raspberrypi ~ $ swapon -s
Filename                                Type            Size    Used    Priority
/var/swap                               file            1048572 0       -1
  1. Confirm by meminfo
    ===========================
pi@raspberrypi ~ $ cat /proc/meminfo
MemTotal:         497764 kB
MemFree:          361356 kB
...
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
...