]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/madvise.2
Use the ``.Rv -std'' mdoc(7) macro in appropriate cases.
[FreeBSD/FreeBSD.git] / lib / libc / sys / madvise.2
1 .\" Copyright (c) 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)madvise.2   8.1 (Berkeley) 6/9/93
33 .\" $FreeBSD$
34 .\"
35 .Dd July 19, 1996
36 .Dt MADVISE 2
37 .Os
38 .Sh NAME
39 .Nm madvise
40 .Nd give advice about use of memory
41 .Sh LIBRARY
42 .Lb libc
43 .Sh SYNOPSIS
44 .Fd #include <sys/types.h>
45 .Fd #include <sys/mman.h>
46 .Ft int
47 .Fn madvise "void *addr" "size_t len" "int behav"
48 .Sh DESCRIPTION
49 The
50 .Fn madvise
51 system call
52 allows a process that has knowledge of its memory behavior
53 to describe it to the system.
54 The known behaviors are given in
55 .Aq Pa sys/mman.h :
56 .Bd -literal
57 #define MADV_NORMAL     0 /* no further special treatment */
58 #define MADV_RANDOM     1 /* expect random page references */
59 #define MADV_SEQUENTIAL 2 /* expect sequential references */
60 #define MADV_WILLNEED   3 /* will need these pages */
61 #define MADV_DONTNEED   4 /* don't need these pages */
62 #define MADV_FREE       5 /* data is now unimportant */
63 #define MADV_NOSYNC     6 /* no explicit commit to physical backing store */
64 #define MADV_AUTOSYNC   7 /* default commit method to physical backing store */
65 #define MADV_NOCORE     8 /* do not include these pages in a core file */
66 #define MADV_CORE       9 /* revert to including pages in a core file */
67 .Ed
68 .Pp
69 .Bl -tag -width MADV_SEQUENTIAL
70 .It Dv MADV_NORMAL
71 Tells the system to revert to the default paging
72 behavior.
73 .It Dv MADV_RANDOM
74 Is a hint that pages will be accessed randomly, and prefetching
75 is likely not advantageous.
76 .It Dv MADV_SEQUENTIAL
77 Causes the VM system to depress the priority of
78 pages immediately preceding a given page when it is faulted in.
79 .It Dv MADV_WILLNEED
80 Causes pages that are in a given virtual address range
81 to temporarily have higher priority, and if they are in
82 memory, decrease the likelihood of them being freed.  Additionally,
83 the pages that are already in memory will be immediately mapped into
84 the process, thereby eliminating unnecessary overhead of going through
85 the entire process of faulting the pages in.  This WILL NOT fault
86 pages in from backing store, but quickly map the pages already in memory
87 into the calling process.
88 .It Dv MADV_DONTNEED
89 Allows the VM system to decrease the in-memory priority
90 of pages in the specified range.  Additionally future references to
91 this address range will incur a page fault.
92 .It Dv MADV_FREE
93 Gives the VM system the freedom to free pages,
94 and tells the system that information in the specified page range
95 is no longer important.  This is an efficient way of allowing
96 .Xr malloc 3
97 to free pages anywhere in the address space, while keeping the address space
98 valid.  The next time that the page is referenced, the page might be demand
99 zeroed, or might contain the data that was there before the
100 .Dv MADV_FREE
101 call.
102 References made to that address space range will not make the VM system
103 page the information back in from backing store until the page is
104 modified again.
105 .It Dv MADV_NOSYNC
106 Request that the system not flush the data associated with this map to
107 physical backing store unless it needs to.  Typically this prevents the
108 filesystem update daemon from gratuitously writing pages dirtied
109 by the VM system to physical disk.  Note that VM/filesystem coherency is
110 always maintained, this feature simply ensures that the mapped data is
111 only flush when it needs to be, usually by the system pager.
112 .Pp
113 This feature is typically used when you want to use a file-backed shared
114 memory area to communicate between processes (IPC) and do not particularly
115 need the data being stored in that area to be physically written to disk.
116 With this feature you get the equivalent performance with mmap that you
117 would expect to get with SysV shared memory calls, but in a more controllable
118 and less restrictive manner.  However, note that this feature is not portable
119 across UNIX platforms (though some may do the right thing by default).
120 For more information see the MAP_NOSYNC section of
121 .Xr mmap 2
122 .It Dv MADV_AUTOSYNC
123 Undoes the effects of MADV_NOSYNC for any future pages dirtied within the
124 address range.  The effect on pages already dirtied is indeterminate - they
125 may or may not be reverted.  You can guarentee reversion by using the
126 .Xr msync 2
127 or
128 .Xr fsync 2
129 system calls.
130 .It Dv MADV_NOCORE
131 Region is not included in a core file.
132 .It Dv MADV_CORE
133 Include region in a core file.
134 .El
135 .Sh RETURN VALUES
136 .Rv -std madvise
137 .Sh ERRORS
138 The
139 .Fn madvise
140 function will fail if:
141 .Bl -tag -width Er
142 .It Bq Er EINVAL
143 The virtual address range specified by the
144 .Fa addr
145 and
146 .Fa len
147 arguments is not valid.
148 .El
149 .Sh SEE ALSO
150 .Xr mincore 2 ,
151 .Xr mprotect 2 ,
152 .Xr msync 2 ,
153 .Xr munmap 2
154 .Sh HISTORY
155 The
156 .Fn madvise
157 function first appeared in
158 .Bx 4.4 .