在Windows上禁用或刷新页面缓存 [英] Disable or flush page cache on Windows

查看:117
本文介绍了在Windows上禁用或刷新页面缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为Windows具有与Linux页面缓存类似的概念,用于将磁盘,文件,可执行文件和动态库等数据存储在内存中。我想知道是否完全有可能禁用这种缓存,或者至少可以清除/刷新它。

I assume Windows has a similar concept to Linux's page cache for storing in memory data from disks, like files, executables and dynamic libraries. I wonder if it is possible at all to disable such cache or to the very least to clear/flush it.

推荐答案

这是在Windows下称为待机列表。您可以全局清除它,或清除一个卷,或清除一个文件句柄。

This is called Standby List under windows. You can purge it globally, or for one volume, or for one file handle.

全局

通过选择<$ c,使用Microsoft Technet中的可用程序 $ c> Empty →空待机列表

Globally
You can do it using a readily available program from Microsoft Technet, by selecting EmptyEmpty Standby List

通过编程,您可以实现相同的功能使用未记录的 NtSetSystemInformation 函数,有关详细信息,请参见程序中第239行与前面提到的功能相同。

Programmatically, you can achieve the same thing using the undocumented NtSetSystemInformation function, for details see line 239 in a program which does the same thing as the previously mentioned one, among other things.

用于一个文件句柄

使用 FILE_FLAG_NO_BUFFERING 打开文件:该文档在说 you 无需缓冲即可打开文件,从Windows 98到Windows 98的所有Windows版本上的真实,可观察的行为Windows 8只是简单地丢弃了该文件的完整缓存内容(所有人!),并且不会从使用此句柄的读取中重新填充缓存。

For one file handle
Open the file with FILE_FLAG_NO_BUFFERING: The documentation is lying insofar as it says that you open the file without buffering, but the true, observable behavior on all Windows versions from Windows 98 up to Windows 8 is that it simply throws away the complete cache contents for that file (for everyone!) and doesn't repopulate the cache from reads that use this handle.

对于一个完整的卷

一个卷句柄只是一个文件句柄(虽然有些特殊,但仍然如此),因此,假设您有适当的特权来打开一个卷句柄,则可以

For one complete volume
A volume handle is just a file handle (a somewhat special one, but still), so assuming you have appropriate privilegues to open a volume handle, you can do the same for a complete volume.

此外,正如Mehrdad的回答中指出的那样在这里,似乎有一个功能/错误(feature-bug?),即使没有适当的特权,该功能/错误也可以使您仅通过尝试在没有共享写入的情况下就打开卷,即使在没有适当特权的情况下也是如此(至少在Windows的最新版本中) .br

完全可以理解,当任何有效的写操作成功打开时,就会发生这种情况,因为您可能会更改文件系统内部数据(当然这是一项功能),但是显然,在打开卷失败(这是一个错误)。

Also, as pointed out in Mehrdad's answer here, there seems to be a feature/bug (feature-bug?) which allows you to invalidate a volume's cache even without proper privilegues merely by attepting to open it without shared writes, at least under one recent version of Windows.
It makes perfect sense that this happens when any open which is valid for writing succeeds as you may change filesystem-internal data doing so (insofar it is a feature), but apparently it also works when opening the volume fails (which is a bug).

这篇关于在Windows上禁用或刷新页面缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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