我对msync()的理解

int  msync(void *addr,size_t len,int flags)

该函数的作用就是将映射区的数据冲洗到磁盘。

其中flags值可为 MS_ASYNC,MS_SYNC,MS_INVALIDATE

MS_ASYNC的作用是,不管映射区是否更新,直接冲洗返回。

MS_SYNC的作用是,如果映射区更新了,则冲洗返回,如果映射区没有更新,则等待,知道更新完毕,就冲洗返回。

MS_INVALIDATE的作用是,丢弃映射区中和原文件相同的部分。



参考文献:http://linux.die.net/man/2/msync

msync() flushes changes made to the in-core copy of a file that was mapped into memory using mmap(2) back to disk. Without use of this call there is no guarantee that changes are written back before munmap(2) is called. To be more precise, the part of the file that corresponds to the memory area starting at addr and having length lengthis updated.

The flags argument may have the bits MS_ASYNCMS_SYNC, and MS_INVALIDATEset, but not both MS_ASYNC and MS_SYNCMS_ASYNC specifies that an update be scheduled, but the call returns immediately. MS_SYNC asks for an update and waits for it to complete. MS_INVALIDATE asks to invalidate other mappings of the same file (so that they can be updated with the fresh values just written).



  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值