Disable or flush page cache on Windows

前端 未结 1 1756
感情败类
感情败类 2020-12-15 09:46

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 possibl

相关标签:
1条回答
  • 2020-12-15 10:26

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

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

    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.

    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.

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

    0 讨论(0)
提交回复
热议问题