Adjusting the Amount Of Swap

Swap or Swappiness is the amount of storage that the Linux OS can use as virutal memory, just like how a Windows OS can use storage and use it as virtual memory. This works side by side with your physical memory can comes into play when either the amount of physical memory is exhausted or the percentage of physical memory has hit the swap threshold, which the swap memory can be consumed. However this is also works against the server in the aspect that when swap is used, I/O performance is lowered. This can lead to slower read and writes against the drive, which can impact databases and apache process, and cause your server to halt altogether. 

This article will explain how to view the amount of swap that your server can use and how you can adjust this. Please note this article is written for Redhat (Rhel) and Centos OS's. You will need to make this adjustments using SSH and is recommended for those who are comfortable navigating their server using SSH.

How To View And Adjust Swap

Log into your Linux server using SSH.
Once logged in, run the following command to view the amount of swap that is set to be used. By default, the value of 60 should be returned, memory that swap will take over at 60% of the physical memory being used;

"cat /proc/sys/vm/swappiness"

This tells us that the server will use swap more than the actual physical memory. So what you want to do is change it so the server will use more physical memory than swap. We recommend that this value by changed to 25, which is an optimal value for a server.

Before changing the value, you can test different values on a temporary basis. This way you can see what value gives you a better performance change. To test the values, enter the following;

"sysctl -w vm.swappiness=25"

Once you determine that the following change works for you, you can now make the change permenant.

To change the value, you will need to edit the "/etc/sysctl.conf" file. Since the value is added by default, the entry will not exist in the file, so it iwll need to be added. To do this you will need to open it with a text editor, so for this example we will use VI.

"vi /etc/sysctl.conf"

In the file you will need to add a entry at the end of the file. Add this line;

"vm.swappiness=25"

Be sure to save the change.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Installing htop

htop is an interactive process viewer for Linux, which is a powerful alternative to the...

Bind Multiple IP Addresses to a Single Network Interface Card (NIC)

This tutorial demonstrates how to bind multiple IP addresses to a single NICI'll be using LAN...

Clear Memory Cache on Linux Server

By default the Linux OS has a very efficient memory management process that should be freeing any...

Set the time on a Linux server

Log into the server via SSHAt the shell prompt run the following command:date MMDDHHmmYYYYFor...

Check your disk usage in Linux

A good way to check your disk usage for folders on your Linux server is via shell.Download...