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