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