From nobody Mon Jun 29 16:46:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03CBEC43219 for ; Mon, 7 Feb 2022 13:52:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388764AbiBGNuW (ORCPT ); Mon, 7 Feb 2022 08:50:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387672AbiBGNiC (ORCPT ); Mon, 7 Feb 2022 08:38:02 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88650C0401D5 for ; Mon, 7 Feb 2022 05:37:24 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4JsnCD1VTwz1FD17; Mon, 7 Feb 2022 21:33:12 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 7 Feb 2022 21:37:22 +0800 From: Miaohe Lin To: CC: , , Subject: [PATCH 1/4] mm/memory_hotplug: remove obsolete comment of __add_pages Date: Mon, 7 Feb 2022 21:36:40 +0800 Message-ID: <20220207133643.23427-2-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220207133643.23427-1-linmiaohe@huawei.com> References: <20220207133643.23427-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since commit f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online"), there is no need to pass in the zone. Signed-off-by: Miaohe Lin --- mm/memory_hotplug.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index a4f69d399929..cbc67c27e0dd 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -296,10 +296,7 @@ struct page *pfn_to_online_page(unsigned long pfn) EXPORT_SYMBOL_GPL(pfn_to_online_page); =20 /* - * Reasonably generic function for adding memory. It is - * expected that archs that support memory hotplug will - * call this function after deciding the zone to which to - * add the new pages. + * Reasonably generic function for adding memory. */ int __ref __add_pages(int nid, unsigned long pfn, unsigned long nr_pages, struct mhp_params *params) --=20 2.23.0 From nobody Mon Jun 29 16:46:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AFC3C433FE for ; Mon, 7 Feb 2022 13:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389219AbiBGNvX (ORCPT ); Mon, 7 Feb 2022 08:51:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387669AbiBGNiC (ORCPT ); Mon, 7 Feb 2022 08:38:02 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C562C0401D4 for ; Mon, 7 Feb 2022 05:37:24 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JsnCD2jbDzZfPd; Mon, 7 Feb 2022 21:33:12 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 7 Feb 2022 21:37:22 +0800 From: Miaohe Lin To: CC: , , Subject: [PATCH 2/4] mm/memory_hotplug: avoid calling zone_intersects() for ZONE_NORMAL Date: Mon, 7 Feb 2022 21:36:41 +0800 Message-ID: <20220207133643.23427-3-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220207133643.23427-1-linmiaohe@huawei.com> References: <20220207133643.23427-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If zid reaches ZONE_NORMAL, the caller will always get the NORMAL zone no matter what zone_intersects() returns. So we can save some possible cpu cycles by avoid calling zone_intersects() for ZONE_NORMAL. Signed-off-by: Miaohe Lin Reviewed-by: David Hildenbrand Reviewed-by: Oscar Salvador --- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index cbc67c27e0dd..140809e60e9a 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -826,7 +826,7 @@ static struct zone *default_kernel_zone_for_pfn(int nid= , unsigned long start_pfn struct pglist_data *pgdat =3D NODE_DATA(nid); int zid; =20 - for (zid =3D 0; zid <=3D ZONE_NORMAL; zid++) { + for (zid =3D 0; zid < ZONE_NORMAL; zid++) { struct zone *zone =3D &pgdat->node_zones[zid]; =20 if (zone_intersects(zone, start_pfn, nr_pages)) --=20 2.23.0 From nobody Mon Jun 29 16:46:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 181F4C4332F for ; Mon, 7 Feb 2022 13:51:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238523AbiBGNum (ORCPT ); Mon, 7 Feb 2022 08:50:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387674AbiBGNiC (ORCPT ); Mon, 7 Feb 2022 08:38:02 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DFFEC0401D6 for ; Mon, 7 Feb 2022 05:37:25 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4JsnDP0m57zdZRb; Mon, 7 Feb 2022 21:34:13 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 7 Feb 2022 21:37:22 +0800 From: Miaohe Lin To: CC: , , Subject: [PATCH 3/4] mm/memory_hotplug: clean up try_offline_node Date: Mon, 7 Feb 2022 21:36:42 +0800 Message-ID: <20220207133643.23427-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220207133643.23427-1-linmiaohe@huawei.com> References: <20220207133643.23427-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We can use helper macro node_spanned_pages to check whether node spans pages. And we can change the parameter of check_cpu_on_node to nid as that's what it really cares. Thus we can further get rid of the local variable pgdat and improve the readability a bit. Signed-off-by: Miaohe Lin Reviewed-by: David Hildenbrand --- mm/memory_hotplug.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 140809e60e9a..4b9eef861ee4 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -2008,12 +2008,12 @@ static int get_nr_vmemmap_pages_cb(struct memory_bl= ock *mem, void *arg) return mem->nr_vmemmap_pages; } =20 -static int check_cpu_on_node(pg_data_t *pgdat) +static int check_cpu_on_node(int nid) { int cpu; =20 for_each_present_cpu(cpu) { - if (cpu_to_node(cpu) =3D=3D pgdat->node_id) + if (cpu_to_node(cpu) =3D=3D nid) /* * the cpu on this node isn't removed, and we can't * offline this node. @@ -2047,7 +2047,6 @@ static int check_no_memblock_for_node_cb(struct memor= y_block *mem, void *arg) */ void try_offline_node(int nid) { - pg_data_t *pgdat =3D NODE_DATA(nid); int rc; =20 /* @@ -2055,7 +2054,7 @@ void try_offline_node(int nid) * offline it. A node spans memory after move_pfn_range_to_zone(), * e.g., after the memory block was onlined. */ - if (pgdat->node_spanned_pages) + if (node_spanned_pages(nid)) return; =20 /* @@ -2067,7 +2066,7 @@ void try_offline_node(int nid) if (rc) return; =20 - if (check_cpu_on_node(pgdat)) + if (check_cpu_on_node(nid)) return; =20 /* --=20 2.23.0 From nobody Mon Jun 29 16:46:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50968C4167E for ; Mon, 7 Feb 2022 13:52:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388814AbiBGNu1 (ORCPT ); Mon, 7 Feb 2022 08:50:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387675AbiBGNiC (ORCPT ); Mon, 7 Feb 2022 08:38:02 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5329EC0401D7 for ; Mon, 7 Feb 2022 05:37:25 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4JsnGv5RHjzbkFL; Mon, 7 Feb 2022 21:36:23 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 7 Feb 2022 21:37:23 +0800 From: Miaohe Lin To: CC: , , Subject: [PATCH 4/4] mm/memory_hotplug: fix misplaced comment in offline_pages Date: Mon, 7 Feb 2022 21:36:43 +0800 Message-ID: <20220207133643.23427-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220207133643.23427-1-linmiaohe@huawei.com> References: <20220207133643.23427-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It's misplaced since commit 7960509329c2 ("mm, memory_hotplug: print reason for the offlining failure"). Move it to the right place. Signed-off-by: Miaohe Lin Reviewed-by: David Hildenbrand --- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 4b9eef861ee4..7dc7e12302db 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1966,6 +1966,7 @@ int __ref offline_pages(unsigned long start_pfn, unsi= gned long nr_pages, return 0; =20 failed_removal_isolated: + /* pushback to free area */ undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE); memory_notify(MEM_CANCEL_OFFLINE, &arg); failed_removal_pcplists_disabled: @@ -1976,7 +1977,6 @@ int __ref offline_pages(unsigned long start_pfn, unsi= gned long nr_pages, (unsigned long long) start_pfn << PAGE_SHIFT, ((unsigned long long) end_pfn << PAGE_SHIFT) - 1, reason); - /* pushback to free area */ mem_hotplug_done(); return ret; } --=20 2.23.0