Linux:为进程禁用文件缓存? [英] Linux : Disabling File cache for a process?
问题描述
我有两个进程运行A和B.
我希望由A打开的文件保留在缓存中。
和
我不想为B启用文件缓存,所以它不会替换内存中进程缓存的文件。
有没有办法为特定的进程禁用文件缓存?
没有我知道的...唯一的选择是全局/设备特定的:
- 使用-sync选项和mount
- 使用 drop_caches
另外一点:$ b
$ b即使你可以做你所要求的,也不能保证任何其他进程C,D,E等)以内存中的进程A缓存的文件的方式取代...
UPDATE - after来自OP ragarding performance的评论: 你可以在过程A中实现你想要的功能... 结帐 Is there a way to disable file cache for a particular process ? I have two process running A and B. I want file opened by A to remain in cache. and
I don't want to enable file cache for B so It doesn't replace the file cached by process in the memory. Is there a way to disable file cache for a particular process? None that I know of... the only option are global/device-specific: Another point: Even IF you could do what you ask for there is no guarantee that any other processes (C, D, E etc.) behaves in a way that "the file cached by process A in the memory" gets replaced... UPDATE - after comments from OP ragarding performance: Linux offers (as most modern OS) something called "memory-mapped file" - basically this is a way to access the file's contents in-memory... the OS assigns the file (depending on the given params) part of the address space and loads the content of the file into that address space (again: exact behaviour depends on the given params). You would do this in Process A to achieve what you want... Checkout the 这篇关于Linux:为进程禁用文件缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
Linux提供了一个叫做内存映射文件的东西(基本上这是一种访问文件的内容在内存中...操作系统分配地址空间的文件(取决于给定的参数)的一部分,并将文件的内容加载到地址空间(再次:确切的行为取决于给定的参数)。
mmap
API调用以获取详细信息。
mmap
API calls for details.