You are not logged in.

#1 2011-12-24 11:29:44

ShwangShwing
Member
Registered: 2011-04-20
Posts: 17

Cannot understand Swappiness

Long ago when I first began having this: https://bbs.archlinux.org/viewtopic.php?id=112846 problem (system freeze with high i/o) I researched quite a bit how virtual memory works. There's something about the swappiness that I can't understand. Everywhere I read that swappiness=100 and the system will swap a lot and swappiness=0 will swap when absolutely necessary. So I thought that swappiness=0 means that applications will use RAM and when it is exhausted completely then some pages will be swapped to disc and the newly requested memory will be available in RAM. However what happens is a bit different. When the RAM is exhausted the HDD LED lights up and intense disc activity begins. The system becomes unusable. And you will think that once the memory is swapped the system should be responsive again but that's not the case. It doesn't ever stop. I've tried waiting for an hour and the HDD LED is still constantly on and the system is almost unusable. If I manage to write "echo "100" > /proc/sys/vm/swappiness" then everything calms down in seconds.
So can some of you exactly how the swappiness controls swapping and why swappiness=0 has such effects on my comp?

Offline

#2 2011-12-24 22:52:21

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: Cannot understand Swappiness

Swappiness = 100 is a BAD idea, as you're seeing. I find swappiness = 20 on a modern machine is fairly good.

Refer:

http://gentooexperimental.org/~patrick/weblog/archives/2009-11.html#e2009-11-10T20_18_46.txt wrote:

Now you might be tempted to tune it down to 0. Avoid swap. Swap is slow. All is good?
Not quite. At 0 your machine will try to avoid swapping until the last moment. Then it will have killed all filesystem cache (so every file operation will hit the disks) and in addition to that you start swapping like a madman. The result is usually a "swap storm" that hits very sudden. At the point where you might need some performance your machine doesn't provide it and might just be unresponsive to your input for a few minutes.

Offline

#3 2011-12-24 22:58:08

samuvuo
Member
From: Finland
Registered: 2011-02-20
Posts: 84

Re: Cannot understand Swappiness

I found this discussion on the topic interesting + informing:

http://kerneltrap.org/node/3000

Offline

#4 2011-12-25 00:50:27

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Cannot understand Swappiness

I use swappiness 100 on all my PCs, as it makes more sense to me, especially on long-running PCs, even more so on the hibernated ones (less useless memory to write/read to the HDD). Unless there is memory pressure, only untouched/rarely touched parts of the processes get swapped out. On a KDE/GNOME desktop not running some bigger things, it's easy enough to have as much stuff in RAM as in swap (now, on a PC with 2 GB RAM, I have 265 MB of memory and 186 MB of swap taken on a KDE desktop with Dolphin, Konsole, mpd and two Okular instances running - if I closed Okulars, those would be level; doing things like opening "Configure profiles" in Konsole would swap in just a bit, if I didn't use it before/for a long time, but it's not really noticeable; mpd, playing music, has 5.9 MB swapped out and 4.2 MB in memory, perhaps only updating database or doing some obscure things with mpd would swap in a bit, which wouldn't be really noticeable anyway). If I had swappiness set to a lower value, I would have to provide a greater memory pressure to put those unused parts of processes in swap, and, confronted with great memory pressure, I'd have to bear the delay of swapping out. The only downside from my point of view (considering my usage pattern) is that swapping out has to occur at some point, but it's so gradual it isn't noticeable. Also, running "swapoff" on a partition filled in a greater degree takes longer - hence a longer shutdown, which I do only when updating the kernel anyway. So, I suggest you don't be afraid of high swappiness and just see how different swappiness values work for your usage patterns. You can use "smem" to see how much memory and swap each process uses, "free" for general memory/swap usage and "dstat" for monitoring swapping out/in itself.

Offline

#5 2011-12-25 11:59:58

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: Cannot understand Swappiness

I experienced the same thing (unusable system when swap starts to be used, hard reboot required) which is why I don't bother anymore and disable swap altogether. I'd rather have a single app killed properly to free RAM than risk filesystem errors because of the reboot. (I very probably had swappiness set to 0; maybe setting it to 5 or 10 would work better...)

Last edited by stqn (2011-12-25 12:01:18)

Offline

Board footer

Powered by FluxBB