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: Syh0CgAXC+ksnr9kFkPOOg--.2821S6 X-Coremail-Antispam: 1UD129KBjvJXoWxAF15Aw45WrWrCr1DWr1DAwb_yoWrXryxpF 4kGasIyr4kZFy3WF4ftr4ruFs0g34fXF47Ar4Sk3WfJa1FvF93Gw1SyFyUuFWrXryavFZ5 WFs8Jr18AF47Z3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_JF0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0 rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6x IIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xv wVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFc xC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_ Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2 IErcIFxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_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);