xref: /openbsd/lib/libc/sys/mlockall.2 (revision 898184e3)
1.\"	$OpenBSD: mlockall.2,v 1.5 2008/06/26 05:42:05 ray Exp $
2.\"	$NetBSD: mlockall.2,v 1.6 2000/06/26 17:00:02 kleink Exp $
3.\"
4.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9.\" NASA Ames Research Center.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\"    notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\"    notice, this list of conditions and the following disclaimer in the
18.\"    documentation and/or other materials provided with the distribution.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30.\" POSSIBILITY OF SUCH DAMAGE.
31.\"
32.Dd $Mdocdate: June 26 2008 $
33.Dt MLOCKALL 2
34.Os
35.Sh NAME
36.Nm mlockall ,
37.Nm munlockall
38.Nd lock (unlock) the address space of a process
39.Sh SYNOPSIS
40.Fd #include <sys/types.h>
41.Fd #include <sys/mman.h>
42.Ft int
43.Fn mlockall "int flags"
44.Ft int
45.Fn munlockall "void"
46.Sh DESCRIPTION
47The
48.Nm 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.Nm mlockall :
55.Bl -tag -width 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 and the per-process
70.Dv RLIMIT_MEMLOCK
71resource limit.
72.Pp
73The
74.Nm munlockall
75call unlocks any locked memory regions in the process address space.
76Any regions mapped after an
77.Nm munlockall
78call will not be locked.
79.Sh RETURN VALUES
80A return value of 0 indicates that the call
81succeeded and all pages in the range have either been locked or unlocked.
82A return value of -1 indicates an error occurred and the locked
83status of all pages in the range remains unchanged.
84In this case, the global location
85.Va errno
86is set to indicate the error.
87.Sh ERRORS
88.Fn mlockall
89will fail if:
90.Bl -tag -width Er
91.It Bq Er EINVAL
92The
93.Ar flags
94argument is zero or includes unimplemented flags or
95.Fa addr
96and
97.Fa size
98specify a region that would extend beyond the end of the address space.
99.It Bq Er ENOMEM
100Locking the indicated range would exceed either the system or per-process
101limit for locked memory.
102.It Bq Er EAGAIN
103Some or all of the memory mapped into the process's address space
104could not be locked when the call was made.
105.It Bq Er EPERM
106The calling process does not have the appropriate privileges to perform
107the 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
116The
117.Fn mlockall
118and
119.Fn munlockall
120functions conform to
121.St -p1003.1b-93 .
122.Sh HISTORY
123The
124.Fn mlockall
125and
126.Fn munlockall
127functions first appeared in
128.Ox 2.9 .
129.Sh BUGS
130The per-process resource limit is a limit on the amount of virtual
131memory locked, while the system-wide limit is for the number of locked
132physical pages.
133Hence a process with two distinct locked mappings of the same physical page
134counts as 2 pages against the per-process limit and only as a single page
135in the system limit.
136