xref: /freebsd/lib/libsys/mlockall.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\"	$NetBSD: mlockall.2,v 1.11 2003/04/16 13:34:54 wiz Exp $
2*8269e767SBrooks Davis.\"
3*8269e767SBrooks Davis.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
4*8269e767SBrooks Davis.\" All rights reserved.
5*8269e767SBrooks Davis.\"
6*8269e767SBrooks Davis.\" This code is derived from software contributed to The NetBSD Foundation
7*8269e767SBrooks Davis.\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
8*8269e767SBrooks Davis.\" NASA Ames Research Center.
9*8269e767SBrooks Davis.\"
10*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
11*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
12*8269e767SBrooks Davis.\" are met:
13*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
14*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
15*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
16*8269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
17*8269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
18*8269e767SBrooks Davis.\"
19*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*8269e767SBrooks Davis.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*8269e767SBrooks Davis.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*8269e767SBrooks Davis.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*8269e767SBrooks Davis.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*8269e767SBrooks Davis.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*8269e767SBrooks Davis.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*8269e767SBrooks Davis.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*8269e767SBrooks Davis.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*8269e767SBrooks Davis.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*8269e767SBrooks Davis.\" POSSIBILITY OF SUCH DAMAGE.
30*8269e767SBrooks Davis.\"
31*8269e767SBrooks Davis.Dd May 13, 2019
32*8269e767SBrooks Davis.Dt MLOCKALL 2
33*8269e767SBrooks Davis.Os
34*8269e767SBrooks Davis.Sh NAME
35*8269e767SBrooks Davis.Nm mlockall ,
36*8269e767SBrooks Davis.Nm munlockall
37*8269e767SBrooks Davis.Nd lock (unlock) the address space of a process
38*8269e767SBrooks Davis.Sh LIBRARY
39*8269e767SBrooks Davis.Lb libc
40*8269e767SBrooks Davis.Sh SYNOPSIS
41*8269e767SBrooks Davis.In sys/mman.h
42*8269e767SBrooks Davis.Ft int
43*8269e767SBrooks Davis.Fn mlockall "int flags"
44*8269e767SBrooks Davis.Ft int
45*8269e767SBrooks Davis.Fn munlockall "void"
46*8269e767SBrooks Davis.Sh DESCRIPTION
47*8269e767SBrooks DavisThe
48*8269e767SBrooks Davis.Fn mlockall
49*8269e767SBrooks Davissystem call locks into memory the physical pages associated with the
50*8269e767SBrooks Davisaddress space of a process until the address space is unlocked, the
51*8269e767SBrooks Davisprocess exits, or execs another program image.
52*8269e767SBrooks Davis.Pp
53*8269e767SBrooks DavisThe following flags affect the behavior of
54*8269e767SBrooks Davis.Fn mlockall :
55*8269e767SBrooks Davis.Bl -tag -width ".Dv MCL_CURRENT"
56*8269e767SBrooks Davis.It Dv MCL_CURRENT
57*8269e767SBrooks DavisLock all pages currently mapped into the process's address space.
58*8269e767SBrooks Davis.It Dv MCL_FUTURE
59*8269e767SBrooks DavisLock all pages mapped into the process's address space in the future,
60*8269e767SBrooks Davisat the time the mapping is established.
61*8269e767SBrooks DavisNote that this may cause future mappings to fail if those mappings
62*8269e767SBrooks Daviscause resource limits to be exceeded.
63*8269e767SBrooks Davis.El
64*8269e767SBrooks Davis.Pp
65*8269e767SBrooks DavisSince physical memory is a potentially scarce resource, processes are
66*8269e767SBrooks Davislimited in how much they can lock down.
67*8269e767SBrooks DavisA single process can lock the minimum of a system-wide
68*8269e767SBrooks Davis.Dq wired pages
69*8269e767SBrooks Davislimit
70*8269e767SBrooks Davis.Va vm.max_user_wired
71*8269e767SBrooks Davisand the per-process
72*8269e767SBrooks Davis.Dv RLIMIT_MEMLOCK
73*8269e767SBrooks Davisresource limit.
74*8269e767SBrooks Davis.Pp
75*8269e767SBrooks DavisIf
76*8269e767SBrooks Davis.Va security.bsd.unprivileged_mlock
77*8269e767SBrooks Davisis set to 0 these calls are only available to the super-user.
78*8269e767SBrooks DavisIf
79*8269e767SBrooks Davis.Va vm.old_mlock
80*8269e767SBrooks Davisis set to 1 the per-process
81*8269e767SBrooks Davis.Dv RLIMIT_MEMLOCK
82*8269e767SBrooks Davisresource limit will not be applied for
83*8269e767SBrooks Davis.Fn mlockall
84*8269e767SBrooks Daviscalls.
85*8269e767SBrooks Davis.Pp
86*8269e767SBrooks DavisThe
87*8269e767SBrooks Davis.Fn munlockall
88*8269e767SBrooks Daviscall unlocks any locked memory regions in the process address space.
89*8269e767SBrooks DavisAny regions mapped after an
90*8269e767SBrooks Davis.Fn munlockall
91*8269e767SBrooks Daviscall will not be locked.
92*8269e767SBrooks Davis.Sh RETURN VALUES
93*8269e767SBrooks DavisA return value of 0 indicates that the call
94*8269e767SBrooks Davissucceeded and all pages in the range have either been locked or unlocked.
95*8269e767SBrooks DavisA return value of \-1 indicates an error occurred and the locked
96*8269e767SBrooks Davisstatus of all pages in the range remains unchanged.
97*8269e767SBrooks DavisIn this case, the global location
98*8269e767SBrooks Davis.Va errno
99*8269e767SBrooks Davisis set to indicate the error.
100*8269e767SBrooks Davis.Sh ERRORS
101*8269e767SBrooks Davis.Fn mlockall
102*8269e767SBrooks Daviswill fail if:
103*8269e767SBrooks Davis.Bl -tag -width Er
104*8269e767SBrooks Davis.It Bq Er EINVAL
105*8269e767SBrooks DavisThe
106*8269e767SBrooks Davis.Fa flags
107*8269e767SBrooks Davisargument is zero, or includes unimplemented flags.
108*8269e767SBrooks Davis.It Bq Er ENOMEM
109*8269e767SBrooks DavisLocking the indicated range would exceed either the system or per-process
110*8269e767SBrooks Davislimit for locked memory.
111*8269e767SBrooks Davis.It Bq Er EAGAIN
112*8269e767SBrooks DavisSome or all of the memory mapped into the process's address space
113*8269e767SBrooks Daviscould not be locked when the call was made.
114*8269e767SBrooks Davis.It Bq Er EPERM
115*8269e767SBrooks DavisThe calling process does not have the appropriate privilege to perform
116*8269e767SBrooks Davisthe requested operation.
117*8269e767SBrooks Davis.El
118*8269e767SBrooks Davis.Sh SEE ALSO
119*8269e767SBrooks Davis.Xr mincore 2 ,
120*8269e767SBrooks Davis.Xr mlock 2 ,
121*8269e767SBrooks Davis.Xr mmap 2 ,
122*8269e767SBrooks Davis.Xr munmap 2 ,
123*8269e767SBrooks Davis.Xr setrlimit 2
124*8269e767SBrooks Davis.Sh STANDARDS
125*8269e767SBrooks DavisThe
126*8269e767SBrooks Davis.Fn mlockall
127*8269e767SBrooks Davisand
128*8269e767SBrooks Davis.Fn munlockall
129*8269e767SBrooks Davisfunctions are believed to conform to
130*8269e767SBrooks Davis.St -p1003.1-2001 .
131*8269e767SBrooks Davis.Sh HISTORY
132*8269e767SBrooks DavisThe
133*8269e767SBrooks Davis.Fn mlockall
134*8269e767SBrooks Davisand
135*8269e767SBrooks Davis.Fn munlockall
136*8269e767SBrooks Davisfunctions first appeared in
137*8269e767SBrooks Davis.Fx 5.1 .
138*8269e767SBrooks Davis.Sh BUGS
139*8269e767SBrooks DavisThe per-process and system-wide resource limits of locked memory apply
140*8269e767SBrooks Davisto the amount of virtual memory locked, not the amount of locked physical
141*8269e767SBrooks Davispages.
142*8269e767SBrooks DavisHence two distinct locked mappings of the same physical page counts as
143*8269e767SBrooks Davis2 pages aginst the system limit, and also against the per-process limit
144*8269e767SBrooks Davisif both mappings belong to the same physical map.
145