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