Hi,
I wonder if you guys can help me with the following. This may sound like a user-land problem, but bear with me for a bit.
Given a file name, I’d like to be able to tell if the file (or its head part) is currently present in Windows cache. This in the context of cache-friendly massive copying application (think - a backup proggy), and the idea is to utilize the cache if a file is in it, and fall back to the unbuffered IO otherwise. In other words - try and not put anything into cache, but still read from it if possible.
There is no Cache Manager API or at least nothing public - this much I know. So this leaves me with two options -
(a) to write some kernel component to poke around the Cache and report the results to the user-space process
(b) to try and understand cache status of a file by timing the execution of Win API calls
–
The (a) I haven’t touched yet, but I did run some tests along the (b) lines.
The most obvious option is to open the file and read a small amount of data from it. Do it twice, once - with FLAG_FILE_NO_BUFFERING, and second time - without. Compare the read times and if latter is substantially smaller than former, then the read block was in the cache. If the file appears to be cached, then keep reading it in small-ish chunks until the read time jumps indicating the cache miss. Re-open file unbuffered and continue reading.
This works, but it still pushes small amount of data into the cache, and it becomes a problem when reading large amounts of small files. The cache gets thrashed.
–
Now, if I haven’t lost you yet, the question. Can anyone think of an File I/O API call that has an IF (hinging on the cache presence) in it, and that does NOT change the cache?
It would take me some time to find my copy of SoftICE and get all set for stepping through the kernel… which is something that I am fully intended to do. But meanwhile if anyone has any thought or alternative suggestions, I am all ears.
Cheers,
Alex