From patchwork Tue Aug 27 11:47:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13779372 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 7A92BC54735 for ; Tue, 27 Aug 2024 11:47:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 381BE6B0092; Tue, 27 Aug 2024 07:47:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30A726B0093; Tue, 27 Aug 2024 07:47:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15D5F6B0095; Tue, 27 Aug 2024 07:47:44 -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 E4E9A6B0092 for ; Tue, 27 Aug 2024 07:47:43 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9C900141849 for ; Tue, 27 Aug 2024 11:47:43 +0000 (UTC) X-FDA: 82497850806.09.DCDF69D Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf29.hostedemail.com (Postfix) with ESMTP id 1A168120013 for ; Tue, 27 Aug 2024 11:47:40 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1724759218; a=rsa-sha256; cv=none; b=DUMEegSNAoOyhf+SN1Yvct9uqT9ckpaTMIWaCITm7idJ29HKHHthqfQE+5hCE2wEv3UCE0 PD5WfEYiKzYHaOWeXb0T/uYypGxbAK6XxIFKLJyeXevgnD4aJco8H09qcDDIm2FQ1UX8pj pBut8RopP2YWwPiqyX4V+uRM/nSyx0g= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1724759218; 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=jwe2IIHCoCHMWiaxC0pKLadiDVs7qKzatsjBVzmhakM=; b=DLGMzYN34O8tPAWW6Np/1kU/1HyMaRpbRrzSe5n9SkSFMbWB1DbZMbo/8/mYsrJAxmc9Ty f6m0VRPbJD6TAwIY6+aoxPXEh40u5D4AVEVcDo717BQ956e57NAuLFXsFuNliX8dk0kPhM x+ppjIBJ+mezatcMTeuTYo4qT6Z82dE= Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WtQkL4v6VzyQZH; Tue, 27 Aug 2024 19:46:50 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id DBEC118007C; Tue, 27 Aug 2024 19:47:37 +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; Tue, 27 Aug 2024 19:47:37 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , , Jonathan Cameron , Kefeng Wang Subject: [PATCH v3 5/5] mm: memory_hotplug: unify Huge/LRU/non-LRU movable folio isolation Date: Tue, 27 Aug 2024 19:47:28 +0800 Message-ID: <20240827114728.3212578-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240827114728.3212578-1-wangkefeng.wang@huawei.com> References: <20240827114728.3212578-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf100008.china.huawei.com (7.185.36.138) X-Stat-Signature: 5zahp6485qar4umzef5p4r6q9x1ab7jc X-Rspamd-Queue-Id: 1A168120013 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724759260-916792 X-HE-Meta: U2FsdGVkX19FEnHVuDE48OqKxJ9IxTjjrN4iM8rXCkVxbfY9jQyI+s5dmdRL6tb5peyo13cwrtxc2UC9daZ5rBVEV54a+98yfK9INYOsaGn581eqpQC6omi5/QOrfkgY7KTSXGaKbcsnPZr4Wj9CzYjiMYe5OdaCvdHOMQ70MeBqIx1bmakMxdE2JkeTo/URc2lH3Fhi4EDfD/8PwbV+WBJz/7Kk2co0aer/iTA7N4AUtdlaQZVSIMM6ZQaIWBYRYRZbzrzZ+VNFx6ioC7x265bhkPFYLyt8CRulNcb0SEkUYnBzrI33SuJG8g7fvifNDncVh8nNuqfE62H9/N3Ur0tQjnfbGntPjyySo8gxtwHe7IfF501jaLjA6L3sHkh8e95fNyKWVoiAQ2gIqb94P19FUvjOR33CtWNJ71il1oAqCTedpl7bQGyev28E9B7+4qB6DRiK7woOFyXsz2kGOA4GI9vLmT/BoPFm2nDQVvlC+EUUoK3/KX3wNZ5hz21B4u+hLltw5NSwMnc7cEVa+6cR56Sh9tOe4JIXc8gmpDL9PhlqpNUMuRBd69YfJ6VapX7C/0kKWpA8AXmHgO79oqscMoB2cAAJ7gmtnYpM8qi+QUpLJnlBweCkGwGOJBAYUklQ2o/czndMqupcLs8l1dqzv+O6dgQavSrKnKly3nWsrxHevhGoAKr2Taw1UwN7oQhR11AisNegOmhXdrgTY6OewaT6G+ysuShHLicDrHwj+zNVtF9PGftKkWXlk9cTwGyvh5cWMSUD0iaL/PkBv8Ln26LA+hOGi/kVe5fjt/6TfiZHpCmmjtw/KO7v11ylnBl3a+4kNIRy1GQxkgVgBcmpfFgPTbBMmq9XeSXRDxRaZoFI96kki/qEu3OEHt33BIgI2R0O6lWsl2FMNzJjqzuz3qO6geHbp0NT5t0CKktPpdMNy3Ikh6WYJXsz85r0RQk557mj/VLU0+BhIVH dtXoDw+K nEiYCnrfSROa8XKf4HpaZ+B2Gu6wE8SFFYMyP+WUAMWIeAUsoE+t1DHFVeqZ7btZe7XGBXg/iAr7tHpAF13UhnquiEA147Kv+vFwk9URU9XGI63uRG5gdQBCirc8yOWeJCf3/p8lZWWdxAPtnFj34p1YarM+PXLFtftqTUtHT6HyZy5I8H5XdYHwINI1z5Jewaea32tcQyq8YksDnHjbm+CCdFDay3m2kLVmux9D0LyFApQjYfSL1rdYqOtfg+7tF6bAPPS5TDlzEWAE= 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 Reviewed-by: Miaohe Lin --- 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 1335fb6ef7fa..5f09866d17cf 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1772,15 +1772,15 @@ static int scan_movable_pages(unsigned long start, unsigned long end, static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) { + struct folio *folio; unsigned long pfn; - struct page *page; LIST_HEAD(source); 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 hugetlb; if (!pfn_valid(pfn)) continue; @@ -1811,34 +1811,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; + hugetlb = folio_test_hugetlb(folio); + if (!hugetlb) { + 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 (!hugetlb) + folio_put(folio); } if (!list_empty(&source)) { nodemask_t nmask = node_states[N_MEMORY]; @@ -1853,7 +1841,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 @@ -1866,11 +1854,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);