sync_file_range - sync a file segment with disk (None of these operations writes out the file's metadata)

sync_file_range 可以将文件的部分范围作为目标,将对应范围内的脏页刷回磁盘,而不是整个文件的范围。

好处是,当我们对大文件进行了修改时,如果修改了大量的数据块,我们最后fsync的时候,可能会很慢。即使fdatasync,也是有问题的,例如这个大文件的长度在我们的修改过程中发生了变化,那么fdatasync将同时写metadata,而对于文件系统来说,单个文件系统的写metadata 是串行的,这势必导致影响其他用户操作metadata(如创建文件)。

sync_file_range是绝对不会写metadata的,所以用它非常合适,每次对文件做了小范围的修改时,立即调用sync_file_range,把对应的脏数据刷到磁盘,那么在结束对文件的修改后,再调用fdatasync (flush dirty data page), fsync(flush dirty data+metadata page)都是很块的。

sync_file_range的几个flag, 注意SYNC_FILE_RANGE_WRITE是异步的,所以如果你要达到以上目的话,那么最好不要使用异步模式,或者至少在调用fdatasync和fsync前,使用SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE |

       SYNC_FILE_RANGE_WAIT_AFTER做一次全文件范围的sync_file_range。从而保证在调用fdatasync或fsync前,该文件的dirty page已经全部刷到磁盘了。

       SYNC_FILE_RANGE_WAIT_BEFORE

              Wait upon write-out of all pages in the specified range that

              have already been submitted to the device driver for write-out

              before performing any write.

       SYNC_FILE_RANGE_WRITE

              Initiate write-out of all dirty pages in the specified range

              which are not presently submitted write-out.  Note that even

              this may block if you attempt to write more than request queue

              size.

       SYNC_FILE_RANGE_WAIT_AFTER

              Wait upon write-out of all pages in the range after performing

              any write.

       Useful combinations of the flags bits are:

       SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE

              Ensures that all pages in the specified range which were dirty

              when sync_file_range() was called are placed under write-out.

              This is a start-write-for-data-integrity operation.

       SYNC_FILE_RANGE_WRITE

              Start write-out of all dirty pages in the specified range

              which are not presently under write-out.  This is an

              asynchronous flush-to-disk operation.  This is not suitable

              for data integrity operations.

       SYNC_FILE_RANGE_WAIT_BEFORE (or SYNC_FILE_RANGE_WAIT_AFTER)

              Wait for completion of write-out of all pages in the specified

              range.  This can be used after an earlier

              SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE operation

              to wait for completion of that operation, and obtain its

              result.

       SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE |

       SYNC_FILE_RANGE_WAIT_AFTER

              This is a write-for-data-integrity operation that will ensure

              that all pages in the specified range which were dirty when

              sync_file_range() was called are committed to disk.

[参考]
1. http://man7.org/linux/man-pages/man2/sync_file_range.2.html

时间: 2024-08-29 07:50:10

sync_file_range - sync a file segment with disk (None of these operations writes out the file's metadata)的相关文章

后台file为null-jquery ajax 上传文件 后台取不到file

问题描述 jquery ajax 上传文件 后台取不到file 正在做一个文件上传的程序,在上传之前需要验证文件的大小,不能超过10M,我采用的是jquery ajax的方式提交到后台Action,由后台Action判断文件大小. 首先看jsp页面: 上传的文件不得大于10M ....省略部分.... javascript代码: function checkFileSize() { var uploadfile = jq("#uploadfile"); var returnval =

PostgreSQL 9.6 平滑fsync, write原理浅析

PostgreSQL 9.6 平滑fsync, write原理浅析 作者 digoal 日期 2016-10-06 标签 PostgreSQL , 9.6 , 平滑 fsync , write , smooth fsync 背景 汽车换挡是否平顺,通常取决于档位数,或者换挡技术. 档位数越多,换挡时感觉会约平顺,档位数较少的情况下,换挡可能会有比较明显的顿挫感觉. 数据库也一样,有些时候可能就会出现卡顿的现象,比如尖锐(堆积)的IO需求时. 本文将给大家介绍9.6在fsync, write方面的

PostgreSQL 9.6 平滑fsync, write深入分析

背景 汽车换挡是否平顺,通常取决于档位数,或者换挡技术. 档位数越多,换挡时感觉会约平顺,档位数较少的情况下,换挡可能会有比较明显的顿挫感觉. 数据库也一样,有些时候可能就会出现卡顿的现象,比如尖锐(堆积)的IO需求时. 本文将给大家介绍9.6在fsync, write方面的平顺性改进,减少尖锐的IO需求. 数据库为了保证数据可靠性,同时还要保证好的读写性能,以及读写的一致性,经过多年的发展,REDO日志,shared buffer基本已经成为数据库的标配. 为了保证数据的可靠性,通常需要在将d

GNU Radio中的数据元(Metadata)

A stream of samples is much more interesting when there is parsable metadata connected to that stream, such as the time of reception, centre frequency, sampling rate or even protocol-specific information such as node identification. In GNU Radio, add

Spark技术内幕:Shuffle Read的整体流程

回忆一下,每个Stage的上边界,要么需要从外部存储读取数据,要么需要读取上一个Stage的输出:而下边界,要么是需要写入本地文件系统(需要Shuffle),以供childStage读取,要么是最后一个Stage,需要输出结果.这里的Stage,在运行时的时候就是可以以pipeline的方式运行的一组Task,除了最后一个Stage对应的是ResultTask,其余的Stage对应的都是ShuffleMap Task. 而除了需要从外部存储读取数据和RDD已经做过cache或者checkpoin

Statspack之十四-"log file sync" 等待事件

原文出处: http://www.eygle.com/statspack/statspack14-LogFileSync.htm 当一个用户提交(commits)或者回滚(rollback),session的redo信息需要写出到redo logfile中.用户进程将通知LGWR执行写出操作,LGWR完成任务以后会通知用户进程.这个等待事件就是指用户进程等待LGWR的写完成通知. 对于回滚操作,该事件记录从用户发出rollback命令到回滚完成的时间. 如果该等待过多,可能说明LGWR的写出效率

log file sync 等侍值高的一般通用解决办法

log file sync等待时间发生在redo log从log buffer写入到log file期间. 下面对log file sync做个详细的解释. 何时发生日志写入: 1.commit或者rollback 2.每3秒 3.log buffer 1/3满或者已经有1M的redo数据.       更精确的解释:_LOG_IO_SIZE 大小默认是LOG_BUFFER的1/3,当log buffer中redo数据达到_LOG_IO_SIZE 大小时,发生日志写入. 4.DBWR写之前 _l

PostgreSQL 9.6 检查点柔性优化(SYNC_FILE_RANGE) - 在单机多实例下的IO Hang问题浅析与优化

背景 PostgreSQL检查点是将shared buffer中的脏页打标记,并集中将其刷到磁盘的动作(fsync).(期间可能有刷盘的调度,降低当脏页很多时带来的IO影响) 在检查点之外,平时bgwriter进程则会使用bufferio的方式(write)将脏页写到OS的dirty page. 如果shared buffer非常大,而且数据库应用如果是频繁产生脏页的应用,那么检查点带来的性能影响会非常的明显. 例如shared buffer有100G,活跃数据有100G,同时活跃数据在不停的被

ORACLE等待事件: log file parallel write

log file parallel write概念介绍 log file parallel write 事件是LGWR进程专属的等待事件,发生在LGWR将日志缓冲区(log_buffer)中的重做日志信息写入联机重做日志文件组的成员文件,LGWR在该事件上等待该写入过程的完成.该事件的等待表示重做日志所处的磁盘设备缓慢或存在争用.下面看看官方一些资料是如何解释log file parallel write等待事件的.   log file parallel write   Writing red