A blog dedicated to text editing and general exploration of computing knowledge
Thursday, February 14, 2008
Ok, this isn't a Vim tip, but it does apply to development that a lot of people do with Vim. I do a lot of SQL work here at Grooveshark and constantly wrestle with trying to get an accurate picture of how efficient a given query is. Linux and MySQL both cache very aggressively, which makes benchmarking a pain. MySQL provides the SQL_NO_CACHE query option to avoid it's query cache, which is convenient; however, Linux still caches the disk reads; thereby, skewing any performance measurements. In the past, I've been forced to do ridiculous things like cat a file larger than available RAM to /dev/null or unmount and remount the filesystem that the database files are housed on. Luckily, Linux kernels 2.6.16 and newer provide a mechanism to clear the inode, page, and dentry caches on demand avoiding all this headache. All you have to do is echo a value to the proc filesystem, and you're done.
To free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches
Note: this must be done as root, and you should issue a sync before doing so.