1MSYNC(2)                   Linux Programmer's Manual                  MSYNC(2)
2
3
4

NAME

6       msync - synchronize a file with a memory map
7

SYNOPSIS

9       #include <sys/mman.h>
10
11       int msync(void *addr, size_t length, int flags);
12

DESCRIPTION

14       msync()  flushes  changes  made  to the in-core copy of a file that was
15       mapped into memory using mmap(2) back to the filesystem.   Without  use
16       of  this  call,  there  is  no  guarantee that changes are written back
17       before munmap(2) is called.  To be more precise, the part of  the  file
18       that  corresponds to the memory area starting at addr and having length
19       length is updated.
20
21       The flags argument should specify exactly one of MS_ASYNC and  MS_SYNC,
22       and  may  additionally  include the MS_INVALIDATE bit.  These bits have
23       the following meanings:
24
25       MS_ASYNC
26              Specifies that an update be  scheduled,  but  the  call  returns
27              immediately.
28
29       MS_SYNC
30              Requests an update and waits for it to complete.
31
32       MS_INVALIDATE
33              Asks to invalidate other mappings of the same file (so that they
34              can be updated with the fresh values just written).
35

RETURN VALUE

37       On success, zero is returned.  On error, -1 is returned, and  errno  is
38       set appropriately.
39

ERRORS

41       EBUSY  MS_INVALIDATE  was  specified in flags, and a memory lock exists
42              for the specified address range.
43
44       EINVAL addr is not a multiple  of  PAGESIZE;  or  any  bit  other  than
45              MS_ASYNC  |  MS_INVALIDATE  |  MS_SYNC  is set in flags; or both
46              MS_SYNC and MS_ASYNC are set in flags.
47
48       ENOMEM The indicated memory (or part of it) was not mapped.
49

CONFORMING TO

51       POSIX.1-2001, POSIX.1-2008.
52
53       This call was introduced in Linux 1.3.21, and then used EFAULT  instead
54       of  ENOMEM.   In  Linux  2.4.19,  this  was  changed to the POSIX value
55       ENOMEM.
56

AVAILABILITY

58       On   POSIX   systems   on   which   msync()    is    available,    both
59       _POSIX_MAPPED_FILES   and   _POSIX_SYNCHRONIZED_IO   are   defined   in
60       <unistd.h> to a value greater than 0.  (See also sysconf(3).)
61

NOTES

63       According to POSIX, either MS_SYNC or MS_ASYNC  must  be  specified  in
64       flags,  and  indeed  failure  to  include one of these flags will cause
65       msync() to fail on some systems.  However,  Linux  permits  a  call  to
66       msync()  that specifies neither of these flags, with semantics that are
67       (currently) equivalent to specifying MS_ASYNC.   (Since  Linux  2.6.19,
68       MS_ASYNC  is  in  fact  a no-op, since the kernel properly tracks dirty
69       pages and flushes them to storage as necessary.)   Notwithstanding  the
70       Linux  behavior, portable, future-proof applications should ensure that
71       they specify either MS_SYNC or MS_ASYNC in flags.
72

SEE ALSO

74       mmap(2)
75
76       B.O. Gallmeister, POSIX.4, O'Reilly, pp. 128–129 and 389–391.
77

COLOPHON

79       This page is part of release 5.04 of the Linux  man-pages  project.   A
80       description  of  the project, information about reporting bugs, and the
81       latest    version    of    this    page,    can     be     found     at
82       https://www.kernel.org/doc/man-pages/.
83
84
85
86Linux                             2017-09-15                          MSYNC(2)
Impressum