enable swap
Verify if Swap
root@investormonkey:~# free -m total used free shared buff/cache available Mem: 1975 291 771 42 912 1469 Swap: 0 0 0
root@investormonkey:~# swapon –show
Review Partitions
root@investormonkey:~# df -h Filesystem Size Used Avail Use% Mounted on tmpfs 198M 1012K 197M 1% /run /dev/vda1 58G 3.1G 55G 6% / tmpfs 988M 0 988M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock /dev/vda15 105M 6.1M 99M 6% /boot/efi tmpfs 198M 4.0K 198M 1% /run/user/0
Allocate Partition
root@investormonkey:~# fallocate -l 2G /swapfile
Review Partition
root@investormonkey:~# ll /swapfile -h -rw-r–r– 1 root root 2.0G Feb 16 18:49 /swapfile
Set Permissions
root@investormonkey:~# chmod 600 /swapfile
Convert partition
root@investormonkey:~# mkswap /swapfile Setting up swapspace version 1, size = 2 GiB (2147479552 bytes) no label, UUID=64f696fd-8003-4ac1-bffd-0e8a72ae8854
Enable Swap
root@investormonkey:~# swapon /swapfile
Show Swapfile
root@investormonkey:~# swapon –show NAME TYPE SIZE USED PRIO /swapfile file 2G 0B -2
Verify swap
root@investormonkey:~# free -h total used free shared buff/cache available Mem: 1.9Gi 310Mi 750Mi 43Mi 914Mi 1.4Gi Swap: 2.0Gi 0B 2.0Gi
Make persistent
root@investormonkey:~# cp /etc/fstab /etc/fstab.20230216 root@investormonkey:~# echo ‘/swapfile none swap sw 0 0’ | sudo tee -a /etc/fstab /swapfile none swap sw 0 0
optimize swap
root@investormonkey:~# cat /proc/sys/vm/swappiness 60 root@investormonkey:~# sysctl vm.swappiness=10 vm.swappiness = 10 root@investormonkey:~# cat /proc/sys/vm/swappiness 10 root@investormonkey:~# vim /etc/sysctl.conf root@investormonkey:~# cat /proc/sys/vm/vfs_cache_pressure 100 root@investormonkey:~# sysctl vm.vfs_cache_pressure=50 vm.vfs_cache_pressure = 50 root@investormonkey:~# vim /etc/sysctl.conf root@investormonkey:~# tail -n 2 /etc/sysctl.conf vm.swappiness=10 vm.vfs_cache_pressure=50