1MSYNC(2) Linux Programmer's Manual MSYNC(2)
2
3
4
6 msync - synchronize a file with a memory map
7
9 #include <sys/mman.h>
10
11 int msync(void *addr, size_t length, int flags);
12
14 msync() flushes changes made to the in-core copy of a file that was
15 mapped into memory using mmap(2) back to disk. Without use of this
16 call there is no guarantee that changes are written back before mun‐
17 map(2) is called. To be more precise, the part of the file that corre‐
18 sponds to the memory area starting at addr and having length length is
19 updated.
20
21 The flags argument may have the bits MS_ASYNC, MS_SYNC, and MS_INVALI‐
22 DATE set, but not both MS_ASYNC and MS_SYNC. MS_ASYNC specifies that
23 an update be scheduled, but the call returns immediately. MS_SYNC asks
24 for an update and waits for it to complete. MS_INVALIDATE asks to
25 invalidate other mappings of the same file (so that they can be updated
26 with the fresh values just written).
27
29 On success, zero is returned. On error, -1 is returned, and errno is
30 set appropriately.
31
33 EBUSY MS_INVALIDATE was specified in flags, and a memory lock exists
34 for the specified address range.
35
36 EINVAL addr is not a multiple of PAGESIZE; or any bit other than
37 MS_ASYNC | MS_INVALIDATE | MS_SYNC is set in flags; or both
38 MS_SYNC and MS_ASYNC are set in flags.
39
40 ENOMEM The indicated memory (or part of it) was not mapped.
41
43 POSIX.1-2001.
44
45 This call was introduced in Linux 1.3.21, and then used EFAULT instead
46 of ENOMEM. In Linux 2.4.19 this was changed to the POSIX value ENOMEM.
47
49 On POSIX systems on which msync() is available, both
50 _POSIX_MAPPED_FILES and _POSIX_SYNCHRONIZED_IO are defined in
51 <unistd.h> to a value greater than 0. (See also sysconf(3).)
52
54 mmap(2)
55
56 B.O. Gallmeister, POSIX.4, O'Reilly, pp. 128-129 and 389-391.
57
59 This page is part of release 3.53 of the Linux man-pages project. A
60 description of the project, and information about reporting bugs, can
61 be found at http://www.kernel.org/doc/man-pages/.
62
63
64
65Linux 2008-04-22 MSYNC(2)