Linux fflush 与 fsync的区别
来源:互联网 发布:综合素质考试大纲知乎 编辑:程序博客网 时间:2024/06/05 18:09
在学习innodb_flush_method的方法时,看到下面的文章:
http://www.orczhou.com/index.php/2009/08/innodb_flush_method-file-io/
文章对此参数介绍的比较详细。(摘录其中一段。。。。)
参数Innodb_flush_method(Linux)可以设定为:Fdatasync、O_DSYNC、O_DIRECT。我们看看这个三个参数是如何影响程序MySQL对日志和数据文件的操作:
O_DIRECT
Fsync()- O_SYNC
- The file is opened for synchronous I/O. Any write()s on the resulting file descriptor will block the calling process until the data has beenphysically written to the underlying hardware. But see RESTRICTIONS below.
- Restrictions
- There are many infelicities in the protocol underlying NFS, affecting amongst othersO_SYNC and O_NDELAY.
POSIX provides for three different variants of synchronised I/O, corresponding to the flags O_SYNC, O_DSYNC and O_RSYNC. Currently(2.1.130) these are all synonymous under Linux.
#include <stdio.h>
int fflush(FILE *stream);
Description
The function fflush() forces a write of all user-space buffered data for the given output or update stream via the stream's underlying write function. The open status of the stream is unaffected.
Notes
Note that fflush() only flushes the user space buffers provided by the C library. To ensure that the data is physically stored on disk the kernel buffers must be flushed too.
此时就需要用到fsync 或者sync函数。
#include <unistd.h>
void sync(void);
Description
sync() first commits inodes to buffers, and then buffers to disk.
#include <unistd.h>
int fsync(int fd);
int fdatasync(int fd);
Description
fsync() transfers ("flushes") all modified in-core data of (i.e., modified buffer cache pages for) the file referred to by the file descriptor fd to the disk device (or other permanent storage device) where that file resides. The call blocks until the device reports that the transfer has completed. It also flushes metadata information associated with the file (see stat(2)).
fsync 将文件相关的所有更改都发送到disk device。 这个调用是阻塞的,直到disk通知此函数传输完成。此函数也会将该文件的文件信息flush到disk。
Calling fsync() does not necessarily ensure that the entry in the directory containing the file has also reached disk. For that an explicit fsync() on a file descriptor for the directory is also needed.
fdatasync() is similar to fsync(), but does not flush modified metadata unless that metadata is needed in order to allow a subsequent data retrieval to be correctly handled. For example, changes to st_atime or st_mtime (respectively, time of last access and time of last modification; see stat(2)) do not not require flushing because they are not necessary for a subsequent data read to be handled correctly. On the other hand, a change to the file size (st_size, as made by say ftruncate(2)), would require a metadata flush.
The aim of fdatasync(2) is to reduce disk activity for applications that do not require all metadata to be synchronised with the disk.
fdatasync与fsync的区别在于fdatasync不会flush文件的metadata信息。这个是为了减少对磁盘的操作。。。
Notes
If the underlying hard disk has write caching enabled, then the data may not really be on permanent storage when fsync() / fdatasync() return.
When an ext2 file system is mounted with the sync option, directory entries are also implicitly synced by fsync().
On kernels before 2.4, fsync() on big files can be inefficient. An alternative might be to use the O_SYNC flag to open.
- Linux fflush 与 fsync的区别
- fflush和fsync的区别
- fflush和fsync的区别
- fflush与fsync的关系
- linux之sync和fsync,fsync和fflush的区别和联系
- fflush和fsync的联系和区别
- fflush和fsync的联系和区别
- fflush和fsync的联系和区别
- fflush和fsync的联系和区别
- fflush和fsync的联系和区别
- fflush和fsync的联系和区别
- fflush and fsync区别
- fflush与fsync
- read/write/fsync与fread/fwrite/fflush的关系和区别
- read/write/fsync与fread/fwrite/fflush的关系和区别
- read/write/fsync与fread/fwrite/fflush的关系和区别
- sync fsync fdatasync fflush区别
- linux 同步IO: sync msync、fsync、fdatasync与 fflush
- BW:表空间
- BW顾问需要的技能
- 哈呀嗓,济南
- TCP建立及关闭过程
- Linux下如何测试及使用USB转串口线
- Linux fflush 与 fsync的区别
- profile实现购物车
- Linux下library知识
- php checkbox集合
- Java 设置JTextField组件的焦点事件
- struts 2.2.1发布以及javassist问题
- [转]收藏一个利用SCN回复数据的例子
- Dll文件
- linux c/c++ GDB教程详解 zz