Swap: Difference between revisions

From Run Your Own
Jump to navigation Jump to search
(Created page with "Swap space is used to free chunks (pages) of memory from the RAM. This is needed when the physical memory is running out, or when pages initially created by a program are not...")
 
Line 23: Line 23:
  /usr/local/sbin/scw-swapfile start  # create and activate a 4GB swap file in /swapfile
  /usr/local/sbin/scw-swapfile start  # create and activate a 4GB swap file in /swapfile
  /usr/local/sbin/scw-swapfile stop    # de=activate and delete /swapfile
  /usr/local/sbin/scw-swapfile stop    # de=activate and delete /swapfile
If you need an different swap file size, you can edit SWAPFILE_SIZE in the script.

Revision as of 21:15, 27 April 2018

Swap space is used to free chunks (pages) of memory from the RAM. This is needed when the physical memory is running out, or when pages initially created by a program are not needed any more. There are two types of swap space: swap partition and swap file.

Swap Partition

TODO

Swap File

More flexible than swap partition and well supported today. May not be the best choice on old fragmented hard disk though.

Setup

  • As root, create the swap file:
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
  • Activate the swap file:
swapon /swapfile
  • Optionally make it available when system starts, in /etc/fstab, add:
/swapfile none swap defaults 0 0
  • If you need to delete it:
swapoff -a
rm /swapfile

Server specific things

Scaleway provides a script that does exactly above, with the exception of adding the swap file to the fstab. The script can be used like this:

/usr/local/sbin/scw-swapfile start   # create and activate a 4GB swap file in /swapfile
/usr/local/sbin/scw-swapfile stop    # de=activate and delete /swapfile

If you need an different swap file size, you can edit SWAPFILE_SIZE in the script.