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(), From patchwork Tue Jul 25 18:04:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13326259 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 C52A4C001E0 for ; Tue, 25 Jul 2023 10:04:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4E546B0081; Tue, 25 Jul 2023 06:04:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD5D36B0082; 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 A4E916B0083; Tue, 25 Jul 2023 06:04:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 912756B0081 for ; Tue, 25 Jul 2023 06:04:39 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 66EF91C9926 for ; Tue, 25 Jul 2023 10:04:39 +0000 (UTC) X-FDA: 81049699878.05.7F6B94C Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf03.hostedemail.com (Postfix) with ESMTP id C94092001A for ; Tue, 25 Jul 2023 10:04:35 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; spf=none (imf03.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none 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=awPybspYBqJhakmb86/rO0BqZIwjOzPt8SuDXp7yaAM=; b=IIg/KsVKnGPp4YUPhETURL8G5H1sDZgjekHuXZjkzid1jPQ0lN1IO7toCN44Nn60vFAkfN SP0aW0z5+orNkz1Z2QAmrdmDFqsCWRk9MmQLR5qSg0jAR6/K5ZLrwZJ41itaZ8PUgf5bVL GQ1IXer50SWxZtVrcgBJTfUTViSVdLY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690279476; a=rsa-sha256; cv=none; b=L4jYo6RDZD2iUacpdRX0/Epwf3doy2987eiF1MzBVITdW70s9wwuGvqadwuc8AAaPVpChk /eDbe7ICk4otPSytdLUFHKBsykHms6tDXxh4urxwSlzbyul90RF1MgyvLwbxGWEi31W1zd 6y8qySRcOS4bq2Y/h9wJCSxFb+BUpuE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; spf=none (imf03.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4R9CLN5hYGz4f3kjs 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--.2821S4; 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 2/4] mm/compaction: use "spinlock_t *" to record held lock in isolate_migratepages_block Date: Wed, 26 Jul 2023 02:04:54 +0800 Message-Id: <20230725180456.2146626-3-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--.2821S4 X-Coremail-Antispam: 1UD129KBjvJXoWxGryUGFWDKw13JFyDuF4rKrg_yoW5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SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: C94092001A X-Rspam-User: X-Stat-Signature: 1ek3tu7otumsya6uf15renor9yb6m8wd X-Rspamd-Server: rspam03 X-HE-Tag: 1690279475-907495 X-HE-Meta: U2FsdGVkX1+urIbI5phzLE7lWG/Qodu6GoZ+3sS1ywrD+hV2hYSdterP+NanB1FhaZVzVBFqnU8BzOymvDcpGZA5t09iE+uULjPARA0rPPOWctpo4ukLSJs7Um85u2Dz5MfeA3niOCfaIq4aVrkXFDsVL3OmsV5n0CT/2WhbMRumkG2IEAP5CG3eDd1oTHn250M7aomVphx5Jg42cbvYI2K5YfKfb/FzNiCRRW2YD4dbnLfI1i5pGVwQVmAinHTXlusDP3U51yMFstoNoFp6n/Okc4ictZ78u46csgHIuMKZm6GiLRZUrjQx4VysNibJpDidnFMfCDR3D7g2xkZyrEV+mO7QhrE+jGkG0wbXEBlGj0xV5p33xuIsDagtp5yOn7uqwNv0A4vH/RWSBjihtdYs7eAfQu71x5DkFtt+XSQTtLe0TnYY715ppKHAafDA8x9ZbGNNUddKwSLbbcD/oov3nr6eFbq7eQ/Vi0WFK9+/4EVc4rB8e6ZE2KOHu8nnbwbrJN9NGRj4uYIy398vbPrygXEVg350Z1+3IIOmwwJi8dF5u+qpTH4zF8uykFs16NcBrQj/Ycbr6PIG3qeezx7D1FLRU3E8H2lQw+Cj+OE+RES1CdSVHmf3HLdCgzxs3Cw7afj/s9rzZ52qY91pVksJ9QsTbZ9vVkKxwdAAjwFpqAuYAqNrUVutxdkTjztfFAEKKX1kv9p5HAfUuLhnv/E8oIzXLteoJ1ajrgcFGv9lsQI5ZrzyR6LDr1XwBQXkR1R1DjB7zJvKv3ATUGIWWoBRoOkVDT7BquTT4yHmUaAsWrA7H8dMEmqgyzodba+pgxbPr/Nwmy6McD3fYNOm1t7fEAHPakReF30ND3v2+g/OgN6AqyPkSmWRtjArE/MpZPBVptwnPVBU2DwgIFmMfj81n9xaAL9phBqu5CRjj2lMDpKGq3xU3OB8ocxoo9G8Hvlou09YB/Y3BAopfEt 0m9j9EbO xKZgwcP11y8oWWu3CvTLVthRD+AmmN8M0b6OmgdCqyRQkQkrwWI+xxhlgbauTC6PjTYuOZl9D17nrZiGElm/wIPRybKh0pfgSL0LlFHQKJpIC4KQtIhy0CSQTZJB35cIwtaPwIpRS68cVCa8CgYitpbzIyk1Tf4c35fJkQJ/hDt2KKmT7GF50cvR1V2tSWqgZaSDexAwfRuUrm/kya2rP4ukzcokonh+llFUQ9amFbzMfnOv9dMnWHC+jYikyKMqwzSrPa7R1n9R8Vh4ClOLseN9kLhRgw+Hy/Y76pqSZkUgkp6i3OKmgRFaIuDy59S42oYgJ 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: Use "spinlock_t *" instead of "struct lruvec *" to record held lock in isolate_migratepages_block. 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 | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index dfef14d3ef78..638146a49e89 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -840,7 +840,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, unsigned long nr_scanned = 0, nr_isolated = 0; struct lruvec *lruvec; unsigned long flags = 0; - struct lruvec *locked = NULL; + spinlock_t *locked = NULL; struct folio *folio = NULL; struct page *page = NULL, *valid_page = NULL; struct address_space *mapping; @@ -911,7 +911,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, */ if (!(low_pfn % COMPACT_CLUSTER_MAX)) { if (locked) { - unlock_page_lruvec_irqrestore(locked, flags); + spin_unlock_irqrestore(locked, flags); locked = NULL; } @@ -946,7 +946,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, if (PageHuge(page) && cc->alloc_contig) { if (locked) { - unlock_page_lruvec_irqrestore(locked, flags); + spin_unlock_irqrestore(locked, flags); locked = NULL; } @@ -1035,7 +1035,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, if (unlikely(__PageMovable(page)) && !PageIsolated(page)) { if (locked) { - unlock_page_lruvec_irqrestore(locked, flags); + spin_unlock_irqrestore(locked, flags); locked = NULL; } @@ -1120,12 +1120,11 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, lruvec = folio_lruvec(folio); /* If we already hold the lock, we can skip some rechecking */ - if (lruvec != locked) { + if (&lruvec->lru_lock != locked) { if (locked) - unlock_page_lruvec_irqrestore(locked, flags); + spin_unlock_irqrestore(locked, flags); - compact_lock_irqsave(&lruvec->lru_lock, &flags, cc); - locked = lruvec; + locked = compact_lock_irqsave(&lruvec->lru_lock, &flags, cc); lruvec_memcg_debug(lruvec, folio); @@ -1188,7 +1187,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, isolate_fail_put: /* Avoid potential deadlock in freeing page under lru_lock */ if (locked) { - unlock_page_lruvec_irqrestore(locked, flags); + spin_unlock_irqrestore(locked, flags); locked = NULL; } folio_put(folio); @@ -1204,7 +1203,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, */ if (nr_isolated) { if (locked) { - unlock_page_lruvec_irqrestore(locked, flags); + spin_unlock_irqrestore(locked, flags); locked = NULL; } putback_movable_pages(&cc->migratepages); @@ -1236,7 +1235,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, isolate_abort: if (locked) - unlock_page_lruvec_irqrestore(locked, flags); + spin_unlock_irqrestore(locked, flags); if (folio) { folio_set_lru(folio); folio_put(folio); From patchwork Tue Jul 25 18:04:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13326260 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 0F3F3C001DE for ; Tue, 25 Jul 2023 10:04:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D3506B0082; Tue, 25 Jul 2023 06:04:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E76B6B0083; Tue, 25 Jul 2023 06:04:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 261688D0001; Tue, 25 Jul 2023 06:04:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D9EB56B0083 for ; Tue, 25 Jul 2023 06:04:39 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A31D8C0D41 for ; Tue, 25 Jul 2023 10:04:39 +0000 (UTC) X-FDA: 81049699878.01.A28877F Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf19.hostedemail.com (Postfix) with ESMTP id 226701A0008 for ; Tue, 25 Jul 2023 10:04:36 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=none (imf19.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690279477; 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=x9v0+bXHLbOs8FPC2KuF031VIxfFu8wt05pC+Hq88L0=; b=wTnDi/gOY4k/2Pc6RsgGiKGI9KievVvuYunhvBUHRe2mvrYft4qitVHX5eXeG3zP+mMzpl TpOm6AlpDD0iBT3ZnagljNawbUam5iR6XzX81EYf6hmYUzHJWwH5R/7LBqLIHw6w6JbLDD YFM9AaR7SIj5SMv5qBnkRuRzY7149ik= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690279477; a=rsa-sha256; cv=none; b=Q2v6xdA+xpexfq+s/F0lX1pbv0w1+2KeCFknfFZN151PpkPVrPhDtfhzY4zJItN0KS3CBe YKV5sqP0iUB/K37/6I+/TETzF/oL5UTLgBDLxZNheB4wTl4X+LopI8btX8UjTzTrzwQcZl B0MGEzj159A5FDhJVBFsqWccsHeefCE= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=none (imf19.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.51) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4R9CLP3gpSz4f3l8X for ; Tue, 25 Jul 2023 18:04:29 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP2 (Coremail) with SMTP id Syh0CgAXC+ksnr9kFkPOOg--.2821S6; Tue, 25 Jul 2023 18:04:30 +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 4/4] mm/compaction: add compact_unlock_irqrestore to remove repeat code Date: Wed, 26 Jul 2023 02:04:56 +0800 Message-Id: <20230725180456.2146626-5-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: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IIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0pRHa0PU UUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 226701A0008 X-Rspam-User: X-Stat-Signature: 71uaxummzhn9rwcrupinne3pqie8wp19 X-Rspamd-Server: rspam03 X-HE-Tag: 1690279476-666700 X-HE-Meta: U2FsdGVkX19ctUxXARKQt/PWApJrRfuACEU6qBpI5YvDdM1mgMxzdyJxPR1ENRsg/TQxyZ/aXx1SOr44YgOkaswjPcIeZeLOdoNbMYLNzUxRdGCCv9sYbW3HSpLQVTt6OE7eunnyCxOnq/ZqQUyt5fMTVbQnMxHfAbyi8fJd/BCQKnkKjPPYZLiGPTHeO54KiKGhZBPqZ6IX5mMjivwXfpPF56I5y9wQcDpx5+Rnvnt8BOt8oK6/SRrnLK9O8DhKHFeca/Bfmu4VEx6QqRvKkFQTMNa3v/erkc+LEAtIvDXLCuXnsiee8V9xcVTO4GWji6SO5NbJ93BXyQ2qgB7acUcO8g3RwtOzmvGKwVShl0us9pYm/huSl/eLyBOyV6/DoKNi3E6h7WNo765Uq799KUKWWqXzeWJ01RI+bL6q0/IgBIQb54aNiysosV+M8DGD7xOe3c+8HkgULQJ7Pi7kka0juNe5F19LeTNEEnSUyXLoTukVQBn0CnnwEb0xxjQBcBppbl4X4HmIm2qogptXF7roirisC7t8BrcKx981WecCvzNvPmewpSoJK34HBK/D3Dfei6GsbLpTl8yr/atkSmeANez0U1heCYnPC5h7seq4+zNHOOTSG6WL7Atthc7nkd9EQknzN6sfWi2mO8hiSASeKaEGJvAzOGQf1TFQsW/Dew9Z6cgwYd4P+tGvzY86NdzB+Gz8E29gs17sKmHg7+UQM6/8ba3PtQOFlGdyy3+18tZn1efPHqTWxN94IfF3ghhLKSjOuHHHiIBzVdrFgXs1M9SCRX4Tud/1huhIL7RCPeFSPyfE4yUpKkwsZoVqsHpWOvmsYvb+er8xvIwBH3Gy6nkBI9Wbd0x72JBO6QbfvlOdy6Mhyt/AgLUBW6SHK5aK7NZKSyRvGJG0I88XP2Ubg+kkWTwK6CNLnTHk4P+bgcAWMcMHphWZl9gHS793szy6nXm/gCjaW7fZ71V ZxTbmeqb YmpkGyZmMlqWXUpASFUpfXTT1w8fIEJ0QFF97nG74muFzjdZlAfUO3xbRxagD9p5QHLfRZSPmqF1e9QcjchaHr/SVqmBtV5e8S0vM91v+keQycBWENmCz5SZBKWXlBzpCE+JBq0q1Q6pvaBCB9gb35Vc+BplBlqGStkuqSGZqRjAjhBdZPa9D0fRicmP0wwo8N0fEiMhcdNYf5NiTONU8B9MW0WPhI8XCy0vpPY2PbytZzzJSTRJveZe7jIzasWlu+UNt40GTPhEz/zY12eX5pBAGMXt/341OWjyNsqUm4S7YtMljlgDVDHCWh0uurcWC7Wvx 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: Add compact_unlock_irqrestore to remove repeat code. This also make compact lock functions sereis complete as we can call compact_lock_irqsave/compact_unlock_irqrestore in pair. Signed-off-by: Kemeng Shi --- mm/compaction.c | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index c1dc821ac6e1..eb1d3d9a422c 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -541,6 +541,14 @@ static spinlock_t *compact_lock_irqsave(spinlock_t *lock, unsigned long *flags, return lock; } +static inline void compact_unlock_irqrestore(spinlock_t **locked, unsigned long flags) +{ + if (*locked) { + spin_unlock_irqrestore(*locked, flags); + *locked = NULL; + } +} + /* * Compaction requires the taking of some coarse locks that are potentially * very heavily contended. The lock should be periodically unlocked to avoid @@ -556,10 +564,7 @@ static spinlock_t *compact_lock_irqsave(spinlock_t *lock, unsigned long *flags, static bool compact_unlock_should_abort(spinlock_t **locked, unsigned long flags, struct compact_control *cc) { - if (*locked) { - spin_unlock_irqrestore(*locked, flags); - *locked = NULL; - } + compact_unlock_irqrestore(locked, flags); if (fatal_signal_pending(current)) { cc->contended = true; @@ -671,8 +676,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc, } - if (locked) - spin_unlock_irqrestore(locked, flags); + compact_unlock_irqrestore(&locked, flags); /* * There is a tiny chance that we have read bogus compound_order(), @@ -935,10 +939,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, } if (PageHuge(page) && cc->alloc_contig) { - if (locked) { - spin_unlock_irqrestore(locked, flags); - locked = NULL; - } + compact_unlock_irqrestore(&locked, flags); ret = isolate_or_dissolve_huge_page(page, &cc->migratepages); @@ -1024,10 +1025,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, */ if (unlikely(__PageMovable(page)) && !PageIsolated(page)) { - if (locked) { - spin_unlock_irqrestore(locked, flags); - locked = NULL; - } + compact_unlock_irqrestore(&locked, flags); if (isolate_movable_page(page, mode)) { folio = page_folio(page); @@ -1111,9 +1109,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, /* If we already hold the lock, we can skip some rechecking */ if (&lruvec->lru_lock != locked) { - if (locked) - spin_unlock_irqrestore(locked, flags); - + compact_unlock_irqrestore(&locked, flags); locked = compact_lock_irqsave(&lruvec->lru_lock, &flags, cc); lruvec_memcg_debug(lruvec, folio); @@ -1176,10 +1172,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, isolate_fail_put: /* Avoid potential deadlock in freeing page under lru_lock */ - if (locked) { - spin_unlock_irqrestore(locked, flags); - locked = NULL; - } + compact_unlock_irqrestore(&locked, flags); folio_put(folio); isolate_fail: @@ -1192,10 +1185,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, * page anyway. */ if (nr_isolated) { - if (locked) { - spin_unlock_irqrestore(locked, flags); - locked = NULL; - } + compact_unlock_irqrestore(&locked, flags); putback_movable_pages(&cc->migratepages); cc->nr_migratepages = 0; nr_isolated = 0; @@ -1224,8 +1214,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, folio = NULL; isolate_abort: - if (locked) - spin_unlock_irqrestore(locked, flags); + compact_unlock_irqrestore(&locked, flags); if (folio) { folio_set_lru(folio); folio_put(folio);