1.\" $OpenBSD: mlockall.2,v 1.2 2001/03/11 05:23:18 aaron 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 June 12, 1999 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 SYNOPSIS 47.Fd #include <sys/types.h> 48.Fd #include <sys/mman.h> 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. 68Note that this may cause future mappings to fail if those mappings 69cause resource limits to be 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.Dv 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 privileges 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.Ox 2.9 . 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 only as a single page 138in the system limit. 139