What is SWAP  space?

SWAP space in Linux is used when the physical memory of system gets full. If the system needs more memory resources and RAM is full then memory is moved to SWAP space. But SWAP cannot be used as a RAM replacement.

What is the benefit of SWAP space?

The main benefit of SWAP to save the system from get crashed, system may get slow but your application won’t crash.

How to add SWAP space?

Run the below commands to add SWAP:

  1. Create swap file:
    sudo fallocate -l 1G /var/swapfile
  2. Change the file permission so that only owner can read and write:
    chmod 600 /var/swapfile
  3. Mark the file as swap space:
    sudo mkswap /var/swapfile
  4. Enable the swap file:
    sudo swapon /var/swapfile
  5. To make it permanent so that swap settings will stay even if we reboot, edit fstab file:
    sudo vi /etc/fstab
  6. Add the below line in fstab file and save it:
    /var/swapfile swap swap defaults 0 0
  7. To verify swap is added and enabled use below command:
    free -m
    sudo swapon -s

Leave a Reply

Your email address will not be published. Required fields are marked *