Buffer handling (setting PG_referenced on access)

Zlatko Calusic
1999-01-11T09:33:24Z

Linus Torvalds <torvalds@transmeta.com> writes:

> Btw, if there are people there who actually like timing different things
> (something I _hate_ doing - I lose interest if things become just a matter
> of numbers rather than trying to get some algorithm right), then there's
> one thing I'd love to hear about: the effect of trying to do some
> access bit setting on buffer cache pages.

OK, implementation was easy and simple, much simpler than it was made
before (with BH_Touched copying...), but I must admit that even after
lots of testing I couldn't find any difference. Not in performance,
not in CPU usage, not in overall behaviour. Whatever results I have
accomplished, they were too much in the statistical noise, so I don't
have any useful data. Maybe, others can try and see.

But, nevertheless, four lines added to the kernel look very correct to
me. My vote for including, if for nothing, then to make balance with
page cache. It won't harm anything, that's for sure. Patch applies
cleanly on pre-7, as found in testing directory on ftp.kernel.org.

Index: 2206.7/include/linux/fs.h
--- 2206.7/include/linux/fs.h Mon, 04 Jan 1999 17:24:06 +0100 zcalusic (linux-2.1/z/b/10_fs.h 1.1.5.1.1.3 644)
+++ 2206.8(w)/include/linux/fs.h Mon, 11 Jan 1999 08:31:48 +0100 zcalusic (linux-2.1/z/b/10_fs.h 1.1.5.1.1.3.1.1 644)
@@ -178,6 +178,9 @@
#define BH_Req 3 /* 0 if the buffer has been invalidated */
#define BH_Protected 6 /* 1 if the buffer is protected */

+#define buffer_page(bh) (mem_map + MAP_NR((bh)->b_data))
+#define touch_buffer(bh) set_bit(PG_referenced, &buffer_page(bh)->flags)
+
/*
* Try to keep the most commonly used fields in single cache lines (16
* bytes) to improve performance. This ordering should be
@@ -250,19 +253,6 @@
{
return test_bit(BH_Protected, &bh->b_state);
}
-
-/*
- * Deprecated - we don't keep per-buffer reference flags
- * any more.
- *
- * We _could_ try to update the page reference, but that
- * doesn't seem to really be worth it either. If we did,
- * it would look something like this:
- *
- * #define buffer_page(bh) (mem_map + MAP_NR((bh)->b_data))
- * #define touch_buffer(bh) set_bit(PG_referenced, &buffer_page(bh)->flags)
- */
-#define touch_buffer(bh) do { } while (0)

#include <linux/pipe_fs_i.h>
#include <linux/minix_fs_i.h>
Index: 2206.7/fs/buffer.c
--- 2206.7/fs/buffer.c Sat, 09 Jan 1999 03:44:23 +0100 zcalusic (linux-2.1/G/b/41_buffer.c 1.1.1.1.1.3.2.1.2.1 644)
+++ 2206.8(w)/fs/buffer.c Mon, 11 Jan 1999 08:31:48 +0100 zcalusic (linux-2.1/G/b/41_buffer.c 1.1.1.1.1.3.2.1.2.1.1.1 644)
@@ -737,6 +737,7 @@
put_last_lru(bh);
bh->b_flushtime = 0;
}
+ touch_buffer(bh);
return bh;
}

@@ -754,6 +755,7 @@
bh->b_lru_time = jiffies;
bh->b_state=0;
insert_into_queues(bh);
+ touch_buffer(bh);
return bh;

/*

Regards,
--
Zlatko