In Chris Down’s In defence of swap blog post he explains the importance of swap and that it is still best practice to add swap to systems and not depend on memory alone.
When a system runs out of memory and does not have swap, or does have swap but it is in full use, you can add a temp swap to get yourself out of a tight spot if you have a local volume with free space.
# review your current memory and swap usage
free-h
swapon
# verify you have free disk space
df-h
# create an empty file for use as swap
ddif=/dev/zeroof=/tmp_swapbs=1Mcount=256# note, you may be able to use 'fallocate -l 256M /tmp/tmp_swap' to create the swap file on some file systems. This may create a file with 'holes', and is not suggested on xfs, see below# secure the swap file as it may contain secrets
chmod600/tmp_swap
# setup the file as a swap area
mkswap/tmp_swap
# enable the swap file for usage by the kernel
swapon/tmp_swap
# review your new memory and swap usage
free-h
swapon
# if you need this to persist after a reboot, do the following
vi/etc/fstab
appendthefollowingtofstab
/tmp_swapswapswapdefaults00# when ready to remove the swap remove it from fstab and perform
swapoff-v/tmp_swap
rm/tmp_swap