tags:

views:

180

answers:

1

I'm trying compare the performance of a windows program when the disk cache is in its best state (when all files needed for the program to run are in memory cache, I just run it multiple times to get this state), and when the cache is in its worst state, that is completely empty.

The only way way I know to ensure that the cache is completely empty is by rebooting the computer, but this is not ideal since its takes too much time. Is there any way to do this without rebooting? I tried sync, but it does not invalidate the read cache...

A: 

In your call to CreateFile, include the FILE_FLAG_NO_BUFFERING flag. See the CreateFile reference page at MSDN for more information. Note in particular the requirements.

If it's too much effort to modify your code to do this, try writing a simple utility program to read a file that is larger than physical memory. This may be enough to flush the files you care about from the filesystem cache.

Steve Madsen
CreateFile with this flags seems to work fine, but I'm looking for a way to do it for an entire folder (and subfolders). I'm really hoping that I should not iterate through every file, since there are I think about a few million files in the folder I need to invalidate.About writing a utility that reads a huge file, how am I garanteed that it will empty the cache? Maybe windows manages its cache in a way that it will not cache all of the huge file, and keep some space for more files. Or maybe not... actually I have no idea. Anyways, I'll give it a try and see the results.
Nicolas Rousseau-Dupuis
If you're iterating through a large number of files, won't you have only a small number of CreateFile calls to add that flag to? It's a part of opening the file for reading, not a two-step process where you invalidate the cache (for that file), then open it.
Steve Madsen