linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org,
	linux-rt-users-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Sebastian Andrzej Siewior
	<bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Subject: [PATCH] mlock.2: document that is a bad idea to fork() after mlock()
Date: Tue, 30 Aug 2016 10:59:11 +0200	[thread overview]
Message-ID: <20160830085911.5336-1-bigeasy@linutronix.de> (raw)

fork() will remove the write PTE bit from the page table on each VMA
which will be copied via COW. A such such, the memory is available but
marked read only in the page table and will fault on write access.
This renders the previous mlock() operation almost useless because in a
multi threaded application the RT thread may block on mmap_sem while the
thread with low priority is holding the mmap_sem (for instance because
it is allocating memory which needs to be mapped in).

There is actually nothing we can do to mitigate the outcome. We could
add a warning to the kernel for people that are not yet aware of the
updated documentation.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
---
 man2/mlock.2 | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/man2/mlock.2 b/man2/mlock.2
index e34bb3b4e045..27f80f6664ef 100644
--- a/man2/mlock.2
+++ b/man2/mlock.2
@@ -350,6 +350,20 @@ settings are not inherited by a child created via
 and are cleared during an
 .BR execve (2).
 
+Note that
+.BR fork (2)
+will prepare the address space for a copy-on-write operation. The consequence
+is that any write access that follows will cause a page fault which in turn may
+cause high latencies for a real-time process. Therefore it is crucial not to
+invoke
+.BR fork (2)
+after the
+.BR mlockall ()
+or
+.BR mlock ()
+operation not even from thread which runs at a low priority within a process
+which also has a thread running at elevated priority.
+
 The memory lock on an address range is automatically removed
 if the address range is unmapped via
 .BR munmap (2).
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2016-08-30  8:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-30  8:59 Sebastian Andrzej Siewior [this message]
     [not found] ` <20160830085911.5336-1-bigeasy-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2016-08-30 19:20   ` [PATCH] mlock.2: document that is a bad idea to fork() after mlock() Michael Kerrisk (man-pages)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160830085911.5336-1-bigeasy@linutronix.de \
    --to=bigeasy-hfztesqfncyowbw4kg4ksq@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
    --cc=linux-rt-users-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).