Add the lchflags() syscall.
[dragonfly.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: src/lib/libc/sys/madvise.2,v 1.17.2.8 2003/01/06 23:33:59 trhodes Exp $
34 .\" $DragonFly: src/lib/libc/sys/madvise.2,v 1.7 2008/10/06 21:01:37 swildner Exp $
35 .\"
36 .Dd October 6, 2008
37 .Dt MADVISE 2
38 .Os
39 .Sh NAME
40 .Nm madvise ,
41 .Nm posix_madvise ,
42 .Nm mcontrol
43 .Nd give advice about use of memory
44 .Sh LIBRARY
45 .Lb libc
46 .Sh SYNOPSIS
47 .In sys/types.h
48 .In sys/mman.h
49 .Ft int
50 .Fn madvise "void *addr" "size_t len" "int behav"
51 .Ft int
52 .Fn posix_madvise "void *addr" "size_t len" "int behav"
53 .Ft int
54 .Fn mcontrol "void *addr" "size_t len" "int behav" "off_t value"
55 .Sh DESCRIPTION
56 The
57 .Fn madvise
58 system call
59 allows a process that has knowledge of its memory behavior
60 to describe it to the system.
61 The
62 .Fn posix_madvise
63 interface is identical and is provided for standards conformance.
64 The
65 .Fn mcontrol
66 system call is an extension of
67 .Fn madvise
68 that takes an additional
69 .Fa value
70 argument (see the description of the
71 .Dv MADV_SETMAP
72 behavior below).
73 .Pp
74 The known behaviors are:
75 .Bl -tag -width MADV_SEQUENTIAL
76 .It Dv MADV_NORMAL
77 Tells the system to revert to the default paging
78 behavior.
79 .It Dv MADV_RANDOM
80 Is a hint that pages will be accessed randomly, and prefetching
81 is likely not advantageous.
82 .It Dv MADV_SEQUENTIAL
83 Causes the VM system to depress the priority of
84 pages immediately preceding a given page when it is faulted in.
85 .It Dv MADV_WILLNEED
86 Causes pages that are in a given virtual address range
87 to temporarily have higher priority, and if they are in
88 memory, decrease the likelihood of them being freed.  Additionally,
89 the pages that are already in memory will be immediately mapped into
90 the process, thereby eliminating unnecessary overhead of going through
91 the entire process of faulting the pages in.  This WILL NOT fault
92 pages in from backing store, but quickly map the pages already in memory
93 into the calling process.
94 .It Dv MADV_DONTNEED
95 Allows the VM system to decrease the in-memory priority
96 of pages in the specified range.  Additionally future references to
97 this address range will incur a page fault.
98 .It Dv MADV_FREE
99 Gives the VM system the freedom to free pages,
100 and tells the system that information in the specified page range
101 is no longer important.  This is an efficient way of allowing
102 .Xr malloc 3
103 to free pages anywhere in the address space, while keeping the address space
104 valid.  The next time that the page is referenced, the page might be demand
105 zeroed, or might contain the data that was there before the
106 .Dv MADV_FREE
107 call.
108 References made to that address space range will not make the VM system
109 page the information back in from backing store until the page is
110 modified again.
111 .It Dv MADV_NOSYNC
112 Request that the system not flush the data associated with this map to
113 physical backing store unless it needs to.  Typically this prevents the
114 filesystem update daemon from gratuitously writing pages dirtied
115 by the VM system to physical disk.  Note that VM/filesystem coherency is
116 always maintained, this feature simply ensures that the mapped data is
117 only flush when it needs to be, usually by the system pager.
118 .Pp
119 This feature is typically used when you want to use a file-backed shared
120 memory area to communicate between processes (IPC) and do not particularly
121 need the data being stored in that area to be physically written to disk.
122 With this feature you get the equivalent performance with mmap that you
123 would expect to get with SysV shared memory calls, but in a more controllable
124 and less restrictive manner.  However, note that this feature is not portable
125 across
126 .Ux
127 platforms (though some may do the right thing by default).
128 For more information see the MAP_NOSYNC section of
129 .Xr mmap 2
130 .It Dv MADV_AUTOSYNC
131 Undoes the effects of MADV_NOSYNC for any future pages dirtied within the
132 address range.  The effect on pages already dirtied is indeterminate - they
133 may or may not be reverted.  You can guarantee reversion by using the
134 .Xr msync 2
135 or
136 .Xr fsync 2
137 system calls.
138 .It Dv MADV_NOCORE
139 Region is not included in a core file.
140 .It Dv MADV_CORE
141 Include region in a core file.
142 .It Dv MADV_INVAL
143 Invalidate the hardware page table for a region of memory, forcing
144 accesses to re-fault the pages.
145 This command is primarily meant to be used in areas of memory
146 governed by a virtual page table after modifications have been made
147 to it.
148 .It Dv MADV_SETMAP
149 Set the offset of the page directory page to
150 .Fa value
151 for the virtual page table governing
152 the specified area of memory.  The entire memory area under virtual page table
153 management should be specified.  You may encounter unexpected effects
154 if you only set the page directory page for part of the mapping.
155 .El
156 .Pp
157 Portable programs that call the
158 .Fn posix_madvise
159 interface should use the aliases
160 .Dv POSIX_MADV_NORMAL , POSIX_MADV_SEQUENTIAL ,
161 .Dv POSIX_MADV_RANDOM , POSIX_MADV_WILLNEED ,
162 and
163 .Dv POSIX_MADV_DONTNEED
164 rather than the flags described above.
165 .Sh RETURN VALUES
166 .Rv -std madvise posix_madvise mcontrol
167 .Sh ERRORS
168 The
169 .Fn madvise ,
170 .Fn posix_madvise ,
171 and
172 .Fn mcontrol
173 functions will fail if:
174 .Bl -tag -width Er
175 .It Bq Er EINVAL
176 The
177 .Fa behav
178 argument is not valid or the virtual address range specified by the
179 .Fa addr
180 and
181 .Fa len
182 arguments is not valid.
183 .El
184 .Sh SEE ALSO
185 .Xr mincore 2 ,
186 .Xr mprotect 2 ,
187 .Xr msync 2 ,
188 .Xr munmap 2
189 .Sh STANDARDS
190 The
191 .Fn posix_madvise
192 interface conforms to
193 .St -p1003.1-2001 .
194 .Sh HISTORY
195 The
196 .Fn madvise
197 function first appeared in
198 .Bx 4.4 .
199 The
200 .Fn mcontrol
201 function was added in
202 .Dx 1.7 .