namespaces.7: ffix
[man-pages.git] / man2 / msync.2
blobc613a795a3125d09d11cc72179f24e44ffe452a9
1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH MSYNC 2 2021-03-22 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 msync \- synchronize a file with a memory map
28 .SH SYNOPSIS
29 .nf
30 .B #include <sys/mman.h>
31 .PP
32 .BI "int msync(void *" addr ", size_t " length ", int " flags );
33 .fi
34 .SH DESCRIPTION
35 .BR msync ()
36 flushes changes made to the in-core copy of a file that was mapped
37 into memory using
38 .BR mmap (2)
39 back to the filesystem.
40 Without use of this call,
41 there is no guarantee that changes are written back before
42 .BR munmap (2)
43 is called.
44 To be more precise, the part of the file that
45 corresponds to the memory area starting at
46 .I addr
47 and having length
48 .I length
49 is updated.
50 .PP
51 The
52 .I flags
53 argument should specify exactly one of
54 .BR MS_ASYNC
55 and
56 .BR MS_SYNC ,
57 and may additionally include the
58 .B MS_INVALIDATE
59 bit.
60 These bits have the following meanings:
61 .TP
62 .B MS_ASYNC
63 Specifies that an update be scheduled, but the call returns immediately.
64 .TP
65 .B MS_SYNC
66 Requests an update and waits for it to complete.
67 .TP
68 .B MS_INVALIDATE
69 .\" Since Linux 2.4, this seems to be a no-op (other than the
70 .\" EBUSY check for VM_LOCKED).
71 Asks to invalidate other mappings of the same file
72 (so that they can be updated with the fresh values just written).
73 .SH RETURN VALUE
74 On success, zero is returned.
75 On error, \-1 is returned, and
76 .I errno
77 is set to indicate the error.
78 .SH ERRORS
79 .TP
80 .B EBUSY
81 .B MS_INVALIDATE
82 was specified in
83 .IR flags ,
84 and a memory lock exists for the specified address range.
85 .TP
86 .B EINVAL
87 .I addr
88 is not a multiple of PAGESIZE; or any bit other than
89 .BR MS_ASYNC " | " MS_INVALIDATE " | " MS_SYNC
90 is set in
91 .IR flags ;
92 or both
93 .B MS_SYNC
94 and
95 .B MS_ASYNC
96 are set in
97 .IR flags .
98 .TP
99 .B ENOMEM
100 The indicated memory (or part of it) was not mapped.
101 .SH CONFORMING TO
102 POSIX.1-2001, POSIX.1-2008.
104 This call was introduced in Linux 1.3.21, and then used
105 .B EFAULT
106 instead of
107 .BR ENOMEM .
108 In Linux 2.4.19, this was changed to the POSIX value
109 .BR ENOMEM .
111 On POSIX systems on which
112 .BR msync ()
113 is available, both
114 .B _POSIX_MAPPED_FILES
116 .B _POSIX_SYNCHRONIZED_IO
117 are defined in
118 .I <unistd.h>
119 to a value greater than 0.
120 (See also
121 .BR sysconf (3).)
122 .\" POSIX.1-2001: It shall be defined to -1 or 0 or 200112L.
123 .\" -1: unavailable, 0: ask using sysconf().
124 .\" glibc defines them to 1.
125 .SH NOTES
126 According to POSIX, either
127 .BR MS_SYNC
129 .BR MS_ASYNC
130 must be specified in
131 .IR flags ,
132 and indeed failure to include one of these flags will cause
133 .BR msync ()
134 to fail on some systems.
135 However, Linux permits a call to
136 .BR msync ()
137 that specifies neither of these flags,
138 with semantics that are (currently) equivalent to specifying
139 .BR MS_ASYNC .
140 (Since Linux 2.6.19,
141 .\" commit 204ec841fbea3e5138168edbc3a76d46747cc987
142 .BR MS_ASYNC
143 is in fact a no-op, since the kernel properly tracks dirty
144 pages and flushes them to storage as necessary.)
145 Notwithstanding the Linux behavior,
146 portable, future-proof applications should ensure that they specify either
147 .BR MS_SYNC
149 .BR MS_ASYNC
151 .IR flags .
152 .SH SEE ALSO
153 .BR mmap (2)
155 B.O. Gallmeister, POSIX.4, O'Reilly, pp. 128\(en129 and 389\(en391.