release used memory

Rajat Sharma fs.rajat at gmail.com
Fri Mar 11 13:22:41 EST 2011


> If I have enough input data, the memory is not enough (the "free" value gets
> smaller and smaller, and the "cached" value gets bigger and bigger). Then
> kswapd appears in the list of running processes. I would expect that Linux
> gets rid of the "cached" stuff so that the program gets more memory. Instead,
> nothing happens and kswapd is activated. What's the sense of keeping some
> filesystem buffers when they are not used anymore?

Its filesystem's cache (more popularly known as Page Cache in Linux
(buffer cache historically)).
Writing to memory (DRAM) is always faster than writing to Disk,
similarly if you try to read back the same data, and if it is already
in cache, it would be faster to read it from DRAM. So, linux
page-cache is used for following purpose:
1. Write-back cache
2. Read-caching
3. prefetch more data in case of reading file sequentially i.e. doing
single large read from disk instead of multiple reads.

Linux implementation of page-cache is boundless it can grow as much as
available memory however there are kernel threads to do the cleanup
stuff - bdflush process (not kswapd). There are two things to be dealt
with:
1. writing dirty data to disk to make pages in memory clean. Note that
pages are still kept with file-system page-cache but are clean pages
so can be removed from cache on memory pressure.
2. reclaiming unwanted memory pages. This is done only if there is not
sufficient memory. Although there are multiple ways to clean memory
e.g. swapping out unwanted process but page-cache pages are the most
obvious target. First clean pages are removed from page-cache and if
that it not sufficient dirty pages are flushed to disk first and then
removed from page-cache.

Hope it helps.

Rajat



On Fri, Mar 11, 2011 at 11:24 PM, Andreas Leppert <wudmx at web.de> wrote:
> Hello,
>
> for study reasons, I evaluate a kernel module by running a parallel version of
> bzip. Input data are some senseless data files (500 x 10MB for example). While
> the bzip program runs, I took a look at the output of top and noticed
> something which I do not understand.
>
> In the following, I'm refering to that two lines of top which look something
> like that:
>
> Mem:   8185716k total,  5603224k used,  2582492k free,     9104k buffers
> Swap:  8388604k total,        0k used,  8388604k free,  5374400k cached
>
> While the bzip program runs, it uses memory and thus, the value before "free"
> in the Mem: line is getting smaller. As you can see above, there is also some
> "cached stuff" (5374400k). What is meant by this value? Someone explained me
> that it has to do something with filesystem buffers which were read or
> written. Could you elaborate on this?
>
> If I have enough input data, the memory is not enough (the "free" value gets
> smaller and smaller, and the "cached" value gets bigger and bigger). Then
> kswapd appears in the list of running processes. I would expect that Linux
> gets rid of the "cached" stuff so that the program gets more memory. Instead,
> nothing happens and kswapd is activated. What's the sense of keeping some
> filesystem buffers when they are not used anymore?
>
> The main problem is that I do not understand what by "buffers" and "cached" is
> meant. It would be nice if you can help me on this.
>
> Thanks in advance
> Andreas
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



More information about the Kernelnewbies mailing list