From patchwork Tue Jul 25 18:04:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13326258 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 EF8CEC001DE for ; Tue, 25 Jul 2023 10:04:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6332E6B0080; Tue, 25 Jul 2023 06:04:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BB146B0081; Tue, 25 Jul 2023 06:04:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45C526B0082; Tue, 25 Jul 2023 06:04:39 -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 2FE756B0080 for ; Tue, 25 Jul 2023 06:04:39 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 07225140CDF for ; Tue, 25 Jul 2023 10:04:39 +0000 (UTC) X-FDA: 81049699878.12.CC166D2 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf17.hostedemail.com (Postfix) with ESMTP id E13574000C for ; Tue, 25 Jul 2023 10:04:35 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=none; spf=none (imf17.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690279476; 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:in-reply-to:references:references; bh=2JsmnFo+xD2trSm2Cr2ZnL8sa/khrwxZODHQ0eoC3F4=; b=tImYUpaNZBwA+9t54uiDtC6ZHqzBa6sU0IeJFvB7wUezaRysiPKQomwmfw4KFEfAYtXxYG UqvgL2IW4QXMBCM7CjBJObxTAYjOsM7ocCFECbkXWNDmFJbHgvrHYXKxvQSM3AgsY6acYa QzZMkF2KClU/4+T75qwn00ue3tmgG4E= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=none; spf=none (imf17.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690279476; a=rsa-sha256; cv=none; b=D8iyEuCn/74cqIl2JjRaWaCwvpFP+YOHL7cE+BfkgJr9AqMPb4AeREEUI+uuub6TBOyDmw 6rfyMYLoqKRqIMegouVSC8ydL6epfLwug17WhatIijbOUMUzvNBWh8fQGLQJhSTWf0mnwJ AsPs+H4J5HLtbW/9sMQRJof5kYexCNc= Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4R9CLN0Wqsz4f4TdC for ; Tue, 25 Jul 2023 18:04:28 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP2 (Coremail) with SMTP id Syh0CgAXC+ksnr9kFkPOOg--.2821S3; Tue, 25 Jul 2023 18:04:29 +0800 (CST) From: Kemeng Shi To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: willy@infradead.org, baolin.wang@linux.alibaba.com, david@redhat.com, shikemeng@huaweicloud.com Subject: [PATCH 1/4] mm/compaction: use "spinlock_t *" to record held lock in compact [un]lock functions Date: Wed, 26 Jul 2023 02:04:53 +0800 Message-Id: <20230725180456.2146626-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230725180456.2146626-1-shikemeng@huaweicloud.com> References: <20230725180456.2146626-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgAXC+ksnr9kFkPOOg--.2821S3 X-Coremail-Antispam: 1UD129KBjvJXoWxAw4fKFWUtr1rKFy7CFWktFb_yoW5AF4rpF 1xG3Wayr18Zay5uF4ftFW8WF43Xw1fWa4UAwsIqw1rJF45tF13Gw10ya4UurWUXasavFZa qFW3tFyUAay7ZaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBK14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_Jr4l82xGYIkIc2x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2 F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjx v20xvEc7CjxVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E 87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64 kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm 72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYx C7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_ Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x 0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8 JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIx AIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7sREK0PDUUUUU= = X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: E13574000C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: cdr9a4psf9spm4qubpyx6onro9chxf1e X-HE-Tag: 1690279475-350585 X-HE-Meta: U2FsdGVkX1/H1hpiOfN8nJoK4EK2LKUtgzKXxZ4yZwo+jODcHeimGFTgfzlPHpzVBpvamPyw3HHruNBabxd7B3bECGtCPonS4U/NjXktu0zk8rYfGrcBV6AClKVQ5w0I9SD0aVj/KAqjVkAXeze1Vu2LjfVl6lD7sGKOV81PMY7IGoUuFAImJJIuefjKSA/oorPQsGaiTB1TomexpTZzSfv9XF36ahVffBH1qawsNyVvzW+KhJE2XyLZKIbQ29LFH5gzYSjCkfgeK9+Az/TUT+ZTrPsYUD5rDXsLmhgcK4BuzvOOsnHNbVpWLkK81S/yYOV0HJqKvdTxw6BVJFPUyRkIkczBmnCahshdUNojndIutWlZT2N5Oa+j9PvMjnBcL3poPM8tXEjA3xl3kGyz/cczmea7ChPHKGUHTMUk9p7wowPcufBnPdP+1F8fBnJOEXAs1z0xDqGyfWQQYJBGag7/8CrITumNeJ7ecnwaiuCnKPc2rFGvX+55LXBnZBSg9SPn3FeK88O++ub2KXnUeP13IY3afpNTM9ahXSCQYbqYHI66N/0D2ScjAMjyLcV0ISNWx6R6CQlpgQQI3I16tEcASv453+hHUxM1hsgvNhfP1GCScdOU2YQSHCxGRu4eYrly8aZxHmpaZfLtk0WSUX7+MhAp5wfIRPTOsCNuTU5z+K1MdKa2PTixS8i8wuN/mNWgBOYD/n5lj/Zpf5lKTUvGEjy4oWawXbhU3xUtAdwgqjD5Y47A7hS/o6U/NxDlD21YYmDGAmXotDbbRhuw2L4k+JfbgoU4UZDpHeoOJOgdA/VAt/bF0n6QKdpXsOZLQbaDlwOW9Tg9iabra4MLotTldwsbmFtq1CDr7yagqycv1LG9NNzGD2cxBHjP17J7zKIH1bN6yVOUZLI6ki8NY99WISTSg923dYw5fb/XB+R51WDSQGOvwz6+Top2Bb3V1bMEEHIpkAMaOywtznW k1GR33du bbLLWw9a9DxH3o17o5DfwDvGhmQgOLbu42fuL7g26YdSnZVG55opDlwvtXkRcOWLsu5GG+JDORsKClAT96CpbDkMDLGN/rNMQzI310HRkslRYe41I2r+JZQPjVQ1nhKLHKqiqY9rWEev8vnDfnVWHPSEExVVCJ5ytY7WcP6kOg3amOrCjiQePTA8MD6TUyAk3AespyLHxhuZsHv4tItKwHH3qxYthW/6TTBagtsXzT73s5B6Yy6/QC0hB5qGnzL/7RqCuOTPA0dAcPGCpASi0xte/psOXGG6GiK7IDd4rE4lnoi5Kcl+vvgDGqvFYZlnkb8ZS X-Bogosity: Ham, tests=bogofilter, spamicity=0.000011, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Make compact_lock_irqsave and compact_unlock_should_abort use "spinlock_t *" to record held lock. This is a preparation to use compact_unlock_should_abort in isolate_migratepages_block to remove repeat code. Signed-off-by: Kemeng Shi --- mm/compaction.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 9641e2131901..dfef14d3ef78 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -523,22 +523,22 @@ static bool test_and_set_skip(struct compact_control *cc, struct page *page) * abort when the current block is finished regardless of success rate. * Sync compaction acquires the lock. * - * Always returns true which makes it easier to track lock state in callers. + * Always returns lock which makes it easier to track lock state in callers. */ -static bool compact_lock_irqsave(spinlock_t *lock, unsigned long *flags, +static spinlock_t *compact_lock_irqsave(spinlock_t *lock, unsigned long *flags, struct compact_control *cc) __acquires(lock) { /* Track if the lock is contended in async mode */ if (cc->mode == MIGRATE_ASYNC && !cc->contended) { if (spin_trylock_irqsave(lock, *flags)) - return true; + return lock; cc->contended = true; } spin_lock_irqsave(lock, *flags); - return true; + return lock; } /* @@ -553,12 +553,12 @@ static bool compact_lock_irqsave(spinlock_t *lock, unsigned long *flags, * Returns true if compaction should abort due to fatal signal pending. * Returns false when compaction can continue. */ -static bool compact_unlock_should_abort(spinlock_t *lock, - unsigned long flags, bool *locked, struct compact_control *cc) +static bool compact_unlock_should_abort(spinlock_t **locked, + unsigned long flags, struct compact_control *cc) { if (*locked) { - spin_unlock_irqrestore(lock, flags); - *locked = false; + spin_unlock_irqrestore(*locked, flags); + *locked = NULL; } if (fatal_signal_pending(current)) { @@ -586,7 +586,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, int nr_scanned = 0, total_isolated = 0; struct page *cursor; unsigned long flags = 0; - bool locked = false; + spinlock_t *locked = NULL; unsigned long blockpfn = *start_pfn; unsigned int order; @@ -607,8 +607,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, * pending. */ if (!(blockpfn % COMPACT_CLUSTER_MAX) - && compact_unlock_should_abort(&cc->zone->lock, flags, - &locked, cc)) + && compact_unlock_should_abort(&locked, flags, cc)) break; nr_scanned++; @@ -673,7 +672,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, } if (locked) - spin_unlock_irqrestore(&cc->zone->lock, flags); + spin_unlock_irqrestore(locked, flags); /* * There is a tiny chance that we have read bogus compound_order(),