]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/madvise.2
This commit was generated by cvs2svn to compensate for changes in r147078,
[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 , posix_madvise
40 .Nd give advice about use of memory
41 .Sh LIBRARY
42 .Lb libc
43 .Sh SYNOPSIS
44 .In sys/mman.h
45 .Ft int
46 .Fn madvise "void *addr" "size_t len" "int behav"
47 .Ft int
48 .Fn posix_madvise "void *addr" "size_t len" "int behav"
49 .Sh DESCRIPTION
50 The
51 .Fn madvise
52 system call
53 allows a process that has knowledge of its memory behavior
54 to describe it to the system.
55 The
56 .Fn posix_madvise
57 interface is identical and is provided for standards conformance.
58 .Pp
59 The known behaviors are:
60 .Bl -tag -width MADV_SEQUENTIAL
61 .It Dv MADV_NORMAL
62 Tells the system to revert to the default paging
63 behavior.
64 .It Dv MADV_RANDOM
65 Is a hint that pages will be accessed randomly, and prefetching
66 is likely not advantageous.
67 .It Dv MADV_SEQUENTIAL
68 Causes the VM system to depress the priority of
69 pages immediately preceding a given page when it is faulted in.
70 .It Dv MADV_WILLNEED
71 Causes pages that are in a given virtual address range
72 to temporarily have higher priority, and if they are in
73 memory, decrease the likelihood of them being freed.
74 Additionally,
75 the pages that are already in memory will be immediately mapped into
76 the process, thereby eliminating unnecessary overhead of going through
77 the entire process of faulting the pages in.
78 This WILL NOT fault
79 pages in from backing store, but quickly map the pages already in memory
80 into the calling process.
81 .It Dv MADV_DONTNEED
82 Allows the VM system to decrease the in-memory priority
83 of pages in the specified range.
84 Additionally future references to
85 this address range will incur a page fault.
86 .It Dv MADV_FREE
87 Gives the VM system the freedom to free pages,
88 and tells the system that information in the specified page range
89 is no longer important.
90 This is an efficient way of allowing
91 .Xr malloc 3
92 to free pages anywhere in the address space, while keeping the address space
93 valid.
94 The next time that the page is referenced, the page might be demand
95 zeroed, or might contain the data that was there before the
96 .Dv MADV_FREE
97 call.
98 References made to that address space range will not make the VM system
99 page the information back in from backing store until the page is
100 modified again.
101 .It Dv MADV_NOSYNC
102 Request that the system not flush the data associated with this map to
103 physical backing store unless it needs to.
104 Typically this prevents the
105 file system update daemon from gratuitously writing pages dirtied
106 by the VM system to physical disk.
107 Note that VM/file system coherency is
108 always maintained, this feature simply ensures that the mapped data is
109 only flush when it needs to be, usually by the system pager.
110 .Pp
111 This feature is typically used when you want to use a file-backed shared
112 memory area to communicate between processes (IPC) and do not particularly
113 need the data being stored in that area to be physically written to disk.
114 With this feature you get the equivalent performance with mmap that you
115 would expect to get with SysV shared memory calls, but in a more controllable
116 and less restrictive manner.
117 However, note that this feature is not portable
118 across UNIX platforms (though some may do the right thing by default).
119 For more information see the MAP_NOSYNC section of
120 .Xr mmap 2
121 .It Dv MADV_AUTOSYNC
122 Undoes the effects of MADV_NOSYNC for any future pages dirtied within the
123 address range.
124 The effect on pages already dirtied is indeterminate - they
125 may or may not be reverted.
126 You can guarantee reversion by using the
127 .Xr msync 2
128 or
129 .Xr fsync 2
130 system calls.
131 .It Dv MADV_NOCORE
132 Region is not included in a core file.
133 .It Dv MADV_CORE
134 Include region in a core file.
135 .It Dv MADV_PROTECT
136 Informs the VM system this process should not be killed when the
137 swap space is exhausted.
138 The process must have superuser privileges.
139 This should be used judiciously in processes that must remain running
140 for the system to properly function.
141 .El
142 .Pp
143 Portable programs that call the
144 .Fn posix_madvise
145 interface should use the aliases
146 .Dv POSIX_MADV_NORMAL , POSIX_MADV_SEQUENTIAL ,
147 .Dv POSIX_MADV_RANDOM , POSIX_MADV_WILLNEED ,
148 and
149 .Dv POSIX_MADV_DONTNEED
150 rather than the flags described above.
151 .Sh RETURN VALUES
152 .Rv -std madvise
153 .Sh ERRORS
154 The
155 .Fn madvise
156 system call will fail if:
157 .Bl -tag -width Er
158 .It Bq Er EINVAL
159 The
160 .Fa behav
161 argument is not valid.
162 .It Bq Er ENOMEM
163 The virtual address range specified by the
164 .Fa addr
165 and
166 .Fa len
167 arguments is not valid.
168 .It Bq Er EPERM
169 .Dv MADV_PROTECT
170 was specified and the process does not have superuser privileges.
171 .El
172 .Sh SEE ALSO
173 .Xr mincore 2 ,
174 .Xr mprotect 2 ,
175 .Xr msync 2 ,
176 .Xr munmap 2
177 .Sh STANDARDS
178 The
179 .Fn posix_madvise
180 interface conforms to
181 .St -p1003.1-2001 .
182 .Sh HISTORY
183 The
184 .Fn madvise
185 system call first appeared in
186 .Bx 4.4 .