- 论坛徽章:
- 3
|
回复 1# almeydifer
Synchronous mode -
This flag affects only the write operation (read operatios are always blocking), which blocks the calling process until the data is effectively written to disk.
Direct I/O mode -
Any read or write operations transfers data directly from the User Mode address space to disk, or vise versa, by passing the page cache.
依我的理解是, 设置O_sync 会影响的进程的行为(即是进程执行了IO请求后, 是否需要睡眠直到IO解释.). 而O_direct会影响的是数据流动的行为(是否会流动到page cache).
当同时设置了O_sync和O_direct, 进程对文件进行写操作时, 数据将从ram直接写回到disk中, 同时因为设置了O_sync, 进程必须等待睡眠直到数据写到disk, IO结束才会唤醒.
另外当你没有设置O_direct时, 数据一般会写到page cache就会表示“已经完成了IO”.
这个是Virtual filesystem层的事情. 设置O_direct, 越过page cache, 只是从VFS层直接跳到mapping 层,而不需要经过page cache缓存. 下面还要经过generic block 层. IO scheculing层的转换, 最终才到设备驱动层执行真正的IO。所以我认为O_direct不会影响到物理设备. |
|