在学习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对日志和数据文件的操作:

#mytable td{text-align:center}

Open log

Flush log

Open datafile

Flush data

Fdatasync

fsync()

fsync()

O_DSYNC

O_SYNC

fsync()

O_DIRECT

fsync()

O_DIRECT

Fsync()

Linux man page 上对open的O_SYNC的描述:

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 been physically written to the underlying hardware.

But see RESTRICTIONS below .

Restrictions

There are many infelicities in the protocol underlying NFS, affecting amongst others

O_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.

Linux man page上对fflush,fsync,sync和fdatasync的解释:

#include

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

void sync(void);

Description

sync() first commits inodes to buffers, and then buffers to disk.

#include

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,Linux fflush 与 fsync的区别相关推荐

  1. 漫谈linux文件io,Linux文件IO与通用块层的请求合并

    本文参考https://mp.weixin.qq.com/s/Imt4BW-zoHPpcOpcKZs_AQ, 公众号"Linux阅码场" 请求合并就是将进程内或者进程间产生的在物理 ...

  2. 【Android 逆向】Linux 文件权限 ( Linux 权限简介 | 系统权限 | 用户权限 | 匿名用户权限 | 读 | 写 | 执行 | 更改组 | 更改用户 | 粘滞 )

    文章目录 一.Linux 权限简介 二.系统权限 / 用户权限 / 匿名用户权限 1.系统权限 2.用户权限 3.匿名用户权限 一.Linux 权限简介 Linux 是基于文件的系统 , 内存 , 设 ...

  3. linux 文件理解,linux文件系统理解

    1.  文件即数据的集合,无论你有任何信息需要存储在计算机中,都要以文件的信息存在:而文件常常和具体的设备相关联,如磁盘.软盘等等. 2. 目录,即一个文件组. 3. linux支持的文件系统: Ex ...

  4. linux文件构成,Linux文件结构及管理(1)

    Linux系统其一的哲学思想为一切皆文件,在Linux系统中有众多的文件系统下面我们就对Linux文件系统做一个简单的介绍. Linux的文件类型查看方式为:file /path/to/somefil ...

  5. redis linux 文件位置,Linux下Redis的安装和部署

    一.Redis介绍 Redis是当前比较热门的NOSQL系统之一 它是一个key-value存储系统.和Memcache类似,但很大程度补偿了Memcache的不足,它支持存储的value类型相对更多 ...

  6. linux文件历史,Linux文件系统的历史透视

    与维基百科页面一样,Block(数据存储)虽然在链接所有关键字方面过于旺盛,但仍具有丰富的信息量. 在计算(特别是数据传输和数据存储)中,块是具有标称长度(块大小)的字节或比特序列.据说这样构建的数据 ...

  7. linux 文件服务,Linux操作系统之文件服务(ftp、nfs)

    一.FTP server 1.简介 名词解释:FTP(File Transfer Protocol,文件传输协议) 是 TCP/IP 协议组中应用层的协议之一. logo: 作用: 提供文件共享服务, ...

  8. linux 文件服务,linux系统文件服务

    我们之前的学习都是以个人计算机的形式去操作,今天则可以作为服务器来操作.服务器必备的功能是文件的传输,所以我们现在讲的是怎么让用户能在你这里下载和上传文件. 环境准备 做本次实验前,需要你关闭防火墙和 ...

  9. 查看linux文件系统结构,linux的文件系统架构

    linux的文件系统是由若干个树形以及链表的结构组成的,其中众所周知,所有的目录和文件组成了视觉上"一棵"树,在这"一棵"树背后有一条挂载链表,如果说每一个文件 ...

  10. 内存属于linux文件吗,linux下的/dev/shm是什么? 内存 文件系统

    linux下的/dev/shm是什么? /dev/shm/是linux下一个目录,/dev/shm目录不在磁盘上,而是在内存里,因此使用linux /dev/shm/的效率非常高,直接写进内存. 我们 ...

最新文章

  1. 任何网络都能山寨!新型黑盒对抗攻击可模拟未知网络进行攻击 | CVPR 2021
  2. 企业应用架构模式学习笔记
  3. 安装php时,configure: error: xml2-config not found. Please check your libxml2 installation
  4. Quartz执行周期配置
  5. 阿里巴巴java规范检查_阿里巴巴Java开发规范
  6. 凭证 金蝶_金蝶软件账务处理流程之——凭证录入
  7. Alex Hanna博士:Google道德AI小组研究员
  8. python dicom图像分割_python读取DICOM头文件的实例
  9. python输出用逗号隔开的数字_Python:从字符串中提取带有点和逗号的数字
  10. thinkphp [数据分页]
  11. linux PS1 变量设置
  12. 最嗨的不是抽奖,看看人家公司的年会
  13. 淘宝技术这十年(淘宝技术大学校长解密淘宝十年)
  14. 偏差-方差分解(转)
  15. 西安电子科技大学计算机科学与技术拔尖班,西安电子科技大学入选基础学科拔尖学生培养计划2.0基地...
  16. 微信公众号:提示“redirect_uri 参数错误”
  17. centos7系统开启ftp服务器,centos7 开启ftp服务器
  18. 北大2011年计算机系录取浙江毛,湖州这11位同学被清华北大录取!
  19. PDF如何在线压缩?PDF压缩到最小的方法
  20. Android Context 到底是什么?

热门文章

  1. 容器:forward_list用法及示例
  2. JAVAOooooo。。。。。ooo0000OOOOO
  3. python爬虫入门(5)----- 阿里巴巴供应商爬虫
  4. java 用户拒绝对代码授予权限_java – @Secured函数获取授权用户的拒绝访问权限...
  5. 转载:bat批处理简易教程
  6. 自学单片机是否先学c语言,学习单片机需要先学好C语言再去学单片机吗
  7. bi数据分析工具有哪些?
  8. ARM公司为何如此成功
  9. 力推个p站相关站点 画师美图和各种工具方法
  10. 破立之间:金融科技时代的普惠新机会、新挑战