From patchwork Wed Sep 21 03:27:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rongwei Wang X-Patchwork-Id: 12983131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47896C32771 for ; Wed, 21 Sep 2022 03:28:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B54F940007; Tue, 20 Sep 2022 23:28:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 764CF6B0073; Tue, 20 Sep 2022 23:28:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65398940007; Tue, 20 Sep 2022 23:28:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5420B6B0072 for ; Tue, 20 Sep 2022 23:28:10 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2365C1A0E6E for ; Wed, 21 Sep 2022 03:28:10 +0000 (UTC) X-FDA: 79934659140.20.A94C2F9 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf05.hostedemail.com (Postfix) with ESMTP id 0F712100003 for ; Wed, 21 Sep 2022 03:28:06 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R241e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=rongwei.wang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0VQM6ATB_1663730881; Received: from localhost.localdomain(mailfrom:rongwei.wang@linux.alibaba.com fp:SMTPD_---0VQM6ATB_1663730881) by smtp.aliyun-inc.com; Wed, 21 Sep 2022 11:28:03 +0800 From: Rongwei Wang 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 Message-Id: <20220921032759.41473-1-rongwei.wang@linux.alibaba.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663730889; a=rsa-sha256; cv=none; b=eOW8u1+Lf+tFbsohPqWgt/CxxrjI/iBJHf7WSakpUeaxH0OtaGwMXvpr3wynjSefIdd4TO q4lSjIL0f2TSoCvz2een5vkWR9nBrOuWjbphoSp65i5KZT393L/SgmCuVsWiec2m8h3weK At4UxSG/nidbvPmhMZKOYjtEd4tcnXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663730889; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=wlVQwy8XHGElVAlBvbVNkqmoJGuCkRVTgHN2bqP++kE=; b=qRpZSX7GQbUV9Qdtsu6cjnndL2oVVZCIU5UVfSWvjv2ejXjuQSl695QOgtvMSrni5NALK7 tRyDyDFFo6wQB4OFEypwzUwBwOWCr5jJWnrptCKaZ3puRg+NoHWt9KB0w4MdqdxTSSlUI0 o6rJEsXIwg+4XZhBQ+OVoPWhaBUfgEA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf05.hostedemail.com: domain of rongwei.wang@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=rongwei.wang@linux.alibaba.com X-Stat-Signature: 9xmfz7sa9ye8zns5atmyskpdt9ybpgoz X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 0F712100003 Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf05.hostedemail.com: domain of rongwei.wang@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=rongwei.wang@linux.alibaba.com X-Rspam-User: X-HE-Tag: 1663730886-466761 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- 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)