在OS块缓冲区中保留一个文件 [英] Keeping a file in the OS block buffer

查看:137
本文介绍了在OS块缓冲区中保留一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在操作系统块缓存中保留尽可能多的大文件,尽管它大于我可以放在内存中,而且我不断读取另一个非常大的文件。 ATM我将从系统缓存中删除大块重要的文件,当我流读取形式另一个文件。

解决方案

在一个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块缓冲区中保留一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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