cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Commander Commander
Commander
  • 2,076 Views

Swappiness

Jump to solution

Swappiness controls how often the system uses swap space instead of RAM. A high swappiness value can lead to excessive swapping, slowing down your system.


To check the current swappiness value:

              $  sudo cat /proc/sys/vm/swappiness

 

The default value on my Linux system is 60.  To reduce swappiness, I will  need to edit the /etc/sysctl.conf file.

Once you're in this file, add or modify the following line.

            vm.swappiness=10

Note:  The value of 10 is just a suggestion!  There's nothing in the rule book that says that this is the only possible value to be used.  One size does not fit all!!!  The primary takeaway here is that the smaller the swappiness value, the less swapping (i.e. less use of swap space).


After making that addition (or modification), save the file, and apply the changes, using the following command:

           $  sudo sysctl -p

 

 

Trevor "Red Hat Evangelist" Chandler
Labels (3)
1 Solution

Accepted Solutions
Chetan_Tiwary_
Community Manager
Community Manager
  • 2,023 Views

To add what @Trevor has shared - a very important topic for system performance tuning and for interviews -

The vm.swappiness setting dictates how eagerly the Linux kernel will move anonymous memory pages to swap compared to discarding data from the file cache. Typically, most Linux systems default to a swappiness value of 60. This default generally implies that the kernel will postpone swapping anonymous memory until about 80% of the RAM is actively being used, prioritizing the remaining 20% for file system caching.

The default swappiness of 60 was selected to strike a balance between reducing disk input/output operations (by utilizing RAM for caching) and guaranteeing sufficient memory for active applications. When vm.swappiness is set to 60, the kernel internally assigns a lower priority (60) to swapping out anonymous memory compared to the higher priority (200 – 60 = 140) given to evicting file cache. This prioritization means the kernel will tend to discard cached data first to free up memory, and only resort to swapping anonymous memory when the demand for it increases.

Note :

1. Anonymous pages - process memory like heaps and stacks.

2. File cache pages - filesystem‐backed data services by the page cache.

Some important points to see :

1. It is correctly pointed out that a high swappiness value can cause excessive swapping, resulting in noticeable system slowdowns. This happens because swap space resides on storage devices, which are significantly slower than RAM; moving data between RAM and swap introduces latency that bottlenecks performance.

2. When swappiness is set high > 80, the kernel aggressively moves inactive memory pages to swap even if there is still sufficient free RAM available, causing the system to spend more time on slow disk I/O rather than using fast memory access. In severe cases, especially with limited RAM, this can lead to thrashing, where the system endlessly swaps data in and out instead of executing applications, making it severely unresponsive.

3. However, in low-memory environments, a moderate swappiness value can actually help maintain system stability by avoiding out-of-memory crashes, even if it slightly impacts performance eg for Databases <=10 is apt but for other workloads where stability is primarily important - a value of 20-30 is apt but yes - no one size fits all aproach here, it is all custom tailored.

View solution in original post

3 Replies
Blue_bird
Starfighter Starfighter
Starfighter
  • 2,041 Views

Informative..!

Thanks for sharing..!

Chetan_Tiwary_
Community Manager
Community Manager
  • 2,024 Views

To add what @Trevor has shared - a very important topic for system performance tuning and for interviews -

The vm.swappiness setting dictates how eagerly the Linux kernel will move anonymous memory pages to swap compared to discarding data from the file cache. Typically, most Linux systems default to a swappiness value of 60. This default generally implies that the kernel will postpone swapping anonymous memory until about 80% of the RAM is actively being used, prioritizing the remaining 20% for file system caching.

The default swappiness of 60 was selected to strike a balance between reducing disk input/output operations (by utilizing RAM for caching) and guaranteeing sufficient memory for active applications. When vm.swappiness is set to 60, the kernel internally assigns a lower priority (60) to swapping out anonymous memory compared to the higher priority (200 – 60 = 140) given to evicting file cache. This prioritization means the kernel will tend to discard cached data first to free up memory, and only resort to swapping anonymous memory when the demand for it increases.

Note :

1. Anonymous pages - process memory like heaps and stacks.

2. File cache pages - filesystem‐backed data services by the page cache.

Some important points to see :

1. It is correctly pointed out that a high swappiness value can cause excessive swapping, resulting in noticeable system slowdowns. This happens because swap space resides on storage devices, which are significantly slower than RAM; moving data between RAM and swap introduces latency that bottlenecks performance.

2. When swappiness is set high > 80, the kernel aggressively moves inactive memory pages to swap even if there is still sufficient free RAM available, causing the system to spend more time on slow disk I/O rather than using fast memory access. In severe cases, especially with limited RAM, this can lead to thrashing, where the system endlessly swaps data in and out instead of executing applications, making it severely unresponsive.

3. However, in low-memory environments, a moderate swappiness value can actually help maintain system stability by avoiding out-of-memory crashes, even if it slightly impacts performance eg for Databases <=10 is apt but for other workloads where stability is primarily important - a value of 20-30 is apt but yes - no one size fits all aproach here, it is all custom tailored.

Trevor
Commander Commander
Commander
  • 2,002 Views

A complete lesson on swappiness!!!

Trevor "Red Hat Evangelist" Chandler
Join the discussion
You must log in to join this conversation.