![]() |
![]() |
![]() |
Synchronize memory with physical storage
#include <sys/mman.h> int msync( void * addr, size_t len, int flags );
libc
The msync() function 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. The msync() function is used with memory mapped files. If no such storage exists, msync() need not have any effect. If requested, the msync() function then invalidates cached copies of data.
For mappings to files, this function ensures that all write operations are completed as defined for synchronized I/O data integrity completion.
![]() |
Mappings to files aren't implemented on all filesystems. |
When the msync() function is called on MAP_PRIVATE mappings, any modified data won't be written to the underlying object and won't 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:
Symbolic Constant | Description |
---|---|
MS_ASYNC | Perform asynchronous writes. Returns immediately once all the write operations are initiated or queued for servicing. |
MS_INVALIDATE | Invalidate cached data. 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. |
MS_INVALIDATE_ICACHE | (QNX 6 extension) If you're dynamically modifying code, use this flag to make sure that the new code is what will be executed. |
MS_SYNC | Perform synchronous writes. Doesn't return until all write operations are completed as defined for synchronized I/O data integrity completion. |
![]() |
Either MS_ASYNC or MS_SYNC may be specified, but not both. |
The behavior of msync() is unspecified if the mapping wasn't established by a call to mmap().
If msync() causes any write to a file, the file's st_ctime and st_mtime fields are marked for update.
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
MS_INVALIDATE_ICACHE is a QNX 6 extension.
![]() |
![]() |
![]() |