Blame SOURCES/1573281-mpo-7.6.0-mlock.2-mlock2.2.patch

eb7712
From 88a7af51d8ef4d9199ff9073bc09eabb5182fe80 Mon Sep 17 00:00:00 2001
eb7712
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
eb7712
Date: Tue, 19 Jun 2018 13:14:13 +0200
eb7712
Subject: [PATCH 2/3] mlock.2, mlock2.2: document mlock2(2) and MCL_ONFAULT
eb7712
---
eb7712
 man-pages/man2/mlock.2 | 152 ++++++++++++++++++++++++++++++++++++-----
eb7712
 1 file changed, 136 insertions(+), 16 deletions(-)
eb7712
eb7712
diff --git a/man-pages/man2/mlock.2 b/man-pages/man2/mlock.2
eb7712
index 27189d8..595c9e9 100644
eb7712
--- a/man-pages/man2/mlock.2
eb7712
+++ b/man-pages/man2/mlock.2
eb7712
@@ -23,35 +23,39 @@
eb7712
 .\" <http://www.gnu.org/licenses/>.
eb7712
 .\" %%%LICENSE_END
eb7712
 .\"
eb7712
-.TH MLOCK 2 2011-09-14 "Linux" "Linux Programmer's Manual"
eb7712
+.TH MLOCK 2 2015-08-28 "Linux" "Linux Programmer's Manual"
eb7712
 .SH NAME
eb7712
-mlock, munlock, mlockall, munlockall \- lock and unlock memory
eb7712
+mlock, mlock2, munlock, mlockall, munlockall \- lock and unlock memory
eb7712
 .SH SYNOPSIS
eb7712
 .nf
eb7712
 .B #include <sys/mman.h>
eb7712
 .sp
eb7712
 .BI "int mlock(const void *" addr ", size_t " len );
eb7712
+.BI "int mlock2(const void *" addr ", size_t " len ", int " flags );
eb7712
 .BI "int munlock(const void *" addr ", size_t " len );
eb7712
 .sp
eb7712
 .BI "int mlockall(int " flags );
eb7712
 .B int munlockall(void);
eb7712
 .fi
eb7712
 .SH DESCRIPTION
eb7712
-.BR mlock ()
eb7712
+.BR mlock (),
eb7712
+.BR mlock2 (),
eb7712
 and
eb7712
 .BR mlockall ()
eb7712
-respectively lock part or all of the calling process's virtual address
eb7712
+lock part or all of the calling process's virtual address
eb7712
 space into RAM, preventing that memory from being paged to the
eb7712
 swap area.
eb7712
+
eb7712
 .BR munlock ()
eb7712
 and
eb7712
 .BR munlockall ()
eb7712
 perform the converse operation,
eb7712
-respectively unlocking part or all of the calling process's virtual
eb7712
+unlocking part or all of the calling process's virtual
eb7712
 address space, so that pages in the specified virtual address range may
eb7712
 once more to be swapped out if required by the kernel memory manager.
eb7712
+
eb7712
 Memory locking and unlocking are performed in units of whole pages.
eb7712
-.SS mlock() and munlock()
eb7712
+.SS mlock(), mlock2(), and munlock()
eb7712
 .BR mlock ()
eb7712
 locks pages in the address range starting at
eb7712
 .I addr
eb7712
@@ -62,6 +66,41 @@ All pages that contain a part of the specified address range are
eb7712
 guaranteed to be resident in RAM when the call returns successfully;
eb7712
 the pages are guaranteed to stay in RAM until later unlocked.
eb7712
 
eb7712
+.BR mlock2 ()
eb7712
+.\" commit a8ca5d0ecbdde5cc3d7accacbd69968b0c98764e
eb7712
+.\" commit de60f5f10c58d4f34b68622442c0e04180367f3f
eb7712
+.\" commit b0f205c2a3082dd9081f9a94e50658c5fa906ff1
eb7712
+also locks pages in the specified range starting at
eb7712
+.I addr
eb7712
+and continuing for
eb7712
+.I len
eb7712
+bytes.
eb7712
+However, the state of the pages contained in that range after the call
eb7712
+returns successfully will depend on the value in the
eb7712
+.I flags
eb7712
+argument.
eb7712
+
eb7712
+The
eb7712
+.I flags
eb7712
+argument can be either 0 or the following constant:
eb7712
+.TP
eb7712
+.B MLOCK_ONFAULT
eb7712
+Lock pages that are currently resident and mark the entire range to have
eb7712
+pages locked when they are populated by the page fault.
eb7712
+.PP
eb7712
+
eb7712
+If
eb7712
+.I flags
eb7712
+is 0,
eb7712
+.BR mlock2 ()
eb7712
+behaves exactly the same as
eb7712
+.BR mlock ().
eb7712
+
eb7712
+Note: currently, there is not a glibc wrapper for
eb7712
+.BR mlock2 (),
eb7712
+so it will need to be invoked using
eb7712
+.BR syscall (2).
eb7712
+
eb7712
 .BR munlock ()
eb7712
 unlocks pages in the address range starting at
eb7712
 .I addr
eb7712
@@ -93,9 +132,36 @@ the process.
eb7712
 .B MCL_FUTURE
eb7712
 Lock all pages which will become mapped into the address space of the
eb7712
 process in the future.
eb7712
-These could be for instance new pages required
eb7712
-by a growing heap and stack as well as new memory mapped files or
eb7712
+These could be, for instance, new pages required
eb7712
+by a growing heap and stack as well as new memory-mapped files or
eb7712
 shared memory regions.
eb7712
+.TP
eb7712
+.BR MCL_ONFAULT " (since Linux 4.4)"
eb7712
+Used together with
eb7712
+.BR MCL_CURRENT ,
eb7712
+.BR MCL_FUTURE ,
eb7712
+or both.
eb7712
+Mark all current (with
eb7712
+.BR MCL_CURRENT )
eb7712
+or future (with
eb7712
+.BR MCL_FUTURE )
eb7712
+mappings to lock pages when they are faulted in.
eb7712
+When used with
eb7712
+.BR MCL_CURRENT ,
eb7712
+all present pages are locked, but
eb7712
+.BR mlockall ()
eb7712
+will not fault in non-present pages.
eb7712
+When used with
eb7712
+.BR MCL_FUTURE ,
eb7712
+all future mappings will be marked to lock pages when they are faulted
eb7712
+in, but they will not be populated by the lock when the mapping is
eb7712
+created.
eb7712
+.B MCL_ONFAULT
eb7712
+must be used with either
eb7712
+.B MCL_CURRENT
eb7712
+or
eb7712
+.B MCL_FUTURE
eb7712
+or both.
eb7712
 .PP
eb7712
 If
eb7712
 .B MCL_FUTURE
eb7712
@@ -148,7 +214,8 @@ to perform the requested operation.
eb7712
 .\"SVr4 documents an additional EAGAIN error code.
eb7712
 .LP
eb7712
 For
eb7712
-.BR mlock ()
eb7712
+.BR mlock (),
eb7712
+.BR mlock2 (),
eb7712
 and
eb7712
 .BR munlock ():
eb7712
 .TP
eb7712
@@ -157,9 +224,9 @@ Some or all of the specified address range could not be locked.
eb7712
 .TP
eb7712
 .B EINVAL
eb7712
 The result of the addition
eb7712
-.IR start + len
eb7712
+.IR addr + len
eb7712
 was less than
eb7712
-.IR start
eb7712
+.IR addr
eb7712
 (e.g., the addition may have resulted in an overflow).
eb7712
 .TP
eb7712
 .B EINVAL
eb7712
@@ -172,19 +239,36 @@ Some of the specified address range does not correspond to mapped
eb7712
 pages in the address space of the process.
eb7712
 .LP
eb7712
 For
eb7712
-.BR mlockall ():
eb7712
+.BR mlock2 ():
eb7712
 .TP
eb7712
 .B EINVAL
eb7712
 Unknown \fIflags\fP were specified.
eb7712
 .LP
eb7712
 For
eb7712
+.BR mlockall ():
eb7712
+.TP
eb7712
+.B EINVAL
eb7712
+Unknown \fIflags\fP were specified or
eb7712
+.B MCL_ONFAULT
eb7712
+was specified without either
eb7712
+.B MCL_FUTURE
eb7712
+or
eb7712
+.BR MCL_CURRENT .
eb7712
+.LP
eb7712
+For
eb7712
 .BR munlockall ():
eb7712
 .TP
eb7712
 .B EPERM
eb7712
 (Linux 2.6.8 and earlier) The caller was not privileged
eb7712
 .RB ( CAP_IPC_LOCK ).
eb7712
+.SH VERSIONS
eb7712
+.BR mlock2 (2)
eb7712
+is available since Linux 4.4.
eb7712
 .SH CONFORMING TO
eb7712
-POSIX.1-2001, SVr4.
eb7712
+POSIX.1-2001, POSIX.1-2008, SVr4.
eb7712
+
eb7712
+mlock2 ()
eb7712
+is Linux specific.
eb7712
 .SH AVAILABILITY
eb7712
 On POSIX systems on which
eb7712
 .BR mlock ()
eb7712
@@ -247,6 +331,15 @@ Memory locks are not inherited by a child created via
eb7712
 and are automatically removed (unlocked) during an
eb7712
 .BR execve (2)
eb7712
 or when the process terminates.
eb7712
+The
eb7712
+.BR mlockall ()
eb7712
+.B MCL_FUTURE
eb7712
+and
eb7712
+.B MCL_FUTURE | MCL_ONFAULT
eb7712
+settings are not inherited by a child created via
eb7712
+.BR fork (2)
eb7712
+and are cleared during an
eb7712
+.BR execve (2).
eb7712
 
eb7712
 The memory lock on an address range is automatically removed
eb7712
 if the address range is unmapped via
eb7712
@@ -254,7 +347,8 @@ if the address range is unmapped via
eb7712
 
eb7712
 Memory locks do not stack, that is, pages which have been locked several times
eb7712
 by calls to
eb7712
-.BR mlock ()
eb7712
+.BR mlock (),
eb7712
+.BR mlock2 (),
eb7712
 or
eb7712
 .BR mlockall ()
eb7712
 will be unlocked by a single call to
eb7712
@@ -264,15 +358,40 @@ for the corresponding range or by
eb7712
 Pages which are mapped to several locations or by several processes stay
eb7712
 locked into RAM as long as they are locked at least at one location or by
eb7712
 at least one process.
eb7712
+
eb7712
+If a call to
eb7712
+.BR mlockall ()
eb7712
+which uses the
eb7712
+.B MCL_FUTURE
eb7712
+flag is followed by another call that does not specify this flag, the
eb7712
+changes made by the
eb7712
+.B MCL_FUTURE
eb7712
+call will be lost.
eb7712
+
eb7712
+The
eb7712
+.BR mlock2 ()
eb7712
+.B MLOCK_ONFAULT
eb7712
+flag and the
eb7712
+.BR mlockall ()
eb7712
+.B MCL_ONFAULT
eb7712
+flag allow efficient memory locking for applications that deal with
eb7712
+large mappings where only a (small) portion of pages in the mapping are touched.
eb7712
+In such cases, locking all of the pages in a mapping would incur
eb7712
+a significant penalty for memory locking.
eb7712
 .SS Linux notes
eb7712
 Under Linux,
eb7712
-.BR mlock ()
eb7712
+.BR mlock (),
eb7712
+.BR mlock2 (),
eb7712
 and
eb7712
 .BR munlock ()
eb7712
 automatically round
eb7712
 .I addr
eb7712
 down to the nearest page boundary.
eb7712
-However, POSIX.1-2001 allows an implementation to require that
eb7712
+However, the POSIX.1 specification of
eb7712
+.BR mlock ()
eb7712
+and
eb7712
+.BR munlock ()
eb7712
+allows an implementation to require that
eb7712
 .I addr
eb7712
 is page aligned, so portable applications should ensure this.
eb7712
 
eb7712
@@ -284,6 +403,7 @@ file shows how many kilobytes of memory the process with ID
eb7712
 .I PID
eb7712
 has locked using
eb7712
 .BR mlock (),
eb7712
+.BR mlock2 (),
eb7712
 .BR mlockall (),
eb7712
 and
eb7712
 .BR mmap (2)
eb7712
-- 
eb7712
2.17.1
eb7712