]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/sys/mlockall.2
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.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 December 25, 2012
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
72 .Va vm.max_wired
73 and the per-process
74 .Dv RLIMIT_MEMLOCK
75 resource limit.
76 .Pp
77 If
78 .Va security.bsd.unprivileged_mlock
79 is set to 0 these calls are only available to the super-user.
80 If
81 .Va vm.old_mlock
82 is set to 1 the per-process
83 .Dv RLIMIT_MEMLOCK
84 resource limit will not be applied for
85 .Fn mlockall
86 calls.
87 .Pp
88 The
89 .Fn munlockall
90 call unlocks any locked memory regions in the process address space.
91 Any regions mapped after an
92 .Fn munlockall
93 call will not be locked.
94 .Sh RETURN VALUES
95 A return value of 0 indicates that the call
96 succeeded and all pages in the range have either been locked or unlocked.
97 A return value of \-1 indicates an error occurred and the locked
98 status of all pages in the range remains unchanged.
99 In this case, the global location
100 .Va errno
101 is set to indicate the error.
102 .Sh ERRORS
103 .Fn mlockall
104 will fail if:
105 .Bl -tag -width Er
106 .It Bq Er EINVAL
107 The
108 .Fa flags
109 argument is zero, or includes unimplemented flags.
110 .It Bq Er ENOMEM
111 Locking the indicated range would exceed either the system or per-process
112 limit for locked memory.
113 .It Bq Er EAGAIN
114 Some or all of the memory mapped into the process's address space
115 could not be locked when the call was made.
116 .It Bq Er EPERM
117 The calling process does not have the appropriate privilege to perform
118 the requested operation.
119 .El
120 .Sh SEE ALSO
121 .Xr mincore 2 ,
122 .Xr mlock 2 ,
123 .Xr mmap 2 ,
124 .Xr munmap 2 ,
125 .Xr setrlimit 2
126 .Sh STANDARDS
127 The
128 .Fn mlockall
129 and
130 .Fn munlockall
131 functions are believed to conform to
132 .St -p1003.1-2001 .
133 .Sh HISTORY
134 The
135 .Fn mlockall
136 and
137 .Fn munlockall
138 functions first appeared in
139 .Fx 5.1 .
140 .Sh BUGS
141 The per-process resource limit is a limit on the amount of virtual
142 memory locked, while the system-wide limit is for the number of locked
143 physical pages.
144 Hence a process with two distinct locked mappings of the same physical page
145 counts as 2 pages against the per-process limit and as only a single page
146 in the system limit.