How To Increase SWAP on Linux Debian?

Increasing virtual memory (also known as swap space) on a Linux system, such as Debian, involves creating a swap file or partition and configuring the system to use it. Here are the steps to achieve this:

Step 1: Check Existing Swap Space

  1. Open a terminal.
  2. Check the current swap space by running:
    sudo swapon --show
    If there’s no output, it means there is no swap space currently enabled.

Step 2: Create a Swap File

  1. Decide the size of the swap file. For example, to create a 2 GB swap file:
    sudo fallocate -l 2G /swapfile
    If fallocate is not available, use dd:
    sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
  2. Set the correct permissions:
    sudo chmod 600 /swapfile
  3. Set up the swap area:
    sudo mkswap /swapfile
  4. Enable the swap file:
    sudo swapon /swapfile
  5. Verify that the swap file is active:
    sudo swapon --show

Step 3: Make the Swap File Permanent

  1. Add the swap file entry to /etc/fstab:
    echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Step 4: Adjust Swappiness (Optional)

The swappiness parameter controls the relative weight given to swapping out runtime memory as opposed to dropping pages from the system page cache. To check the current swappiness value:

cat /proc/sys/vm/swappiness

To temporarily change the swappiness value to, for example, 10:

sudo sysctl vm.swappiness=10

To make this change permanent, add the following line to /etc/sysctl.conf:

echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf

Step 5: Verify the Changes

Reboot the system and verify that the swap file is active and swappiness is set correctly:

sudo swapon --show
cat /proc/sys/vm/swappiness

This process increases the virtual memory available to your system by adding a swap file. If you need more swap space in the future, you can either increase the size of the existing swap file or create additional swap files.


Posted

in

,

by

Tags: