From patchwork Wed Jul 19 11:30:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13318077 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 A4F7EEB64DD for ; Wed, 19 Jul 2023 03:29:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24ABE8D0038; Tue, 18 Jul 2023 23:29:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FB4D8D0012; Tue, 18 Jul 2023 23:29:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C30A8D0038; Tue, 18 Jul 2023 23:29:38 -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 F11B98D0012 for ; Tue, 18 Jul 2023 23:29:37 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A0561140133 for ; Wed, 19 Jul 2023 03:29:37 +0000 (UTC) X-FDA: 81026931594.08.BD819A7 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf03.hostedemail.com (Postfix) with ESMTP id 1BBC12001A for ; Wed, 19 Jul 2023 03:29:34 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=none; spf=none (imf03.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.56) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689737375; 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=XnBxFyaozZFVGiP1bUbiAhAbQZNtmNSl60XiW4fqkpeYYGMskKF50s/wzLAn5bAB8PGvHg F0cA55RhhXnpb5y8NBAWPtPGkc11MHGoMWa/M+R+97f6+2wctucxarZ8PObD8aCkM9Ih+G 073ju9/x5O0uqL1B+DeIekOHMjL/A24= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=none; spf=none (imf03.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.56) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689737375; a=rsa-sha256; cv=none; b=qj32dOLpELiPAzx9dO90HBDzjbg02vGoU912Wiy4G26HBJrI5z3gFYU1RRbRvaLsmFE+oZ afIAJgfF07LWaYNRdhdInz5Xusd8CCumVti5AOl1JZL8J9+of/80K+9XmArlDui1t/RXMy I08SsJRevuO3M9OsN61T3bcEeflLuD8= Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4R5LsL0g6Rz4f3lY0 for ; Wed, 19 Jul 2023 11:29:26 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP2 (Coremail) with SMTP id Syh0CgAXC+mVWLdkI7bmOA--.28977S6; Wed, 19 Jul 2023 11:29:28 +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 4/4] mm/compaction: add compact_unlock_irqrestore to remove repeat code Date: Wed, 19 Jul 2023 19:30:01 +0800 Message-Id: <20230719113001.2023703-5-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--.28977S6 X-Coremail-Antispam: 1UD129KBjvJXoWxAF15Aw45WrWrCr1DWr1DAwb_yoWrXryxpF 4kGasIyr4kZFy3WF4ftr4ruFs0g34fXF47Ar4Sk3WfJa1FvF93Gw1SyFyUuFWrXryavFZ5 WFs8Jr18AF47Z3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPmb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUAVCq3wA2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAv FVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJw A2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE 3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr2 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjI I2zVCS5cI20VAGYxC7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I 3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxV WUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8I cVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aV AFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZE Xa7sRNv31UUUUUU== X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 1BBC12001A X-Stat-Signature: f6xxuh1ughedjhzjucf7pijmn7fjkggg X-Rspam-User: X-HE-Tag: 1689737374-384425 X-HE-Meta: U2FsdGVkX199x7ss/4VU9uN+lIH0pYstIRQ51BG9jSR1YQURIaF7yU/MTxw3zLhfjC3MZCLndG95S7tX3f2KDVnsB0yIvI6qCIQWjgekUv77G6DkbVoD8YbtBBDL5yG4W8Lh6SHFQYt370/IljDfIPss3jpyO6uBehaHgcCmjHX4mSsA2C/L5WjsCb7p8JYjc60GTbfbJXvcTFx7ceJ++FLxGr+ffObGyX24GoPV1VtJVvuNn46OTJSXYwonxpazZIN8ImdsyISPBMH2IV160sjVyaS6R1TjQfSYSMDfCSBmo5sAPqxL2fLo8JBOYfSMGBcummU0wDtBtMAh1TPbLaW0H9Az3GVnRe7/tCJNZQIjIP4gxfsUk3vBdBF2XqotGtsvrFDf0KvmtG2ElweUuuIoPe+l44Byv1UMKCFMzNp1CD5GSbBf+JHFHgoubkbhKfCqx9aQocg4QG6EO9bT+zGx4kDGSyLL/IY1vzFaliw6F4hBi8TXmsKn5DFvOBmdvrxdCKQ2Qc5Z0r7lUh94d1u1HCyKMR95Af4SZ5lO/zibXo/rpuxykIDgmtveVMbkvLTeKHecDADhb7tGKmAgroeKhj2znW9qgInT9+zGz8Lyp4wGhWHgEC5PBn5tUQf2Wxz2IrEreRSReiTK1aTshtYw+X6X+0zB78BBerSO65ssFqBZQw8sV/KLFSdIEkyfGUNUnnkLMVbV0vxU3zscazyDRyBPX3UIWN/77Fm0xWEruEQDJDCHVjxNGXOTHusGuZLlqRp+jzcZFGU3t6Krkssnq4mQ7TOHHn+F9Qo1htl0Osi8o4sdHJqrrDMTXzgCAbcYSEJ4oppWrFkQ2Oh5ml3qzNmawPlEylNsNKU0wNdgfAhm5/Ew79Q9KvpsgS+xLg6usQfVoM7g0eyS2sStvB7kkqkdNmGdUO+h2UaytZHSCTdQACt9AfqaeXZOOvvzn9aCzU0nuHLvV1ZBaW6 Q1uMe283 m8OUDc/V8SP7NOlvi2yBvrwOZSfaQ4vxxstA6z5ZIMp2PgzEf9QBWopRBqhI29NYGABHGPLjBDFjItpO7fwbH2gumbSWYSCD0cMxPOBhIBc4p5D+7N6PGXSsEUOuZJJyAwnrmIwFuWaKXQgrtMtdYlg+Hpaw2EoZOJYt4K4uTktyMftXg5zJDegXS06ZgBA1LXNkYzZa+HNprivpc28KvlkJrNSlGhS1+QniZuWa1pXpdMAlENgVc7UZ3txVzh9UtXEWv4JyGpVbkNcOtSHDDMddCkYLLYp+eJ0e+3fXvl6wIw+frlVos2ysakHSYEZYLp/fj 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);