Merge branch 'vendor/OPENBSD_LIBM'
[dragonfly.git] / lib / libc / sys / mlockall.2
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
56 The
57 .Fn mlockall
58 system call locks into memory the physical pages associated with the
59 address space of a process until the address space is unlocked, the
60 process exits, or execs another program image.
61 .Pp
62 The following flags affect the behavior of
63 .Fn mlockall :
64 .Bl -tag -width ".Dv MCL_CURRENT"
65 .It Dv MCL_CURRENT
66 Lock all pages currently mapped into the process's address space.
67 .It Dv MCL_FUTURE
68 Lock all pages mapped into the process's address space in the future,
69 at the time the mapping is established.
70 Note that this may cause future mappings to fail if those mappings
71 cause resource limits to be exceeded.
72 .El
73 .Pp
74 Since physical memory is a potentially scarce resource, processes are
75 limited in how much they can lock down.
76 A single process can lock the minimum of a system-wide
77 .Dq wired pages
78 limit and the per-process
79 .Dv RLIMIT_MEMLOCK
80 resource limit.
81 .Pp
82 The
83 .Fn munlockall
84 call unlocks any locked memory regions in the process address space.
85 Any regions mapped after an
86 .Fn munlockall
87 call will not be locked.
88 .Sh RETURN VALUES
89 A return value of 0 indicates that the call
90 succeeded and all pages in the range have either been locked or unlocked.
91 A return value of \-1 indicates an error occurred and the locked
92 status of all pages in the range remains unchanged.
93 In this case, the global location
94 .Va errno
95 is set to indicate the error.
96 .Sh ERRORS
97 .Fn mlockall
98 will fail if:
99 .Bl -tag -width Er
100 .It Bq Er EINVAL
101 The
102 .Fa flags
103 argument is zero, or includes unimplemented flags.
104 .It Bq Er ENOMEM
105 Locking the indicated range would exceed either the system or per-process
106 limit for locked memory.
107 .It Bq Er EPERM
108 The calling process does not have the appropriate privilege to perform
109 the requested operation.
110 .El
111 .Sh SEE ALSO
112 .Xr mincore 2 ,
113 .Xr mlock 2 ,
114 .Xr setrlimit 2
115 .Sh STANDARDS
116 The
117 .Fn mlockall
118 and
119 .Fn munlockall
120 functions are believed to conform to
121 .St -p1003.1-2001 .
122 .Sh HISTORY
123 The
124 .Fn mlockall
125 and
126 .Fn munlockall
127 functions first appeared in
128 .Dx 2.9 .
129 .Sh BUGS
130 The
131 .Dv MCL_CURRENT
132 flag does not function in
133 .Dx
134 currently.