For performance testing I need to clear Windows' disk read cache. I tried googling but I couldn't find anything other than rebooting or other manual stuff. Before I give in and do that, I'd like to know if anyone knows of a way to clear Windows disk read cache. I'm testing on Windows 7, but I'm also interested in Windows XP solutions.

Alternatively, you can take all available RAM. Windows will release the file cache in order to use that RAM. For details see the answer provided by Stephen Denne.
–
AltarMay 18 '11 at 9:50

I was hoping for something less 'work-around' but I think your suggestion is easiest to implement in an automatic test script in my situation. Thanks for the suggestion.
–
Sebastiaan MegensApr 3 '12 at 14:09

For a much better view of the Windows XP Filesystem Cache - try ATM by Tim Murgent - it allows you to see both the filesystem cache Working Set size and Standby List size in a more detailed and accurate view. For Windows XP - you need the old version 1 of ATM which is available for download here since V2 and V3 require Server 2003,Vista, or higher.

You will observe that although Cacheset will reduce the "Cache WS Min" - the actual data still continues to exist in the form of Standby lists from where it can be used until it has been replaced with something else. To then replace it with something else use a tool such as MemAlloc, flushmem by Chad Austin, or Consume.exe from the Windows Server 2003 Resource Kit Tools.

The best practice is to ensure that any test files that you are benchmarking with are 2x larger than the array controller cache (or windows os memory if benchmarking in a vm guest), with a minimum 1 GB test file. This ensures that any caching will be negated. We use SQLIO for disk benchmarking; there is a wealth of information in the accompanying documentation.

Echoing Greg, the way to work around this problem is to ensure that the data-set you're working with greatly exceeds the amount of available RAM. If you're doing testing on a hardware platform that also includes significant amount of controller and disk based caches, you'll want to ensure you're exceeding those amounts as well. This will ensure that the performance you see is more tied in with true hardware performance than the software optimizations all those layers of cache introduce.

That said, if you're really just looking to purge the read cache of useful data before running your benchmarks which WANT to use read-cache, the way to do it is to read in a single file sized just under your read-cache memory and do some file operations to it. This will purge the cache and fill it with this single large file. Once you close it, your cache is effectively flushed of the data you care about. The tricky part is figuring out how large that file needs to be, which these days could very well be on the order of 3GB in size; at which point you may need several 1GB junk-files to make it work.

I think most any option will be "manual stuff". Under UNIX, it's pretty standard to unmount/remount a device before each benchmark run, often with a "newfs" thrown in for good measure. I don't know if you can use command-line tools under Windows to unmount/mount devices, but if automation is your goal, then it would be worth looking for such utilities.

Under Linux if unmount/remuont is not an option for some reason you can also do sync; echo 3 > /proc/sys/vm/drop_caches - though this affects all cache/buffers not just those pertaining to a particular volume. I've previously looked for a similar trick for Windows but did not find one.
–
David SpillettDec 8 '09 at 10:15