From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Cc: thuth@redhat.com, frankja@linux.ibm.com, borntraeger@de.ibm.com,
Ulrich.Weigand@de.ibm.com, heiko.carstens@de.ibm.com,
david@redhat.com, ultrachin@163.com, akpm@linux-foundation.org,
vbabka@suse.cz, brookxu.cn@gmail.com, xiaoggchen@tencent.com,
linuszeng@tencent.com, yihuilu@tencent.com, mhocko@suse.com,
daniel.m.jordan@oracle.com, axboe@kernel.dk, legion@kernel.org,
peterz@infradead.org, aarcange@redhat.com, christian@brauner.io,
ebiederm@xmission.com, tglx@linutronix.de
Subject: [RFC v1 4/4] kernel/fork.c: process_mmput_async: stop OOM while freeing memory
Date: Thu, 11 Nov 2021 10:50:08 +0100 [thread overview]
Message-ID: <20211111095008.264412-6-imbrenda@linux.ibm.com> (raw)
In-Reply-To: <20211111095008.264412-1-imbrenda@linux.ibm.com>
This patch implements a simple OOM notifier to stop the OOM killer
while a mm is being reclaimed asynchronously using the
process_mmput_async syscall.
Tested on s390x.
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
kernel/fork.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/kernel/fork.c b/kernel/fork.c
index 0da39b76005c..7279209eb69c 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -118,6 +118,11 @@
*/
#define MAX_THREADS FUTEX_TID_MASK
+/*
+ * Priority for the OOM notifier used in process_mmput_async
+ */
+#define PROCESS_MMPUT_ASYNC_OOM_NOTIFY_PRIORITY 70
+
/*
* Protected counters by write_lock_irq(&tasklist_lock)
*/
@@ -3203,13 +3208,27 @@ int sysctl_max_threads(struct ctl_table *table, int write,
return 0;
}
+/* Prevent the OOM from being triggered while we are cleaning up asynchronously */
+static int mmput_async_oom_notifier(struct notifier_block *nb, unsigned long dummy, void *parm)
+{
+ /*
+ * We cannot know the speed at which pages are being freed, so we
+ * fake it and say it's at least one. This is already enough to
+ * stop the OOM killer.
+ */
+ *(unsigned long *)parm += PAGE_SIZE;
+ return NOTIFY_OK;
+}
+
SYSCALL_DEFINE2(process_mmput_async, int, pidfd, unsigned int, flags)
{
#ifdef CONFIG_MMU
+ struct notifier_block oom_nb;
struct mm_struct *mm = NULL;
struct task_struct *task;
unsigned int tmp;
struct pid *pid;
+ int r;
if (flags)
return -EINVAL;
@@ -3280,8 +3299,17 @@ SYSCALL_DEFINE2(process_mmput_async, int, pidfd, unsigned int, flags)
if (atomic_read(&mm->mm_users))
panic("mm_users not 0 but trying to __mmput anyway!");
+ /*
+ * Register an OOM notifier, to stop the OOM while we are
+ * asynchronously freeing the mm.
+ */
+ oom_nb.priority = PROCESS_MMPUT_ASYNC_OOM_NOTIFY_PRIORITY;
+ oom_nb.notifier_call = mmput_async_oom_notifier;
+ r = register_oom_notifier(&oom_nb);
/* Do the actual work */
__mmput(mm);
+ if (!r)
+ unregister_oom_notifier(&oom_nb);
/* And put the extra reference taken above */
mmdrop(mm);
--
2.31.1
next prev parent reply other threads:[~2021-11-11 9:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-11 9:50 [RFC v1 0/4] Two alternatives for mm async teardown Claudio Imbrenda
2021-11-11 9:50 ` [RFC v1 1/4] add arch mmput hook in exit.c Claudio Imbrenda
2021-11-11 9:50 ` [RFC v1 1/4] exit: add arch mmput hook in exit_mm Claudio Imbrenda
2021-11-11 18:43 ` Eric W. Biederman
2021-11-11 9:50 ` [RFC v1 2/4] kernel/fork.c: implement new process_mmput_async syscall Claudio Imbrenda
2021-11-11 19:20 ` Eric W. Biederman
2021-11-12 9:27 ` Claudio Imbrenda
2021-11-12 9:34 ` Claudio Imbrenda
2021-11-12 14:57 ` Eric W. Biederman
2021-11-12 16:53 ` Claudio Imbrenda
2021-11-15 10:43 ` Michal Hocko
2021-11-11 9:50 ` [RFC v1 3/4] mm: wire up the " Claudio Imbrenda
2021-11-11 9:50 ` Claudio Imbrenda [this message]
2021-11-12 10:15 ` [RFC v1 0/4] Two alternatives for mm async teardown Michal Hocko
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=20211111095008.264412-6-imbrenda@linux.ibm.com \
--to=imbrenda@linux.ibm.com \
--cc=Ulrich.Weigand@de.ibm.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=borntraeger@de.ibm.com \
--cc=brookxu.cn@gmail.com \
--cc=christian@brauner.io \
--cc=daniel.m.jordan@oracle.com \
--cc=david@redhat.com \
--cc=ebiederm@xmission.com \
--cc=frankja@linux.ibm.com \
--cc=heiko.carstens@de.ibm.com \
--cc=legion@kernel.org \
--cc=linuszeng@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=thuth@redhat.com \
--cc=ultrachin@163.com \
--cc=vbabka@suse.cz \
--cc=xiaoggchen@tencent.com \
--cc=yihuilu@tencent.com \
/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