系统接口 open接口参数O_DIRECT无法屏蔽系统cache问题

内核编译和嵌入式产品的设计与开发
回复
ubuntu_Star
帖子: 1
注册时间: 2023-02-24 20:56
系统: ubuntu

系统接口 open接口参数O_DIRECT无法屏蔽系统cache问题

#1

帖子 ubuntu_Star » 2023-02-24 20:59

系统接口 open(const char * pathname, int flags, mode_t mode); 其中,参数2,O_DIRECT该参数用于屏蔽系统cache,read/write可以实时读写文件物理位置, 目前发现O_DIRECT该参数无法屏蔽系统cache,导致无法实时读写文件,请教诸位这个问题应该如何解决?
头像
astolia
论坛版主
帖子: 6450
注册时间: 2008-09-18 13:11

Re: 系统接口 open接口参数O_DIRECT无法屏蔽系统cache问题

#2

帖子 astolia » 2023-02-26 10:40

为什么不读一下manpage呢?
先sudo apt install manpages-dev

代码: 全选

man 2 open

代码: 全选

       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 an effort to transfer data synchronously, but does  not
              give  the  guarantees  of  the O_SYNC flag that data and necessary metadata are trans‐
              ferred.  To guarantee synchronous I/O, O_SYNC must be used in  addition  to  O_DIRECT.
              See NOTES below for further discussion.
回复