1.\" $OpenBSD: mlockall.2,v 1.10 2019/01/11 18:46:30 deraadt 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.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30.\" POSSIBILITY OF SUCH DAMAGE. 31.\" 32.Dd $Mdocdate: January 11 2019 $ 33.Dt MLOCKALL 2 34.Os 35.Sh NAME 36.Nm mlockall , 37.Nm munlockall 38.Nd lock (unlock) the address space of a process 39.Sh SYNOPSIS 40.In sys/mman.h 41.Ft int 42.Fn mlockall "int flags" 43.Ft int 44.Fn munlockall "void" 45.Sh DESCRIPTION 46The 47.Fn mlockall 48system call locks into memory the physical pages associated with the 49address space of a process until the address space is unlocked, the 50process exits, or execs another program image. 51.Pp 52The following flags affect the behavior of 53.Fn mlockall : 54.Bl -tag -width MCL_CURRENT 55.It Dv MCL_CURRENT 56Lock all pages currently mapped into the process's address space. 57.It Dv MCL_FUTURE 58Lock all pages mapped into the process's address space in the future, 59at the time the mapping is established. 60Note that this may cause future mappings to fail if those mappings 61cause resource limits to be exceeded. 62.El 63.Pp 64Since physical memory is a potentially scarce resource, processes are 65limited in how much they can lock down. 66A single process can lock the minimum of a system-wide 67.Dq wired pages 68limit and the per-process 69.Dv RLIMIT_MEMLOCK 70resource limit. 71.Pp 72The 73.Fn munlockall 74call unlocks any locked memory regions in the process address space. 75Any regions mapped after an 76.Fn munlockall 77call will not be locked. 78.Sh RETURN VALUES 79.Rv -std mlockall munlockall 80.Sh ERRORS 81.Fn mlockall 82will fail if: 83.Bl -tag -width Er 84.It Bq Er EINVAL 85The 86.Fa flags 87argument is zero or includes unimplemented flags. 88.It Bq Er ENOMEM 89Locking all of the pages currently mapped would exceed either 90the system or per-process 91limit for locked memory. 92.It Bq Er EAGAIN 93Some or all of the memory mapped into the process's address space 94could not be locked when the call was made. 95.It Bq Er EPERM 96The calling process does not have the appropriate privileges to perform 97the requested operation. 98.El 99.Sh SEE ALSO 100.Xr mlock 2 , 101.Xr mmap 2 , 102.Xr munmap 2 , 103.Xr setrlimit 2 104.Sh STANDARDS 105The 106.Fn mlockall 107and 108.Fn munlockall 109functions conform to 110.St -p1003.1-2008 . 111.Sh HISTORY 112The 113.Fn mlockall 114and 115.Fn munlockall 116functions first appeared in 117.Ox 2.9 . 118.Sh BUGS 119The per-process resource limit is a limit on the amount of virtual 120memory locked, while the system-wide limit is for the number of locked 121physical pages. 122Hence a process with two distinct locked mappings of the same physical page 123counts as 2 pages against the per-process limit and only as a single page 124in the system limit. 125