Swappiness

Magistar

Verified User
Joined
May 31, 2014
Messages
105
I was wondering why my centos was using 400MB swap when I have 200MB ram unsused (and 1000MB available). I googled and found the swappiness setting. Now I can perfectly change it BUT on a reboot I lose the setting.

According to google it should be in /etc/sysctl.conf but that file is pretty spartan and does not contain the setting. Is it somewhere else in DA or do I need to add it on the last line?

regards
 
Hi there.
[root@vps1 ~]# sysctl -a | grep swap
vm.swappiness = 30
Used to be 60. I halved it to 30 now but on reboot that setting is lost and it is back to 60.
 
A quick Search on Google:

"vm.swappiness is a tunable kernel parameter that controls how much the kernel favors swap over RAM. At the source code level, it’s also defined as the tendency to steal mapped memory. A high swappiness value means that the kernel will be more apt to unmap mapped pages. A low swappiness value means the opposite, the kernel will be less apt to unmap mapped pages. In other words, the higher the vm.swappiness value, the more the system will swap.

The default value I have seen on RHEL/CentOS/SLES is 60.

To find out what the default value is on a particular server run this Command:

[root@server]# sysctl vm.swappiness
vm.swappiness = 60

The value is also located in /proc/sys/vm/swappiness.

[root@server]# cat /proc/sys/vm/swappiness
60

Note: You can set the maximum value up to 100, the minimum is 0."

------------------------------------------------

Interesting though, always like to tune. I have "vm.swappiness = 10" on my server, think I run some kernel tuning module, don't remember right now. But it's 10 on my server.
 
Hello,

No, add your new value here: /etc/sysctl.conf that should be enough.

According to google it should be in /etc/sysctl.conf but that file is pretty spartan and does not contain the setting. Is it somewhere else in DA or do I need to add it on the last line?
 
I use "tuned" myself, with the "virtual-host" profile. RedHad page Power_Management_Guide/tuned-adm

I might have tweaked it a little, can't remember, but I think "tuned" is responsible for my vm.swappiness = 10. I don't really think about it, it just works, otherwise I just choose another profile which fits.

Paste:

Tuned is a daemon that monitors the use of system components and dynamically tunes system settings based on that monitoring information. Dynamic tuning accounts for the way that various system components are used differently throughout the uptime for any given system. For example, the hard drive is used heavily during startup and login, but is barely used later when a user might mainly work with applications like OpenOffice or email clients. Similarly, the CPU and network devices are used differently at different times. Tuned monitors the activity of these components and reacts to changes in their use.

As a practical example, consider a typical office workstation. Most of the time, the Ethernet network interface will be very inactive. Only a few emails will go in and out every once in a while or some web pages might be loaded. For those kinds of loads, the network interface doesn't have to run at full speed all the time, as it does by default. Tuned has a monitoring and tuning plugin for network devices that can detect that low activity and then automatically lower the speed of that interface, typically resulting in lower power usage. If activity on the interface increases drastically for a longer period of time, for example because a DVD image is being downloaded or an email with a large attachment is opened, tuned detects this and sets the interface speed to maximum to offer the best performance while the activity level is so high. This principle is used for the other plugins for CPU and hard disks as well.

And....

virtual-guest profile:
This profile is optimized for virtual machines. It is based on the enterprise-storage profile, but also decreases the swappiness of virtual memory. This profile is available in Red Hat Enterprise Linux 6.3 and later.

Here is the value of my current profile:

[admin@server]# tuned-adm list
Available profiles:
- laptop-battery-powersave
- spindown-disk
- virtual-guest
- server-powersave
- default
- desktop-powersave
- virtual-host
- throughput-performance
- latency-performance
- enterprise-storage
- laptop-ac-powersave
- sap
Current active profile: virtual-host
[admin@server]#

It works... and might show you some info on what to choose in your swappines :) - and thank you for asking, was actually thinking of changing profile to "virtual-guest" instead, but need to read more because I can't remember why I picked that specific profile back then :), think it was because I wanted to reduce swapping and I/O traffic on my KVM VD. But I will read up on it and maybe file a hint.

Or just like Alex said:

"edit /etc/sysctl.conf

add:
vm.swappiness = <value>

replace <value> with a number 1 to 100

Many people say just to add an "echo <value> > /proc/sys/vm/swappiness" - but this wont persist after a reboot. Sysctl is a utility provided by most distributions to set this up after reboot."

vm.swappiness = 10 is just like no swap at all, but still some :)
 
Last edited:
Thanks guys, will find out if it works on my next reboot (probably in 30 days :P).

Note to self: I really need to get a local Cent OS install for testing.
 
Just switched profile to virtuel-guest, and I cannot see any changes, yet, I have to test it under load. But these are my current mem stats:

With virtual-host profile:

Mem: 5990968k total, 3087364k used, 2903604k free, 65172k buffers
Swap: 4063228k total, 0k used, 4063228k free, 2067196k cached

With virtual-guest profile:

Mem: 5990968k total, 3113020k used, 2877948k free, 65404k buffers
Swap: 4063228k total, 0k used, 4063228k free, 2090768k cached

free -l:
total used free shared buffers cached
Mem: 5990968 3114756 2876212 0 65844 2093224
Low: 5990968 3114756 2876212
High: 0 0 0
-/+ buffers/cache: 955688 5035280
Swap: 4063228 0 4063228

Again this is just after eight hours of nightly uptime, because I had to restart the VM due to adding more RAM. I do not yet have the "hotplug" kernel modules (qemu disk,nic,cpu,memory) installed in the guest. But again, I think the virtuel-guest profile handles cache better. As of I/O I don't know, have to make some tests. I also added 2 more cores of CPU.

All in all, it's pretty cool to switch profiles for the different types of environments. Maybe "tuned-adm" can make some magic for you? - but you have to be really concervative with what you choose to run with only 1GB RAM, though I'v had KVMs that were running with 1GB/2GB RAM with no issues, without LAMP though, for a LAMP server you need more. Tuned-adm handles the load dynamically and is making the changes for you on the go, but if you run out of RAM then it's going to crawl.

Just found this: https://www.digitalocean.com/community/tutorials/how-to-configure-virtual-memory-swap-file-on-a-vps
Nice info, though I just skimmed it.. I'm sure you can use it to help your server run more smooth.
 
Last edited:
Only thing that worries me on the captainkvm article is the following

The other thing that you might want to remember is that swap space on a virtual disk is slower than swap on a real disk.

My VPS actually has a very decent IO. It hits like 300-500 MB/s and can peak up to 80.000 IO/s because it is a big datastorage layer with built-in SSD caching. So I do not want it to nerf my IO:P.
 
Only thing that worries me on the captainkvm article is the following

My VPS actually has a very decent IO. It hits like 300-500 MB/s and can peak up to 80.000 IO/s because it is a big datastorage layer with built-in SSD caching. So I do not want it to nerf my IO:P.

Dunno why he said that, he is working with enterprise storage solutions... so, I need to read some more to understand RH's SSD strategy. There is also a question about XFS vs EXT4, etc. XFS is default in RH7, DiskRead-aHead, and so on. Need to follow up on this and educate myself. Things change....fortunately.

I'm just reading through these interesting slides:

http://www.slideshare.net/tommylee98229/shak-larryjederperfandtuningsummit14part1final?related=1

http://www.slideshare.net/tommylee98229/shak-larryjederperfandtuningsummit14part2final?related=2

Part 1:
1. Performance Analysis and Tuning – Part 1 D. John Shakshober (Shak) Sr Consulting Eng / Director Performance Engineering Larry Woodman Senior Consulting Engineer / Kernel VM Jeremy Eder Principal Software Engineer/ Performance Engineering
2. Agenda: Performance Analysis Tuning Part I • Part I •RHEL Evolution 5->6->7 – out-of-the-box tuned for Clouds - “tuned” •Auto_NUMA_Balance – tuned for NonUniform Memory Access (NUMA) •Cgroups / Containers • Scalabilty – Scheduler tunables • Transparent Hugepages, Static Hugepages 4K/2MB/1GB • Part II •Disk and Filesystem IO - Throughput-performance •Network Performance and Latency-performance • System Performance/Tools – perf, tuna, systemtap, performance-co-pilot •Q & A
etc.......

Part 2:
1. Performance Analysis and Tuning – Part 2 D. John Shakshober (Shak) Sr Consulting Eng / Director Performance Engineering Larry Woodman Senior Consulting Engineer / Kernel VM Jeremy Eder Principal Software Engineer/ Performance Engineering
2. Agenda: Performance Analysis Tuning Part II • Part I • RHEL Evolution 5*> 6*> 7 – out*of*the*box tuned for Clouds *“ tuned” • Auto_NUMA_Balance – tuned for NonUniform Memory Access (NUMA) • Cgroups / Containers • Scalabilty – Scheduler tunables • Transparent Hugepages, Static Hugepages 4K/2MB/1GB • Part II • Disk and Filesystem IO *Throughput*performance • Network Performance and Latency*performance
etc........

...to be continued
 
FYI: After switching to virtual-guest profile, my swapiness=30. Did not change anything according to "top", still no swap.

Picture of profiles in 6.3.

tuned_6.3.png

Soon to change in RH7.

It's also possible to change profiles via CRON, so that it's possible to use another profile during peak hours.
 
Last edited:
Back
Top