[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20220921032759.41473-1-rongwei.wang@linux.alibaba.com>
Date: Wed, 21 Sep 2022 11:27:59 +0800
From: Rongwei Wang <rongwei.wang@...ux.alibaba.com>
To: akpm@...ux-foundation.org, ebiederm@...ssion.com,
keescook@...omium.org, tglx@...utronix.de, axboe@...nel.dk,
peterz@...radead.org, arnd@...db.de
Cc: linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: [PATCH RFC] mm/khugepaged: Improve awareness for exiting processes
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@...ux.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
Powered by blists - more mailing lists