From patchwork Thu Apr 25 08:40:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13642969 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 284F6C4345F for ; Thu, 25 Apr 2024 08:41:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BC266B008A; Thu, 25 Apr 2024 04:40:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B97FA6B008C; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 863346B0089; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 372A86B0093 for ; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DC781A14CC for ; Thu, 25 Apr 2024 08:40:55 +0000 (UTC) X-FDA: 82047408870.22.FD15FF3 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf15.hostedemail.com (Postfix) with ESMTP id 84C87A0012 for ; Thu, 25 Apr 2024 08:40:53 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 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=1714034454; a=rsa-sha256; cv=none; b=6glpfcBeLwaRG0iYwxr3CNcQX+G6wnvXOo6KFwIDeexsOPejeZj2n5e7I+vqCiYHZGjEuD l0gCL0DqkDqzdJ01Nr2+KQkxn64dZS6ols+inT4RD6fXOVCrIsePV+Q7rxkqC99PhzrVgl 4yHqIuWGPZcZucog+jsEaI2R2Pz0NAU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 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=1714034454; 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=QR17o8ZWSMif88LPZe8fBm/tebFuGlvVlTbjrpnY1mc=; b=fwrmyrr4U2KFJHSf2Psd6neyjbRmhhDh9tbI8Yj34cA0XqeppdF1xGVvYb5RjfwDCBxQof P/jsPnbL56CT8/9XAjeSyivxO+t6ybn8ng3G2f6YRAxv5okja5Jn0ZrvEZq4RZIwaiKA+6 sQx1sVJaOCMup7E2ImvPnC423pvMpWU= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4VQ8Rl38tSz1HBkY; Thu, 25 Apr 2024 16:39:47 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id CD0211401E9; Thu, 25 Apr 2024 16:40:49 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 25 Apr 2024 16:40:49 +0800 From: Kefeng Wang To: Andrew Morton CC: , David Hildenbrand , Miaohe Lin , Naoya Horiguchi , Oscar Salvador , Zi Yan , Hugh Dickins , Jonathan Corbet , , Vishal Moola , Kefeng Wang Subject: [PATCH v2 03/10] mm: memory_hotplug: unify Huge/LRU/non-LRU folio isolation Date: Thu, 25 Apr 2024 16:40:21 +0800 Message-ID: <20240425084028.3888403-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240425084028.3888403-1-wangkefeng.wang@huawei.com> References: <20240425084028.3888403-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 dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 84C87A0012 X-Stat-Signature: r3zto9ajykw8x4ax5tm4wduiyjdmq4cq X-Rspam-User: X-HE-Tag: 1714034453-329844 X-HE-Meta: U2FsdGVkX18ybr97O6Yw15GuqkD1vR9D+B0EqMvtMg2cCzzROcArLLfsl6Us/o/umdzW6dUIVe9D+6j6cjdLJOag0Q5QzQDUMWaMPDRyclZhvfydnUqc15bW+G5PKL7bGlMViyk0XbfwQg+67KKTERUfoEMNqpNlgQUExB4Y2zeNVkEH1JWJs2dFG/+moIuDeUuD19ZVwqEFx+TpHzBzPEdcJh6uTP7oKih9mgm1f5kA6xR2eSj6hGnCNzeMt3fZCKLAG1MxT4LxeqiBUL4UnD9t3YG/vtTGdcpgutcxoBFO3k44mIMw33bi1PDAafZeyWrjafuKsyqv4GafM1bu1ZsUdFZNGeNYgWPY3G/PsGXPwRHpiCg2Cad9fsAKwQ//TPopNYmD9jDFA+1chu20ysXppaqQfE0sWWkTZUpeGDPVbv5jTUiPuB/VncpzNCsLmSQyYZBcXhiIhQZNuQoRZ1wzENORqPxf6JMtTb/z+aAQpjkp102prKokrq5H1xIuBvmyI/lq9m6Ve4FQs3oIslqqE4qlZwayzdhaqxpoY2IvZ/SxoMxrJk4tbCOr/n8s/hUl2WwIsbLYI61vu/ZLVh52rHuKy4ULkxqwva9GZe7VSMGJ+HBLATuXBFW3Pn01DLDPMh/YQBaWW8XY2qS0U9v8hInFm4t6aj/XDk0RzQ6WKdFRCdmen2AEwqqvq/GQlqKF8uQhVnZPgXCNPvF+hOw7TgosZcld9qyG7bLce4k8tWthiDHOR2dS6eltP4JOBKTdwyR7GLQNCO7QZPpSVdGod73oBNt27I9FaHUz5uhBvxxWxg1/MKT/atA+RmMDt4qxOZer88ndtA6f28g8dD4rLqa0Q7PocxhxwKUn6TjtodfbI0myUK64OFH/gPPuGIEXJB36mDBFSWMTTuc52Inx/5MOMX7fIzCgrJm9ycGPPbpEFPWOj8rlguKhNRVB1Fi3cNCXcNnpbrFQHoh w52Vr+5o PJuZZ0Yvhcpo5F5gp7+83in80XijWc1EbjNpaw1EEx3eDHe14b9oMnPIxUzEZ985A64UiC/ax9haA1r1lsKD9RE3zwKgBkXe/d/bi04Z30oCFHhpNXZCIhHq3joeMaFHSfjUpSI9z8WB1Kv9FfKGPPLa5yC0G8tCwAb7/RwFu7qNpvYYlnMHeFF2Ip0Aa60TIEuPpWuFmiCtfpgVPPuUcEKCMtHvjClRI4k76rDInmpebaXXZdzqx2UN59UFvESwlxA0nHt7zEDM17VWDcoV3JRbPMZEje7zvBmQvrgbZzbKQjPU= 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 | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 1985caf73e5a..0e40ee39aa88 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1804,20 +1804,17 @@ static bool isolate_and_unmap_hwposion_folio(struct folio *folio) 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 @@ -1839,36 +1836,21 @@ 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)); + if (folio_test_large(folio)) + pfn = folio_pfn(folio) + folio_nr_pages(folio) - 1; - } 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); + folio_put(folio); } if (!list_empty(&source)) { nodemask_t nmask = node_states[N_MEMORY]; @@ -1883,7 +1865,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 @@ -1896,11 +1878,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);