Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

The problem I think is somewhat similar to this thread.

It doesn't matter if I have swap enabled or disabled, whenever the real used RAM amount starts going close to maximum and there is almost no space left for disk cache, system becomes totally unresponsive.

Disk is spinnig wildly, and sometimes after long waits 10-30 minutes it will unfreeze, and sometimes not (or I run out of patiance). Sometimes if I act quickly I can manage to slowly open console and kill some of ram eating applications like browser, and the system unfreezes almost instantly.

Because of this problem I almost never see anything in the swap, only sometimes there are some few MB there, and then soon after this problem appears. My not so educated guess would be that it is connected somehow to the disk cache being too greedy, or memory management too lenient, so when the memory is needed it is not freed quickly enough and starves the system.

Problem can be achieved really fast if working with lagrge files (500MB+) which are loaded in disk cache and aparantly afterwards system is unable to unload them fast enough.

Any help or Ideas will be greatly appreciated.

For now I have to live in constant fear, when doing something computer can just freeze and I usually have to restart It, if it is really running out of ram I would much more like it to just kill some of userspace applications, like broser (preferably if I could somehow mark which to kill first)

Although the mistery is why doesnt swap save me in this situation.

UPDATE: It didnt hang for some time, but now I got several occurances again. I am now keeping ram monitor on my screen at all times and when the hang happened it still showed ~30% free (Used by disk cache probably). Additional symptoms: If at the time I am watching video (VLC player) the sound stops first, after a few seconds the image stops. While the sound has stopped I still have some control over PC, but when the image stops I cannot even move the mouse anymore, so I restarted it after some waiting. Btw, this didnt happen when I started to watch the video but some time in (20min) and I didn't actively do anything else at the time, even though browser and oowrite were open on the second screen the whole time. Basically something just decides to happen at one point and hangs the system.

As per request in the comments I ran dmesg right after the hang. I didnt notice anything weird, but didnt know for what to look, so here it is: https://docs.google.com/document/d/1iQih0Ee2DwsGd3VuQZu0bPbg0JGjSOCRZhu0B05CMYs/edit?hl=en_US&authkey=CPzF7bcC

share|improve this question
add comment

2 Answers

My guess is that you've set your vm.swappiness to a very low value, which causes the kernel to swap too late, leaving too low RAM for the system to work with.

You can show your current swappiness setting by executing:

sysctl vm.swappiness

By default, this is set to 60. The Ubuntu Wiki recommends to set it to 10, but feel free to set it to a higher value. You can change it by running:

sudo sysctl vm.swappiness=10

This will change it for the current session only, to make it persistent, you need to add vm.swappiness = 10 to the /etc/sysctl.conf file.

If your disk is slow, consider buying a new one.

share|improve this answer
    
Actually reducing swapiness reduced the problem (it happened more rarely). I am keeping it at 5 now. Although maybe it was another problem with higer swapinness, because, when it was 60, and I decided to watch a movie or edit a big file, whole file og almost a GB was loaded in memory and then instantly system started swapping out programs I was actively using and even user interface itself. The thing is I think I understand the swapping part, what I want is killing greedy user applications instead of freezing the machine when running out of ram. (And preferably limit file size in cache) –  Krišjānis Nesenbergs May 10 '11 at 14:22
    
@Krisa: when the system runs out of memory (RAM and swap), the kernel calls oom_kill which kills processes to save memory. Unfortunately, you cannot control target processes. To trigger it manually, press the Alt + SysRq + F. When running the dmesg command, you should see some information (and the process name + id) of the process. I think you'd better off with buying a new, faster disk. Or upgrade your RAM. –  Lekensteyn May 10 '11 at 15:37
    
The problem is, that oom_kill just doesn't get called before the computer has locked up for some 30 minues. Also - is there at least a way to know which process will be killed first? –  Krišjānis Nesenbergs May 10 '11 at 20:18
    
I have 2GB Ram and the HDD is 5400rpm. I really dont think that it is such an old system which justifies half an hour freezes while watching some video on one monitor and browsing some 20-30 tabs in the other. Actually I would be quite happy if I just could allways access console and kill some processes - is there a way to make user input and terminal super high priority so it works while system freezes? –  Krišjānis Nesenbergs May 10 '11 at 20:28
    
@Krisa: Hmm, I've always been running 7200rpm+ even on notebooks (and now running 0rpm). oom_kill is only called if you run out of memory (both swap and RAM). If the system is in the process of swapping, the system may become unresponsible with such a slow disk. You might be better off with disabling the swap (or setting a low swappiness) and uppgrade your RAM. 20-30 open tabs is a pretty high amount, I usually have about 10 tabs open (Firefox). 2GB on old P4 desktop, 8GB on notebook. –  Lekensteyn May 10 '11 at 21:30
show 2 more comments
up vote 5 down vote accepted

TO fix this problem I have found that you need to set the following setting to something approx 5%-6% of your total physical RAM:

sysctl -w vm.min_free_kbytes=65536

(Keep in mind that this ir per Core setting, so I have 2GB RAM and two Cores, then I calculated 6% of only 1 GB and added some little extra just to be safe) This forces the computer to try to keep this amount of RAM free, and in doing so limits the ability to cache disk files. Of course it still tries to cache them and immeadiately swap them out, so you should probably limit your swapping aswell like this:

sysctl -w vm.swappiness=5

(100 = swap as often as possible, 0= swap only on total necessity)

The result is that linux no longer randomly decides to load a whole movie file of approx 1GB in ram while watching it, and killing the machine in doing so. Now there is enough reserved space to avoid memory starvation, which aparrently was the problem (seeing as there are no more freezes like before).

After testing for a day - lockups are gone, sometimes there are minor slowdowns, because stuff gets cached more often, but I can live with that if I dont have to restart computer every few hours.

The lesson here is - default memory management is just one of use cases and is not allways the best, even though some people try to suggest otherwise - home entertainment ubuntu should be configured differently than server.

P.s. You can make these settings permanent by adding them to your /etc/sysctl.conf like this:

vm.swappiness=5
vm.min_free_kbytes=65536
share|improve this answer
    
Good find, try to report bugs about it so there's more awareness of the issue and hopefully someone will come up with a solution to not randomly load the whole movie, –  Oxwivi May 25 '11 at 12:29
    
thanks, great detail and explains my issue. Much appreciated! –  odedbd Aug 28 '13 at 19:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.