在一个POSIX系统如Linux或Solaris,请尝试使用posix_fadvise。
在流文件上,执行如下操作:
posix_fadvise(fd,0,0,POSIX_FADV_SEQUENTIAL); while(bytes> 0){ bytes = pread(fd,buffer,64 * 1024,current_pos); current_pos + = 64 * 1024; posix_fadvise(fd,0,current_pos,POSIX_FADV_DONTNEED); $ b $ p $ b你可以将POSIX_FADV_WILLNEED应用到你的其他文件, 。 现在,我知道Windows Vista和Server 2008也可以做内存优先级的漂亮技巧。像XP这样的老版本也可以做更多的基本技巧。但是我不知道这些功能是否在我头上,也没有时间查看它们。I need to keep as much as I can of large file in the operating system block cache even though it's bigger than I can fit in ram, and I'm continously reading another very very large file. ATM I'll remove large chunk of large important file from system cache when I stream read form another file.
解决方案In a POSIX system like Linux or Solaris, try using posix_fadvise.
On the streaming file, do something like this:
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); while( bytes > 0 ) { bytes = pread(fd, buffer, 64 * 1024, current_pos); current_pos += 64 * 1024; posix_fadvise(fd, 0, current_pos, POSIX_FADV_DONTNEED); }And you can apply POSIX_FADV_WILLNEED to your other file, which should raise its memory priority.
Now, I know that Windows Vista and Server 2008 can also do nifty tricks with memory priorities. Probably older versions like XP can do more basic tricks as well. But I don't know the functions off the top of my head and don't have time to look them up.
更多推荐
在OS块缓冲区中保留一个文件
发布评论