Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Why not set swappiness to zero?

avatar
Explorer

Previously, the recommendation for vm.swappiness was always to set it to 0. I have seen some posts stating that it changed. Since when and what was the reasoning?

1 ACCEPTED SOLUTION

avatar
Super Guru

@Connor O'Neal

The value used to have the meaning "don't swap unless out of memory". The meaning is different since Linux kernel version 3.5-rc1. That change was back ported to many distributions, including RedHatas of kernel 2.6.32-303. This changed the meaning of the value 0 to "never swap". It is for this reason that a value of 1 is now recommended.

***

If this helped, pls vote/accept answer.

View solution in original post

4 REPLIES 4

avatar
Super Guru

@Connor O'Neal

The value used to have the meaning "don't swap unless out of memory". The meaning is different since Linux kernel version 3.5-rc1. That change was back ported to many distributions, including RedHatas of kernel 2.6.32-303. This changed the meaning of the value 0 to "never swap". It is for this reason that a value of 1 is now recommended.

***

If this helped, pls vote/accept answer.

avatar
New Contributor

hi guru, i am beginner and just switch over to linux about 2 weeks ago. now using pop os. love the simple looks and full ubuntu based command. and formatted about 20 times due to keep trying others distribution.. finally back to pop os.

 

i have memory 32gb ddr4 3000mhz installed in my system. should i keep the default 4gb swap or set the value to zero or 1 ? i rarely seen swap is using.. mostly just below 50mb used. and my ram used less than 15% for standard operation. like web browsing and text processing.

in games used less than 12gb ram and i dont know swap file usage in games.

 

so, should i set to Zero or 1 which is better ?

actually 4gb space wastage is nothing, i have 1st drive that install the os is 480gb nvme, 2nd drive is 2tb SSD and 3rd drive is 2tb HDD for my rubbished...

 

just want to run full performance in my system. and Wipe away windows 10 pro... due to Virus, malware and spyware...

hope to hear from you..

by the way i am from Malaysia.. i am only an old man that play offline pc games..

avatar
Community Manager

@GreenMonster, the thread you've posted your question to was marked 'Solved' quite a while ago and hasn't had any activity recently. While we welcome your question and a member of the Cloudera Community might well be able to answer it, I believe you would be much more likely to obtain a timely solution if you posted it to the Ubuntu Community.



Regards,

Vidya Sargur,
Community Manager


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community:

avatar
Super Collaborator

Hi @Connor O'Neal

The main reason for why swap is enabled in the first place is to prevent the Linux OOM (Out-Of-Memory) Killer terminating processes when the memory pressure is too high (memory usage without buffers is close to 100%).

The general recommendation for worker nodes is to have the Swap disabled. The logic is that in a distributed system, it's preferable to have the OS terminate processes (which can easily recover) than having 1 or 2 processes (YARN containers) that greatly degrade the performance of a distributed job running on the cluster. If there's an internal policy that requires for swap to be present, the least intrusive action is to set swappiness to 1, which will reduce the likelihood of swapping as much as possible (only swap when absolutely necessary).

The general recommendation for master nodes is to have the Swap enabled but reduce the likelihood of swapping. If master services are abruptly terminated by the OOM killer (similar with kill -9) then the cluster availability is affected (especially if there are no HA services) and increases the possibility of some data corruption (as the services are not allowed to gracefully terminate).

In conclusion, the recommendation is to set swappiness to 1 on all cluster nodes and discuss with your systems administrator the possibility to set swappiness to 0 (equivalent to disabling swap) on the worker nodes. This can be achieved on a running system with the following command:

echo 1 > /proc/sys/vm/swappiness

For a permanent setting, add vm.swappiness=1 to /etc/sysctl.conf.

Also a word of caution regarding CentOS/RHEL7. For a permanent setting, which can last after reboot, updating /etc/sysctl.conf in RHEL7 might not always work. RHEL7 introduces a new service called tuned which overwrites values set in /etc/sysctl.conf. Thus if this service is active, create the file, for example /etc/tuned/hdp/tuned.conf with the following content:

[main]
include=throughput-performance

[sysctl]
vm.swappiness=1

[vm]
transparent_hugepages=never

And run the following command:

tuned-adm profile hdp

The throughput-performance profile is already the default in RHEL7 so this only applies changes on top of it.