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