1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH MSYNC 2 2014-04-20 "Linux" "Linux Programmer's Manual"
27 msync \- synchronize a file with a memory map
29 .B #include <sys/mman.h>
31 .BI "int msync(void *" addr ", size_t " length ", int " flags );
34 flushes changes made to the in-core copy of a file that was mapped
37 back to the filesystem.
38 Without use of this call
39 there is no guarantee that changes are written back before
42 To be more precise, the part of the file that
43 corresponds to the memory area starting at
51 argument may have the bits
61 specifies that an update be scheduled, but the call
64 asks for an update and waits for it to complete.
66 asks to invalidate other mappings of the same file
67 (so that they can be updated with the fresh values just written).
69 On success, zero is returned.
70 On error, \-1 is returned, and
79 and a memory lock exists for the specified address range.
83 is not a multiple of PAGESIZE; or any bit other than
84 .BR MS_ASYNC " | " MS_INVALIDATE " | " MS_SYNC
95 The indicated memory (or part of it) was not mapped.
99 This call was introduced in Linux 1.3.21, and then used
103 In Linux 2.4.19, this was changed to the POSIX value
106 On POSIX systems on which
109 .B _POSIX_MAPPED_FILES
111 .B _POSIX_SYNCHRONIZED_IO
114 to a value greater than 0.
117 .\" POSIX.1-2001: It shall be defined to -1 or 0 or 200112L.
118 .\" -1: unavailable, 0: ask using sysconf().
119 .\" glibc defines them to 1.
121 According to POSIX, either
127 and indeed failure to include one of these flags will cause
129 to fail on some systems.
130 However, Linux permits a call to
132 that specifies neither of these flags,
133 with semantics that are (currently) equivalent to specifying
136 .\" commit 204ec841fbea3e5138168edbc3a76d46747cc987
138 is in fact a no-op, since the kernel properly tracks dirty
139 pages and flushes them to storage as necessary.)
140 Notwithstanding the Linux behavior,
141 portable, future-proof applications should ensure that they specify either
150 B.O. Gallmeister, POSIX.4, O'Reilly, pp. 128-129 and 389-391.
152 This page is part of release 3.67 of the Linux
155 A description of the project,
156 information about reporting bugs,
157 and the latest version of this page,
159 \%http://www.kernel.org/doc/man\-pages/.