I have an issue where when I try to build a really large project, my machine starts swapping (several GB) even though there's plenty of memory (14 GB in fact). When I run free, it shows that it's not the disk cache:

$ free -m
             total       used       free     shared    buffers     cached
Mem:         12900       6350       6549          0          7         77
-/+ buffers/cache:       6266       6633
Swap:         9211        233       8978

So 6.3 GB of memory is actually in use, but if I look at top, sorted by % memory usage, nothing is using any memory:

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                               
38669 blong     20   0 1282m 378m  42m S    2  2.9   0:50.79 firefox                                               
 1327 root      20   0  365m 126m 4056 S    4  1.0  40:23.94 Xorg                                                  
 2540 blong     20   0 1578m  67m  10m S    2  0.5  21:33.35 gnome-shell                                           
13943 blong     20   0  579m  12m 5604 S    2  0.1   1:07.01 gnome-terminal                                        
30093 blong     20   0  540m 8664 5572 S    0  0.1   0:03.96 icemon                                                
 2558 blong     20   0  362m 5964 1808 S    0  0.0   5:17.44 vmtoolsd                                              
 2526 blong     20   0  672m 5056 2000 S    0  0.0   0:26.81 gnome-settings-                                       
 2546 blong     20   0  354m 3484 2244 S    0  0.0   5:08.96 pulseaudio

Am I missing something?

Restarting the VM fixes this, but I'd prefer to figure out what's actually happening.


Swap is not a bad thing. In this case it's likely a good thing. There is a kernel parameter (vm.swappiness) which controls the kernel's tendency to swap out inactive pages of memory. It does this so that the RAM can be better used for things like the filesystem cache.

While I generally discourage tuning kernel parameters without knowing what's going on, you can disable this behavior by adding vm.swappiness = 0 to /etc/sysctl.conf and executing sysctl -p.

As for what is using your memory, that's not an easy answer. There are a lot of things other than application private memory and cache that will use system memory. There are other things such as shared memory, mapped memory, and the kernel slab.

You can get a great deal of info on your system's memory usage by looking at /proc/meminfo. But it's not for the faint of heart. Linux's VM system is insanely complex.

  • In this case it's likely a good thing -- A multi-hour compile job because the machine is swapping several GB of memory is not a good thing. I'll look into /proc/meminfo. Apr 9 '13 at 22:39
  • @BrendanLong well the free output you provided only shows 233mb used. A trivial amount. If you can provide the output while the system is having issues it might show a totally different picture. Providing the contents of /proc/meminfo during this time would be helpful as well.
    – phemmer
    Apr 9 '13 at 22:42
  • The free output is pretty bad -- It's using 6 GB of memory, and none of the programs are using any and there's no cache being used. I'll try to run it again while it's linking, but it basically looks like that, except all of the memory is being used and 3 GB of swap is too, despite the linker only using 6 GB of memory. Apr 9 '13 at 22:56
  • @BrendanLong: "free" reads /proc/meminfo. "Used" is MainTotal - MainFree as per lxr.linux.no/#linux+v3.8.6/Documentation/filesystems/… - You might be more in luck trying smem
    – Runium
    Apr 9 '13 at 23:07
  • /proc/meminfo was kind of helpful. I'm pretty sure my problem is actually a bug in VMWare though, since I don't have any problems with the exact same workload on Virtualbox. Apr 10 '13 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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