From patchwork Sat Aug 17 08:49:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13767072 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 B1081C52D7D for ; Sat, 17 Aug 2024 08:54:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89DBB6B02A0; Sat, 17 Aug 2024 04:54:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 826F26B041A; Sat, 17 Aug 2024 04:54:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6791D6B041B; Sat, 17 Aug 2024 04:54:09 -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 166A36B02A0 for ; Sat, 17 Aug 2024 04:54:09 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CE6EC1A051D for ; Sat, 17 Aug 2024 08:54:08 +0000 (UTC) X-FDA: 82461125376.09.07D3998 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf25.hostedemail.com (Postfix) with ESMTP id 40865A0002 for ; Sat, 17 Aug 2024 08:54:05 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.32 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=1723884810; 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=k4PijjS54tHclFDjnkXcHqSsxQhhlIxc0hCoJeNbyJA=; b=a2LXL7h4Rjf4T1pXTtKBQkzbdB7PPrLHxzkFq2d0PbpwRYhVg+TthFOlpepCxFZbSnlQPc cwyC1Z4CRYw7ioH0YofsYloYxEt8VEm/asdwenQr92Bi9deadRcIirilD22KJdO07OLjte 7hcgWS8lpOWnNqN7sUjkmku3V7m3huo= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.32 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=1723884810; a=rsa-sha256; cv=none; b=UjQ/52Crrn0MG32xr/jfDtZzKLMI1lfctc057x+/3mGx3I59bQRTHBD6n/AQQk0hyqlR54 GOWsL16G5iR2LqdVy9hJtm2thA3jOVI4XplnFKaFdevoEhQ8OdTrf/2NkSkIb0R2QoYqQn bK/jsf2UCsrlDJnhRZx3Io6GvbYccMQ= Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4WmCKN5rmrz1xvDn; Sat, 17 Aug 2024 16:52:08 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 86D1A140138; Sat, 17 Aug 2024 16:54:01 +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; Sat, 17 Aug 2024 16:54:01 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , Kefeng Wang Subject: [PATCH v2 5/5] mm: memory_hotplug: unify Huge/LRU/non-LRU movable folio isolation Date: Sat, 17 Aug 2024 16:49:41 +0800 Message-ID: <20240817084941.2375713-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240817084941.2375713-1-wangkefeng.wang@huawei.com> References: <20240817084941.2375713-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 40865A0002 X-Stat-Signature: tz1atqkhx8b49c875tw3c69gifj7wjtn X-HE-Tag: 1723884845-987712 X-HE-Meta: U2FsdGVkX18oCP5GSNyi7ovodzr12r88ZxejA4yAZcqchDFIPdfsVw0s6lYHCQbJDnaoqZGVj/ckptQXuvKZA+AXPYhCBpJT47OiuumYaQAMZzA9mrPszsOzlCFl7YOQwDLIPABnrtMuNktnAKosd5EFA0p2TScQLAKCQndmAGMTxHoABWlI2k7mMLCa5chEsHtzZ+GXZsofK97SYBMoY08d0WHAaZQiJSbq8xlhq8jNPQMcRwv3Z4cQseUBbQt8jNq6OJkxSo/HUuwX9kYGa8T2meyhE8Dua2khVNPF85Tz55MSz0inM7mwnGDyU/Kc/dsjHB9KBdfpgSqlyEIPAew07f33+5jQptiEkajcLxGPuIMOkBMFGH+igyiDJTxLhlU4dHsRq5p/L7aNTr62PiKfaKT4+0QS4AeJyeAZpXVjh7jdO+4yvrVaDABkzDHCgN0JVy212KriChUnpexaNpX2L9ZzXRNrHMrRXJm33dYk7CPv7nWf9LR/7IDFVtAYLR/7o/m8416d4Eb7ipu6fre/L1R7tffKOO/F6Mtup/KOWJl9WcNHI6Rs2d3fAgR77+0tbL9jDAbAttffiyDZJ5bZzhDTXk7aAeX/Lf+jgQb1kMhBboQII03k+40+HNe4NzAki4hTtvD/14mbmuzfArYtNdaMxPprIGRr83n9mSYLgyy0ZS4qkE7OfrXVMI71DUOofwNl882xDCDN2qmIiBhPcIvFLgz8eTb8vRK5/+mbvRQVRJBHefdSmCT6cMyjDfGa39oIcTI/2hFMITXaQcBNLp0TY7YNrWsRed7GEUkl+zh1/h0efOUzXbGaAMvNSA2kthBLaTzzde65aXqUg3psjOKWwV+CpKbspZEPxocoBA+4RycqAJTZh82MwlDrIa4kW8kMsB97MkHrboQkZxqqe0xARWkL4FGeZfaH1QTV0OLUEmbSdrULk+wNVVydODNqddRST7eF2dZok1t SHF1KvGH ioPiJfuhlZmtYc1Wi+BE+Hl3ONMnfX+ff5Xc3ryoMxpfGwNxHHkzgn+CvSEEYRroiUUMCbk08FNB4ERnst8aJQGjKRoz7Rj5ghP0kDmOehzPexWH+CNkw63ENUafVGRNW3o1RkiIKnMPUHnPRk3ttmfOWCPuWvUWvYDS4VJ/AAcW8G1yAANgErPPQR/nTc2+/NXGtRxD8OpjetDz657XbCSQQzASHjhlFk2TatZ7gDDntNGKPvyIpaqNERLRPgL7njxa2 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: 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 | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 02a0d4fbc3fe..cc9c16db2f8c 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1773,14 +1773,14 @@ 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; 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; + bool huge; if (!pfn_valid(pfn)) continue; @@ -1812,34 +1812,22 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) continue; } - if (folio_test_hugetlb(folio)) { - isolate_hugetlb(folio, &source); - continue; + huge = folio_test_hugetlb(folio); + if (!huge) { + folio = folio_get_nontail_page(page); + if (!folio) + continue; } - 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 { + 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 (!huge) + folio_put(folio); } if (!list_empty(&source)) { nodemask_t nmask = node_states[N_MEMORY]; @@ -1854,7 +1842,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 @@ -1867,11 +1855,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);