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