Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My laptop is Thinkpad x220, 4G ram, harddisk is 7200rpm, installed with Ubuntu 12.04, using Unity desktop.

When I open eclipse and chrome, they eat about 2G memory. Here is the free -m result:

             total       used       free     shared    buffers     cached
Mem:          3841       3301        540          0         10        956
-/+ buffers/cache:       2334       1507
Swap:         8187        306       7881

And the top result:

 Mem:   3934188k total,  3540508k used,   393680k free,    45680k buffers
 Swap:  8384508k total,   313512k used,  8070996k free,  1078888k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                       
 5552 martin    20   0 4249m 388m 6560 S    0 10.1   2:46.28 java                                                                       
 3369 martin    20   0 2548m 182m  32m R    1  4.7  29:19.64 chrome                                                                     
 3406 martin    20   0 1000m 155m  16m S    0  4.1   4:18.97 chrome                                                                     
 2736 martin    20   0 1582m 106m  29m S    1  2.8  13:10.27 compiz                                                                     
 3704 martin    20   0  945m  85m 8396 S    0  2.2   0:15.60 chrome                                                                     
11047 martin    20   0  926m  82m  23m S    0  2.2   0:06.52 chrome                                                                     
11443 martin    20   0  915m  72m  21m S    0  1.9   0:46.08 chrome                                                                     
 4280 martin    20   0  822m  66m  12m S    4  1.7  14:59.41 chrome

After some periods about 10 minutes, I have only 100M+ memory available, then the system starts to swap memory to disk, that causes my computer freeze totally, it would recover after the swap finished.

I already have vm.swappiness = 10

I've searched google, and some article said that when memory is not enough, the system will free the cache, and use it as memory. But it seems to me that the cache is never freed. When the system lacks of memory (But actually I have enough memory, some memory is just used for cache), it will not use cache, instead, it swap the memory directly to disk, that causes freeze.

How can I avoid this?

Decreasing the cached memory?

share|improve this question
I don't think your diagnosis is correct. Your freeze probably has nothing to do with memory usage. In any event, reducing swapiness causes the system to swap less, which means less memory will be free. (The system swaps to make physical memory free.) And decreasing the cache will just mean more disk access. (The purpose of the cache is to avoid disk accesses.) – David Schwartz Jul 31 '12 at 9:44
I'm experiencing the very same situation - running a Dell Precision M4500 laptop with 4GB of memory. After launching of Eclipse, MySQL Server, 4 tabs in Chrome, Skype and Tomcat with GWT application only about 300 MB remain when I run free -m. When I start to rebuild GWT application (this takes up to 1 GB of RAM when there is enough RAM) system freezes (no mouse moving etc) and doesn't recover - I simply have to restart my laptop. When, however, I free enough RAM, GWT app rebuild passes fine. @David could you please advise how can I investigate the problem? Thanks in advance – Yura Jul 3 '13 at 9:34
@David or is it better to ask separate question? – Yura Jul 3 '13 at 9:39
@Yura: I'd suggest you make your own question. – David Schwartz Jul 3 '13 at 15:38
If someone has ideas, please also look at this similar problem:… – Yura Jul 4 '13 at 9:10

If you want more memory free, you can get it by setting vm.min_free_kbytes. For example, if you want the system to waste 256MB of memory, use this command:

sysctl -w vm.min_free_kbytes=262144

The system will now keep 256MB free and have 256MB less memory to work with. That will make performance worse, but it will make the cache smaller, as you requested.

But I think you are missing an important point -- free memory is no better than memory that is not installed in the computer at all. Neither of them help the computer to perform better.

You should restore all settings to defaults and work on your actual problem -- that your computer is freezing.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .