1MSYNC(P) POSIX Programmer's Manual MSYNC(P)
2
3
4
6 msync - synchronize memory with physical storage
7
9 #include <sys/mman.h>
10
11 int msync(void *addr, size_t len, int flags);
12
13
15 The msync() function shall write all modified data to permanent storage
16 locations, if any, in those whole pages containing any part of the
17 address space of the process starting at address addr and continuing
18 for len bytes. If no such storage exists, msync() need not have any
19 effect. If requested, the msync() function shall then invalidate cached
20 copies of data.
21
22 The implementation shall require that addr be a multiple of the page
23 size as returned by sysconf().
24
25 For mappings to files, the msync() function shall ensure that all write
26 operations are completed as defined for synchronized I/O data integrity
27 completion. It is unspecified whether the implementation also writes
28 out other file attributes. When the msync() function is called on
29 MAP_PRIVATE mappings, any modified data shall not be written to the
30 underlying object and shall not cause such data to be made visible to
31 other processes. It is unspecified whether data in MAP_PRIVATE map‐
32 pings has any permanent storage locations. The effect of msync() on
33 a shared memory object or a typed memory object is unspecified. The
34 behavior of this function is unspecified if the mapping was not estab‐
35 lished by a call to mmap().
36
37 The flags argument is constructed from the bitwise-inclusive OR of one
38 or more of the following flags defined in the <sys/mman.h> header:
39
40 Symbolic Constant Description
41 MS_ASYNC Perform asynchronous writes.
42 MS_SYNC Perform synchronous writes.
43 MS_INVALIDATE Invalidate cached data.
44
45 When MS_ASYNC is specified, msync() shall return immediately once all
46 the write operations are initiated or queued for servicing; when
47 MS_SYNC is specified, msync() shall not return until all write opera‐
48 tions are completed as defined for synchronized I/O data integrity com‐
49 pletion. Either MS_ASYNC or MS_SYNC is specified, but not both.
50
51 When MS_INVALIDATE is specified, msync() shall invalidate all cached
52 copies of mapped data that are inconsistent with the permanent storage
53 locations such that subsequent references shall obtain data that was
54 consistent with the permanent storage locations sometime between the
55 call to msync() and the first subsequent memory reference to the data.
56
57 If msync() causes any write to a file, the file's st_ctime and st_mtime
58 fields shall be marked for update.
59
61 Upon successful completion, msync() shall return 0; otherwise, it shall
62 return -1 and set errno to indicate the error.
63
65 The msync() function shall fail if:
66
67 EBUSY Some or all of the addresses in the range starting at addr and
68 continuing for len bytes are locked, and MS_INVALIDATE is speci‐
69 fied.
70
71 EINVAL The value of flags is invalid.
72
73 EINVAL The value of addr is not a multiple of the page size {PAGESIZE}.
74
75 ENOMEM The addresses in the range starting at addr and continuing for
76 len bytes are outside the range allowed for the address space of
77 a process or specify one or more pages that are not mapped.
78
79
80 The following sections are informative.
81
83 None.
84
86 The msync() function is only supported if the Memory Mapped Files
87 option and the Synchronized Input and Output option are supported, and
88 thus need not be available on all implementations.
89
90 The msync() function should be used by programs that require a memory
91 object to be in a known state; for example, in building transaction
92 facilities.
93
94 Normal system activity can cause pages to be written to disk. There‐
95 fore, there are no guarantees that msync() is the only control over
96 when pages are or are not written to disk.
97
99 The msync() function writes out data in a mapped region to the perma‐
100 nent storage for the underlying object. The call to msync() ensures
101 data integrity of the file.
102
103 After the data is written out, any cached data may be invalidated if
104 the MS_INVALIDATE flag was specified. This is useful on systems that do
105 not support read/write consistency.
106
108 None.
109
111 mmap() , sysconf() , the Base Definitions volume of
112 IEEE Std 1003.1-2001, <sys/mman.h>
113
115 Portions of this text are reprinted and reproduced in electronic form
116 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
117 -- Portable Operating System Interface (POSIX), The Open Group Base
118 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
119 Electrical and Electronics Engineers, Inc and The Open Group. In the
120 event of any discrepancy between this version and the original IEEE and
121 The Open Group Standard, the original IEEE and The Open Group Standard
122 is the referee document. The original Standard can be obtained online
123 at http://www.opengroup.org/unix/online.html .
124
125
126
127IEEE/The Open Group 2003 MSYNC(P)