Linux : Disabling File cache for a process?

2019-08-18 23:22发布

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?

2条回答
仙女界的扛把子
2楼-- · 2019-08-19 00:09

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 mmap API calls for details.

查看更多
戒情不戒烟
3楼-- · 2019-08-19 00:13

Process B could use fadvise() to direct the kernel to not cache data read from a given file descriptor.

查看更多
登录 后发表回答