msync()

synchronize a mapped region 

Function


SYNOPSIS

#include <sys/mman.h>

int msync(void *addr, size_t len, int flags);


DESCRIPTION

The function msync() writes all modified data to permanent storage locations, if any, in those whole pages containing any part of the address space of the process starting at address addr and continuing for len bytes. If no such storage exists, msync() does not have any effect. If requested, the msync() function then invalidates cached copies of data.

addr must be a multiple of the page size as returned by sysconf().

For mappings to files, the msync() function ensures that all write operations are completed as defined for synchronized I/O data integrity completion. It is unspecified whether the implementation also writes out other file attributes. When the msync() function is called on MAP_PRIVATE mappings, any modified data is not written to the underlying object and does not cause such data to be made visible to other processes.

The flags argument is constructed from the bitwise inclusive OR of one or more of the following flags:

MS_ASYNC 

Perform asynchronous writes

MS_SYNC 

Perform synchronous writes.

MS_INVALIDATE 

Invalidate cached data.

When MS_ASYNC is specified, msync() returns immediately once all the write operations are initiated or queued for servicing; when MS_SYNC is specified, msync() does not return until all write operations are completed as defined for synchronized I/O data integrity completion. Either MS_ASYNC or MS_SYNC is specified, but not both.

When MS_INVALIDATE is specified, msync() invalidates all cached copies of mapped data that are inconsistent with the permanent storage locations such that subsequent references obtain data that was consistent with the permanent storage locations sometime between the call to msync() and the first subsequent memory reference to the data.


PARAMETERS

addr 

Is the address of the region from where data should be written to the permanent storage locations.

len 

Is the number of bytes to be written to the permanent storage locations.

flags 

Is the bitwise inclusive OR of MS_ASYNC (or MS_SYNC) and MS_INVALIDATE.


RETURN VALUES

If successful, the msync() function returns 0. Otherwise, it returns -1 and sets errno to one of the following values.

EINVAL 

The addr argument is not a multiple of the page size as returned by sysconf().

EINVAL 

The value in flags is invalid.

ENOMEM 

Addresses in the range [addr, addr + len] are invalid for the address space of a process, or specify one or more pages which are not mapped.


CONFORMANCE

UNIX 98, with exceptions.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

Windows does not distinguish the flags MS_SYNC and MS_ASYNC. The flag MS_INVALIDATE is ignored by the system.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
mmap(), sysconf()


PTC MKS Toolkit 10.4 Documentation Build 39.