xref: /netbsd/lib/libc/sys/mlockall.2 (revision bf9ec67e)
1.\"	$NetBSD: mlockall.2,v 1.8 2002/02/08 01:28:19 ross 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.\" 3. All advertising materials mentioning features or use of this software
19.\"    must display the following acknowledgement:
20.\"        This product includes software developed by the NetBSD
21.\"        Foundation, Inc. and its contributors.
22.\" 4. Neither the name of The NetBSD Foundation nor the names of its
23.\"    contributors may be used to endorse or promote products derived
24.\"    from this software without specific prior written permission.
25.\"
26.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36.\" POSSIBILITY OF SUCH DAMAGE.
37.\"
38.Dd June 12, 1999
39.Dt MLOCKALL 2
40.Os
41.Sh NAME
42.Nm mlockall ,
43.Nm munlockall
44.Nd lock (unlock) the address space of a process
45.Sh LIBRARY
46.Lb libc
47.Sh SYNOPSIS
48.Fd #include \*[Lt]sys/mman.h\*[Gt]
49.Ft int
50.Fn mlockall "int flags"
51.Ft int
52.Fn munlockall "void"
53.Sh DESCRIPTION
54The
55.Nm mlockall
56system call locks into memory the physical pages associated with the
57address space of a process until the address space is unlocked, the
58process exits, or execs another program image.
59.Pp
60The following flags affect the behavior of
61.Nm mlockall :
62.Bl -tag -width MCL_CURRENT
63.It Dv MCL_CURRENT
64Lock all pages currently mapped into the process's address space.
65.It Dv MCL_FUTURE
66Lock all pages mapped into the process's address space in the future,
67at the time the mapping is established.  Note that this may cause
68future mappings to fail if those mappings cause resource limits to
69be exceeded.
70.El
71.Pp
72Since physical memory is a potentially scarce resource, processes are
73limited in how much they can lock down.
74A single process can lock the minimum of a system-wide
75.Dq wired pages
76limit and the per-process
77.Li RLIMIT_MEMLOCK
78resource limit.
79.Pp
80The
81.Nm munlockall
82call unlocks any locked memory regions in the process address space.
83Any regions mapped after an
84.Nm munlockall
85call will not be locked.
86.Sh RETURN VALUES
87A return value of 0 indicates that the call
88succeeded and all pages in the range have either been locked or unlocked.
89A return value of -1 indicates an error occurred and the locked
90status of all pages in the range remains unchanged.
91In this case, the global location
92.Va errno
93is set to indicate the error.
94.Sh ERRORS
95.Fn mlockall
96will fail if:
97.Bl -tag -width Er
98.It Bq Er EINVAL
99The
100.Ar flags
101argument is zero, or includes unimplemented flags.
102.It Bq Er ENOMEM
103Locking the indicated range would exceed either the system or per-process
104limit for locked memory.
105.It Bq Er EAGAIN
106Some or all of the memory mapped into the process's address space
107could not be locked when the call was made.
108.It Bq Er EPERM
109The calling process does not have the appropriate privilege to perform
110the requested operation.
111.El
112.Sh SEE ALSO
113.Xr mincore 2 ,
114.Xr mlock 2 ,
115.Xr mmap 2 ,
116.Xr munmap 2 ,
117.Xr setrlimit 2
118.Sh STANDARDS
119The
120.Fn mlockall
121and
122.Fn munlockall
123functions conform to
124.St -p1003.1b-93 .
125.Sh HISTORY
126The
127.Fn mlockall
128and
129.Fn munlockall
130functions first appeared in
131.Nx 1.5 .
132.Sh BUGS
133The per-process resource limit is a limit on the amount of virtual
134memory locked, while the system-wide limit is for the number of locked
135physical pages.
136Hence a process with two distinct locked mappings of the same physical page
137counts as 2 pages against the per-process limit and as only a single page
138in the system limit.
139