4

The system is not overloaded and there is no huge process that eats memory (RAM) but still it has only 20-40 MB free.

Who is taking RAM and should I avoid it? (how?)

0

6 Answers 6

16

See: http://www.linuxatemyram.com

See also: http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html

3
  • I'd never seen linuxatemyram.com, great link!
    – ceejayoz
    May 28, 2009 at 13:55
  • +1: Good link, don't knew it...
    – sebthebert
    Jun 1, 2009 at 15:37
  • +1 Fantastic link. I've started using pmap now that I have a better understanding of how to cross ref it to ps aux.
    – Patrick R
    Feb 16, 2010 at 18:39
4

Linux considers free RAM a waste of resources. Any memory not being used to store a program is used as buffer space to cache recent disk activity etc. It will flush the buffers to disk to make space as required for program memory allocation needs.

4

The 'free' command will show you buffers and cache. The line that starts with -/+ buffers/cache shows the amount of really used and free memory with the buffers and cache subtracted.

             total       used       free     shared    buffers     cached
Mem:           373        350         23          0        135        109
-/+ buffers/cache:        105        268
Swap:          511          0        511

Notice that:

  • this machine has 373MB of RAM, of which 350MB is use, leaving 23MB memory free
  • that 350MB includes 135MB of buffers and 109MB of cache
  • when we subtract those buffers and cache amounts, only 105MB is actually used, leaving 268MB of memory free

The moment it is needed, cache is dropped and buffers are flushed to free memory. This provides very little overhead when the memory the moment the memory needs to be freed and provides significant performance increase as long as the memory can be used as buffers / cache.

So, if you want to know the total amount of free (as in: usable by programs) memory, look at the amount in the 'free'-column in the '-/+ buffers/cache' row.

2

A similar question to this was asked in ServerFault recently

Why does Red Hat Linux report less free memory on the system than is actually available?

disclaimer: I am currently the highest rated answer on that question

1

Install htop to actually have that visualized.

htop

Note that memory occupied by applications or really occupied is marked green. Blue and orange are buffers and cache.

0

Operating systems tend not to let good RAM go to waste. Whether it is Linux or Windows or Mac OS X, you can be pretty sure all your memory that is visible to the OS has been put to good use. The OS will use everything as cache unless that memory is specifically required for something else. The way the different memory reporting utilities display a "Memory Used" single number or graph is a design decision that estimates what type of memory usage the user is most likely to want to know.