How to add swap space on Linux ubuntu 18.04

👽 Check disk space

tuenhai@ubuntu18.04:~$ sudo swapon --show
$ free -h
$ df -h

🐯 Create swap sapce

tuenhai@ubnutu:~$ sudo fallocate -l 3G /swap
$ ls -lh /swap
$ sudo chown root:root /swap
$ sudo chmod 600 /swap

$ ls -lh /swap

$ sudo mkswap /swap
$ sudo swapon /swap

$ sudo swapon --show
$ free -h

🏈 keep the swap file permently

tuenhai@ubnutu:~$ sudo cp /etc/fstab /etc/fstab.bak
$ echo '/swap none swap sw 0 0' | sudo tee -a /etc/fstab

😼 Tuning your Swap Settings

tuenhai@ubnutu:~# echo 'vm.swappiness=20' > /etc/sysctl.d/98-swap.conf

Optional cache setting:

tuenhai@ubnutu18.04:~# echo 'vm.vfs_cache_pressure=50' >> /etc/sysctl.d/98-swap.conf

Apply settings:

tuenhai@ubnutu18.04:~$ sudo sysctl --system

check values:

tuenhai@ubnutu:~$ cat /proc/sys/vm/swappiness
$ cat /proc/sys/vm/vfs_cache_pressure

Refrence:

results matching ""

    No results matching ""