Re: buffer leakage in kernel?

From: Andrew Morton (akpm@digeo.com)
Date: Mon Jan 27 2003 - 15:51:38 EST


Roman Dementiev <dementiev@mpi-sb.mpg.de> wrote:
>
> Application allocates 512 MB and never uses more.
> 2MB buffers are used for each read() and write() calls.
> Each file has only one read or write request going any time. There is no othr
> memory-
> hungry applications running.

OK.

> > Please perform this test:
> >
> > 1: Wait until you have 500M "Buffers"
> > 2: cat 64_gig_file > /dev/null
> > 3: Now see how large "Buffers" is. It should have reduced a lot.
>
> Yes, it worked, they had reduced.
> Does this mean, that cached indirect buffers can't be kicked out of memory
> automatically
> and ONLY non-O_DIRECT access can do it? I suppose, they should be displaced by
> newly allocated indirect buffers and user memory allocation.

I suspect what is happening is that you've managed to find a code path in
which the kernel is allocating lots of memory in a mode in which it cannot
run effective page reclaim. This would be more likely to be true if you only
see the failures when writing.

It would help if you could change mm/vmscan.c:try_to_free_pages_zone()
thusly:

        /*
         * Hmm.. Cache shrink failed - time to kill something?
         * Mhwahahhaha! This is the part I really like. Giggle.
         */
+ show_stack(0);
        out_of_memory();
        return 0;
 }

and pass the resulting log output through ksyoops.

And here's a protopatch to teach the kernel to make sure that there's a
decent amount of free memory before it goes and performs GFP_NOFS pagecache
allocations:

diff -puN fs/buffer.c~a fs/buffer.c
--- 24/fs/buffer.c~a 2003-01-27 12:28:02.000000000 -0800
+++ 24-akpm/fs/buffer.c 2003-01-27 12:28:23.000000000 -0800
@@ -2112,6 +2112,8 @@ int generic_direct_IO(int rw, struct ino
         for (i = 0; i < nr_blocks; i++, blocknr++) {
                 struct buffer_head bh;
 
+ try_to_free_pages(GFP_KERNEL);
+
                 bh.b_state = 0;
                 bh.b_dev = inode->i_dev;
                 bh.b_size = blocksize;

If that sheds no light, please send me the app and I'll see if I can
reproduce it. Thanks.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Jan 31 2003 - 22:00:17 EST