Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force Windows to clear all disk read cache data? [duplicate]

Tags:

windows

winapi

Possible Duplicate:
How to invalidate the file system cache?

I'm writing a disk intensive win32 program. The first time it runs, it runs a lot slower while it scans the user's folders using FindFirstFile()/FindNextFile().

How can I repeat this first time performance without rebooting? Is there any way to force the system to discard everything in its disk cache?

I know that if I were reading a single file, I can disable caching by passing the FILE_FLAG_NO_BUFFERING flag to a call to CreateFile(). But it doesn't seem possible to do this when searching for files.

like image 890
Steve Hanov Avatar asked Jul 18 '10 15:07

Steve Hanov


2 Answers

Have you thought about doing it on a different volume, and dismounting / remounting the volume? That will cause the vast majority of everything to be re-read from disk (though the cache down there won't care).

like image 92
jrtipton Avatar answered Oct 10 '22 09:10

jrtipton


You need to create enough memory pressure to cause the memory manager and cache manager to discard the previously caches results. For the cache manager, you could try to open a large (I.e. Bigger than physical ram) file with caching enabled and then read it backwards (to avoid any sequential I/o optimizations). The interactions between vm and cache manager are a little more complex and much more dependent on os version.

There are also caches on the controller (possibly, but unlikely) and on the disk drive itself (likely). There are specific IoCtls to flush this cache, but in my experience, disk firmware is untested in this arena.

like image 22
MJZ Avatar answered Oct 10 '22 09:10

MJZ