Re: [PATCH] mm/memblock: Introduce memblock_alloc_node_or_panic() helper
Mike Rapoport <[email protected]> Thu, 4 Jun 2026 08:44:17 +0300
| Newsgroups | org.kernel.vger.sparclinux,org.kernel.vger.linux-kernel,org.kernel.vger.linux-sh,org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Jun 04, 2026 at 11:41:39AM +0800, Zhen Ni wrote: > During early boot, several subsystems allocate memory from specific > NUMA nodes using memblock_alloc_node(). When allocation fails, the > typical requirement is to panic immediately. > > Introduce memblock_alloc_node_or_panic() to automatically panic on > allocation failure. This reduces repetitive error checking, improves code > consistency across subsystems, and enhances code readability. memblock_alloc_or_panic() made sense because it's the most used memblock API. Adding panic() versions for a handful of uses is unnecessary churn. A better patch would be to update panic() messages to convey more useful information. > Signed-off-by: Zhen Ni <[email protected]> > --- > arch/sh/mm/numa.c | 10 ++++------ > arch/sparc/kernel/setup_64.c | 16 ++++++---------- > arch/x86/coco/sev/core.c | 5 ++--- > include/linux/memblock.h | 6 ++++++ > mm/memblock.c | 22 ++++++++++++++++++++++ > mm/mm_init.c | 11 ++++------- > mm/sparse.c | 13 +++++-------- > 7 files changed, 49 insertions(+), 34 deletions(-) > > diff --git a/arch/sh/mm/numa.c b/arch/sh/mm/numa.c > index 9bc212b5e762..32b01697b27f 100644 > --- a/arch/sh/mm/numa.c > +++ b/arch/sh/mm/numa.c > @@ -38,12 +38,10 @@ void __init setup_bootmem_node(int nid, unsigned long start, unsigned long end) > __add_active_range(nid, start_pfn, end_pfn); > > /* Node-local pgdat */ > - NODE_DATA(nid) = memblock_alloc_node(sizeof(struct pglist_data), > - SMP_CACHE_BYTES, nid); > - if (!NODE_DATA(nid)) > - panic("%s: Failed to allocate %zu bytes align=0x%x nid=%d\n", > - __func__, sizeof(struct pglist_data), SMP_CACHE_BYTES, > - nid); > + NODE_DATA(nid) = memblock_alloc_node_or_panic( > + sizeof(struct pglist_data), > + SMP_CACHE_BYTES, > + nid); Please don't touch this, the entire file is going away after rc1. > > NODE_DATA(nid)->node_start_pfn = start_pfn; > NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn; -- Sincerely yours, Mike.