You are not logged in.

#1 2009-03-06 13:10:10

b9anders
Member
Registered: 2007-11-07
Posts: 691

aggressive [unwated] swapping grinds system to near halt

I have 2 GB of ram and have set swappiness to 2, as I don't really use apps in a way that would ever have me using more than 2 GB ram.

However, I find that sometimes when I go above 1GB usage, the system starts to swap anyway, ignoring my settings, and furthermore it swaps extremely aggresively, consuming so much cpu power for extended periods (10-15 minutes) that my pc is virtually unusable (kwin even disables compositing due to reduced performance).

It is faster for me to force a reboot when this happens than it is to stick it out which to me is just not acceptable behaviour.

Is there any way for me to fix this? Why does it not respect the swappiness I have set and why so aggressive swapping?

Offline

#2 2009-03-06 13:34:27

SanskritFritz
Member
From: Budapest, Hungary
Registered: 2009-01-08
Posts: 1,923
Website

Re: aggressive [unwated] swapping grinds system to near halt

There is probably a program with memory leak. Enable the magic sysrq keys, and when your system starts to swap, press Alt-SysRq-F, that kills the process with most memory consuption. This way you can quickly revert to a normal state and see which program was killed.


zʇıɹɟʇıɹʞsuɐs AUR || Cycling in Budapest with a helmet camera || Revised log levels proposal: "FYI" "WTF" and "OMG" (John Barnette)

Offline

#3 2009-03-25 22:35:19

b9anders
Member
Registered: 2007-11-07
Posts: 691

Re: aggressive [unwated] swapping grinds system to near halt

am bumbping this as I believe I have identified the problem being with cached memory. As is apparently proper behaviour, the system greedily appropriates ram for caching. That would be fine if not for the fact that once  it has used up my ram for this it then starts swapping.

This is very undesirable behaviour. I can keep it in check somewhat by freeing up the cache, but it is not something I should have to do at semi-regular intervals. How can I keep it from using swap until I am approaching my swap limit for actual used ram?

Offline

#4 2009-03-25 23:31:41

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: aggressive [unwated] swapping grinds system to near halt

i read an article (can't find the link) wher eyou can optimize your system by adding the following to /etc/sysctl.conf and rebooting:

# Adjust how you utilize swap
vm.swappiness = 1
vm.vfs_cache_pressure = 50

might help, might not.  i've seen no insane improvements but then again, i never really touched swap since i've had this machine (quad core - 4GB ram)

Offline

#5 2009-03-26 02:01:03

broch
Banned
From: L.A. California
Registered: 2006-11-13
Posts: 975

Re: aggressive [unwated] swapping grinds system to near halt

b9anders wrote:

I have 2 GB of ram and have set swappiness to 2, as I don't really use apps in a way that would ever have me using more than 2 GB ram.

However, I find that sometimes when I go above 1GB usage, the system starts to swap anyway, ignoring my settings, and furthermore it swaps extremely aggresively, consuming so much cpu power for extended periods (10-15 minutes) that my pc is virtually unusable (kwin even disables compositing due to reduced performance).

It is faster for me to force a reboot when this happens than it is to stick it out which to me is just not acceptable behaviour.

Is there any way for me to fix this? Why does it not respect the swappiness I have set and why so aggressive swapping?

set vm.swappiness back to 60%

your disk is grinding because kernel and some apps need swap
you set swap allowable to 2% which is 40MB.

long time ago someone thought that setting swappiness low will "speed up" system. That is not the case.
set it back to the original value (by commenting out/deleting entry from sysctl.conf). Your system will not suffer any slowdowns and hopefully you will see less disk activity.

your apps and kernel need swap file. This is how VM is managed so put it back. (after this either restart box to clean swap or run swapoff/swapon),
So what you did setting swappiness=2 is probably the main cause of your problem.

I hope that this will help

i've seen no insane improvements but then again, i never really touched swap since i've had this machine (quad core - 4GB ram)

VM and RAM are not equivalent. I have 4GB of RAM and some apps will still swap even though there is still free RAM memory available.

Last edited by broch (2009-03-26 02:15:37)

Offline

#6 2009-03-26 03:44:40

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: aggressive [unwated] swapping grinds system to near halt

broch: You say kernel and some apps need swap but I used to run my laptop with no swap partition at all and I had no problems whatsoever.


neutral

Offline

#7 2009-03-26 12:18:37

broch
Banned
From: L.A. California
Registered: 2006-11-13
Posts: 975

Re: aggressive [unwated] swapping grinds system to near halt

sand_man wrote:

broch: You say kernel and some apps need swap but I used to run my laptop with no swap partition at all and I had no problems whatsoever.

shrug, this means that you did not gain anything because:
1) you are not using system in full so it really does not matter if you have swap or not
2) there is a lot of available information regarding VM. This would explain why your approach is not beneficial and why you may loose performance not gain it.

Offline

#8 2009-03-28 16:08:07

b9anders
Member
Registered: 2007-11-07
Posts: 691

Re: aggressive [unwated] swapping grinds system to near halt

brooch - following your advice did indeed alleviate it somewhat. Although I am still not all satisfied with the decrease in performance that does happen when swapping, the toll on the system was much less aggressive and certainly not show-stoppingly bad when it happened.

However, I am currently all swapped out (granted, only 1 GB swap, as I haven't enlarged the partition since adding another 1gb stick of ram) and the ram uses some 1200MB ram (meaning, in theory the kernel should release the remaining 800 MB ram as I may require for it to work at all again) but nonetheless am beginning to experience the same kind of niggling slowness. Not as prolonged and shwstopping as before (where I simply had to restart X), but bad enough for kwin to deactivate composite due to reduced performance and basically me having to just sit there for a minute until it has re-arranged things.

I am still thinking that this ought not to be happening.

Offline

#9 2009-03-28 17:02:39

Dheart
Member
From: Sofia, Bulgaria
Registered: 2006-10-26
Posts: 956

Re: aggressive [unwated] swapping grinds system to near halt

Hmm... I have a system with 512 ram and it happens so that when I play some games (Background I have running opera, AIM, httpd, mysqld, cups, mpd, sonata, ktorrent and so on). Most of things are cached to ram and making the opera window active, or simply switching to another inactive window takes forever to load the needed data in the RAM. I found a solution:

su
swapoff -a
swapon -a

Turning off swap forces moving everything in the ram and the system becomes noticebly more responsive. When the swap is turned on again it doesn't start caching back to free up ram - it only starts doing so if I start another ram intensive thingie...


My victim you are meant to be
No, you cannot hide nor flee
You know what I'm looking for
Pleasure your torture, I will endure...

Offline

#10 2009-03-28 18:08:07

Ranguvar
Member
Registered: 2008-08-12
Posts: 2,545

Re: aggressive [unwated] swapping grinds system to near halt

vm.swappiness and vm.vfs_cache_pressure are good to play with. Test some stuff and see what works for you.

(Some of this may be unrelated, but it's all good to know)
http://lwn.net/Articles/83588/
http://www.linux.com/feature/121916
http://lwn.net/Articles/153353/
http://rudd-o.com/en/linux-and-free-sof … o-fix-that

Last edited by Ranguvar (2009-03-28 18:08:26)

Offline

#11 2009-03-28 22:36:27

broch
Banned
From: L.A. California
Registered: 2006-11-13
Posts: 975

Re: aggressive [unwated] swapping grinds system to near halt

b9anders wrote:

brooch - following your advice did indeed alleviate it somewhat. Although I am still not all satisfied with the decrease in performance that does happen when swapping, the toll on the system was much less aggressive and certainly not show-stoppingly bad when it happened.

However, I am currently all swapped out (granted, only 1 GB swap, as I haven't enlarged the partition since adding another 1gb stick of ram) and the ram uses some 1200MB ram (meaning, in theory the kernel should release the remaining 800 MB ram as I may require for it to work at all again) but nonetheless am beginning to experience the same kind of niggling slowness. Not as prolonged and shwstopping as before (where I simply had to restart X), but bad enough for kwin to deactivate composite due to reduced performance and basically me having to just sit there for a minute until it has re-arranged things.

I am still thinking that this ought not to be happening.

you have more homework to do then wink

note:
if you modified syscalls, your setting may be wrong (combination of them). Try first to run system with defaults.

Then if this will not alleviate memory starving try maybe these settings:

vm.dirty_background_ratio try to set 10
vm.dirty_ratio set 40
vm.swappiness set 30-60
vm.overcommit_memory set 2 (very careful with this one you are basically saying that you do not have more than you really have, some memory demanding apps may protest, double swap file size)
in short this will stabilize system and kill app that is going berserk with memory requirements (so you need to be careful)

then there is also vm.vfs_cache_pressure
instead of doing what most suggest try
vm.vfs_cache_pressure = 200 up to 10000 increasing this number will force kernel to free cache. It means that you will see (not necessary) some slowdowns in repeated operations but there is going to be more memory available so this will lower tendency to swap

each step requires patience and calibration meaning that you have a lot of testing but eventually this should work.
One warning though. Properly set, the above will not prevent swapping, it should direct kernel for better swapping of unused pages. Unless you have tenths of GBs of RAM and tuned kernel I doubt that you can completely prevent kernel from swapping as it is. If someone is running swapp-les system without any problem, then it means that this person with or without swap will run linux just fine never causing pagecaches to swap.


I hope this will help a little

Offline

Board footer

Powered by FluxBB