1.\" $NetBSD: mlockall.2,v 1.11 2003/04/16 13:34:54 wiz 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.\" $FreeBSD$ 39.\" 40.Dd June 12, 1999 41.Dt MLOCKALL 2 42.Os 43.Sh NAME 44.Nm mlockall , 45.Nm munlockall 46.Nd lock (unlock) the address space of a process 47.Sh LIBRARY 48.Lb libc 49.Sh SYNOPSIS 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 EAGAIN 108Some or all of the memory mapped into the process's address space 109could not be locked when the call was made. 110.It Bq Er EPERM 111The calling process does not have the appropriate privilege to perform 112the requested operation. 113.El 114.Sh SEE ALSO 115.Xr mincore 2 , 116.Xr mlock 2 , 117.Xr mmap 2 , 118.Xr munmap 2 , 119.Xr setrlimit 2 120.Sh STANDARDS 121The 122.Fn mlockall 123and 124.Fn munlockall 125functions are believed to conform to 126.St -p1003.1-2001 . 127.Sh HISTORY 128The 129.Fn mlockall 130and 131.Fn munlockall 132functions first appeared in 133.Fx 5.1 . 134.Sh BUGS 135The per-process resource limit is a limit on the amount of virtual 136memory locked, while the system-wide limit is for the number of locked 137physical pages. 138Hence a process with two distinct locked mappings of the same physical page 139counts as 2 pages against the per-process limit and as only a single page 140in the system limit. 141