简体   繁体   English

Windows相当于Linux的readahead系统调用?

[英]Windows equivalent to Linux's readahead syscall?

Is there a Windows equivalent to Linux's readahead syscall? 是否有Windows等同于Linux的readahead系统调用?

EDIT: 编辑:

I would like a full function signature if possible, showing the equivalent offset/count parameters (or lower/upper). 如果可能,我想要一个完整的函数签名,显示等效的偏移/计数参数(或更低/更高)。

Eg: The Linux function signature is: 例如:Linux函数签名是:

ssize_t readahead(int fd, off64_t *offset, size_t count);

and an example of it's use is 它的一个例子就是使用它

readahead(file, 100, 500);

Where "file" is a file descriptor previously set by a function like mmap. 其中“file”是先前由mmap等函数设置的文件描述符。 This call is reading 500 bytes at index 100. 此调用在索引100处读取500个字节。

EDIT 2: Please read this if you are unsure what readahead does: http://linux.die.net/man/2/readahead 编辑2:如果您不确定什么是预读,请阅读此内容: http//linux.die.net/man/2/readahead

Yes. 是。 It is FileSystemControl FSCTL_FILE_PREFETCH . 它是FileSystemControl FSCTL_FILE_PREFETCH

It is used in Windows Vista and above for prefetching both when an application starts and at boot time. 它在Windows Vista及更高版本中用于在应用程序启动和启动时预取。

It is also used by the SuperFetch technology that uses heuristics to load applications at approximately the times of day you generally use them. 它也被SuperFetch技术使用,该技术使用启发式技术在您通常使用它们的大约一天中加载应用程序。

FSCTL_FILE_PREFETCH itself is not documented on MSDN, but it is easy to figure out the parameter format by examining the DeviceIoControl calls made on app startup: Just start an application in the debugger that already has a .pf file in the c:\\Windows\\Prefetch directory and break on DeviceIoControl (or if you're using a kernel debugger, break when the NTFS driver receives its first FSCTL_FILE_PREFETCH). FSCTL_FILE_PREFETCH本身没有在MSDN上记录,但通过检查在应用启动时进行的DeviceIoControl调用很容易找出参数格式:只需在调试器中启动一个已在c:\\Windows\\Prefetch有.pf文件的应用程序目录并在DeviceIoControl中断(或者如果您使用的是内核调试器,则在NTFS驱动程序收到其第一个FSCTL_FILE_PREFETCH时中断)。 Examine the buffer passed in and compare it with the .pf file and the range actually used later. 检查传入的缓冲区,并将其与.pf文件和稍后实际使用的范围进行比较。 I did this once out of curiosity but didn't record the details. 出于好奇,我做了一次,但没有记录细节。

In case you are unfamiliar with DeviceIoControl and IRP_MJ_FILESYSTEM_CONTROL , here are some links to look at: 如果您不熟悉DeviceIoControlIRP_MJ_FILESYSTEM_CONTROL ,请IRP_MJ_FILESYSTEM_CONTROL以下链接:

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). 从Windows 8开始,存在或多或少直接等同于madvise(MADV_WILLNEED) ,这实际上是相同的(Windows具有统一的VM /缓存系统)。

Assuming that you have memory-mapped the file, you can thus use PrefetchVirtualMemory to prefetch it. 假设您已对内存映射文件,则可以使用PrefetchVirtualMemory来预取它。

This is still slightly more complicated than you'd wish, but not nearly as harsh as DeviceIoControl . 这仍然比你想要的要复杂一点,但不像DeviceIoControl那么苛刻。 Also note that you can easily prefetch several independent, discontinuous ranges. 另请注意,您可以轻松预取几个独立的不连续范围。

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. 我不确定我是否理解正确,你所说的' Where'文件“是一个先前由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... 这个调用在索引100处读取500个字节。这听起来像是在寻找偏移并读取500个字节......但是你希望它能够提前预取...

In C Code, it would look something like this: 在C代码中,它看起来像这样:

fseek(fp, 100, SEEK_CUR);
fread(&data, 500, 1, fp);

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... 说实话,我没有遇到过预先获取数据的事情......但Ray的回答令我感到惊讶,但是如果你想要保持兼容性,那么它只会对Vista提升...这是要保持的东西记住......但下面的链接可能会有所帮助......

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... 好吧,有一个博客讨论这个,一个用Delphi编写的库,源代码在这里 ,在这里浏览代码,好吧,它可能不是你想要的但是它可能会帮助你指明方向...对不起,如果它不是你想要的...

Hope this helps, Best regards, Tom. 希望这会有所帮助,最好的问候,汤姆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM