美文网首页
[file system] file related

[file system] file related

作者: 酒桶九筒 | 来源:发表于2017-11-23 12:49 被阅读0次

setbuf

reference:

  1. setbuf man
  2. C语言setbuf()函数:把缓冲区与流相关联

buffering type:

  1. unbuffered
  2. block buffered
  3. line buffered

Normally all files are block buffered. If a stream refers to a terminal (as stdout normally does), it is line buffered. The standard error stream stderr is always unbuffered by default.


O_SYNC vs O_DIRECT

reference:

  1. UNIX高级环境编程(14)文件IO - O_DIRECT和O_SYNC详解 < 海棠花溪 >
    若一进程以O_DIRECT标志打开某文件,而另一进程以普通(即使用了高速缓存缓冲区)打开同一文件,则由直接IO所读写的数据与缓冲区高速缓存中内容之间不存在一致性,应尽量避免这一场景。
  2. Ensuring data reaches disk
    O_DIRECT alone only promises that the kernel will avoid copying data from user space to kernel space, and will instead write it directly via DMA (Direct memory access; if possible). Data does not go into caches. There is no strict guarantee that the function will return only after all data has been transferred.
    O_SYNC guarantees that the call will not return before all data has been transferred to the disk (as far as the OS can tell). This still does not guarantee that the data isn't somewhere in the harddisk write cache, but it is as much as the OS can guarantee.
    O_DIRECT|O_SYNC is the combination of these, i.e. "DMA + guarantee".
  3. open man
    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 transferred.

相关文章

网友评论

      本文标题:[file system] file related

      本文链接:https://www.haomeiwen.com/subject/eubimxtx.html