@@ -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);
@@ -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)
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(-)