Windows 相当于 Linux 的 readahead 系统调用?
Windows 是否有相当于 Linux 的 readahead 系统调用?
编辑:
如果可能的话,我想要一个完整的函数签名,显示等效的偏移/计数参数(或下/上)。
例如: Linux 函数签名是:
ssize_t readahead(int fd, off64_t *offset, size_t count);
它的使用示例是
readahead(file, 100, 500);
其中“file”是先前由 mmap 等函数设置的文件描述符。此调用在索引 100 处读取 500 个字节。
编辑 2: 如果您不确定 readahead 的作用,请阅读以下内容: http://linux.die.net/man/ 2/预读
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。它是
FileSystemControl FSCTL_FILE_PREFETCH
。它在 Windows Vista 及更高版本中用于在应用程序启动时和启动时进行预取。
SuperFetch 技术也使用它,该技术使用启发式方法在大约一天中您通常使用应用程序的时间加载应用程序。
FSCTL_FILE_PREFETCH
本身没有在 MSDN 上记录,但通过检查应用程序启动时进行的DeviceIoControl
调用很容易找出参数格式:只需在调试器中启动一个应用程序即可c:\Windows\Prefetch
目录中已有一个 .pf 文件,并在DeviceIoControl
上中断(或者如果您使用的是内核调试器,则在 NTFS 驱动程序接收到它的第一个 FSCTL_FILE_PREFETCH)。检查传入的缓冲区并将其与.pf文件以及稍后实际使用的范围进行比较。我出于好奇做过一次,但没有记录细节。如果您不熟悉
DeviceIoControl
和IRP_MJ_FILESYSTEM_CONTROL
,请查看以下一些链接:Yes. It is
FileSystemControl FSCTL_FILE_PREFETCH
.It is used in Windows Vista and above for prefetching both when an application starts and at boot time.
It is also used by the SuperFetch technology that uses heuristics to load applications at approximately the times of day you generally use them.
FSCTL_FILE_PREFETCH
itself is not documented on MSDN, but it is easy to figure out the parameter format by examining theDeviceIoControl
calls made on app startup: Just start an application in the debugger that already has a .pf file in thec:\Windows\Prefetch
directory and break onDeviceIoControl
(or if you're using a kernel debugger, break when the NTFS driver receives its first FSCTL_FILE_PREFETCH). Examine the buffer passed in and compare it with the .pf file and the range actually used later. I did this once out of curiosity but didn't record the details.In case you are unfamiliar with
DeviceIoControl
andIRP_MJ_FILESYSTEM_CONTROL
, here are some links to look at:从 Windows 8 开始,存在或多或少与 madvise(MADV_WILLNEED) 直接等效的函数,这实际上是相同的事情(Windows 具有统一的虚拟机/缓存系统)。
假设您已对文件进行内存映射,则可以使用 PrefetchVirtualMemory 来预取它。
这仍然比您希望的稍微复杂一些,但并不像
DeviceIoControl
那么严格。另请注意,您可以轻松预取几个独立的、不连续的范围。As of Windows 8, there exists a more or less direct equivalent to
madvise(MADV_WILLNEED)
, which is effectively the same thing (Windows has an unified VM/cache system).Assuming that you have memory-mapped the file, you can thus use PrefetchVirtualMemory to prefetch it.
This is still slightly more complicated than you'd wish, but not nearly as harsh as
DeviceIoControl
. Also note that you can easily prefetch several independent, discontinuous ranges.我不确定我是否理解正确,您所说的“其中“文件”是先前由 mmap 等函数设置的文件描述符。此调用在索引 100 处读取 500 个字节。' 这听起来很像寻找偏移量并读取 500 个字节...但您希望提前预取它...
在 C 代码中,它看起来像像这样的东西:
但是预取它,我想,你会想要使用等待句柄来连接某种事件,并且当事件被引发时,数据被存储在缓冲区中的某个地方......
说实话,我还没有来跨越这样一个预取数据的东西...但是Ray的回答让我感到惊讶,但话又说回来,它仅适用于Vista以上,如果你想保持兼容性...这是需要记住的事情...但是链接下面可能有帮助...
好吧,有一个 博客讨论这个,一个用Delphi编写的库,源代码在这里,浏览代码这里,好吧,可能不是你想要的想要,但它可能会帮助您指明方向...抱歉,如果这不是您要找的...
希望这有帮助,
此致,
汤姆.
I am not sure if I understand correctly, in what you said 'Where "file" is a file descriptor previously set by a function like mmap. This call is reading 500 bytes at index 100.' That sounds suspiciously like seeking to the offset and read 500 bytes... but you want it to be pre-fetched ahead...
In C Code, it would look something like this:
But prefetching it, I guess, you would want to hook up some kind of events using waithandles, and when the event gets raised, the data gets stored somewhere in a buffer...
To be honest, I have not come across a such thing that does pre-fetching data...but Ray's answer surprised me, but then again it is only for Vista upwards, if you want to maintain compatibility...that's something to keep in mind... but the links below may be of help...
Ok, there was a blog discussing this, a library written in Delphi, the source code is here, browsing the code here, ok, it may not be what you want but it may help you point in the direction... Sorry if its not what you are looking for...
Hope this helps,
Best regards,
Tom.