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_ASYNC, MS_SYNC, and MS_INVALIDATEset, but not both MS_ASYNC and MS_SYNC. MS_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).