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 - i.e. 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.