]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/msync.2
man*/, man-pages.7: VERSIONS, STANDARDS, HISTORY: Reorganize sections
[thirdparty/man-pages.git] / man2 / msync.2
CommitLineData
fea681da
MK
1.\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
fea681da 4.\"
4c1c5274 5.TH msync 2 (date) "Linux man-pages (unreleased)"
fea681da
MK
6.SH NAME
7msync \- synchronize a file with a memory map
c3f6df48
AC
8.SH LIBRARY
9Standard C library
8fc3b2cf 10.RI ( libc ", " \-lc )
fea681da 11.SH SYNOPSIS
c7db92b9 12.nf
fea681da 13.B #include <sys/mman.h>
68e4db0a 14.PP
c64cd13e 15.BI "int msync(void " addr [. length "], size_t " length ", int " flags );
c7db92b9 16.fi
fea681da 17.SH DESCRIPTION
e511ffb6 18.BR msync ()
fea681da
MK
19flushes changes made to the in-core copy of a file that was mapped
20into memory using
21.BR mmap (2)
840324c0 22back to the filesystem.
44a48411 23Without use of this call,
fea681da
MK
24there is no guarantee that changes are written back before
25.BR munmap (2)
c13182ef
MK
26is called.
27To be more precise, the part of the file that
fea681da 28corresponds to the memory area starting at
14f5ae6d 29.I addr
fea681da
MK
30and having length
31.I length
c13182ef 32is updated.
efeece04 33.PP
9f339d4e 34The
fea681da 35.I flags
31f0e8c8 36argument should specify exactly one of
1ae6b2c7 37.B MS_ASYNC
c13182ef 38and
31f0e8c8
MK
39.BR MS_SYNC ,
40and may additionally include the
9f339d4e 41.B MS_INVALIDATE
31f0e8c8
MK
42bit.
43These bits have the following meanings:
44.TP
c13182ef 45.B MS_ASYNC
31f0e8c8
MK
46Specifies that an update be scheduled, but the call returns immediately.
47.TP
c13182ef 48.B MS_SYNC
31f0e8c8
MK
49Requests an update and waits for it to complete.
50.TP
c13182ef 51.B MS_INVALIDATE
31f0e8c8
MK
52.\" Since Linux 2.4, this seems to be a no-op (other than the
53.\" EBUSY check for VM_LOCKED).
54Asks to invalidate other mappings of the same file
fea681da 55(so that they can be updated with the fresh values just written).
47297adb 56.SH RETURN VALUE
c13182ef
MK
57On success, zero is returned.
58On error, \-1 is returned, and
fea681da 59.I errno
f6a4078b 60is set to indicate the error.
fea681da
MK
61.SH ERRORS
62.TP
0daa9e92 63.B EBUSY
2f0af33b
MK
64.B MS_INVALIDATE
65was specified in
c13182ef 66.IR flags ,
9f339d4e
MK
67and a memory lock exists for the specified address range.
68.TP
0daa9e92 69.B EINVAL
14f5ae6d 70.I addr
24bd9a49 71is not a multiple of PAGESIZE; or any bit other than
682edefb
MK
72.BR MS_ASYNC " | " MS_INVALIDATE " | " MS_SYNC
73is set in
24bd9a49 74.IR flags ;
c13182ef 75or both
682edefb
MK
76.B MS_SYNC
77and
78.B MS_ASYNC
79are set in
a5e0a0e4 80.IR flags .
fea681da
MK
81.TP
82.B ENOMEM
83The indicated memory (or part of it) was not mapped.
4131356c 84.SH VERSIONS
b60d9859 85According to POSIX, either
1ae6b2c7 86.B MS_SYNC
b60d9859 87or
1ae6b2c7 88.B MS_ASYNC
fe8b1358 89must be specified in
b1c5c4ec
MK
90.IR flags ,
91and indeed failure to include one of these flags will cause
92.BR msync ()
93to fail on some systems.
433e3408
MK
94However, Linux permits a call to
95.BR msync ()
96that specifies neither of these flags,
97with semantics that are (currently) equivalent to specifying
98.BR MS_ASYNC .
99(Since Linux 2.6.19,
100.\" commit 204ec841fbea3e5138168edbc3a76d46747cc987
1ae6b2c7 101.B MS_ASYNC
433e3408
MK
102is in fact a no-op, since the kernel properly tracks dirty
103pages and flushes them to storage as necessary.)
104Notwithstanding the Linux behavior,
b1c5c4ec 105portable, future-proof applications should ensure that they specify either
1ae6b2c7 106.B MS_SYNC
b60d9859 107or
1ae6b2c7 108.B MS_ASYNC
433e3408
MK
109in
110.IR flags .
4131356c
AC
111.SH STANDARDS
112POSIX.1-2008.
113.SH HISTORY
114POSIX.1-2001.
115.PP
116This call was introduced in Linux 1.3.21, and then used
117.B EFAULT
118instead of
119.BR ENOMEM .
120In Linux 2.4.19, this was changed to the POSIX value
121.BR ENOMEM .
122.PP
123On POSIX systems on which
124.BR msync ()
125is available, both
126.B _POSIX_MAPPED_FILES
127and
128.B _POSIX_SYNCHRONIZED_IO
129are defined in
130.I <unistd.h>
131to a value greater than 0.
132(See also
133.BR sysconf (3).)
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.
47297adb 137.SH SEE ALSO
fea681da 138.BR mmap (2)
efeece04 139.PP
523869f6 140B.O. Gallmeister, POSIX.4, O'Reilly, pp. 128\[en]129 and 389\[en]391.