xref: /freebsd/lib/libsys/mlockall.2 (revision a64729f5077d77e13b9497cb33ecb3c82e606ee8)
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.Dd May 13, 2019
32.Dt MLOCKALL 2
33.Os
34.Sh NAME
35.Nm mlockall ,
36.Nm munlockall
37.Nd lock (unlock) the address space of a process
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In sys/mman.h
42.Ft int
43.Fn mlockall "int flags"
44.Ft int
45.Fn munlockall "void"
46.Sh DESCRIPTION
47The
48.Fn mlockall
49system call locks into memory the physical pages associated with the
50address space of a process until the address space is unlocked, the
51process exits, or execs another program image.
52.Pp
53The following flags affect the behavior of
54.Fn mlockall :
55.Bl -tag -width ".Dv MCL_CURRENT"
56.It Dv MCL_CURRENT
57Lock all pages currently mapped into the process's address space.
58.It Dv MCL_FUTURE
59Lock all pages mapped into the process's address space in the future,
60at the time the mapping is established.
61Note that this may cause future mappings to fail if those mappings
62cause resource limits to be exceeded.
63.El
64.Pp
65Since physical memory is a potentially scarce resource, processes are
66limited in how much they can lock down.
67A single process can lock the minimum of a system-wide
68.Dq wired pages
69limit
70.Va vm.max_user_wired
71and the per-process
72.Dv RLIMIT_MEMLOCK
73resource limit.
74.Pp
75If
76.Va security.bsd.unprivileged_mlock
77is set to 0 these calls are only available to the super-user.
78If
79.Va vm.old_mlock
80is set to 1 the per-process
81.Dv RLIMIT_MEMLOCK
82resource limit will not be applied for
83.Fn mlockall
84calls.
85.Pp
86The
87.Fn munlockall
88call unlocks any locked memory regions in the process address space.
89Any regions mapped after an
90.Fn munlockall
91call will not be locked.
92.Sh RETURN VALUES
93A return value of 0 indicates that the call
94succeeded and all pages in the range have either been locked or unlocked.
95A return value of \-1 indicates an error occurred and the locked
96status of all pages in the range remains unchanged.
97In this case, the global location
98.Va errno
99is set to indicate the error.
100.Sh ERRORS
101.Fn mlockall
102will fail if:
103.Bl -tag -width Er
104.It Bq Er EINVAL
105The
106.Fa flags
107argument is zero, or includes unimplemented flags.
108.It Bq Er ENOMEM
109Locking the indicated range would exceed either the system or per-process
110limit for locked memory.
111.It Bq Er EAGAIN
112Some or all of the memory mapped into the process's address space
113could not be locked when the call was made.
114.It Bq Er EPERM
115The calling process does not have the appropriate privilege to perform
116the requested operation.
117.El
118.Sh SEE ALSO
119.Xr mincore 2 ,
120.Xr mlock 2 ,
121.Xr mmap 2 ,
122.Xr munmap 2 ,
123.Xr setrlimit 2
124.Sh STANDARDS
125The
126.Fn mlockall
127and
128.Fn munlockall
129functions are believed to conform to
130.St -p1003.1-2001 .
131.Sh HISTORY
132The
133.Fn mlockall
134and
135.Fn munlockall
136functions first appeared in
137.Fx 5.1 .
138.Sh BUGS
139The per-process and system-wide resource limits of locked memory apply
140to the amount of virtual memory locked, not the amount of locked physical
141pages.
142Hence two distinct locked mappings of the same physical page counts as
1432 pages aginst the system limit, and also against the per-process limit
144if both mappings belong to the same physical map.
145