1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH MSYNC 2 2021-03-22 "Linux" "Linux Programmer's Manual"
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 ", 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 POSIX.1-2001, POSIX.1-2008.
87 This call was introduced in Linux 1.3.21, and then used
91 In Linux 2.4.19, this was changed to the POSIX value
94 On POSIX systems on which
97 .B _POSIX_MAPPED_FILES
99 .B _POSIX_SYNCHRONIZED_IO
102 to a value greater than 0.
105 .\" POSIX.1-2001: It shall be defined to -1 or 0 or 200112L.
106 .\" -1: unavailable, 0: ask using sysconf().
107 .\" glibc defines them to 1.
109 According to POSIX, either
115 and indeed failure to include one of these flags will cause
117 to fail on some systems.
118 However, Linux permits a call to
120 that specifies neither of these flags,
121 with semantics that are (currently) equivalent to specifying
124 .\" commit 204ec841fbea3e5138168edbc3a76d46747cc987
126 is in fact a no-op, since the kernel properly tracks dirty
127 pages and flushes them to storage as necessary.)
128 Notwithstanding the Linux behavior,
129 portable, future-proof applications should ensure that they specify either
138 B.O. Gallmeister, POSIX.4, O'Reilly, pp. 128\(en129 and 389\(en391.