Account Links: Cart | Your Account | Logout

Skip to content

Red Hat Knowledgebase

Red Hat Knowledgebase Search:

Updated Within the Last:

New Solutions within the last day New Solutions within the last week New Solutions within the last month

Browse by topics:


Click to View a Topic
Red Hat Enterprise Linux > AS/ES/WS Basics > Issue <<  13 of 908 >>

Solution Tools:


Email a Solution Postcard Printer version Submit a comment on this answer Update notifications Request an answer Back

Article Reference

Article ID: 705
Last update: 05-11-06
Issue:
My system shows that I am using a lot of memory, I think I have a memory leak. How does the Linux kernel handle cache memory and how is this shown through top or free?
Resolution:

The philosophy in Linux is that an unused resource is a wasted resource. The kernel therefore will use as much RAM as it can to cache information from your local and remote filesystems/disks. This builds up over time as reads and writes are done on the system trying to keep the data stored in RAM as relevant as possible to the processes that have been running on your system. This caching is reported by the system as the sum of two numbers, buffers and pagecache. The cache is reclaimed, not at the time of process exit (you might start up another process soon that needs the same data), but upon demand - i.e. When you start a process that needs a lot of memory to run, the Linux kernel will reclaim memory that had been storing cached data and give it to the new process.

There are some things which get reported as cache which are not directly freeable by the kernel, such as anonymous mmaps and shm regions. These will however, report against all processes attached to them unlike normal cache which is not part of the address space of any running process but is simply a kernel mapping.

For example (Units are in megabytes):

 
# free -m
             total       used       free     shared    buffers     cached
Mem:          1000        900        100          0        350        350
-/+ buffers/cache:        200        800

In this example, as far as applications are concerned the system is using only 200MB of memory and has 800MB free and available for use if needed.

The items to note here are:

 
<Physically Used Memory> = <Actual used memory> + <buffers> + <cache>

<Physically Free Memory> = <Total Physical Memory> - <Actual used memory> - <buffers> - <cache>

<Memory free for Applications> = <Total Physical Memory> - <Actual used memory>

<Memory used  by Applications> = <Actual used memory> - <buffers> - <cache>


How well did this entry answer your question?


good wrong incomplete out of date
Red Hat Enterprise Linux > AS/ES/WS Basics > Issue <<   13  of  908  >>