Ubuntu – My memory is full but processes list is empty

ram

PROBLEM

My memory is full but the processes list is empty of heavy programs!


Usage:

Total memory is 4GB but only 400MB is free:

see usage Screen Shot


Monitor with htop:

When sorting by %MEM -> heavy programs only use 1% of memory!

Which process filled my RAM?

see htop Screen Shot

Best Answer

My memory is full but processes list is empty of heavy program!

That's because the memory is filled with filesystem metadata (aka "buffers") and files' contents (aka "cached") cached by the kernel.

Since it's common for programs / users to access those kind of resources multiple times in a short timeframe and not using memory is a waste, the kernel caches them in order for them to be accessed faster than it would by reading them again from the disk.

The exact amount of cached data is reported on the 5th and 6th columns:

             total       used       free     shared    buffers     cached
Mem:          3838       2895        942        120        461        947
-/+ buffers/cache:       1487       2350
Swap:         4394        615       3779

Since the cached data can be dropped immediately if the memory is required for something else, the cached data isn't really taken and is actually available for programs to use it.

The "real" (net of buffers / cached data) used / free memory is reported in the third row ("-/+ buffers/cache:"):

             total       used       free     shared    buffers     cached
Mem:          3838       2895        942        120        461        947
-/+ buffers/cache:       1487       2350
Swap:         4394        615       3779

For easiness you could add a couple of aliases to print only the "real" used / free memory to ~/.bashrc:

alias real_used="free -m | awk 'NR==3{print $3}'"
alias realf_free="free -m | awk 'NR==3{print $4}'"