Swap

From Run Your Own
Revision as of 21:14, 27 April 2018 by 320x200 (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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