From patchwork Wed Jul 19 11:29:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13318078 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 9AD1DC001DC for ; Wed, 19 Jul 2023 03:29:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C1048D003B; Tue, 18 Jul 2023 23:29:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 271CE8D0012; Tue, 18 Jul 2023 23:29:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C3828D003B; Tue, 18 Jul 2023 23:29:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E640E8D0012 for ; Tue, 18 Jul 2023 23:29:38 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B5CEE16010C for ; Wed, 19 Jul 2023 03:29:38 +0000 (UTC) X-FDA: 81026931636.14.6750DFA Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf29.hostedemail.com (Postfix) with ESMTP id EDBC612000C for ; Wed, 19 Jul 2023 03:29:34 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=none (imf29.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.56) 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=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=awPybspYBqJhakmb86/rO0BqZIwjOzPt8SuDXp7yaAM=; b=WfcML4hHSKn6wi8znyAFo4cqvZ1SybD4GfWtN1KYClcD05bznc28C2gknpVy9yPckfJU7b enZoDegMNcMbAecoDRRN6esJFu9djJ+nfGLJW1EXbiZS2Nd96fHE5iiINu+OsdnnRZATDb +l8liYqtCH/eahg3tyy6o37CzFisLNY= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=none (imf29.hostedemail.com: domain of shikemeng@huaweicloud.com has no SPF policy when checking 45.249.212.56) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689737375; a=rsa-sha256; cv=none; b=TwNpNDtHzFU9ygHuTKoX6M/CnSNCu5+ZXqAQnno5X4Pyn6KSPogJrsxETxIy0k0EVJBfM4 O/jU5xOKROm+nHv8He8eTSbGQyfPXYkMPIDZ5AhLDkkutXhD9wMr/3Faw26Gy9gPSNLtqE 6nhmPiTbCyoTwwTVEKD+Mg2X7s643Kw= Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4R5LsK3YXqz4f3lXs for ; Wed, 19 Jul 2023 11:29:25 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP2 (Coremail) with SMTP id Syh0CgAXC+mVWLdkI7bmOA--.28977S4; 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 2/4] mm/compaction: use "spinlock_t *" to record held lock in isolate_migratepages_block Date: Wed, 19 Jul 2023 19:29:59 +0800 Message-Id: <20230719113001.2023703-3-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--.28977S4 X-Coremail-Antispam: 1UD129KBjvJXoWxGryUGFWDKw13JFyDuF4rKrg_yoW5ury8pF ykCasIkr4kua4agF1aqrs5uFsIg34fJF47Ar43K3WfXF4ftF9rGw1IyFyUurWrZr13AFZ5 CFs8Ka4kAa12v3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_Jryl82xGYIkIc2x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2 F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjx v20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2 z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0pRsXo7UUUUU = X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: EDBC612000C X-Rspam-User: X-Stat-Signature: bmxwiewp35bbpyyr6g4mxe75cjxcrbab X-Rspamd-Server: rspam01 X-HE-Tag: 1689737374-68427 X-HE-Meta: U2FsdGVkX18vrDTN/QUwG7Lt8fvGPQ9KgCtxoPKT1/1nS5YmF+H70of6RMJ303Js4tp8wVqQaOpDy2PKlhXzny+qblzijZDQxGGK3TlpKc5Gqadr+ecaOUr6Vq6567uc9KbBOujoaPs8LFTNCKjR6Cm9YlB1E70u4sHxk48Pytvu9bovlVLOOE41nblKW5k6jEofYJRDFaFdZFWJ3glZV0nv2rEvJ41UxWpKJ3jjn349j6+aILD3kC3kA7kdvu2KUKesPvE2Jf8i6hixCUOfqcB/maUmpV6VaQ/U82EsHxhXZJIqXu34d1Y0bLPoGU/xyyw8UiPxx1V4TFwqnHQ5lMRe9k6c3ZFNv/e/17HnrQ2OQpONeXjs9MhUN0aXESqUlpaoYTHbykqEYhfSmLJ7SwIDbaANGodiHqqH1O98DM4cJLAh/JgBOwo2XXShzJ+cNpqS+EHlx9hL05z6pB1KuBw8j1MyFwdjiGE40tmN2nwUDyJOn30lpny8eWI2tTzVgh3BbRygbt/r4hNFS7sKEANVbHfypi8S5a0k/ganXCwN3NIxc5kaYUlr3bkjRqxeffmKS+flv9jUda+WK+CM50z+rOR7jIusibs0anmr0MYpdlXVJ0qjwlHGUCgMde+x9Hvjk5mS3cO/sgO6PM26E2YqqPQvwFxWwZ6776YdhHnSZ+0hjbK1jUfPUJ85zOLQKjHb310mLoIu0tq41JgNJDJo5ZNm/baMsBIv495BhEC+eWZXHcjwFQ+yz0GKeMiXmgKtiDS2gIYsWl69hjaN7Nd4hKlgWbGr4EOy9MXOQse44fvqgLuk476fNDPw9V3bpGK9z0utXkZAkakJEK1jqfIqa/a8rG9evWnaCtItYyDrc+jjSE9BH4hSwF1TZRpVWVTn2mizPa3p+GMLvl1/sGs2usav8T5EzccWRPXvHqaHKgHb3LJFznhEdssU5EsNfmB6zslQ8KZfzuEKElt 0Xl+uc0C wLPv07J4lwqijhvxK+/05MrhY1eN3KpxQmg5O/jpRBH4qqN4fG96+PI8frQr0QIHSBE5wn5x9hr2Jziks65ExEWGaT1s/JAvJQQ+7Q2+Q63hjSQ87Xz4FomfLsVJqmT6q5isckgvrd3QTCY7GCq2a+aA+YNTAIeXf8/zWbuDBnLFjkIl7ks2cGe0N/2DlVhlKPOky4HAD4aMmp8vhE9BlKdrtpEVFGsE6QHifNEBd/4yhbRPKFFLGuX1hpBd5Cxue/kC7+khFdAEewvGCJfYOAD/rQLrN7gwAFt1ks8FG10Aq1AjqUUQzlLkzw2V7hOAYggMK 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);