Messages in this thread Patch in this message | | | From | (Måns Rullgård) | Subject | Re: how to turn off, or to clear read cache? | Date | Wed, 20 Aug 2003 14:30:18 +0200 |
| |
Sergey Spiridonov <spiridonov@gamic.com> writes:
> I need to make some performance tests. I need to switch off or to > clear read cache, so that consequent reading of the same file will > take the same amount of time. > > Is there an easy way to do it, without rebuilding the kernel?
I never found one, so I made this little patch. It adds a mount option to the ext3 filesystem that makes it drop the cache when a file is closed. Diff is against 2.4.21. It's just a quick hack that accomplishes what I needed. I'm sure there's a better, more generic, way.
Index: include/linux/ext3_fs.h =================================================================== RCS file: /home/cvs/linux-2.4/include/linux/ext3_fs.h,v retrieving revision 1.8 diff -u -r1.8 ext3_fs.h --- include/linux/ext3_fs.h 1 Apr 2003 21:09:23 -0000 1.8 +++ include/linux/ext3_fs.h 17 Jun 2003 09:10:56 -0000 @@ -339,6 +339,7 @@ #define EXT3_MOUNT_WRITEBACK_DATA 0x0C00 /* No data ordering */ #define EXT3_MOUNT_UPDATE_JOURNAL 0x1000 /* Update the journal format */ #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */ +#define EXT3_MOUNT_NOCACHE 0x4000 /* Free cached blocks on close */ /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */ #ifndef _LINUX_EXT2_FS_H Index: fs/ext3/file.c =================================================================== RCS file: /home/cvs/linux-2.4/fs/ext3/file.c,v retrieving revision 1.4 diff -u -r1.4 file.c --- fs/ext3/file.c 28 Aug 2002 21:11:16 -0000 1.4 +++ fs/ext3/file.c 17 Jun 2003 09:10:57 -0000 @@ -35,6 +35,10 @@ { if (filp->f_mode & FMODE_WRITE) ext3_discard_prealloc (inode); + if (inode->i_sb->u.ext3_sb.s_mount_opt & EXT3_MOUNT_NOCACHE){ + write_inode_now(inode, 1); + invalidate_inode_pages(inode); + } return 0; } Index: fs/ext3/super.c =================================================================== RCS file: /home/cvs/linux-2.4/fs/ext3/super.c,v retrieving revision 1.10 diff -u -r1.10 super.c --- fs/ext3/super.c 28 Apr 2003 21:14:51 -0000 1.10 +++ fs/ext3/super.c 17 Jun 2003 09:10:59 -0000 @@ -654,6 +654,8 @@ if (want_numeric(value, "commit", &v)) return 0; sbi->s_commit_interval = (HZ * v); + } else if (!strcmp (this_char, "nocache")){ + set_opt (*mount_options, NOCACHE); } else { printk (KERN_ERR "EXT3-fs: Unrecognized mount option %s\n",
-- Måns Rullgård mru@users.sf.net
- 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/
| |