man-pages/man2/msync.2.html
2021-03-31 01:06:50 +01:00

243 lines
4.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of MSYNC</TITLE>
</HEAD><BODY>
<H1>MSYNC</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
msync - synchronize a file with a memory map
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/sys/mman.h">sys/mman.h</A>&gt;</B>
<P>
<B>int msync(void *</B><I>addr</I><B>, size_t </B><I>length</I><B>, int </B><I>flags</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>msync</B>()
flushes changes made to the in-core copy of a file that was mapped
into memory using
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2)
back to the filesystem.
Without use of this call,
there is no guarantee that changes are written back before
<B><A HREF="/cgi-bin/man/man2html?2+munmap">munmap</A></B>(2)
is called.
To be more precise, the part of the file that
corresponds to the memory area starting at
<I>addr</I>
and having length
<I>length</I>
is updated.
<P>
The
<I>flags</I>
argument should specify exactly one of
<B>MS_ASYNC</B>
and
<B>MS_SYNC</B>,
and may additionally include the
<B>MS_INVALIDATE</B>
bit.
These bits have the following meanings:
<DL COMPACT>
<DT id="1"><B>MS_ASYNC</B>
<DD>
Specifies that an update be scheduled, but the call returns immediately.
<DT id="2"><B>MS_SYNC</B>
<DD>
Requests an update and waits for it to complete.
<DT id="3"><B>MS_INVALIDATE</B>
<DD>
Asks to invalidate other mappings of the same file
(so that they can be updated with the fresh values just written).
</DL>
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, zero is returned.
On error, -1 is returned, and
<I>errno</I>
is set appropriately.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="4"><B>EBUSY</B>
<DD>
<B>MS_INVALIDATE</B>
was specified in
<I>flags</I>,
and a memory lock exists for the specified address range.
<DT id="5"><B>EINVAL</B>
<DD>
<I>addr</I>
is not a multiple of PAGESIZE; or any bit other than
<B>MS_ASYNC</B> | <B>MS_INVALIDATE</B> | <B>MS_SYNC</B>
is set in
<I>flags</I>;
or both
<B>MS_SYNC</B>
and
<B>MS_ASYNC</B>
are set in
<I>flags</I>.
<DT id="6"><B>ENOMEM</B>
<DD>
The indicated memory (or part of it) was not mapped.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008.
<P>
This call was introduced in Linux 1.3.21, and then used
<B>EFAULT</B>
instead of
<B>ENOMEM</B>.
In Linux 2.4.19, this was changed to the POSIX value
<B>ENOMEM</B>.
<A NAME="lbAH">&nbsp;</A>
<H2>AVAILABILITY</H2>
On POSIX systems on which
<B>msync</B>()
is available, both
<B>_POSIX_MAPPED_FILES</B>
and
<B>_POSIX_SYNCHRONIZED_IO</B>
are defined in
<I>&lt;<A HREF="file:///usr/include/unistd.h">unistd.h</A>&gt;</I>
to a value greater than 0.
(See also
<B><A HREF="/cgi-bin/man/man2html?3+sysconf">sysconf</A></B>(3).)
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
According to POSIX, either
<B>MS_SYNC</B>
or
<B>MS_ASYNC</B>
must be specified in
<I>flags</I>,
and indeed failure to include one of these flags will cause
<B>msync</B>()
to fail on some systems.
However, Linux permits a call to
<B>msync</B>()
that specifies neither of these flags,
with semantics that are (currently) equivalent to specifying
<B>MS_ASYNC</B>.
(Since Linux 2.6.19,
<B>MS_ASYNC</B>
is in fact a no-op, since the kernel properly tracks dirty
pages and flushes them to storage as necessary.)
Notwithstanding the Linux behavior,
portable, future-proof applications should ensure that they specify either
<B>MS_SYNC</B>
or
<B>MS_ASYNC</B>
in
<I>flags</I>.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2)
<P>
B.O. Gallmeister, POSIX.4, O'Reilly, pp. 128-129 and 389-391.
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="7"><A HREF="#lbAB">NAME</A><DD>
<DT id="8"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="9"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="10"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="11"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="12"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="13"><A HREF="#lbAH">AVAILABILITY</A><DD>
<DT id="14"><A HREF="#lbAI">NOTES</A><DD>
<DT id="15"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="16"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:33 GMT, March 31, 2021
</BODY>
</HTML>