MSYNC(2) BSD Programmer's Manual MSYNC(2)NAMEmsync - synchronize a mapped region
SYNOPSIS
#include <sys/types.h>
#include <sys/mman.h>
int
msync(void *addr, int len, int flags);
DESCRIPTION
The msync() system call writes any modified pages back to the filesystem
and updates the file modification time. If len is 0, all modified pages
within the region containing addr will be flushed; if len is non-zero,
only the pages containing addr and len succeeding locations will be exam-
ined. Any required synchronization of memory caches will also take place
at this time.
The flags parameter consists of a type and additional flag bits. The
type is mandatory and must be either MS_ASYNC or MS_SYNC, for asyn-
chronous or synchronous flushing, respectively. There is currently just
one flag:
MS_INVALIDATE Invalidate pages after flushing.
RETURN VALUES
Upon successful completion, msync() will return 0; otherwise a value of
-1 is returned and errno is set to indicate the error.
ERRORS
The following errors may be reported:
[EINVAL] The addr parameter was not page aligned.
[EINVAL] The addr parameter did not specify an address part of a
mapped region.
[EINVAL] The len parameter was negative.
[EIO] An I/O error occured while writing to the file system.
SEE ALSOmadvise(2), munmap(2), mprotect(2), mincore(2)HISTORY
The msync() function first appeared in 4.4BSD.
BUGS
This interface is not compatible with the traditional BSD interface. The
flags parameter is currently ignored, so two-parameter calls to msync()
are safe, but this will change in future releases.
The msync() function exposes some of the system's caching policy. If you
map a file for shared updates, running msync() to update a region of the
file will have the same caching behavior as using write() with the same
data to update that region of the file. If you don't use msync() to up-
date a mapped file, then any changes may be cached until a read() or
write() operation on that region of the file forces synchronization.
This may occur long after the process that mapped the file has closed the
file descriptor, or for that matter, long after it has exited.
Note that msync() does not commit the data to disk. Use fsync(2) to en-
sure that data gets written out.