Sometimes running some stressing tests causes some important apps to be killed by the OS because free RAM is approaching zero. Since I don’t actively use the computer while those tests are running, large latencies are tolerable. The following shows how to use storage on disk to mimic RAM.

1
2
3
4
5
6
# creating a swap file of 32G, the same size of my RAM
$ dd if=/dev/zero of=~/swapfile bs=1G count=32 status=progress

$ mkswap ./swapfile
$ sudo chmod 600 ./swapfile
$ sudo swapon ./swapfile

Adding the following to /etc/fstab:

1
2
# my swapfile
/home/albert/swapfile none swap defaults 0 0

One can use free -h to check the swap usage:

1
2
3
4
$ free -h
total used free shared buff/cache available
Mem: 31Gi 8.8Gi 10Gi 282Mi 11Gi 21Gi
Swap: 31Gi 212Mi 31Gi

§Reference