From mboxrd@z Thu Jan 1 00:00:00 1970 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 6DA97C3DA7F for ; Sun, 4 Aug 2024 15:11:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2B726B0085; Sun, 4 Aug 2024 11:11:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB43D6B0088; Sun, 4 Aug 2024 11:11:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 954B56B0089; Sun, 4 Aug 2024 11:11:16 -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 7015C6B0085 for ; Sun, 4 Aug 2024 11:11:16 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E61BEA82F5 for ; Sun, 4 Aug 2024 15:11:15 +0000 (UTC) X-FDA: 82414901310.17.8B52DA7 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf11.hostedemail.com (Postfix) with ESMTP id 5C5BA4000F for ; Sun, 4 Aug 2024 15:11:13 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@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=1722784213; 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=9qClS84G1zhnZUhOfPsD82qvMITT9PmAPuY/oUZ7j88=; b=3ibqQebuSa9LGK5UjPk93+36H0JAWcl82liKnjaj8wdNEHbldIuVDffLG3zfh3S3GFi99P +bvJPQgCMktcES1L1aU1tWRUR6RRTlv/BBSVDKUeRdD4wt1iT4xzMv7hruhi4FZCdVE5Bv V41jbJDTZrCOJzSHTSDnJREWqoZyCz8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722784213; a=rsa-sha256; cv=none; b=alT9ETl9XiWosopG6O+cwEP3I4JqQpJ1AXPhivaiq2QvxYUyXE7/r4PP1zDQYHs02FwwKv 6UffpVX9q84YdZQV+V2AT9zJVhyVpdR0zpS6onSm1Zb1pDqPpOvAcoDneVtqtOoeOLk+66 86egIPYXtQ1l4M2lOBNtosWJAZPTZoY= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of jonathan.cameron@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=jonathan.cameron@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WcNJB6tQWz6K5Vy; Sun, 4 Aug 2024 23:08:58 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id B33CF140A35; Sun, 4 Aug 2024 23:11:09 +0800 (CST) Received: from localhost (10.195.244.131) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Sun, 4 Aug 2024 16:11:08 +0100 Date: Sun, 4 Aug 2024 16:11:19 +0100 From: Jonathan Cameron To: Mike Rapoport CC: Andrew Morton , , Alexander Gordeev , Andreas Larsson , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Christophe Leroy , Dan Williams , Dave Hansen , David Hildenbrand , "David S. Miller" , "Davidlohr Bueso" , Greg Kroah-Hartman , Heiko Carstens , Huacai Chen , Ingo Molnar , Jiaxun Yang , "John Paul Adrian Glaubitz" , Jonathan Corbet , Michael Ellerman , Palmer Dabbelt , "Rafael J. Wysocki" , Rob Herring , Samuel Holland , "Thomas Bogendoerfer" , Thomas Gleixner , Vasily Gorbik , Will Deacon , Zi Yan , , , , , , , , , , , , , , , , Subject: Re: [PATCH v3 07/26] mm: drop CONFIG_HAVE_ARCH_NODEDATA_EXTENSION Message-ID: <20240804161119.00003a02@Huawei.com> In-Reply-To: References: <20240801060826.559858-1-rppt@kernel.org> <20240801060826.559858-8-rppt@kernel.org> <20240802104922.000051a0@Huawei.com> <20240803115813.809f808f1afbe9f9feaae129@linux-foundation.org> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.195.244.131] X-ClientProxiedBy: lhrpeml500003.china.huawei.com (7.191.162.67) To lhrpeml500005.china.huawei.com (7.191.163.240) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5C5BA4000F X-Stat-Signature: 991qy9wff4o77j5ejimc4yrwp1a9irsf X-HE-Tag: 1722784273-189389 X-HE-Meta: U2FsdGVkX18K+ZTdELyGYa75ayMz6aenFTZ69R+2r3eYKhdIPmrIoM1qBpOdUot0LRvxeKXQ7fQTtb6hcB/DMqvy1eMx9t5KTt2T6HIqlTGnbfGhI76pw4BDpLCgPgbP03cecfYIVut9ftKibPVHRLh77slipzaZXlE99rhmYObUIKyuessoMEF2PQ3SlMWyldHd7pBtLRGX9wmsS66P7e1QwmV1wnXKZY3RROwb7GGsZnb7QGSbcbtHAczzv0KVCyT8EKc1E9GGWdzcLE1bsJ2tN+iUWHS/yjqrfVl3z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ilter, 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: On Sun, 4 Aug 2024 10:24:15 +0300 Mike Rapoport wrote: > On Sat, Aug 03, 2024 at 11:58:13AM -0700, Andrew Morton wrote: > > On Fri, 2 Aug 2024 10:49:22 +0100 Jonathan Cameron wrote: > > > > > > --- a/mm/mm_init.c > > > > +++ b/mm/mm_init.c > > > > @@ -1838,11 +1838,10 @@ void __init free_area_init(unsigned long *max_zone_pfn) > > > > > > > > if (!node_online(nid)) { > > > > /* Allocator not initialized yet */ > > > > - pgdat = arch_alloc_nodedata(nid); > > > > + pgdat = memblock_alloc(sizeof(*pgdat), SMP_CACHE_BYTES); > > > > if (!pgdat) > > > > panic("Cannot allocate %zuB for node %d.\n", > > > > sizeof(*pgdat), nid); > > > > - arch_refresh_nodedata(nid, pgdat); > > > > > > This allocates pgdat but never sets node_data[nid] to it > > > and promptly leaks it on the line below. > > > > > > Just to sanity check this I spun up a qemu machine with no memory > > > initially present on some nodes and it went boom as you'd expect. > > > > > > I tested with addition of > > > NODE_DATA(nid) = pgdat; > > > and it all seems to work as expected. > > > > Thanks, I added that. It blew up on x86_64 allnoconfig because > > node_data[] (and hence NODE_DATA()) isn't an lvalue when CONFIG_NUMA=n. > > > > I'll put some #ifdef CONFIG_NUMAs in there for now but > > > > a) NODE_DATA() is upper-case. Implies "constant". Shouldn't be assigned to. > > > > b) NODE_DATA() should be non-lvalue when CONFIG_NUMA=y also. But no, > > we insist on implementing things in cpp instead of in C. > > This looks like a candidate for a separate tree-wide cleanup. > > > c) In fact assigning to anything which ends in "()" is nuts. Please > > clean up my tempfix. > > > > c) Mike, generally I'm wondering if there's a bunch of code here > > which isn't needed on CONFIG_NUMA=n. Please check all of this for > > unneeded bloatiness. > > I believe the patch addresses your concerns, just with this the commit log > needs update. Instead of > > Replace the call to arch_alloc_nodedata() in free_area_init() with > memblock_alloc(), remove arch_refresh_nodedata() and cleanup > include/linux/memory_hotplug.h from the associated ifdefery. > > it should be > > Replace the call to arch_alloc_nodedata() in free_area_init() with a > new helper alloc_offline_node_data(), remove arch_refresh_nodedata() > and cleanup include/linux/memory_hotplug.h from the associated > ifdefery. > > I can send an updated patch if you prefer. This solution looks good to me - except for a Freudian typo that means it won't compile :) Jonathan > > diff --git a/include/linux/numa.h b/include/linux/numa.h > index 3b12d8ca0afd..5a749fd67f39 100644 > --- a/include/linux/numa.h > +++ b/include/linux/numa.h > @@ -34,6 +34,7 @@ extern struct pglist_data *node_data[]; > #define NODE_DATA(nid) (node_data[nid]) > > void __init alloc_node_data(int nid); > +void __init alloc_offline_node_data(int nit); > > /* Generic implementation available */ > int numa_nearest_node(int node, unsigned int state); > @@ -62,6 +63,8 @@ static inline int phys_to_target_node(u64 start) > { > return 0; > } > + > +static inline void alloc_offline_node_data(int nit) {} nid > #endif > > #define numa_map_to_online_node(node) numa_nearest_node(node, N_ONLINE) > diff --git a/mm/mm_init.c b/mm/mm_init.c > index bcc2f2dd8021..2785be04e7bb 100644 > --- a/mm/mm_init.c > +++ b/mm/mm_init.c > @@ -1836,13 +1836,8 @@ void __init free_area_init(unsigned long *max_zone_pfn) > for_each_node(nid) { > pg_data_t *pgdat; > > - if (!node_online(nid)) { > - /* Allocator not initialized yet */ > - pgdat = memblock_alloc(sizeof(*pgdat), SMP_CACHE_BYTES); > - if (!pgdat) > - panic("Cannot allocate %zuB for node %d.\n", > - sizeof(*pgdat), nid); > - } > + if (!node_online(nid)) > + alloc_offline_node_data(nid); > > pgdat = NODE_DATA(nid); > free_area_init_node(nid); > diff --git a/mm/numa.c b/mm/numa.c > index da27eb151dc5..07e486a977c7 100644 > --- a/mm/numa.c > +++ b/mm/numa.c > @@ -34,6 +34,18 @@ void __init alloc_node_data(int nid) > memset(NODE_DATA(nid), 0, sizeof(pg_data_t)); > } > > +void __init alloc_offline_node_data(int nit) nid > +{ > + pg_data_t *pgdat; > + > + pgdat = memblock_alloc(sizeof(*pgdat), SMP_CACHE_BYTES); > + if (!pgdat) > + panic("Cannot allocate %zuB for node %d.\n", > + sizeof(*pgdat), nid); > + > + node_data[nid] = pgdat; > +} > + > /* Stub functions: */ > > #ifndef memory_add_physaddr_to_nid > > >