From patchwork Thu Jul 25 01:16:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13741491 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 527ADC3DA63 for ; Thu, 25 Jul 2024 01:17:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50C316B0089; Wed, 24 Jul 2024 21:16:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C4406B0093; Wed, 24 Jul 2024 21:16:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA9B66B0089; Wed, 24 Jul 2024 21:16:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A65836B0093 for ; Wed, 24 Jul 2024 21:16:58 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 591501C2352 for ; Thu, 25 Jul 2024 01:16:58 +0000 (UTC) X-FDA: 82376510916.26.8997780 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf24.hostedemail.com (Postfix) with ESMTP id C4C1C180002 for ; Thu, 25 Jul 2024 01:16:55 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721870178; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9CW5FobJ48usG6n6/p1kVA8alFXJpddb65rUplA1HdQ=; b=SGdcC8EhYaOCD4hMLNvjAasztAr3iG2YxxQtVo80FOso50ourj9XgusjGMM77pQ0thg12U D89Mhi2LJHiCsSc92Bakv0emLrfzQrWLtUqroSUP6OYsryZ1cGMAdm3j0t2g4OtDLJP6Sq 21hUpiZkOy+dGrNEj1qhUZ2kMW1zi9Y= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721870178; a=rsa-sha256; cv=none; b=KZIFhsIJEe0HCkDutpmvyB4EZvGlGJSJPIFHO/pKBgxqq4Hm2Pi5MCpX8XbYbTgP+RcvpA Ru8dL9/inBce/N1abo0VPEatsltuCWA6UcZLqWoSibv7+cohY9JINo5XTwLi0pOTCOhC7L dFx8dk8WUHy1se41E1t2XYR7vusXrxE= Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4WTtJd563xz1L9L6; Thu, 25 Jul 2024 09:16:49 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 95A6D180101; Thu, 25 Jul 2024 09:16:52 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 25 Jul 2024 09:16:52 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , Kefeng Wang Subject: [PATCH 4/4] mm: memory_hotplug: unify Huge/LRU/non-LRU movable folio isolation Date: Thu, 25 Jul 2024 09:16:47 +0800 Message-ID: <20240725011647.1306045-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240725011647.1306045-1-wangkefeng.wang@huawei.com> References: <20240725011647.1306045-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100008.china.huawei.com (7.185.36.138) X-Stat-Signature: wrsu6ufue6yexr6tqkok47q1y3dcct8g X-Rspam-User: X-Rspamd-Queue-Id: C4C1C180002 X-Rspamd-Server: rspam02 X-HE-Tag: 1721870215-617911 X-HE-Meta: U2FsdGVkX18HImFHJ+r1Ae/oLFW3ZkDMWUw/r5I++StUQCwpMEcSpmCs47uBdqm7w+F5z/HDR7q3n5nws0vwy9MW+HnJPCiP9ayQSOQELClx+WL/e+W9aNF9oNDpOsvbFyGV7sPHRk6lnckbB+RNzz+el/pg42rJpQsJ3oXKl+pMwjh4Dn+4cCbKUbCxU4lyTYmi86ZYWXstcAkQiCrB96x1QYNvkn+GBLgAgSC3nC74nN3M5aMZgzWSLF/D4xgXPVzX1Hw4Wc7UYEzkSzLSSRkf4JRVp/OpLO3TfQ43hnhV6En13DGiE4FjvSUxO3aUUHDAz0T7sdB86Zq3aKC6SRc5yo+MyAKIXwbd3VYLCMhlZysk4LREG/gZzLnOHY2oKgRDlZAD7nCS9eC/+Tf036G4sckQ7RZizJqh8r8Y5Eq82kggki1AE9oDreHqwh6fbI+ryIHXTqeP7hsqS3ptuffMbLpUQ7EIulZwJjvDRHg0dmmzkH29wqwGXzoY6x44CerG8HWz9EnHT3aNk4x8V9Ytxx3BAw4Cajj99h0zX5ttAhtQujYEP1/NYa0Tbw78H2zVAVLUOLglG7F+v3dE12xEYKPfPEmrhvadcaE+pS6G0IEUSnMADaFoknzgdPvyaTYv0C0nkOJ6pFstEeg7QMXke3L5cEFYHrbTrnqlJ7fnustXctXnZqdN07xO+hwXdb6dqGe0EmlxAFLnmpNzi2/uLeKnDm9MCdmfDiCnhiTBQ/y1+z8CSN0VpyExB0u/ZzYlYm9tP6nuyyQKWTidxM+JTEp+g2aNuxaGTsl3pcncMCgA1oRoCZFcm4q6u4Hcju1bCmNRfheq6ZEGJmglt3m7z5EUJ3mVd21xtxetADNxC7OkjDRpLLhZ9kBaC7bkjQNhZAd8O6LzqQx4XC4uyjCe9s2yTAUgQGNqh145M8jzjkge+HDJcdiPWNZJJJaCet/VKxvsrIxkHyrb2pS 8ynr7mH1 l6/FndyCJEaskh9gtn6IXIhkVLHyzWiQ1+dFRNLJwh05+Cuy1AmZUuBUYcuCOKuRTdFfzB8MjVSgBonJoiyt4bhX77aPbmupWtasONns19y5F5VolkVUzBigiasnnzQb7TeBIf8cbqX3cS9K4jLHC7dvsii9Ob7V+muvVOyslJNUvPKvjSckt41Q4Sh2M9FEYTxtLLB8y2VfVfjPpckXL1txDTnm9x0leHZBcrludCKmMEfwf9qwQc05ytxykYPT6cBPFBlUH/vgTpPXBgSGtcW/eki/EKBNo+RMHagmjB/Nc9MI= 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: List-Subscribe: List-Unsubscribe: Move isolate_hugetlb() after grab a reference, and use the isolate_folio_to_list() to unify hugetlb/LRU/non-LRU folio isolation, which cleanup code a bit and save a few calls to compound_head(). Signed-off-by: Kefeng Wang --- mm/memory_hotplug.c | 48 +++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index ccaf4c480aed..057037766efa 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1773,20 +1773,17 @@ static int scan_movable_pages(unsigned long start, unsigned long end, static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) { unsigned long pfn; - struct page *page, *head; LIST_HEAD(source); + struct folio *folio; static DEFINE_RATELIMIT_STATE(migrate_rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); for (pfn = start_pfn; pfn < end_pfn; pfn++) { - struct folio *folio; - bool isolated; + struct page *page; if (!pfn_valid(pfn)) continue; page = pfn_to_page(pfn); - folio = page_folio(page); - head = &folio->page; /* * HWPoison pages have elevated reference counts so the migration would @@ -1808,36 +1805,22 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) continue; } - if (PageHuge(page)) { - pfn = page_to_pfn(head) + compound_nr(head) - 1; - isolate_hugetlb(folio, &source); + folio = folio_get_nontail_page(page); + if (!folio) continue; - } else if (PageTransHuge(page)) - pfn = page_to_pfn(head) + thp_nr_pages(page) - 1; - - if (!get_page_unless_zero(page)) - continue; - /* - * We can skip free pages. And we can deal with pages on - * LRU and non-lru movable pages. - */ - if (PageLRU(page)) - isolated = isolate_lru_page(page); - else - isolated = isolate_movable_page(page, ISOLATE_UNEVICTABLE); - if (isolated) { - list_add_tail(&page->lru, &source); - if (!__PageMovable(page)) - inc_node_page_state(page, NR_ISOLATED_ANON + - page_is_file_lru(page)); - } else { + /* Skip free folios, deal with hugetlb, LRU and non-lru movable folios. */ + if (!isolate_folio_to_list(folio, &source)) { if (__ratelimit(&migrate_rs)) { pr_warn("failed to isolate pfn %lx\n", pfn); dump_page(page, "isolation failed"); } } - put_page(page); + + if (folio_test_large(folio)) + pfn = folio_pfn(folio) + folio_nr_pages(folio) - 1; + + folio_put(folio); } if (!list_empty(&source)) { nodemask_t nmask = node_states[N_MEMORY]; @@ -1852,7 +1835,7 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) * We have checked that migration range is on a single zone so * we can use the nid of the first page to all the others. */ - mtc.nid = page_to_nid(list_first_entry(&source, struct page, lru)); + mtc.nid = folio_nid(list_first_entry(&source, struct folio, lru)); /* * try to allocate from a different node but reuse this node @@ -1865,11 +1848,12 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) ret = migrate_pages(&source, alloc_migration_target, NULL, (unsigned long)&mtc, MIGRATE_SYNC, MR_MEMORY_HOTPLUG, NULL); if (ret) { - list_for_each_entry(page, &source, lru) { + list_for_each_entry(folio, &source, lru) { if (__ratelimit(&migrate_rs)) { pr_warn("migrating pfn %lx failed ret:%d\n", - page_to_pfn(page), ret); - dump_page(page, "migration failure"); + folio_pfn(folio), ret); + dump_page(&folio->page, + "migration failure"); } } putback_movable_pages(&source);