]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - lib/libc/sys/mlockall.2
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.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 .\"
19 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 .\" POSSIBILITY OF SUCH DAMAGE.
30 .\"
31 .\" $FreeBSD$
32 .\"
33 .Dd July 27, 2010
34 .Dt MLOCKALL 2
35 .Os
36 .Sh NAME
37 .Nm mlockall ,
38 .Nm munlockall
39 .Nd lock (unlock) the address space of a process
40 .Sh LIBRARY
41 .Lb libc
42 .Sh SYNOPSIS
43 .In sys/mman.h
44 .Ft int
45 .Fn mlockall "int flags"
46 .Ft int
47 .Fn munlockall "void"
48 .Sh DESCRIPTION
49 The
50 .Fn mlockall
51 system call locks into memory the physical pages associated with the
52 address space of a process until the address space is unlocked, the
53 process exits, or execs another program image.
54 .Pp
55 The following flags affect the behavior of
56 .Fn mlockall :
57 .Bl -tag -width ".Dv MCL_CURRENT"
58 .It Dv MCL_CURRENT
59 Lock all pages currently mapped into the process's address space.
60 .It Dv MCL_FUTURE
61 Lock all pages mapped into the process's address space in the future,
62 at the time the mapping is established.
63 Note that this may cause future mappings to fail if those mappings
64 cause resource limits to be exceeded.
65 .El
66 .Pp
67 Since physical memory is a potentially scarce resource, processes are
68 limited in how much they can lock down.
69 A single process can lock the minimum of a system-wide
70 .Dq wired pages
71 limit and the per-process
72 .Dv RLIMIT_MEMLOCK
73 resource limit.
74 .Pp
75 These calls are only available to the super-user.
76 .Pp
77 The
78 .Fn munlockall
79 call unlocks any locked memory regions in the process address space.
80 Any regions mapped after an
81 .Fn munlockall
82 call will not be locked.
83 .Sh RETURN VALUES
84 A return value of 0 indicates that the call
85 succeeded and all pages in the range have either been locked or unlocked.
86 A return value of \-1 indicates an error occurred and the locked
87 status of all pages in the range remains unchanged.
88 In this case, the global location
89 .Va errno
90 is set to indicate the error.
91 .Sh ERRORS
92 .Fn mlockall
93 will fail if:
94 .Bl -tag -width Er
95 .It Bq Er EINVAL
96 The
97 .Fa flags
98 argument is zero, or includes unimplemented flags.
99 .It Bq Er ENOMEM
100 Locking the indicated range would exceed either the system or per-process
101 limit for locked memory.
102 .It Bq Er EAGAIN
103 Some or all of the memory mapped into the process's address space
104 could not be locked when the call was made.
105 .It Bq Er EPERM
106 The calling process does not have the appropriate privilege to perform
107 the requested operation.
108 .El
109 .Sh SEE ALSO
110 .Xr mincore 2 ,
111 .Xr mlock 2 ,
112 .Xr mmap 2 ,
113 .Xr munmap 2 ,
114 .Xr setrlimit 2
115 .Sh STANDARDS
116 The
117 .Fn mlockall
118 and
119 .Fn munlockall
120 functions are believed to conform to
121 .St -p1003.1-2001 .
122 .Sh HISTORY
123 The
124 .Fn mlockall
125 and
126 .Fn munlockall
127 functions first appeared in
128 .Fx 5.1 .
129 .Sh BUGS
130 The per-process resource limit is a limit on the amount of virtual
131 memory locked, while the system-wide limit is for the number of locked
132 physical pages.
133 Hence a process with two distinct locked mappings of the same physical page
134 counts as 2 pages against the per-process limit and as only a single page
135 in the system limit.