All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: Check for SIGKILL inside dup_mmap() loop.
@ 2018-03-29 11:27 Tetsuo Handa
  2018-03-29 21:30 ` Andrew Morton
  0 siblings, 1 reply; 21+ messages in thread
From: Tetsuo Handa @ 2018-03-29 11:27 UTC (permalink / raw)
  To: linux-mm, linux-fsdevel
  Cc: Tetsuo Handa, Alexander Viro, Andrew Morton, Kirill A. Shutemov,
	Michal Hocko, Rik van Riel

Theoretically it is possible that an mm_struct with 60000+ vmas loops
with potentially allocating memory, with mm->mmap_sem held for write by
the current thread. Unless I overlooked that fatal_signal_pending() is
somewhere in the loop, this is bad if current thread was selected as an
OOM victim, for the current thread will continue allocations using memory
reserves while the OOM reaper is unable to reclaim memory.

But there is no point with continuing the loop from the beginning if
current thread is killed. If there were __GFP_KILLABLE (or something
like memalloc_nofs_save()/memalloc_nofs_restore()), we could apply it
to all allocations inside the loop. But since we don't have such flag,
this patch uses fatal_signal_pending() check inside the loop.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 kernel/fork.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/fork.c b/kernel/fork.c
index 1e8c9a7..38d5baa 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -440,6 +440,10 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
 			continue;
 		}
 		charge = 0;
+		if (fatal_signal_pending(current)) {
+			retval = -EINTR;
+			goto out;
+		}
 		if (mpnt->vm_flags & VM_ACCOUNT) {
 			unsigned long len = vma_pages(mpnt);
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2018-06-08 17:05 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-29 11:27 [PATCH] mm: Check for SIGKILL inside dup_mmap() loop Tetsuo Handa
2018-03-29 21:30 ` Andrew Morton
2018-03-30 10:34   ` Tetsuo Handa
2018-04-03 12:14     ` Matthew Wilcox
2018-04-03 12:19       ` Michal Hocko
2018-04-03 12:25         ` Matthew Wilcox
2018-04-03 14:54           ` Tetsuo Handa
2018-04-03 12:29         ` Tetsuo Handa
2018-04-03 13:06           ` Michal Hocko
2018-04-03 11:16   ` Michal Hocko
2018-04-03 11:32     ` Tetsuo Handa
2018-04-03 11:38       ` Michal Hocko
2018-04-03 11:58   ` Matthew Wilcox
2018-04-03 12:08     ` Michal Hocko
2018-04-07 10:38   ` Tetsuo Handa
2018-04-07 10:38     ` Tetsuo Handa
2018-04-18 21:44     ` Andrew Morton
2018-04-19  1:54       ` Tetsuo Handa
2018-04-19  2:32         ` Andrew Morton
2018-06-07 22:05           ` Andrew Morton
2018-06-08 17:05             ` Matthew Wilcox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.