Invalidate OS disk read cache

时间秒杀一切 提交于 2019-12-24 13:26:35

问题


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...


回答1:


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.



来源:https://stackoverflow.com/questions/1002045/invalidate-os-disk-read-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!