1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH msync 2 (date) "Linux man-pages (unreleased)"
7 msync \- synchronize a file with a memory map
10 .RI ( libc ", " \-lc )
13 .B #include <sys/mman.h>
15 .BI "int msync(void " addr [. length "], size_t " length ", int " flags );
19 flushes changes made to the in-core copy of a file that was mapped
22 back to the filesystem.
23 Without use of this call,
24 there is no guarantee that changes are written back before
27 To be more precise, the part of the file that
28 corresponds to the memory area starting at
36 argument should specify exactly one of
40 and may additionally include the
43 These bits have the following meanings:
46 Specifies that an update be scheduled, but the call returns immediately.
49 Requests an update and waits for it to complete.
52 .\" Since Linux 2.4, this seems to be a no-op (other than the
53 .\" EBUSY check for VM_LOCKED).
54 Asks to invalidate other mappings of the same file
55 (so that they can be updated with the fresh values just written).
57 On success, zero is returned.
58 On error, \-1 is returned, and
60 is set to indicate the error.
67 and a memory lock exists for the specified address range.
71 is not a multiple of PAGESIZE; or any bit other than
72 .BR MS_ASYNC " | " MS_INVALIDATE " | " MS_SYNC
83 The indicated memory (or part of it) was not mapped.
85 According to POSIX, either
91 and indeed failure to include one of these flags will cause
93 to fail on some systems.
94 However, Linux permits a call to
96 that specifies neither of these flags,
97 with semantics that are (currently) equivalent to specifying
100 .\" commit 204ec841fbea3e5138168edbc3a76d46747cc987
102 is in fact a no-op, since the kernel properly tracks dirty
103 pages and flushes them to storage as necessary.)
104 Notwithstanding the Linux behavior,
105 portable, future-proof applications should ensure that they specify either
116 This call was introduced in Linux 1.3.21, and then used
120 In Linux 2.4.19, this was changed to the POSIX value
123 On POSIX systems on which
126 .B _POSIX_MAPPED_FILES
128 .B _POSIX_SYNCHRONIZED_IO
131 to a value greater than 0.
134 .\" POSIX.1-2001: It shall be defined to -1 or 0 or 200112L.
135 .\" -1: unavailable, 0: ask using sysconf().
136 .\" glibc defines them to 1.
140 B.O. Gallmeister, POSIX.4, O'Reilly, pp. 128\[en]129 and 389\[en]391.