简体   繁体   中英

Does msync() write to file only changed pages or wholly cached buffer?

I use a POSIX-function mmap() in Linux. But when I do msync() , then does it write cached buffer to a file wholly, or somehow it is noted somewhere which pages have changed, and which did not, and writes to the file only changed - ie does msync() write to file only changed pages or cached buffer wholly?

Suppose if we work with file of 1 GB by using mmap() , read it all, ie through a lot of page-fault raised in memory of the entire file. Then we changed only one byte, and called msync() , then it will begin to record the whole 1GB to a file or somehow determine the page you want changed and will only keep it, and how it is defined - how does it do this? ?

msync does what you want: it will only write pages which have actually been modified. Actually, msync is largely a no-op on Linux or any system with a proper virtual memory and page cache system; read will immediately see anything written to the mmap ped pages, even without msync . It's largely an analog of fsync , but with a memory address range rather than a file descriptor as its argument. One other observable effect is that it causes the file modification time to be updated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM