1MSYNC(3P) POSIX Programmer's Manual MSYNC(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 msync — synchronize memory with physical storage
13
15 #include <sys/mman.h>
16
17 int msync(void *addr, size_t len, int flags);
18
20 The msync() function shall write all modified data to permanent storage
21 locations, if any, in those whole pages containing any part of the
22 address space of the process starting at address addr and continuing
23 for len bytes. If no such storage exists, msync() need not have any
24 effect. If requested, the msync() function shall then invalidate cached
25 copies of data.
26
27 The implementation may require that addr be a multiple of the page size
28 as returned by sysconf().
29
30 For mappings to files, the msync() function shall ensure that all write
31 operations are completed as defined for synchronized I/O data integrity
32 completion. It is unspecified whether the implementation also writes
33 out other file attributes. When the msync() function is called on
34 MAP_PRIVATE mappings, any modified data shall not be written to the
35 underlying object and shall not cause such data to be made visible to
36 other processes. It is unspecified whether data in MAP_PRIVATE mappings
37 has any permanent storage locations. The effect of msync() on a shared
38 memory object or a typed memory object is unspecified. The behavior of
39 this function is unspecified if the mapping was not established by a
40 call to mmap().
41
42 The flags argument is constructed from the bitwise-inclusive OR of one
43 or more of the following flags defined in the <sys/mman.h> header:
44
45 ┌──────────────────┬──────────────────────────────┐
46 │Symbolic Constant │ Description │
47 ├──────────────────┼──────────────────────────────┤
48 │MS_ASYNC │ Perform asynchronous writes. │
49 │MS_SYNC │ Perform synchronous writes. │
50 │MS_INVALIDATE │ Invalidate cached data. │
51 └──────────────────┴──────────────────────────────┘
52 When MS_ASYNC is specified, msync() shall return immediately once all
53 the write operations are initiated or queued for servicing; when
54 MS_SYNC is specified, msync() shall not return until all write opera‐
55 tions are completed as defined for synchronized I/O data integrity com‐
56 pletion. Either MS_ASYNC or MS_SYNC shall be specified, but not both.
57
58 When MS_INVALIDATE is specified, msync() shall invalidate all cached
59 copies of mapped data that are inconsistent with the permanent storage
60 locations such that subsequent references shall obtain data that was
61 consistent with the permanent storage locations sometime between the
62 call to msync() and the first subsequent memory reference to the data.
63
64 If msync() causes any write to a file, the file's last data modifica‐
65 tion and last file status change timestamps shall be marked for update.
66
68 Upon successful completion, msync() shall return 0; otherwise, it shall
69 return -1 and set errno to indicate the error.
70
72 The msync() function shall fail if:
73
74 EBUSY Some or all of the addresses in the range starting at addr and
75 continuing for len bytes are locked, and MS_INVALIDATE is speci‐
76 fied.
77
78 EINVAL The value of flags is invalid.
79
80 ENOMEM The addresses in the range starting at addr and continuing for
81 len bytes are outside the range allowed for the address space of
82 a process or specify one or more pages that are not mapped.
83
84 The msync() function may fail if:
85
86 EINVAL The value of addr is not a multiple of the page size as returned
87 by sysconf().
88
89 The following sections are informative.
90
92 None.
93
95 The msync() function is only supported if the Synchronized Input and
96 Output option is supported, and thus need not be available on all
97 implementations.
98
99 The msync() function should be used by programs that require a memory
100 object to be in a known state; for example, in building transaction
101 facilities.
102
103 Normal system activity can cause pages to be written to disk. There‐
104 fore, there are no guarantees that msync() is the only control over
105 when pages are or are not written to disk.
106
108 The msync() function writes out data in a mapped region to the perma‐
109 nent storage for the underlying object. The call to msync() ensures
110 data integrity of the file.
111
112 After the data is written out, any cached data may be invalidated if
113 the MS_INVALIDATE flag was specified. This is useful on systems that do
114 not support read/write consistency.
115
117 None.
118
120 mmap(), sysconf()
121
122 The Base Definitions volume of POSIX.1‐2017, <sys_mman.h>
123
125 Portions of this text are reprinted and reproduced in electronic form
126 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
127 table Operating System Interface (POSIX), The Open Group Base Specifi‐
128 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
129 Electrical and Electronics Engineers, Inc and The Open Group. In the
130 event of any discrepancy between this version and the original IEEE and
131 The Open Group Standard, the original IEEE and The Open Group Standard
132 is the referee document. The original Standard can be obtained online
133 at http://www.opengroup.org/unix/online.html .
134
135 Any typographical or formatting errors that appear in this page are
136 most likely to have been introduced during the conversion of the source
137 files to man page format. To report such errors, see https://www.ker‐
138 nel.org/doc/man-pages/reporting_bugs.html .
139
140
141
142IEEE/The Open Group 2017 MSYNC(3P)