[Linux-cachefs] When system don't free cach memory when using mmap

李起宏 liqh at hed.com.cn
Mon Jan 29 01:12:57 UTC 2007


I want to use mmap to replace standard I/O, but I find a problem when I test mmap.
I create a file in 8G bytes, and my physical memory is 8G and my swap memory is 20G, my platform is b4bits of 2.6.9-11.ELsmp.
I call mmap as following 
while (...)
{
    buf = mmap(...);   // every time I get 4M bytes memory map
    ....
    madvise(buf, MADV_DONTNEED);
    unmap(buf, ...);
}

When I run it, I use 'top' and 'free' to monitor memory, I found the `free` memory in `top` and `free` is decreasing quickly and cached memory is growing fastly, at last the free memory is only 15M, and cached memory can arrived at 4G. And kswapd is running at this time. After my program finished, the cached memory don't free. In other words, the cached memory is 4G and free memory is 15M however. But if I delete the file I created, the cached memory is free and free memory is 6G. This problem puzzled me for long time.

I have tested it on redhat9, FC4 and solaris7, it existed too. And I use 'pmap' and 'pgrep' to monitor my program, but they all report it only used memory map in 17M bytes. I use purify to test it, purify saied there no memory leakage.

I wish to know why system don't free cach memory if I don't delete my file.

Thank you!


2007-01-29



More information about the Linux-cachefs mailing list