Linux – Why Red Hat Linux Reports Less Free Memory Than Available

linuxlow-memorymemoryredhat

I have a relatively small home Red Hat Linux server (about 8 GB RAM). I don't use it for much other than running some home grown apps to keep track of various things. The only real things running on the box are a database and a web server.

I've noticed that when checking system counters using tools like NMON and TOP that the total system free memory is relatively low (on the order of a few hundred MB), while the active memory for the database and web server is still low (only consuming a combined 3 GB). Even when including all other running processes the total consumed memory is less than 4 GB.

Why does Red Hat Linux report less free memory than the total memory minus the sum total of used memory of running processes?

Best Answer

Don't confuse free memory with unused memory. Free memory, in the unix world is a page of physical memory that has no logical data mapped to it. Unused memory does have some data mapped to it, but it is currently not in active use by a running process.

% free -m
             total       used       free     shared    buffers     cached
Mem:           997        942         55          0         71        366
-/+ buffers/cache:        504        492
Swap:         2015        618       1397

Linux (and all Unix OS'es) try to have as little free memory as possibly. Instead they use memory which is not actively mapped to processes in the running OS for things like file cache and buffers for various IO transfer operations.

Something else that may be confusing you is you cannot simply add up the memory in use by all running processes to get a total memory in use figure. If you attempted this you would quickly discover that you applications appear to be using more memory than actually exists on the machine. This is for two reasons

  1. Memory can be shared between various processes, through Copy-On-Write memory allocation, memory mapped IO and shared dynamic libraries.
  2. The operating system is at liberty to promise more memory to the application than it has actually supplied. The theory being that most application writers prefer to ask for large amounts of memory in one go, to avoid overhead, and may not actually use all that memory.

There is a recent article on lwn.net discussing this issue.

Related Topic