Consider the following simplified example of the output from the free command:
# free -m total used free shared buffers cached Mem: 1000 900 100 0 350 350 -/+ buffers/cache: 200 800
In the above example, units are in Mb and the total physical memory is 1000 Mb. An inexperiencied system administrator might think that the system was running short of memory since the physically used memory is shown as 900 Mb. This is not the case. As far as applications are concerned the system is using only 200MB of memory and has 800MB free and available for use if needed.
Physically Used Memory = Actual used memory + buffers + cache (200 + 350 + 350) = 900 Mb Physically Free Memory = Total Physical Memory - Actual used memory - buffers - cache (1000 - 200 - 350 - 350) = 100 Mb Memory free for Applications = Total Physical Memory - Actual used memory (1000 - 200) = 800 Mb Memory used by Applications = Physically Used Memory - buffers - cache (900 - 350 - 350) = 200 Mb
Why does this occur? Simple, Linux is borrowing unused memory for disk caching. Disk caching generally speeds up a system. If an application want more memory, it can just take back a chunk of the disk cache. Disk cache can always be given back to applications when needed.
To see the effect that disk cache has on read/write performance, you can clear out most of the disk cache (and thus free up memory) using one of the following:
# free pagecache: echo 1 > /proc/sys/vm/drop_caches # free dentries and inodes: echo 2 > /proc/sys/vm/drop_caches # free pagecache, dentries and inodes: echo 3 > /proc/sys/vm/drop_caches
This kernal tunable was added in 2.6.16. It is a non-destructive operation; dirty objects are not freed. Note that you should run sync; sync first to ensure all cached writes are flushed to disk.
The only time I use this tunable is when doing I/O benchmarking; dropping disk cache forces disk operations to happen on the disk instead of in disk cache.