]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/libc/sys/mlockall.2
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / lib / libc / sys / mlockall.2
1 .\"     $NetBSD: mlockall.2,v 1.11 2003/04/16 13:34:54 wiz Exp $
2 .\"
3 .\" Copyright (c) 1999 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
5 .\"
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
8 .\" NASA Ames Research Center.
9 .\"
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
12 .\" are met:
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\"    notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\"    notice, this list of conditions and the following disclaimer in the
17 .\"    documentation and/or other materials provided with the distribution.
18 .\" 3. All advertising materials mentioning features or use of this software
19 .\"    must display the following acknowledgement:
20 .\"        This product includes software developed by the NetBSD
21 .\"        Foundation, Inc. and its contributors.
22 .\" 4. Neither the name of The NetBSD Foundation nor the names of its
23 .\"    contributors may be used to endorse or promote products derived
24 .\"    from this software without specific prior written permission.
25 .\"
26 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 .\" POSSIBILITY OF SUCH DAMAGE.
37 .\"
38 .\" $FreeBSD$
39 .\"
40 .Dd June 12, 1999
41 .Dt MLOCKALL 2
42 .Os
43 .Sh NAME
44 .Nm mlockall ,
45 .Nm munlockall
46 .Nd lock (unlock) the address space of a process
47 .Sh LIBRARY
48 .Lb libc
49 .Sh SYNOPSIS
50 .In sys/mman.h
51 .Ft int
52 .Fn mlockall "int flags"
53 .Ft int
54 .Fn munlockall "void"
55 .Sh DESCRIPTION
56 The
57 .Fn mlockall
58 system call locks into memory the physical pages associated with the
59 address space of a process until the address space is unlocked, the
60 process exits, or execs another program image.
61 .Pp
62 The following flags affect the behavior of
63 .Fn mlockall :
64 .Bl -tag -width ".Dv MCL_CURRENT"
65 .It Dv MCL_CURRENT
66 Lock all pages currently mapped into the process's address space.
67 .It Dv MCL_FUTURE
68 Lock all pages mapped into the process's address space in the future,
69 at the time the mapping is established.
70 Note that this may cause future mappings to fail if those mappings
71 cause resource limits to be exceeded.
72 .El
73 .Pp
74 Since physical memory is a potentially scarce resource, processes are
75 limited in how much they can lock down.
76 A single process can lock the minimum of a system-wide
77 .Dq wired pages
78 limit and the per-process
79 .Dv RLIMIT_MEMLOCK
80 resource limit.
81 .Pp
82 The
83 .Fn munlockall
84 call unlocks any locked memory regions in the process address space.
85 Any regions mapped after an
86 .Fn munlockall
87 call will not be locked.
88 .Sh RETURN VALUES
89 A return value of 0 indicates that the call
90 succeeded and all pages in the range have either been locked or unlocked.
91 A return value of \-1 indicates an error occurred and the locked
92 status of all pages in the range remains unchanged.
93 In this case, the global location
94 .Va errno
95 is set to indicate the error.
96 .Sh ERRORS
97 .Fn mlockall
98 will fail if:
99 .Bl -tag -width Er
100 .It Bq Er EINVAL
101 The
102 .Fa flags
103 argument is zero, or includes unimplemented flags.
104 .It Bq Er ENOMEM
105 Locking the indicated range would exceed either the system or per-process
106 limit for locked memory.
107 .It Bq Er EAGAIN
108 Some or all of the memory mapped into the process's address space
109 could not be locked when the call was made.
110 .It Bq Er EPERM
111 The calling process does not have the appropriate privilege to perform
112 the requested operation.
113 .El
114 .Sh SEE ALSO
115 .Xr mincore 2 ,
116 .Xr mlock 2 ,
117 .Xr mmap 2 ,
118 .Xr munmap 2 ,
119 .Xr setrlimit 2
120 .Sh STANDARDS
121 The
122 .Fn mlockall
123 and
124 .Fn munlockall
125 functions are believed to conform to
126 .St -p1003.1-2001 .
127 .Sh HISTORY
128 The
129 .Fn mlockall
130 and
131 .Fn munlockall
132 functions first appeared in
133 .Fx 5.1 .
134 .Sh BUGS
135 The per-process resource limit is a limit on the amount of virtual
136 memory locked, while the system-wide limit is for the number of locked
137 physical pages.
138 Hence a process with two distinct locked mappings of the same physical page
139 counts as 2 pages against the per-process limit and as only a single page
140 in the system limit.