-.\" Hey Emacs! This file is -*- nroff -*- source.
-.\"
.\" Copyright (C) Michael Kerrisk, 2004
.\" using some material drawn from earlier man pages
.\" written by Thomas Kuhn, Copyright 1996
.\"
+.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
-.\" License along with this manual; if not, write to the Free
-.\" Software Foundation, Inc., 59 Temple Place, Suite 330,
-.\" Boston, MA 02111, USA.
+.\" License along with this manual; if not, see
+.\" <http://www.gnu.org/licenses/>.
+.\" %%%LICENSE_END
.\"
-.TH MLOCK 2 2010-10-30 "Linux" "Linux Programmer's Manual"
+.TH MLOCK 2 2014-04-14 "Linux" "Linux Programmer's Manual"
.SH NAME
mlock, munlock, mlockall, munlockall \- lock and unlock memory
.SH SYNOPSIS
address space, so that pages in the specified virtual address range may
once more to be swapped out if required by the kernel memory manager.
Memory locking and unlocking are performed in units of whole pages.
-.SS "mlock() and munlock()"
+.SS mlock() and munlock()
.BR mlock ()
locks pages in the address range starting at
.I addr
bytes.
After this call, all pages that contain a part of the specified
memory range can be moved to external swap space again by the kernel.
-.SS "mlockall() and munlockall()"
+.SS mlockall() and munlockall()
.BR mlockall ()
locks all pages mapped into the address space of the
calling process.
Lock all pages which will become mapped into the address space of the
process in the future.
These could be for instance new pages required
-by a growing heap and stack as well as new memory mapped files or
+by a growing heap and stack as well as new memory-mapped files or
shared memory regions.
.PP
If
.BR munlockall ()
unlocks all pages mapped into the address space of the
calling process.
-.SH "RETURN VALUE"
+.SH RETURN VALUE
On success these system calls return 0.
On error, \-1 is returned,
.I errno
.\" pages, which of course is not true. (MTK, Nov 04, kernel 2.4.28)
.TP
.B EPERM
-(Linux 2.6.9 and later) the caller was not privileged
+The caller is not privileged, but needs privilege
.RB ( CAP_IPC_LOCK )
-and its
-.B RLIMIT_MEMLOCK
-soft resource limit was 0.
-.TP
-.B EPERM
-(Linux 2.6.8 and earlier)
-The calling process has insufficient privilege to call
-.BR munlockall ().
-Under Linux the
-.B CAP_IPC_LOCK
-capability is required.
+to perform the requested operation.
.\"SVr4 documents an additional EAGAIN error code.
.LP
For
Some or all of the specified address range could not be locked.
.TP
.B EINVAL
-.I len
-was negative.
+The result of the addition
+.IR start + len
+was less than
+.IR start
+(e.g., the addition may have resulted in an overflow).
.TP
.B EINVAL
(Not on Linux)
.B EPERM
(Linux 2.6.8 and earlier) The caller was not privileged
.RB ( CAP_IPC_LOCK ).
-.SH "CONFORMING TO"
+.SH CONFORMING TO
POSIX.1-2001, SVr4.
.SH AVAILABILITY
On POSIX systems on which
.\" POSIX.1-2001: It shall be defined to -1 or 0 or 200112L.
.\" -1: unavailable, 0: ask using sysconf().
.\" glibc defines it to 1.
-.SH "NOTES"
+.SH NOTES
Memory locking has two main applications: real-time algorithms and
high-security data processing.
Real-time applications require
and are automatically removed (unlocked) during an
.BR execve (2)
or when the process terminates.
+The
+.BR mlockall ()
+.B MCL_FUTURE
+setting is not inherited by a child created via
+.BR fork (2)
+and is cleared during an
+.BR execve (2).
The memory lock on an address range is automatically removed
if the address range is unmapped via
Pages which are mapped to several locations or by several processes stay
locked into RAM as long as they are locked at least at one location or by
at least one process.
-.SS "Linux Notes"
+.SS Linux notes
Under Linux,
.BR mlock ()
and
and
.BR mmap (2)
.BR MAP_LOCKED .
-.SS "Limits and permissions"
+.SS Limits and permissions
In Linux 2.6.8 and earlier,
a process must be privileged
.RB ( CAP_IPC_LOCK )
.B RLIMIT_MEMLOCK
soft resource limit instead defines a limit on how much memory an
unprivileged process may lock.
-.SH "BUGS"
+.SH BUGS
In the 2.4 series Linux kernels up to and including 2.4.17,
a bug caused the
.BR mlockall ()
.\" http://marc.theaimsgroup.com/?l=linux-kernel&m=113801392825023&w=2
.\" "Rationale for RLIMIT_MEMLOCK"
.\" 23 Jan 2006
-.SH "SEE ALSO"
+.SH SEE ALSO
.BR mmap (2),
.BR setrlimit (2),
.BR shmctl (2),
.BR sysconf (3),
.BR proc (5),
.BR capabilities (7)
+.SH COLOPHON
+This page is part of release 3.68 of the Linux
+.I man-pages
+project.
+A description of the project,
+information about reporting bugs,
+and the latest version of this page,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.