使操作系统磁盘读取缓存无效 [英] Invalidate OS disk read cache

查看:147
本文介绍了使操作系统磁盘读取缓存无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图比较一个Windows程序的性能,当磁盘缓存处于最佳状态(当程序运行所需的所有文件都在内存缓存中时,我只是多次运行它来获得这个状态),当缓存处于最坏状态时,这是完全空的。

确保缓存完全清空的唯一方法是重新启动计算机,但这并不理想,因为它需要太多的时间。有没有办法做到这一点,而无需重新启动?我尝试了同步,但它并没有使读取缓存无效...

CreateFile ,包括 FILE_FLAG_NO_BUFFERING 标志。有关更多信息,请参阅 CreateFile参考页面信息。请特别注意要求



如果修改代码的操作太多,可以尝试编写一个简单的实用程序来读取大于物理内存的文件。这可能足以从文件系统缓存中清除您关心的文件。


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

解决方案

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.

这篇关于使操作系统磁盘读取缓存无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆