From: Rongwei Wang <rongwei.wang@linux.alibaba.com>
To: akpm@linux-foundation.org, ebiederm@xmission.com,
keescook@chromium.org, tglx@linutronix.de, axboe@kernel.dk,
peterz@infradead.org, arnd@arndb.de
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH RFC] mm/khugepaged: Improve awareness for exiting processes
Date: Wed, 21 Sep 2022 11:27:59 +0800 [thread overview]
Message-ID: <20220921032759.41473-1-rongwei.wang@linux.alibaba.com> (raw)
In khugepaged, the khugepaged_test_exit() always be called
after mmap_read_lock(mm), and the scanning for mm would be
stopped when mm_users is 0. That indicates the handling
process is exiting. But it's not enough or timely to check
the exiting process only by mm_users (mmput() called after
mmap_read_unlock()).
The patch mainly to improve awareness for the exiting process.
And in addition, this patch seems be helpful for the purpose
of debugging, e.g. avoiding owner is NULL if we want to get
the handling task name.
Signed-off-by: Rongwei Wang <rongwei.wang@linux.alibaba.com>
---
kernel/exit.c | 2 ++
mm/khugepaged.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/exit.c b/kernel/exit.c
index 84021b24f79e..5668bb9971d9 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -505,6 +505,8 @@ static void exit_mm(void)
enter_lazy_tlb(mm, current);
local_irq_enable();
task_unlock(current);
+ if (atomic_read(&mm->mm_users) <= 1)
+ WRITE_ONCE(mm->owner, NULL); /* Update before mmap_unlock */
mmap_read_unlock(mm);
mm_update_next_owner(mm);
mmput(mm);
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 01f71786d530..8a0f97e5efc0 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -427,7 +427,7 @@ static void insert_to_mm_slots_hash(struct mm_struct *mm,
static inline int khugepaged_test_exit(struct mm_struct *mm)
{
- return atomic_read(&mm->mm_users) == 0;
+ return atomic_read(&mm->mm_users) == 0 || !READ_ONCE(mm->owner);
}
void __khugepaged_enter(struct mm_struct *mm)
--
2.27.0
reply other threads:[~2022-09-21 3:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220921032759.41473-1-rongwei.wang@linux.alibaba.com \
--to=rongwei.wang@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=axboe@kernel.dk \
--cc=ebiederm@xmission.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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