Swap Memory Management

12/01/2025


article cover

Why use Swap Memory?


Swap allows the system to use disk space as virtual RAM when physical memory is fully used, helping handle memory-intensive tasks and preventing system crashes. Howver, swap i slower than RAM due to disk access speeds.

Good Swap Size practices


A general rule is to set swap memory to TWICE the size of your RAM. For example:

Managing Swap on Linux


  1. Disable current Swap

    sudo dphys-swapfile swapoff
  2. Open the Swap file

    sudo nano /etc/dphys-swapfile
  3. Locate the line below and modify it to the desired size (in MB):

    CONF_SWAPSIZE=1024 # Example for 1GB Swap
  4. Recreate the Swap file

    sudo dphys-swapfile setup
  5. Re-enable Swap

    sudo dphys-swapfile swapon
  6. Option, but recommended - Reboot

    sudo reboot
  7. Verify the Swap with monitoring tools like htop

    htop

Conclusion


Proper swap memory management helps your Linux system handle resource-intensive tasks more efficiently. While swap can improve performance, finding the right balance is key to avoiding slowdowns or unnecessary storage wear. By optimizing swap settings, you ensure better system stability, responsiveness, and longevity.