how to turn off, or to clear read cache?
Hi,
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?
Please, put me on CC since I'm not subscriber of linux-kernel
Signature · 1 line
Best regards, Sergey Spiridonov
Quoted 5 lines · Sergey Spiridonov
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
linux/ext3_fs.h +1 -0
@@ -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
ext3/file.c +4 -0
@@ -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
ext3/super.c +2 -0
@@ -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",
Signature · 2 lines
Måns Rullgård [email protected]
Quoted 5 lines · Sergey Spiridonov
Hi,
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.
umount/mount cycle will do it, as well as intentional OOMing the box (from non-root account please;)
--
vda
Quoted 2 lines · Denis Vlasenko
umount/mount cycle will do it, as well as intentional OOMing the box (from non-root account please;)
OOMing doesn't help also, since kernel starts to swap and I have performance degradation after. Swithching off the swap is dangerous in conjunction with OOMing.
Signature · 1 line
Best regards, Sergey Spiridonov
Quoted 7 lines · Denis Vlasenko
Quoted 3 lines · Sergey Spiridonov
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.
umount/mount cycle will do it, as well as intentional OOMing the box (from non-root account please;)
umount/mount is impractical when you're testing performance on a big filesystem, which is always being used (e.g. /home).
I'm fairly sure that -o remount used to have this side effect, in fact I used it quite a lot for that purpose, so it should be possible to make it work again, or add a -o flushcache option.
-- Jamie
Quoted 9 lines · Jamie Lokier
Quoted 7 lines · Denis Vlasenko
Quoted 3 lines · Sergey Spiridonov
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.
umount/mount cycle will do it, as well as intentional OOMing the box (from non-root account please;)
Quoted 6 lines
umount/mount is impractical when you're testing performance on a big filesystem, which is always being used (e.g. /home).
I'm fairly sure that -o remount used to have this side effect, in fact I used it quite a lot for that purpose, so it should be possible to make it work again, or add a -o flushcache option.
Won't that hold a lot of locks, and possibly pause the system until the flushing is complete? Hopefully, in 2.6 this doesn't call lock_kernel...