技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> Linux --> Linux下新系统调用sync_file_range

Linux下新系统调用sync_file_range

浏览:1195次  出处信息
    我们在做数据库程序或者IO密集型的程序的时候,通常在更新的时候,比如说数据库程序,希望更新有一定的安全性,我们会在更新操作结束的时候调用fsync或者fdatasync来flush数据到持久设备去。而且通常是以页面为单位,16K一次或者4K一次。 安全性保证了,但是性能就有很大的损害。而且我们更新的时候,通常是更新文件的某一个页面,那么由于是更新覆盖操作,对文件系统的元数据来讲的话,无需变更,所以我们通常不大关心元数据是否写入。 当更新非常频繁的时候,我们时候能够有其他方法减少性能损失。sync_file_range同学出场了。

    Linux下系统调用sync_file_range在2.6.17后加入内存,在RHEL 5U4后面的版本都是可用的。

     这篇文章有他的介绍: http://lwn.net/Articles/178199/

     也可以man sync_file_range下他的具体作用, 但是请注意,sync_file_range是不可移植的,并且只在内核2.6.17及更高版本。

    sync_file_range - sync a file segment with disk

    sync_file_range() permits fine control when synchronising the open file referred to by the file descriptor fd with disk.

    offset is the starting byte of the file range to be synchronised. nbytes specifies the length of the range to be synchronised, in bytes; if nbytes is zero, then all bytes from offset through to the end of file are synchronised. Synchronisation is in units of the system page size: offset is rounded down to a page boundary; (offset+nbytes-1) is rounded up to a page boundary.

    sync_file_range可以让我们在做多个更新后,一次性的刷数据,这样大大提高IO的性能。

    著名的fio工具支持sync_file_range来做sync操作,我们在决定在我们的应用中使用该syscall之前不妨先fio测试一把。

    祝大家玩的开心。

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1