msync(2) msync(2)
NAME
msync - synchronize memory with physical storage
SYNOPSIS
#include <sys/types.h>
#include <sys/mman.h>
int msync(void *addr, sizet len, int flags);
DESCRIPTION
The function msync writes all modified copies of pages over the range
[addr, addr + len) to their backing storage locations. msync optionally
invalidates any copies so that further references to the pages will be
obtained by the system from their backing storage locations. The backing
storage for a modified MAPSHARED mapping is the file the page is mapped
to; the backing storage for a modified MAPPRIVATE mapping is its swap
area.
flags is a bit pattern built from the following values:
MSASYNC perform asynchronous writes
MSSYNC perform synchronous writes
MSINVALIDATE invalidate mappings
If MSASYNC is set, msync returns immediately once all write operations
are scheduled; if MSSYNC is set, msync does not return until all write
operations are completed.
MSINVALIDATE invalidates all cached copies of data in memory, so that
further references to the pages will be obtained by the system from their
backing storage locations.
msync will fail if:
[EINVAL] If addr is not a multiple of the page size as returned by
sysconf(3C).
[EIO] An I/O error occurred while reading from or writing to the
file system.
[ENOMEM] Addresses in the range (addr, addr + len) are outside the
valid range for the address space of a process or pages
not mapped are specified.
[EBUSY] MSINVALIDATE was specified and one or more of the pages
was locked in memory.
SEE ALSO
Page 1