(这主要适用于 Linux,或者理想情况下适用于任何 POSIX 系统。)
当我阅读以下页面时,我正在寻找一种读取大量文件(其中任何一个文件本身可能高达 1GB)的方法,具有以下特征:
- 如果相关磁盘页面已在文件系统缓存中,则使用该页面。
- 如果相关页面不在磁盘缓存中,则会从磁盘中获取该页面,但不会驱逐任何现有的缓存磁盘页面。
这个想法是能够读取所有这些文件,而不会污染磁盘缓存或逐出当前工作集。
有什么指导吗?
在 Linux 上你可以尝试一下O_DIRECT
open()
flag. man open(2)
:
O_DIRECT (Since Linux 2.4.10)
Try to minimize cache effects of the I/O to and from this file.
In general this will degrade performance, but it is useful in
special situations, such as when applications do their own
caching. File I/O is done directly to/from user space buffers.
The O_DIRECT flag on its own makes at an effort to transfer data
synchronously, but does not give the guarantees of the O_SYNC
that data and necessary metadata are transferred. To guarantee
synchronous I/O the O_SYNC must be used in addition to O_DIRECT.
See NOTES below for further discussion.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)