[patch] buffer flushing MM unbalance with bigmem 2.3.25pre3

Andrea Arcangeli (andrea@suse.de)
Mon, 1 Nov 1999 19:58:53 +0100 (CET)


In my original buffer flush patch
(ftp://ftp.*.kernel.org/pub/linux/kernel/people/andrea/patches/v2.3/2.3.21/buffer-flush-6.gz)
I was doing:

+/* -1 -> no need to flush
+ 0 -> async flush
+ 1 -> sync flush (wait for I/O completation) */
+static int balance_dirty_state(kdev_t dev)
+{
+ unsigned long dirty, tot, hard_dirty_limit, soft_dirty_limit;
+
+ dirty = size_buffers_type[BUF_DIRTY] >> PAGE_SHIFT;
+ tot = nr_lru_pages + nr_free_pages - nr_free_bigpages;
+ hard_dirty_limit = tot * bdf_prm.b_un.nfract / 100;
+ soft_dirty_limit = hard_dirty_limit >> 1;
+
+ if (dirty > soft_dirty_limit)
+ {
+ if (dirty > hard_dirty_limit)
+ return 1;
+ return 0;
+ }
+ return -1;
+}

While in the stock kernel the code is doing this:

/* -1 -> no need to flush
0 -> async flush
1 -> sync flush (wait for I/O completation) */
static int balance_dirty_state(kdev_t dev)
{
unsigned long dirty, tot, hard_dirty_limit, soft_dirty_limit;

dirty = size_buffers_type[BUF_DIRTY] >> PAGE_SHIFT;
tot = nr_lru_pages + nr_free_pages + nr_free_highpages;
^

This is wrong as nr_free_pages just includes nr_free_highpages. Suppose
you have 4g of ram all free. Right now the code will think you can alloc
up to 7g of ram in buffers.

When we'll allow bigmem pages to be allocated in the buffer/page cache
we'll be allowed to do simply:

tot = nr_lru_pages + nr_free_pages;

but the above is _not_ safe either right now.

This is the fix against 2.3.25pre3:

--- 2.3.25pre3-i386/fs/buffer.c.~1~ Mon Nov 1 18:44:06 1999
+++ 2.3.25pre3-i386/fs/buffer.c Mon Nov 1 19:50:10 1999
@@ -823,7 +823,7 @@
unsigned long dirty, tot, hard_dirty_limit, soft_dirty_limit;

dirty = size_buffers_type[BUF_DIRTY] >> PAGE_SHIFT;
- tot = nr_lru_pages + nr_free_pages + nr_free_highpages;
+ tot = nr_lru_pages + nr_free_pages - nr_free_highpages;
hard_dirty_limit = tot * bdf_prm.b_un.nfract / 100;
soft_dirty_limit = hard_dirty_limit >> 1;

Andrea

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