Deleted Added
full compact
madvise.2 (14326) madvise.2 (17229)
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.

--- 17 unchanged lines hidden (view full) ---

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.\"
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.

--- 17 unchanged lines hidden (view full) ---

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.\"
34.Dd June 9, 1993
34.Dd Jul 19, 1996
35.Dt MADVISE 2
36.Os
37.Sh NAME
38.Nm madvise
39.Nd give advise about use of memory
40.Sh SYNOPSIS
41.Fd #include <sys/types.h>
42.Fd #include <sys/mman.h>
43.Fn madvise "caddr_t addr" "size_t len" "int behav"
44.Sh DESCRIPTION
45The
46.Fn madvise
47system call
48allows a process that has knowledge of its memory behavior
49to describe it to the system.
50The known behaviors are given in
51.Pa <sys/mman.h> :
52.Bd -literal
35.Dt MADVISE 2
36.Os
37.Sh NAME
38.Nm madvise
39.Nd give advise about use of memory
40.Sh SYNOPSIS
41.Fd #include <sys/types.h>
42.Fd #include <sys/mman.h>
43.Fn madvise "caddr_t addr" "size_t len" "int behav"
44.Sh DESCRIPTION
45The
46.Fn madvise
47system call
48allows a process that has knowledge of its memory behavior
49to describe it to the system.
50The known behaviors are given in
51.Pa <sys/mman.h> :
52.Bd -literal
53#define MADV_NORMAL 0 /* no further special treatment */
54#define MADV_RANDOM 1 /* expect random page references */
55#define MADV_SEQUENTIAL 2 /* expect sequential references */
56#define MADV_WILLNEED 3 /* will need these pages */
57#define MADV_DONTNEED 4 /* don't need these pages */
58#define MADV_SPACEAVAIL 5 /* insure that resources are reserved */
53#define MADV_NORMAL 0 /* no further special treatment */
54#define MADV_RANDOM 1 /* expect random page references */
55#define MADV_SEQUENTIAL 2 /* expect sequential references */
56#define MADV_WILLNEED 3 /* will need these pages */
57#define MADV_DONTNEED 4 /* don't need these pages */
58#define MADV_FREE 5 /* data is now unimportant */
59.Ed
59.Ed
60.sp
61MADV_NORMAL tells the system to revert to the default paging
62behavior.
63.sp
64MADV_RANDOM is a hint that pages will be accessed randomly, and prefetching
65is likely not advantageous.
66.sp
67MADV_SEQUENTIAL causes the VM system to depress the priority of
68pages immediately preceeding a given page when it is faulted in.
69.sp
70MADV_WILLNEED causes pages that are in a given virtual address range
71to temporarily have higher priority, and if they are in
72memory, decrease the likelihood of them being freed. Additionally,
73the pages that are already in memory will be immediately mapped into
74the process, thereby eliminating unnecessary overhead of going through
75the entire process of faulting the pages in. This WILL NOT fault
76pages in from backing store, but quickly map the pages already in memory
77into the calling process.
78.sp
79MADV_DONTNEED allows the VM system to decrease the in-memory priority
80of pages in the specified range. Additionally future references to
81this address range will incur a page fault.
82.sp
83MADV_FREE gives the VM system the freedom to free pages,
84and and tells the system that information in the specified page range
85is no longer important. This is an efficient way of allowing malloc(3) to
86free pages anywhere in the address space, while keeping the address space
87valid. The next time that the page is referenced, the page might be demand
88zeroed, or might contain the data that was there before the MADV_FREE call.
89References made to that address space range will not make the VM system
90page the information back in from backing store until the page is
91modified again.
92
60.Sh SEE ALSO
61.Xr msync 2 ,
62.Xr munmap 2 ,
63.Xr mprotect 2 ,
64.Xr mincore 2 .
65
93.Sh SEE ALSO
94.Xr msync 2 ,
95.Xr munmap 2 ,
96.Xr mprotect 2 ,
97.Xr mincore 2 .
98
66.Sh BUGS
67.Nm madvise
68is not yet implemented.
69
70.Sh HISTORY
71The
72.Nm madvise
73function first appeared in 4.4BSD.
99.Sh HISTORY
100The
101.Nm madvise
102function first appeared in 4.4BSD.