From patchwork Wed Jul 19 11:29:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13318079 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 BC4B7EB64DD for ; Wed, 19 Jul 2023 03:29:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 531928D0040; Tue, 18 Jul 2023 23:29:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E25D8D0012; Tue, 18 Jul 2023 23:29:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A9508D0040; Tue, 18 Jul 2023 23:29:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 296238D0012 for ; Tue, 18 Jul 2023 23:29:42 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EE6444011A for ; Wed, 19 Jul 2023 03:29:41 +0000 (UTC) X-FDA: 81026931762.10.17464B6 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf24.hostedemail.com (Postfix) with ESMTP id 9DE42180002 for ; Wed, 19 Jul 2023 03:29:37 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=none; spf=none (imf24.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=1689737378; 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=hRvwWnsgrAHSRuf+tjLlSrPs/0u+b2HMb+SRFQGBkv4iL/iqSQzA7sWmWLNw96noa80aah RWSq+O8Izo8aV0XHlP9MmRPXJYgR9DQ0RPlJqpjca8oR5ZCxyY5qbvEp5sGWhszK1gThgX wIjDxgJATSDjjvUzFf0j43BK7TJiY6U= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=none (imf24.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=1689737378; a=rsa-sha256; cv=none; b=sXicTj1w6f33/QtJT6GbKOlNM7ZNDbC7QYjGqaLdmKfjHtCbX1dIq4c+BUHdwVeV8EqU3h 9+vnoK3kgaQ7GZd2IItj2Na4I6kLj4Y75tHC6SKDsnvRVhmfxBRES0t9WeHjPw9XDh8QB2 462wzqWax/V3KRJqIhErS8h07kACmm8= Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4R5LsM0JB9z4f3jYt for ; Wed, 19 Jul 2023 11:29:27 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP2 (Coremail) with SMTP id Syh0CgAXC+mVWLdkI7bmOA--.28977S3; Wed, 19 Jul 2023 11:29:27 +0800 (CST) From: Kemeng Shi To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: shikemeng@huaweicloud.com Subject: [PATCH 1/4] mm/compaction: use "spinlock_t *" to record held lock in compact [un]lock functions Date: Wed, 19 Jul 2023 19:29:58 +0800 Message-Id: <20230719113001.2023703-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230719113001.2023703-1-shikemeng@huaweicloud.com> References: <20230719113001.2023703-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgAXC+mVWLdkI7bmOA--.28977S3 X-Coremail-Antispam: 1UD129KBjvJXoWxAw4fKFWUtr1rKFy7CFWktFb_yoW5AF4rpF 1xG3Wayr18Zay5uF4ftFW8WF43Xw1fWa4UAwsIqw1rJF45tF13Gw10ya4UurWUXasavFZa qFW3tFyUAay7ZaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBK14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_Jr4l82xGYIkIc2x26xkF7I0E14v26r1Y6r1xM28lY4IEw2IIxxk0rwA2 F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjx v20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2 z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7sRiDGYDUUUUU= = X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 9DE42180002 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 77fzyy7hfjjkmdseup8wian1i8aqhep1 X-HE-Tag: 1689737377-326837 X-HE-Meta: U2FsdGVkX1+n+KSK/z9AmB6U6/a6VRf952i+JW2UknHz7Oh7OUc00PQd+CUZouZgoH9dd6ITavSDyAZhYkcQIfMvRSaXfWbWne1dvxRctCeD1LISFiUDudKH2iMaWwryD2smhOG0dPiFyRAWRVEmIfwSlCSWzpnsGLaFJyVU4FXZDx5tZdh8OrWOWoe4MkCnDPBxXASQsIg3DfdIzDuB6JeVxLbOihpImZeLNE8dBgeEMp4wssNnFkN1WIY4BswvJzBREquAFo9T8cw3Zh+O66Q+Ja0BsU04NqpdTjnkeJzsmWHuPuUlU89JmFVYw1v/irDe/JCEh7LduDqoAa2Sq0bf8/TEQc9iBQrraaNqGVfgEM+O2lIs2MIZCCc6BgF5gQjlT9g8DMd2t3dx0cWqU/9xg7CbO5+Us0531i/BOMe8tGBKLbPI8zlPcm1xYRX31TvFpeggrOkCi5tMAyrZvVHQ/D4YfhzdzDtKhKsZrqP54rJDpBdnht4YhJ2Gy0GjZnBaYkBZPin9apv9ghen7j0zM1cV+iC3tI3vvGVzlMbRYAV6pfbGTxSRnw6eA8ckyK/GefCPsLHT1xeFOO64x20yAcp31QPrwitjyl3kEbshXl+DjhIvDqDjuIQ24XCawGMPRfoa2sjv6VXj7aBj8eWWrMB6367aQf54ufzY9+7baXivymXlgKFJaDbph+vLqiBvea5LtbfWTBWUvwMZj662Bf3v9jYljBHo8TnadATWXZY5wLWO6jk+JFgHNjSPDLYqC6a+9zW3C9ao6nntRpifjo2ZUjAR7Xkf4foOBsL9DRCP4LvaBQT5sELKWD31Jl7jihrICoDTnw0UC1D+PYusdCpykt6EoOQVjvrkkDkhqYh3aZv5ybbsgCc29fIDul/7g3Kmk+P1QQnQypWdAMN0OGzey+B4RLUYvywm5cVNe0R6UMibxOKQEmeog1uThshWXcwLXr7LroboVGU EG95kEHG v2wIEvNu8i3fIK5Hqc+FoSil9fNFxixBBkqp1lIk56RnGt9J8E5sPLsORWAow3fHZSuZ4dcd5WSxalJsYz43m9ErbEyUpWkxXtN4gZF7rPG9FTiQeb/wGeHRbeWMT61sFHWztnytqD2NkdkyKVffUJfX6eS0zcHfH2mHyZC8P8Q0TCDt9BPJqdR5HY0Vv1veNk4nWrEYlney7nABT7hWs+rufEFKUxbKJfz/VCyY8nCjALIfX+v4ud9n9gEMF6DI+0UcVIC8qXv3il7LgwG+iSH2hN1Fbk1j9Oy/EiyH5oV04tFLzLdJSePIkfwNdfPkJqGic X-Bogosity: Ham, tests=bogofilter, spamicity=0.000075, 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(),