* [PATCH] mlock.2: document that is a bad idea to fork() after mlock()
@ 2016-08-30 8:59 Sebastian Andrzej Siewior
2016-08-30 19:20 ` Michael Kerrisk (man-pages)
0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Andrzej Siewior @ 2016-08-30 8:59 UTC (permalink / raw)
To: mtk.manpages
Cc: linux-man, linux-kernel, linux-mm, linux-rt-users,
Sebastian Andrzej Siewior
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@linutronix.de>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mlock.2: document that is a bad idea to fork() after mlock()
2016-08-30 8:59 [PATCH] mlock.2: document that is a bad idea to fork() after mlock() Sebastian Andrzej Siewior
@ 2016-08-30 19:20 ` Michael Kerrisk (man-pages)
0 siblings, 0 replies; 2+ messages in thread
From: Michael Kerrisk (man-pages) @ 2016-08-30 19:20 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: mtk.manpages, linux-man, linux-kernel, linux-mm, linux-rt-users
Hello Sebastian
On 08/30/2016 08:59 PM, Sebastian Andrzej Siewior wrote:
> 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@linutronix.de>
Thanks! Patch applied.
Cheers,
Michael
> ---
> 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).
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-30 19:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-30 8:59 [PATCH] mlock.2: document that is a bad idea to fork() after mlock() Sebastian Andrzej Siewior
2016-08-30 19:20 ` Michael Kerrisk (man-pages)
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).