Skip to content

How to Configure Swappiness to Use Swap Space Only When RAM is Full

Advertisement

Linux systems use both RAM and swap space to manage memory. RAM is the physical memory, while swap is a space on the hard drive used when RAM is full. By default, Linux can start using swap even if RAM is not full. You can change this by adjusting the swappiness value.

How to Set Swappiness to Use Swap Only When RAM is Full

If you want your system to use swap only when RAM is almost full, you should set the swappiness value to 1.

Steps to Change the Swappiness Value

  1. Open a terminal.
  2. To temporarily set swappiness to 1, type this command:
  3. sudo sysctl vm.swappiness=1
    
  4. To make this change permanent, follow these steps:
    • Open the file /etc/sysctl.conf with a text editor:
    • sudo nano /etc/sysctl.conf
      
    • Add or modify this line in the file:
    • vm.swappiness=1
      
    • Save the file and exit the editor.
  5. To apply the change, run this command:
  6. sudo sysctl -p
    
Lower the Swap Priority over RAM
Lower the Swap Priority over RAM

Conclusion

By setting the swappiness value to 1, your Linux system will prioritize using RAM and only use swap space when the RAM is nearly full. This can help improve performance in most cases.

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

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


Back to top