Type the following command to create 512MB swap file (1024 * 512MB = 524288 block size):
dd if=/dev/zero of=/swapfile bs=1024 count=524288
chown root:root /swapfile
chmod 0600 /swapfile
mkswap /swapfile
swapon /swapfile
Open /etc/fstab
and append the following line:
/swapfile none swap sw 0 0
To disable it:
swapoff /swapfile && swapon -s
The value in /proc/sys/vm/swappiness
file controls how aggressively the kernel will swap memory pages. Higher values increase agressiveness, lower values descrease aggressiveness. The default value is 60. To make changes permanent:
sysctl -w vm.swappiness=VALUE && sysctl -p
CoreOS systemd unit - and for any systemd OS - to execute it at boot time:
$ cat /etc/systemd/system/swap-file.service [Unit] Description=Creates swap file [Service] Type=oneshot ExecStart=/usr/bin/sh -c '/home/core/make-swap.sh' [Install] WantedBy=multi-user.target
Ensure service activation with
sudo systemctl enable swap-file.service
.