[2.1.36] Buffer cache hit/miss patch revisited

Aaron Tiensivu (tiensivu@pilot.msu.edu)
Sat, 3 May 1997 18:21:54 -0400


--+6KMIRAuhnl3hBnn
Content-Type: text/plain; charset=us-ascii

I don't think this went out the first time I sent it, so here it goes again.
Sorry if this is a dup.

This extends the /proc/stat function to give you a little insight into the
cache statistics of the directory name, general buffer cache, and the FAT
cache.

It'll look like this now:

cpu 664111 196 4537 417250
disk 29967 6 1 1
disk_rio 26491 3 1 1
disk_wio 3476 3 0 0
disk_rblk 58169 18 2 2
disk_wblk 27808 24 0 0
page 27723 4642
swap 3 4
intr 1335631 1086094 15054 0 0 197142 0 3 0 8 0 0 0 7257 1 29993 79
ctxt 100713
btime 862687154
processes 336
dircache 335650 8398
bufcache 629995 80585
fatcache 2950 1330

First number is the hit, 2nd number is the miss.

--+6KMIRAuhnl3hBnn
Content-Type: text/plain; charset=us-ascii
Content-Description: [2.1.36] Cache stats
Content-Disposition: attachment; filename="hm.diff"

--- linux/fs/proc/array.c.virgin Mon Apr 28 20:27:42 1997
+++ linux/fs/proc/array.c Mon Apr 28 20:33:27 1997
@@ -28,6 +28,9 @@
*
* Yves Arrouye : remove removal of trailing spaces in get_array.
* <Yves.Arrouye@marin.fdn.fr>
+ *
+ * Aaron Tiensivu : added dir, buffer, and FAT buffer cache hits/misses.
+ * <tiensivu@pilot.msu.edu>
*/

#include <linux/types.h>
@@ -256,10 +259,20 @@
len += sprintf(buffer + len,
"\nctxt %u\n"
"btime %lu\n"
- "processes %lu\n",
+ "processes %lu\n"
+ "dircache %u %u\n"
+ "bufcache %u %u\n"
+ "fatcache %u %u\n",
kstat.context_swtch,
xtime.tv_sec - jiffies / HZ,
- total_forks);
+ total_forks,
+ kstat.dirc_hit,
+ kstat.dirc_miss,
+ kstat.bufc_hit,
+ kstat.bufc_miss,
+ kstat.fatc_hit,
+ kstat.fatc_miss);
+
return len;
}

--- linux/fs/fat/cache.c.virgin Mon Apr 28 20:33:55 1997
+++ linux/fs/fat/cache.c Mon Apr 28 20:35:41 1997
@@ -9,6 +9,7 @@
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/stat.h>
+#include <linux/kernel_stat.h>

#include "msbuffer.h"

@@ -134,8 +135,12 @@
#ifdef DEBUG
printk("cache hit: %d (%d)\n",walk->file_cluster,*d_clu);
#endif
- if ((*f_clu = walk->file_cluster) == cluster) return;
+ if ((*f_clu = walk->file_cluster) == cluster) {
+ kstat.fatc_hit++;
+ return;
+ }
}
+ kstat.fatc_miss++;
#ifdef DEBUG
printk("cache miss\n");
#endif
--- linux/fs/dcache.c.virgin Mon Apr 28 20:12:01 1997
+++ linux/fs/dcache.c Mon Apr 28 20:16:45 1997
@@ -22,6 +22,7 @@

#include <linux/fs.h>
#include <linux/string.h>
+#include <linux/kernel_stat.h>

#include <asm/unaligned.h>
#include <asm/spinlock.h>
@@ -200,9 +201,12 @@
*ino = de->ino;
move_to_level2(de, hash);
ret = 1;
+ kstat.dirc_hit++;
}
spin_unlock(&dcache_lock);
}
+ else kstat.dirc_miss++;
+
return ret;
}

--- linux/fs/buffer.c.virgin Mon Apr 28 20:17:11 1997
+++ linux/fs/buffer.c Mon Apr 28 20:22:57 1997
@@ -36,6 +36,7 @@
#include <linux/smp_lock.h>
#include <linux/vmalloc.h>
#include <linux/blkdev.h>
+#include <linux/kernel_stat.h>

#include <asm/system.h>
#include <asm/uaccess.h>
@@ -498,13 +499,16 @@

for (tmp = hash(dev,block) ; tmp != NULL ; tmp = tmp->b_next)
if (tmp->b_blocknr == block && tmp->b_dev == dev) {
- if (tmp->b_size == size)
+ if (tmp->b_size == size) {
+ kstat.bufc_hit++;
return tmp;
+ }

printk("VFS: Wrong blocksize on device %s\n",
kdevname(dev));
return NULL;
}
+ kstat.bufc_miss++;
return NULL;
}

--- linux/include/linux/kernel_stat.h.virgin Mon Apr 28 20:23:20 1997
+++ linux/include/linux/kernel_stat.h Mon Apr 28 20:25:19 1997
@@ -25,6 +25,9 @@
unsigned int ierrors, oerrors;
unsigned int collisions;
unsigned int context_swtch;
+ unsigned int dirc_hit, dirc_miss;
+ unsigned int bufc_hit, bufc_miss;
+ unsigned int fatc_hit, fatc_miss;
};

extern struct kernel_stat kstat;

--+6KMIRAuhnl3hBnn--