mm: introduce numa_memblks
Subsystems (22)
Mike Rapoport
maintainercover mm: introduce numa_memblks
From: "Mike Rapoport (Microsoft)" <[email protected]>
Hi,
Following the discussion about handling of CXL fixed memory windows on arm64 [1] I decided to bite the bullet and move numa_memblks from x86 to the generic code so they will be available on arm64/riscv and maybe on loongarch sometime later.
While it could be possible to use memblock to describe CXL memory windows, it currently lacks notion of unpopulated memory ranges and numa_memblks does implement this.
Another reason to make numa_memblks generic is that both arch_numa (arm64 and riscv) and loongarch use trimmed copy of x86 code although there is no fundamental reason why the same code cannot be used on all these platforms. Having numa_memblks in mm/ will make it's interaction with ACPI and FDT more consistent and I believe will reduce maintenance burden.
And with generic numa_memblks it is (almost) straightforward to enable NUMA emulation on arm64 and riscv.
The first 5 commits in this series are cleanups that are not strictly related to numa_memblks.
Commits 6-11 slightly reorder code in x86 to allow extracting numa_memblks and NUMA emulation to the generic code.
Commits 12-14 actually move the code from arch/x86/ to mm/ and commit 15 does some aftermath cleanups.
Commit 16 switches arch_numa to numa_memblks.
Commit 17 enables usage of phys_to_target_node() and memory_add_physaddr_to_nid() with numa_memblks.
[1] https://lore.kernel.org/all/[email protected]/
Mike Rapoport (Microsoft) (17):
mm: move kernel/numa.c to mm/
MIPS: sgi-ip27: make NODE_DATA() the same as on all other
architectures
MIPS: loongson64: rename __node_data to node_data
arch, mm: move definition of node_data to generic code arch, mm: pull out allocation of NODE_DATA to generic code x86/numa: simplify numa_distance allocation
x86/numa: move FAKE_NODE_* defines to numa_emu x86/numa_emu: simplify allocation of phys_dist x86/numa_emu: split __apicid_to_node update to a helper function x86/numa_emu: use a helper function to get MAX_DMA32_PFN x86/numa: numa_{add,remove}_cpu: make cpu parameter unsigned
mm: introduce numa_memblks
mm: move numa_distance and related code from x86 to numa_memblks
mm: introduce numa_emulation
mm: make numa_memblks more self-contained
arch_numa: switch over to numa_memblks
mm: make range-to-target_node lookup facility a part of numa_memblks
arch/arm64/include/asm/Kbuild | 1 +
arch/arm64/include/asm/mmzone.h | 13 -
arch/arm64/include/asm/topology.h | 1 +
arch/loongarch/include/asm/Kbuild | 1 +
arch/loongarch/include/asm/mmzone.h | 16 -
arch/loongarch/include/asm/topology.h | 1 +
arch/loongarch/kernel/numa.c | 21 -
arch/mips/include/asm/mach-ip27/mmzone.h | 1 -
.../mips/include/asm/mach-loongson64/mmzone.h | 4 -
arch/mips/loongson64/numa.c | 20 +-
arch/mips/sgi-ip27/ip27-memory.c | 2 +-
arch/powerpc/include/asm/mmzone.h | 6 -
arch/powerpc/mm/numa.c | 26 +-
arch/riscv/include/asm/Kbuild | 1 +
arch/riscv/include/asm/mmzone.h | 13 -
arch/riscv/include/asm/topology.h | 4 +
arch/s390/include/asm/Kbuild | 1 +
arch/s390/include/asm/mmzone.h | 17 -
arch/s390/kernel/numa.c | 3 -
arch/sh/include/asm/mmzone.h | 3 -
arch/sh/mm/init.c | 7 +-
arch/sh/mm/numa.c | 3 -
arch/sparc/include/asm/mmzone.h | 4 -
arch/sparc/mm/init_64.c | 11 +-
arch/x86/Kconfig | 9 +-
arch/x86/include/asm/Kbuild | 1 +
arch/x86/include/asm/mmzone.h | 6 -
arch/x86/include/asm/mmzone_32.h | 17 -
arch/x86/include/asm/mmzone_64.h | 18 -
arch/x86/include/asm/numa.h | 24 +-
arch/x86/include/asm/sparsemem.h | 9 -
arch/x86/mm/Makefile | 1 -
arch/x86/mm/amdtopology.c | 1 +
arch/x86/mm/numa.c | 618 +-----------------
arch/x86/mm/numa_internal.h | 24 -
drivers/acpi/numa/srat.c | 1 +
drivers/base/Kconfig | 1 +
drivers/base/arch_numa.c | 223 ++-----
drivers/cxl/Kconfig | 2 +-
drivers/dax/Kconfig | 2 +-
drivers/of/of_numa.c | 1 +
include/asm-generic/mmzone.h | 5 +
include/asm-generic/numa.h | 6 +-
include/linux/numa.h | 5 +
include/linux/numa_memblks.h | 58 ++
kernel/Makefile | 1 -
kernel/numa.c | 26 -
mm/Kconfig | 11 +
mm/Makefile | 3 +
mm/numa.c | 57 ++
{arch/x86/mm => mm}/numa_emulation.c | 42 +-
mm/numa_memblks.c | 565 ++++++++++++++++
52 files changed, 847 insertions(+), 1070 deletions(-)
delete mode 100644 arch/arm64/include/asm/mmzone.h
delete mode 100644 arch/loongarch/include/asm/mmzone.h
delete mode 100644 arch/riscv/include/asm/mmzone.h
delete mode 100644 arch/s390/include/asm/mmzone.h
delete mode 100644 arch/x86/include/asm/mmzone.h
delete mode 100644 arch/x86/include/asm/mmzone_32.h
delete mode 100644 arch/x86/include/asm/mmzone_64.h
create mode 100644 include/asm-generic/mmzone.h
create mode 100644 include/linux/numa_memblks.h
delete mode 100644 kernel/numa.c
create mode 100644 mm/numa.c
rename {arch/x86/mm => mm}/numa_emulation.c (94%)
create mode 100644 mm/numa_memblks.cbase-commit: 22a40d14b572deb80c0648557f4bd502d7e83826
Signature · 1 line
2.43.0
Mike Rapoport
maintainerPATCH 1/17 mm: move kernel/numa.c to mm/
From: "Mike Rapoport (Microsoft)" <[email protected]>
The stub functions in kernel/numa.c belong to mm/ rather than to kernel/
---
kernel/Makefile | 1 -
mm/Makefile | 1 +
{kernel => mm}/numa.c | 0
3 files changed, 1 insertion(+), 1 deletion(-)
rename {kernel => mm}/numa.c (100%)kernel/Makefile +0 -1
@@ -116,7 +116,6 @@ obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o obj-$(CONFIG_HAVE_STATIC_CALL) += static_call.o obj-$(CONFIG_HAVE_STATIC_CALL_INLINE) += static_call_inline.o obj-$(CONFIG_CFI_CLANG) += cfi.o -obj-$(CONFIG_NUMA) += numa.o obj-$(CONFIG_PERF_EVENTS) += events/
mm/Makefile +1 -0
@@ -139,3 +139,4 @@ obj-$(CONFIG_HAVE_BOOTMEM_INFO_NODE) += bootmem_info.o obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o obj-$(CONFIG_EXECMEM) += execmem.o +obj-$(CONFIG_NUMA) += numa.o
mm/numa.c renamed from kernel/numa.c +0 -0
Signature · 1 line
2.43.0
Re: [PATCH 01/17] mm: move kernel/numa.c to mm/
Quoted 6 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
The stub functions in
kernel/numa.cbelong tomm/rather than tokernel/Signed-off-by Mike Rapoport (Microsoft) <[email protected]>---
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 01/17] mm: move kernel/numa.c to mm/
In reply to Mike RapoportQuoted 5 lines · On Tue, 16 Jul 2024 14:13:30 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
The stub functions in
kernel/numa.cbelong tomm/rather than tokernel/Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Makes sense + all arch specific implementations are in arch/*/mm not arch/*/kernel so this makes it more consistent with that.
Mike Rapoport
maintainerPATCH 2/17 MIPS: sgi-ip27: make NODE_DATA() the same as on all other architectures
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
sgi-ip27 is the only system that defines NODE_DATA() differently than the rest of NUMA machines.
Add node_data array of struct pglist pointers that will point to __node_data[node]->pglist and redefine NODE_DATA() to use node_data array.
This will allow pulling declaration of node_data to the generic mm code in the next commit.
--- arch/mips/include/asm/mach-ip27/mmzone.h | 5 ++++- arch/mips/sgi-ip27/ip27-memory.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
arch/mips/include/asm/mach-ip27/mmzone.h +4 -1
@@ -22,7 +22,10 @@ struct node_data {extern struct node_data *__node_data[]; -#define NODE_DATA (n) (&__node_data[(n)]->pglist)#define hub_data (n) (&__node_data[(n)]->hub) +extern struct pglist_data *node_data[]; + +#define NODE_DATA (nid) (node_data[nid]) +#endif /* _ASM_MACH_MMZONE_H */
arch/mips/sgi-ip27/ip27-memory.c +4 -1
@@ -34,8 +34,10 @@#define SLOT_PFNSHIFT (SLOT_SHIFT - PAGE_SHIFT)#define PFN_NASIDSHFT (NASID_SHFT - PAGE_SHIFT) -struct node_data *__node_data[MAX_NUMNODES ]; +struct pglist_data *node_data[MAX_NUMNODES ]; +EXPORT_SYMBOL (node_data); +struct node_data *__node_data[MAX_NUMNODES ];EXPORT_SYMBOL (__node_data);static u64 gen_region_mask (void )
@@ -361,6 +363,7 @@ static void __init node_mem_init(nasid_t node)*/ __node_data[node] =__va (slot_freepfn <<PAGE_SHIFT );memset (__node_data[node],0 ,PAGE_SIZE ); + node_data[node] = &__node_data[node]->pglist;NODE_DATA (node)->node_start_pfn = start_pfn;NODE_DATA (node)->node_spanned_pages = end_pfn - start_pfn;
Signature · 1 line
2.43.0
Re: [PATCH 02/17] MIPS: sgi-ip27: make NODE_DATA() the same as on all other architectures
Quoted 51 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
sgi-ip27 is the only system that defines
NODE_DATA()differently than the rest of NUMA machines.Add
node_dataarray of struct pglist pointers that will point to __node_data[node]->pglist and redefineNODE_DATA()to usenode_dataarray.This will allow pulling declaration of
node_datato the generic mm code in the next commit.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>--- arch/mips/include/asm/mach-ip27/mmzone.h | 5 ++++- arch/mips/sgi-ip27/ip27-memory.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)arch/mips/include/asm/mach-ip27/mmzone.h +4
-1@@ -22,7 +22,10 @@ struct node_data {extern struct node_data *__node_data[]; -#define NODE_DATA (n) (&__node_data[(n)]->pglist)#define hub_data (n) (&__node_data[(n)]->hub) +extern struct pglist_data *node_data[]; + +#define NODE_DATA (nid) (node_data[nid]) +#endif /* _ASM_MACH_MMZONE_H */ arch/mips/sgi-ip27/ip27-memory.c +3
-1@@ -34,8 +34,10 @@#define SLOT_PFNSHIFT (SLOT_SHIFT - PAGE_SHIFT)#define PFN_NASIDSHFT (NASID_SHFT - PAGE_SHIFT) -struct node_data *__node_data[MAX_NUMNODES ]; +struct pglist_data *node_data[MAX_NUMNODES ]; +EXPORT_SYMBOL (node_data); +struct node_data *__node_data[MAX_NUMNODES ];EXPORT_SYMBOL (__node_data);static u64 gen_region_mask (void )
arch/mips/sgi-ip27/ip27-memory.c static void __init node_mem_init(nasid_t node) · line 369
Quoted 7 lines
arch/mips/sgi-ip27/ip27-memory.c +1
-0@@ -361,6 +363,7 @@ static void __init node_mem_init(nasid_t node)*/ __node_data[node] =__va (slot_freepfn <<PAGE_SHIFT );memset (__node_data[node],0 ,PAGE_SIZE ); + node_data[node] = &__node_data[node]->pglist;NODE_DATA (node)->node_start_pfn = start_pfn;NODE_DATA (node)->node_spanned_pages = end_pfn - start_pfn;
I was assuming we could get rid of __node_data->pglist.
But now I am confused where that is actually set.
Anyhow
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 02/17] MIPS: sgi-ip27: make NODE_DATA() the same as on all other architectures
Quoted 57 lines · On Wed, 17 Jul 2024 16:32:59 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 56 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
sgi-ip27 is the only system that defines
NODE_DATA()differently than the rest of NUMA machines.Add
node_dataarray of struct pglist pointers that will point to __node_data[node]->pglist and redefineNODE_DATA()to usenode_dataarray.This will allow pulling declaration of
node_datato the generic mm code in the next commit.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>--- arch/mips/include/asm/mach-ip27/mmzone.h | 5 ++++- arch/mips/sgi-ip27/ip27-memory.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)arch/mips/include/asm/mach-ip27/mmzone.h +4
-1@@ -22,7 +22,10 @@ struct node_data {extern struct node_data *__node_data[]; -#define NODE_DATA (n) (&__node_data[(n)]->pglist)#define hub_data (n) (&__node_data[(n)]->hub) +extern struct pglist_data *node_data[]; + +#define NODE_DATA (nid) (node_data[nid]) +#endif /* _ASM_MACH_MMZONE_H */ arch/mips/sgi-ip27/ip27-memory.c +4
-1@@ -34,8 +34,10 @@#define SLOT_PFNSHIFT (SLOT_SHIFT - PAGE_SHIFT)#define PFN_NASIDSHFT (NASID_SHFT - PAGE_SHIFT) -struct node_data *__node_data[MAX_NUMNODES ]; +struct pglist_data *node_data[MAX_NUMNODES ]; +EXPORT_SYMBOL (node_data); +struct node_data *__node_data[MAX_NUMNODES ];EXPORT_SYMBOL (__node_data);static u64 gen_region_mask (void )@@ -361,6 +363,7 @@ static void __init node_mem_init(nasid_t node)*/ __node_data[node] =__va (slot_freepfn <<PAGE_SHIFT );memset (__node_data[node],0 ,PAGE_SIZE ); + node_data[node] = &__node_data[node]->pglist;
Quoted 6 lines
arch/mips/sgi-ip27/ip27-memory.c static void __init node_mem_init(nasid_t node) · line 369
Quoted 2 lines
arch/mips/sgi-ip27/ip27-memory.c +0
-0NODE_DATA (node)->node_start_pfn = start_pfn;NODE_DATA (node)->node_spanned_pages = end_pfn - start_pfn;I was assuming we could get rid of
__node_data->pglist.But now I am confused where that is actually set.
It looks nasty... Cast in arch_refresh_nodedata() takes incoming pg_data_t * and casts it to the local version of struct node_data * which I think is this one
struct node_data {
struct pglist_data pglist; (which is pg_data_t pglist)
struct hub_data hub;
};https://elixir.bootlin.com/linux/v6.10/source/arch/mips/sgi-ip27/ip27-memory.c#L432
Now that pg_data_t is allocated byarch_alloc_nodedata() which might be fine (though types could be handled in a more readable fashion via some container_of() magic.
https://elixir.bootlin.com/linux/v6.10/source/arch/mips/sgi-ip27/ip27-memory.c#L427
However that call is:pg_data_t * __init arch_alloc_nodedata(int nid)
{
return memblock_alloc(sizeof(pg_data_t), SMP_CACHE_BYTES);
}So doesn't seem to allocate enough space to me as should be sizeof(struct node_data)
Worth cleaning up whilst here? Proper handling of types would definitely help.
Jonathan
Quoted 5 lines
Anyhow
Reviewed-by David Hildenbrand <[email protected]>
Mike Rapoport
maintainerRe: [PATCH 02/17] MIPS: sgi-ip27: make NODE_DATA() the same as on all other architectures
Quoted 60 lines · Jonathan Cameron
Quoted 57 lines · On Wed, 17 Jul 2024 16:32:59 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 56 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
sgi-ip27 is the only system that defines
NODE_DATA()differently than the rest of NUMA machines.Add
node_dataarray of struct pglist pointers that will point to __node_data[node]->pglist and redefineNODE_DATA()to usenode_dataarray.This will allow pulling declaration of
node_datato the generic mm code in the next commit.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>--- arch/mips/include/asm/mach-ip27/mmzone.h | 5 ++++- arch/mips/sgi-ip27/ip27-memory.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)arch/mips/include/asm/mach-ip27/mmzone.h +4
-1@@ -22,7 +22,10 @@ struct node_data {extern struct node_data *__node_data[]; -#define NODE_DATA (n) (&__node_data[(n)]->pglist)#define hub_data (n) (&__node_data[(n)]->hub) +extern struct pglist_data *node_data[]; + +#define NODE_DATA (nid) (node_data[nid]) +#endif /* _ASM_MACH_MMZONE_H */ arch/mips/sgi-ip27/ip27-memory.c +4
-1@@ -34,8 +34,10 @@#define SLOT_PFNSHIFT (SLOT_SHIFT - PAGE_SHIFT)#define PFN_NASIDSHFT (NASID_SHFT - PAGE_SHIFT) -struct node_data *__node_data[MAX_NUMNODES ]; +struct pglist_data *node_data[MAX_NUMNODES ]; +EXPORT_SYMBOL (node_data); +struct node_data *__node_data[MAX_NUMNODES ];EXPORT_SYMBOL (__node_data);static u64 gen_region_mask (void )@@ -361,6 +363,7 @@ static void __init node_mem_init(nasid_t node)*/ __node_data[node] =__va (slot_freepfn <<PAGE_SHIFT );memset (__node_data[node],0 ,PAGE_SIZE ); + node_data[node] = &__node_data[node]->pglist;
Quoted 8 lines
Quoted 6 lines
arch/mips/sgi-ip27/ip27-memory.c static void __init node_mem_init(nasid_t node) · line 369
Quoted 2 lines
arch/mips/sgi-ip27/ip27-memory.c +0
-0NODE_DATA (node)->node_start_pfn = start_pfn;NODE_DATA (node)->node_spanned_pages = end_pfn - start_pfn;I was assuming we could get rid of
__node_data->pglist.But now I am confused where that is actually set.
It looks nasty...
Nasty indeed :)
Quoted 15 lines
Cast in
arch_refresh_nodedata()takes incomingpg_data_t* and casts it to the local version of structnode_data* which I think is this onestruct node_data { struct pglist_data pglist; (which is pg_data_t pglist) struct hub_data hub; };https://elixir.bootlin.com/linux/v6.10/source/arch/mips/sgi-ip27/ip27-memory.c#L432
Now that
pg_data_tis allocated byarch_alloc_nodedata()which might be fine (though types could be handled in a more readable fashion via somecontainer_of()magic.
https://elixir.bootlin.com/linux/v6.10/source/arch/mips/sgi-ip27/ip27-memory.c#L427
Quoted 7 lines
However that call is:
pg_data_t*__initarch_alloc_nodedata(int nid){ return memblock_alloc(sizeof(pg_data_t), SMP_CACHE_BYTES); }So doesn't seem to allocate enough space to me as should be
sizeof(struct node_data)
Well, it's there to silence a compiler error (commit f8f9f21c7848 ("MIPS:
Fix build error for loongson64 and sgi-ip27")), but this is not a proper fix :(
Luckily nothing calls cpumask_of_node() for offline nodes...
Quoted 2 lines
Worth cleaning up whilst here? Proper handling of types would definitely help.
Worth cleanup indeed, but I'd rather drop arch_alloc_nodedata() on MIPS altogether.
Quoted 1 line
Jonathan
Signature · 2 lines
Sincerely yours, Mike.
Mike Rapoport
maintainerPATCH 3/17 MIPS: loongson64: rename __node_data to node_data
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Make definition of node_data match other architectures.
This will allow pulling declaration of node_data to the generic mm code in the following commit.
--- arch/mips/include/asm/mach-loongson64/mmzone.h | 4 ++-- arch/mips/loongson64/numa.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)
arch/mips/include/asm/mach-loongson64/mmzone.h +2 -2
@@ -14,9 +14,9 @@#define pa_to_nid (addr) (((addr) & 0xf00000000000) >> NODE_ADDRSPACE_SHIFT)#define nid_to_addrbase (nid) ((unsigned long)(nid) << NODE_ADDRSPACE_SHIFT) -extern struct pglist_data *__node_data[]; +extern struct pglist_data *node_data[]; -#define NODE_DATA (n) (__node_data[n]) +#define NODE_DATA (n) (node_data[n])extern void __init prom_init_numa_memory (void );
arch/mips/loongson64/numa.c +4 -4
@@ -29,8 +29,8 @@unsigned char __node_distances[MAX_NUMNODES ][MAX_NUMNODES ];EXPORT_SYMBOL (__node_distances); -struct pglist_data *__node_data[MAX_NUMNODES ]; -EXPORT_SYMBOL (__node_data); +struct pglist_data *node_data[MAX_NUMNODES ]; +EXPORT_SYMBOL (node_data);cpumask_t __node_cpumask[MAX_NUMNODES ];EXPORT_SYMBOL (__node_cpumask);
@@ -107,7 +107,7 @@ static void __init node_mem_init(unsigned int node) tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT );if (tnid != node)pr_info ("NODE_DATA(%d) on node %d\n" , node, tnid); - __node_data[node] = nd; + node_data[node] = nd;NODE_DATA (node)->node_start_pfn = start_pfn;NODE_DATA (node)->node_spanned_pages = end_pfn - start_pfn;
@@ -206,5 +206,5 @@ pg_data_t * __init arch_alloc_nodedata(int nid)void arch_refresh_nodedata (int nid,pg_data_t *pgdat) { - __node_data[nid] = pgdat; + node_data[nid] = pgdat; }
Signature · 1 line
2.43.0
Re: [PATCH 03/17] MIPS: loongson64: rename __node_data to node_data
Quoted 7 lines · 在2024年7月16日七月 下午7:13,Mike Rapoport写道:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Make definition of
node_datamatch other architectures.
This will allow pulling declaration ofnode_datato the generic mm code in the following commit.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
MIPS should go arch_numa at some point as well.
Thanks
- Jiaxun
Quoted 57 lines
--- arch/mips/include/asm/mach-loongson64/mmzone.h | 4 ++-- arch/mips/loongson64/numa.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)arch/mips/include/asm/mach-loongson64/mmzone.h +2
-2@@ -14,9 +14,9 @@#define pa_to_nid (addr) (((addr) & 0xf00000000000) >> NODE_ADDRSPACE_SHIFT)#define nid_to_addrbase (nid) ((unsigned long)(nid) << NODE_ADDRSPACE_SHIFT) -extern struct pglist_data *__node_data[]; +extern struct pglist_data *node_data[]; -#define NODE_DATA (n) (__node_data[n]) +#define NODE_DATA (n) (node_data[n])extern void
__initprom_init_numa_memory(void);arch/mips/loongson64/numa.c +4
-4@@ -29,8 +29,8 @@unsigned char __node_distances[MAX_NUMNODES ][MAX_NUMNODES ];EXPORT_SYMBOL (__node_distances); -struct pglist_data *__node_data[MAX_NUMNODES ]; -EXPORT_SYMBOL (__node_data); +struct pglist_data *node_data[MAX_NUMNODES ]; +EXPORT_SYMBOL (node_data);cpumask_t __node_cpumask[MAX_NUMNODES ];EXPORT_SYMBOL (__node_cpumask);@@ -107,7 +107,7 @@ static void __init node_mem_init(unsigned int node) tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT );if (tnid != node)pr_info ("NODE_DATA(%d) on node %d\n" , node, tnid); - __node_data[node] = nd; + node_data[node] = nd;NODE_DATA (node)->node_start_pfn = start_pfn;NODE_DATA (node)->node_spanned_pages = end_pfn - start_pfn;@@ -206,5 +206,5 @@ pg_data_t * __init arch_alloc_nodedata(int nid)void arch_refresh_nodedata (int nid,pg_data_t *pgdat) { - __node_data[nid] = pgdat; + node_data[nid] = pgdat; }Signature · 1 line
2.43.0
Signature · 1 line
- Jiaxun
Re: [PATCH 03/17] MIPS: loongson64: rename __node_data to node_data
In reply to Mike RapoportQuoted 8 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Make definition of
node_datamatch other architectures.
This will allow pulling declaration ofnode_datato the generic mm code in the following commit.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>---
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 03/17] MIPS: loongson64: rename __node_data to node_data
In reply to Mike RapoportQuoted 7 lines · On Tue, 16 Jul 2024 14:13:32 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Make definition of
node_datamatch other architectures.
This will allow pulling declaration ofnode_datato the generic mm code in the following commit.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
FWIW rename looks fine
Mike Rapoport
maintainerPATCH 4/17 arch, mm: move definition of node_data to generic code
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Every architecture that supports NUMA defines node_data in the same way:
struct pglist_data *node_data[MAX_NUMNODES];
No reason to keep multiple copies of this definition and its forward declarations, especially when such forward declaration is the only thing in include/asm/mmzone.h for many architectures.
Add definition and declaration of node_data to generic code and drop architecture-specific versions.
--- arch/arm64/include/asm/Kbuild | 1 + arch/arm64/include/asm/mmzone.h | 13 ------------- arch/arm64/include/asm/topology.h | 1 + arch/loongarch/include/asm/Kbuild | 1 + arch/loongarch/include/asm/mmzone.h | 16 ---------------- arch/loongarch/include/asm/topology.h | 1 + arch/loongarch/kernel/numa.c | 3 --- arch/mips/include/asm/mach-ip27/mmzone.h | 4 ---- arch/mips/include/asm/mach-loongson64/mmzone.h | 4 ---- arch/mips/loongson64/numa.c | 2 -- arch/mips/sgi-ip27/ip27-memory.c | 3 --- arch/powerpc/include/asm/mmzone.h | 6 ------ arch/powerpc/mm/numa.c | 2 -- arch/riscv/include/asm/Kbuild | 1 + arch/riscv/include/asm/mmzone.h | 13 ------------- arch/riscv/include/asm/topology.h | 4 ++++ arch/s390/include/asm/Kbuild | 1 + arch/s390/include/asm/mmzone.h | 17 ----------------- arch/s390/kernel/numa.c | 3 --- arch/sh/include/asm/mmzone.h | 3 --- arch/sh/mm/numa.c | 3 --- arch/sparc/include/asm/mmzone.h | 4 ---- arch/sparc/mm/init_64.c | 2 -- arch/x86/include/asm/Kbuild | 1 + arch/x86/include/asm/mmzone.h | 6 ------ arch/x86/include/asm/mmzone_32.h | 17 ----------------- arch/x86/include/asm/mmzone_64.h | 18 ------------------ arch/x86/mm/numa.c | 3 --- drivers/base/arch_numa.c | 2 -- include/asm-generic/mmzone.h | 5 +++++ include/linux/numa.h | 3 +++ mm/numa.c | 3 +++ 32 files changed, 22 insertions(+), 144 deletions(-) delete mode 100644 arch/arm64/include/asm/mmzone.h delete mode 100644 arch/loongarch/include/asm/mmzone.h delete mode 100644 arch/riscv/include/asm/mmzone.h delete mode 100644 arch/s390/include/asm/mmzone.h delete mode 100644 arch/x86/include/asm/mmzone.h delete mode 100644 arch/x86/include/asm/mmzone_32.h delete mode 100644 arch/x86/include/asm/mmzone_64.h create mode 100644 include/asm-generic/mmzone.h
arch/arm64/include/asm/Kbuild +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 generic-y += early_ioremap.h generic-y += mcs_spinlock.h +generic-y += mmzone.h generic-y += qrwlock.h generic-y += qspinlock.h generic-y += parport.h
arch/arm64/include/asm/mmzone.h deleted +0 -13
@@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __ASM_MMZONE_H -#define __ASM_MMZONE_H - -#ifdef CONFIG_NUMA - -#include <asm/numa.h> - -extern struct pglist_data *node_data[]; -#define NODE_DATA (nid) (node_data[(nid)]) - -#endif /* CONFIG_NUMA */ -#endif /* __ASM_MMZONE_H */
arch/arm64/include/asm/topology.h +1 -0
@@ -5,6 +5,7 @@#include <linux/cpumask.h> #ifdef CONFIG_NUMA +#include <asm/numa.h> struct pci_bus ;int pcibus_to_node (struct pci_bus *bus);
arch/loongarch/include/asm/Kbuild +1 -0
@@ -15,6 +15,7 @@ generic-y += fcntl.h generic-y += ioctl.h generic-y += ioctls.h generic-y += mman.h +generic-y += mmzone.h generic-y += msgbuf.h generic-y += sembuf.h generic-y += shmbuf.h
arch/loongarch/include/asm/mmzone.h deleted +0 -16
@@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Author: Huacai Chen ([email protected]) -* Copyright (C) 2020-2022 Loongson Technology Corporation Limited -*/ -#ifndef _ASM_MMZONE_H_ -#define _ASM_MMZONE_H_ - -#include <asm/page.h> -#include <asm/numa.h> - -extern struct pglist_data *node_data[]; - -#define NODE_DATA (nid) (node_data[(nid)]) - -#endif /* _ASM_MMZONE_H_ */
arch/loongarch/include/asm/topology.h +1 -0
@@ -8,6 +8,7 @@#include <linux/smp.h> #ifdef CONFIG_NUMA +#include <asm/numa.h> extern cpumask_t cpus_on_node[];
arch/loongarch/kernel/numa.c +0 -3
@@ -27,10 +27,7 @@#include <asm/time.h> int numa_off; -struct pglist_data *node_data[MAX_NUMNODES ];unsigned char node_distances[MAX_NUMNODES ][MAX_NUMNODES ]; - -EXPORT_SYMBOL (node_data);EXPORT_SYMBOL (node_distances);static struct numa_meminfo numa_meminfo;
arch/mips/include/asm/mach-ip27/mmzone.h +0 -4
@@ -24,8 +24,4 @@ extern struct node_data *__node_data[];#define hub_data (n) (&__node_data[(n)]->hub) -extern struct pglist_data *node_data[]; - -#define NODE_DATA (nid) (node_data[nid]) -#endif /* _ASM_MACH_MMZONE_H */
arch/mips/include/asm/mach-loongson64/mmzone.h +0 -4
@@ -14,10 +14,6 @@#define pa_to_nid (addr) (((addr) & 0xf00000000000) >> NODE_ADDRSPACE_SHIFT)#define nid_to_addrbase (nid) ((unsigned long)(nid) << NODE_ADDRSPACE_SHIFT) -extern struct pglist_data *node_data[]; - -#define NODE_DATA (n) (node_data[n]) -extern void __init prom_init_numa_memory (void );#endif /* _ASM_MACH_MMZONE_H */
arch/mips/loongson64/numa.c +0 -2
@@ -29,8 +29,6 @@unsigned char __node_distances[MAX_NUMNODES ][MAX_NUMNODES ];EXPORT_SYMBOL (__node_distances); -struct pglist_data *node_data[MAX_NUMNODES ]; -EXPORT_SYMBOL (node_data);cpumask_t __node_cpumask[MAX_NUMNODES ];EXPORT_SYMBOL (__node_cpumask);
arch/mips/sgi-ip27/ip27-memory.c +0 -3
@@ -34,9 +34,6 @@#define SLOT_PFNSHIFT (SLOT_SHIFT - PAGE_SHIFT)#define PFN_NASIDSHFT (NASID_SHFT - PAGE_SHIFT) -struct pglist_data *node_data[MAX_NUMNODES ]; -EXPORT_SYMBOL (node_data); -struct node_data *__node_data[MAX_NUMNODES ];EXPORT_SYMBOL (__node_data);
arch/powerpc/include/asm/mmzone.h +0 -6
@@ -20,12 +20,6 @@#ifdef CONFIG_NUMA -extern struct pglist_data *node_data[]; -/* -* Return a pointer to the node data for node n. -*/ -#define NODE_DATA (nid) (node_data[nid]) -/* * Following are specific to this numa platform. */
arch/powerpc/mm/numa.c +0 -2
@@ -43,11 +43,9 @@ static char *cmdline __initdata;int numa_cpu_lookup_table[NR_CPUS ];cpumask_var_t node_to_cpumask_map[MAX_NUMNODES ]; -struct pglist_data *node_data[MAX_NUMNODES ];EXPORT_SYMBOL (numa_cpu_lookup_table);EXPORT_SYMBOL (node_to_cpumask_map); -EXPORT_SYMBOL (node_data);static int primary_domain_index;static int n_mem_addr_cells, n_mem_size_cells;
arch/riscv/include/asm/Kbuild +1 -0
@@ -2,6 +2,7 @@ generic-y += early_ioremap.h generic-y += flat.h generic-y += kvm_para.h +generic-y += mmzone.h generic-y += parport.h generic-y += spinlock.h generic-y += spinlock_types.h
arch/riscv/include/asm/mmzone.h deleted +0 -13
@@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __ASM_MMZONE_H -#define __ASM_MMZONE_H - -#ifdef CONFIG_NUMA - -#include <asm/numa.h> - -extern struct pglist_data *node_data[]; -#define NODE_DATA (nid) (node_data[(nid)]) - -#endif /* CONFIG_NUMA */ -#endif /* __ASM_MMZONE_H */
arch/riscv/include/asm/topology.h +4 -0
@@ -4,6 +4,10 @@#include <linux/arch_topology.h> +#ifdef CONFIG_NUMA +#include <asm/numa.h> +#endif +/* Replace task scheduler's default frequency-invariant accounting */ #define arch_scale_freq_tick topology_scale_freq_tick#define arch_set_freq_scale topology_set_freq_scale
arch/s390/include/asm/Kbuild +1 -0
@@ -7,3 +7,4 @@ generated-y += unistd_nr.h generic-y += asm-offsets.h generic-y += kvm_types.h generic-y += mcs_spinlock.h +generic-y += mmzone.h
arch/s390/include/asm/mmzone.h deleted +0 -17
@@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* NUMA support for s390 -* -* Copyright IBM Corp. 2015 -*/ - -#ifndef _ASM_S390_MMZONE_H -#define _ASM_S390_MMZONE_H - -#ifdef CONFIG_NUMA - -extern struct pglist_data *node_data[]; -#define NODE_DATA (nid) (node_data[nid]) - -#endif /* CONFIG_NUMA */ -#endif /* _ASM_S390_MMZONE_H */
arch/s390/kernel/numa.c +0 -3
@@ -14,9 +14,6 @@#include <linux/node.h> #include <asm/numa.h> -struct pglist_data *node_data[MAX_NUMNODES ]; -EXPORT_SYMBOL (node_data); -void __init numa_setup (void ) {int nid;
arch/sh/include/asm/mmzone.h +0 -3
@@ -5,9 +5,6 @@#ifdef CONFIG_NUMA #include <linux/numa.h> -extern struct pglist_data *node_data[]; -#define NODE_DATA (nid) (node_data[nid]) -static inline int pfn_to_nid (unsigned long pfn) {int nid;
arch/sh/mm/numa.c +0 -3
@@ -14,9 +14,6 @@#include <linux/pfn.h> #include <asm/sections.h> -struct pglist_data *node_data[MAX_NUMNODES ]__read_mostly ; -EXPORT_SYMBOL_GPL (node_data); -/* * On SH machines the conventional approach is to stash system RAM * in node 0, and other memory blocks in to node 1 and up, ordered by
arch/sparc/include/asm/mmzone.h +0 -4
@@ -6,10 +6,6 @@#include <linux/cpumask.h> -extern struct pglist_data *node_data[]; - -#define NODE_DATA (nid) (node_data[nid]) -extern int numa_cpu_lookup_table[];extern cpumask_t numa_cpumask_lookup_table[];
arch/sparc/mm/init_64.c +0 -2
@@ -1115,11 +1115,9 @@ static void init_node_masks_nonnuma(void) }#ifdef CONFIG_NUMA -struct pglist_data *node_data[MAX_NUMNODES ];EXPORT_SYMBOL (numa_cpu_lookup_table);EXPORT_SYMBOL (numa_cpumask_lookup_table); -EXPORT_SYMBOL (node_data);static int scan_pio_for_cfg_handle (struct mdesc_handle *md,u64 pio,u32 cfg_handle)
arch/x86/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generated-y += xen-hypercalls.h generic-y += early_ioremap.h generic-y += mcs_spinlock.h +generic-y += mmzone.h
arch/x86/include/asm/mmzone.h deleted +0 -6
@@ -1,6 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifdef CONFIG_X86_32 -# include <asm/mmzone_32.h> -#else -# include <asm/mmzone_64.h> -#endif
arch/x86/include/asm/mmzone_32.h deleted +0 -17
@@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Written by Pat Gaughen ([email protected]) Mar 2002 -* -*/ - -#ifndef _ASM_X86_MMZONE_32_H -#define _ASM_X86_MMZONE_32_H - -#include <asm/smp.h> - -#ifdef CONFIG_NUMA -extern struct pglist_data *node_data[]; -#define NODE_DATA (nid) (node_data[nid]) -#endif /* CONFIG_NUMA */ - -#endif /* _ASM_X86_MMZONE_32_H */
arch/x86/include/asm/mmzone_64.h deleted +0 -18
@@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* K8 NUMA support */ -/* Copyright 2002,2003 by Andi Kleen, SuSE Labs */ -/* 2.5 Version loosely based on the NUMAQ Code by Pat Gaughen. */ -#ifndef _ASM_X86_MMZONE_64_H -#define _ASM_X86_MMZONE_64_H - -#ifdef CONFIG_NUMA - -#include <linux/mmdebug.h> -#include <asm/smp.h> - -extern struct pglist_data *node_data[]; - -#define NODE_DATA (nid) (node_data[nid]) - -#endif -#endif /* _ASM_X86_MMZONE_64_H */
arch/x86/mm/numa.c +0 -3
@@ -24,9 +24,6 @@int numa_off;nodemask_t numa_nodes_parsed__initdata ; -struct pglist_data *node_data[MAX_NUMNODES ]__read_mostly ; -EXPORT_SYMBOL (node_data); - static struct numa_meminfo numa_meminfo __initdata_or_meminfo; static struct numa_meminfo numa_reserved_meminfo __initdata_or_meminfo;
drivers/base/arch_numa.c +0 -2
@@ -15,8 +15,6 @@#include <asm/sections.h> -struct pglist_data *node_data[MAX_NUMNODES ]__read_mostly ; -EXPORT_SYMBOL (node_data);nodemask_t numa_nodes_parsed__initdata ;static int cpu_to_node_map[NR_CPUS ] = { [0 ...NR_CPUS -1 ] =NUMA_NO_NODE };
include/asm-generic/mmzone.h new file +5 -0
@@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_MMZONE_H +#define _ASM_GENERIC_MMZONE_H + +#endif
include/linux/numa.h +3 -0
@@ -30,6 +30,9 @@ static inline bool numa_valid_node(int nid)#ifdef CONFIG_NUMA #include <asm/sparsemem.h> +extern struct pglist_data *node_data[]; +#define NODE_DATA (nid) (node_data[nid]) +/* Generic implementation available */ int numa_nearest_node (int node,unsigned int state);
mm/numa.c +3 -0
@@ -3,6 +3,9 @@#include <linux/printk.h> #include <linux/numa.h> +struct pglist_data *node_data[MAX_NUMNODES ]; +EXPORT_SYMBOL (node_data); +/* Stub functions: */ #ifndef memory_add_physaddr_to_nid
Signature · 1 line
2.43.0
Re: [PATCH 04/17] arch, mm: move definition of node_data to generic code
Quoted 48 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Every architecture that supports NUMA defines
node_datain the same way:struct pglist_data *node_data[MAX_NUMNODES];No reason to keep multiple copies of this definition and its forward declarations, especially when such forward declaration is the only thing in
include/asm/mmzone.hfor many architectures.Add definition and declaration of
node_datato generic code and drop architecture-specific versions.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>--- arch/arm64/include/asm/Kbuild | 1 + arch/arm64/include/asm/mmzone.h | 13 ------------- arch/arm64/include/asm/topology.h | 1 + arch/loongarch/include/asm/Kbuild | 1 + arch/loongarch/include/asm/mmzone.h | 16 ---------------- arch/loongarch/include/asm/topology.h | 1 + arch/loongarch/kernel/numa.c | 3 --- arch/mips/include/asm/mach-ip27/mmzone.h | 4 ---- arch/mips/include/asm/mach-loongson64/mmzone.h | 4 ---- arch/mips/loongson64/numa.c | 2 -- arch/mips/sgi-ip27/ip27-memory.c | 3 --- arch/powerpc/include/asm/mmzone.h | 6 ------ arch/powerpc/mm/numa.c | 2 -- arch/riscv/include/asm/Kbuild | 1 + arch/riscv/include/asm/mmzone.h | 13 ------------- arch/riscv/include/asm/topology.h | 4 ++++ arch/s390/include/asm/Kbuild | 1 + arch/s390/include/asm/mmzone.h | 17 ----------------- arch/s390/kernel/numa.c | 3 --- arch/sh/include/asm/mmzone.h | 3 --- arch/sh/mm/numa.c | 3 --- arch/sparc/include/asm/mmzone.h | 4 ---- arch/sparc/mm/init_64.c | 2 -- arch/x86/include/asm/Kbuild | 1 + arch/x86/include/asm/mmzone.h | 6 ------ arch/x86/include/asm/mmzone_32.h | 17 ----------------- arch/x86/include/asm/mmzone_64.h | 18 ------------------ arch/x86/mm/numa.c | 3 --- drivers/base/arch_numa.c | 2 -- include/asm-generic/mmzone.h | 5 +++++ include/linux/numa.h | 3 +++ mm/numa.c | 3 +++ 32 files changed, 22 insertions(+), 144 deletions(-)
Quoted 8 lines
delete mode 100644
arch/arm64/include/asm/mmzone.hdelete mode 100644arch/loongarch/include/asm/mmzone.hdelete mode 100644arch/riscv/include/asm/mmzone.hdelete mode 100644arch/s390/include/asm/mmzone.hdelete mode 100644arch/x86/include/asm/mmzone.hdelete mode 100644arch/x86/include/asm/mmzone_32.hdelete mode 100644arch/x86/include/asm/mmzone_64.hcreate mode 100644include/asm-generic/mmzone.h
Nice!
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 04/17] arch, mm: move definition of node_data to generic code
In reply to Mike RapoportQuoted 6 lines · On Tue, 16 Jul 2024 14:13:33 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Every architecture that supports NUMA defines
node_datain the same way:struct pglist_data *node_data[MAX_NUMNODES];
Quoted 8 lines
No reason to keep multiple copies of this definition and its forward declarations, especially when such forward declaration is the only thing in
include/asm/mmzone.hfor many architectures.Add definition and declaration of
node_datato generic code and drop architecture-specific versions.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Re: [PATCH 04/17] arch, mm: move definition of node_data to generic code
In reply to Mike RapoportOn Tue, 16 Jul 2024, Mike Rapoport wrote:\n
Quoted 6 lines
From: "Mike Rapoport (Microsoft)" <[email protected]>
Every architecture that supports NUMA defines
node_datain the same way:struct pglist_data *node_data[MAX_NUMNODES];
Quoted 8 lines
No reason to keep multiple copies of this definition and its forward declarations, especially when such forward declaration is the only thing in
include/asm/mmzone.hfor many architectures.Add definition and declaration of
node_datato generic code and drop architecture-specific versions.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Nice cleanup.
Mike Rapoport
maintainerPATCH 5/17 arch, mm: pull out allocation of NODE_DATA to generic code
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Architectures that support NUMA duplicate the code that allocates NODE_DATA on the node-local memory with slight variations in reporting of the addresses where the memory was allocated.
Use x86 version as the basis for the generic alloc_node_data() function and call this function in architecture specific numa initialization.
--- arch/loongarch/kernel/numa.c | 18 ------------------ arch/mips/loongson64/numa.c | 16 ++-------------- arch/powerpc/mm/numa.c | 24 +++--------------------- arch/sh/mm/init.c | 7 +------ arch/sparc/mm/init_64.c | 9 ++------- arch/x86/mm/numa.c | 34 +--------------------------------- drivers/base/arch_numa.c | 21 +-------------------- include/linux/numa.h | 2 ++ mm/numa.c | 27 +++++++++++++++++++++++++++ 9 files changed, 39 insertions(+), 119 deletions(-)
arch/loongarch/kernel/numa.c +0 -18
@@ -187,24 +187,6 @@ int __init numa_add_memblk(int nid, u64 start, u64 end)return numa_add_memblk_to (nid, start, end, &numa_meminfo); } -static void __init alloc_node_data (int nid) -{ -void *nd; -unsigned long nd_pa; -size_t nd_sz =roundup (sizeof (pg_data_t),PAGE_SIZE ); - - nd_pa =memblock_phys_alloc_try_nid (nd_sz,SMP_CACHE_BYTES , nid); -if (!nd_pa) { -pr_err ("Cannot find %zu Byte for node_data (initial node: %d)\n" , nd_sz, nid); -return ; - } - - nd =__va (nd_pa); - - node_data[nid] = nd; -memset (nd,0 ,sizeof (pg_data_t)); -} -static void __init node_mem_init (unsigned int node) {unsigned long start_pfn, end_pfn;
arch/mips/loongson64/numa.c +2 -14
@@ -81,12 +81,8 @@ static void __init init_topology_matrix(void)static void __init node_mem_init (unsigned int node) { -struct pglist_data *nd;unsigned long node_addrspace_offset;unsigned long start_pfn, end_pfn; -unsigned long nd_pa; -int tnid; -const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES ); node_addrspace_offset =nid_to_addrbase (node); pr_info("Node%d's addrspace_offset is 0x%lx\n",
@@ -96,16 +92,8 @@ static void __init node_mem_init(unsigned int node)pr_info ("Node%d: start_pfn=0x%lx, end_pfn=0x%lx\n" , node, start_pfn, end_pfn); - nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , node); -if (!nd_pa) -panic ("Cannot allocate %zu bytes for node %d data\n" , - nd_size, node); - nd =__va (nd_pa); -memset (nd,0 ,sizeof (struct pglist_data )); - tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); -if (tnid != node) -pr_info ("NODE_DATA(%d) on node %d\n" , node, tnid); - node_data[node] = nd; +alloc_node_data (node); +NODE_DATA (node)->node_start_pfn = start_pfn;NODE_DATA (node)->node_spanned_pages = end_pfn - start_pfn;
arch/powerpc/mm/numa.c +3 -21
@@ -1081,27 +1081,9 @@ void __init dump_numa_cpu_topology(void)static void __init setup_node_data (int nid,u64 start_pfn,u64 end_pfn) {u64 spanned_pages = end_pfn - start_pfn; -const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES ); -u64 nd_pa; -void *nd; -int tnid; - - nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); -if (!nd_pa) -panic ("Cannot allocate %zu bytes for node %d data\n" , - nd_size, nid); - - nd =__va (nd_pa); - -/* report and initialize */ -pr_info (" NODE_DATA [mem %#010Lx-%#010Lx]\n" , - nd_pa, nd_pa + nd_size -1 ); - tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); -if (tnid != nid) -pr_info (" NODE_DATA(%d) on node %d\n" , nid, tnid); - - node_data[nid] = nd; -memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); + +alloc_node_data (nid); +NODE_DATA (nid)->node_id = nid;NODE_DATA (nid)->node_start_pfn = start_pfn;NODE_DATA (nid)->node_spanned_pages = spanned_pages;
arch/sh/mm/init.c +1 -6
@@ -212,12 +212,7 @@ void __init allocate_pgdat(unsigned int nid)get_pfn_range_for_nid (nid, &start_pfn, &end_pfn);#ifdef CONFIG_NUMA -NODE_DATA (nid) =memblock_alloc_try_nid ( -sizeof (struct pglist_data ), -SMP_CACHE_BYTES ,MEMBLOCK_LOW_LIMIT , -MEMBLOCK_ALLOC_ACCESSIBLE , nid); -if (!NODE_DATA (nid)) -panic ("Can't allocate pgdat for node %d\n" , nid); +alloc_node_data (nid);#endif NODE_DATA (nid)->node_start_pfn = start_pfn;
arch/sparc/mm/init_64.c +2 -7
@@ -1075,14 +1075,9 @@ static void __init allocate_node_data(int nid) {struct pglist_data *p;unsigned long start_pfn, end_pfn; -#ifdef CONFIG_NUMA -NODE_DATA (nid) =memblock_alloc_node (sizeof (struct pglist_data ), -SMP_CACHE_BYTES , nid); -if (!NODE_DATA (nid)) { -prom_printf ("Cannot allocate pglist_data for nid[%d]\n" , nid); -prom_halt (); - } +#ifdef CONFIG_NUMA +alloc_node_data (nid);NODE_DATA (nid)->node_id = nid;#endif
arch/x86/mm/numa.c +1 -33
@@ -191,39 +191,6 @@ int __init numa_add_memblk(int nid, u64 start, u64 end)return numa_add_memblk_to (nid, start, end, &numa_meminfo); } -/* Allocate NODE_DATA for a node on the local memory */ -static void __init alloc_node_data (int nid) -{ -const size_t nd_size =roundup (sizeof (pg_data_t),PAGE_SIZE ); -u64 nd_pa; -void *nd; -int tnid; - -/* -* Allocate node data. Try node-local memory and then any node. -* Never allocate in DMA zone. -*/ - nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); -if (!nd_pa) { -pr_err ("Cannot find %zu bytes in any node (initial node: %d)\n" , - nd_size, nid); -return ; - } - nd =__va (nd_pa); - -/* report and initialize */ -printk (KERN_INFO "NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n" , nid, - nd_pa, nd_pa + nd_size -1 ); - tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); -if (tnid != nid) -printk (KERN_INFO " NODE_DATA(%d) on node %d\n" , nid, tnid); - - node_data[nid] = nd; -memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); - -node_set_online (nid); -} -/** * numa_cleanup_meminfo - Cleanup a numa_meminfo * @mi: numa_meminfo to clean up
@@ -571,6 +538,7 @@ static int __init numa_register_memblks(struct numa_meminfo *mi)continue ;alloc_node_data (nid); +node_set_online (nid); }/* Dump memblock with node info and return. */
drivers/base/arch_numa.c +1 -20
@@ -216,30 +216,11 @@ int __init numa_add_memblk(int nid, u64 start, u64 end)*/ static void __init setup_node_data (int nid,u64 start_pfn,u64 end_pfn) { -const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES ); -u64 nd_pa; -void *nd; -int tnid; -if (start_pfn >= end_pfn)pr_info ("Initmem setup node %d [<memory-less node>]\n" , nid); - nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); -if (!nd_pa) -panic ("Cannot allocate %zu bytes for node %d data\n" , - nd_size, nid); - - nd =__va (nd_pa); - -/* report and initialize */ -pr_info ("NODE_DATA [mem %#010Lx-%#010Lx]\n" , - nd_pa, nd_pa + nd_size -1 ); - tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); -if (tnid != nid) -pr_info ("NODE_DATA(%d) on node %d\n" , nid, tnid); +alloc_node_data (nid); - node_data[nid] = nd; -memset (NODE_DATA (nid),0 ,sizeof (pg_data_t));NODE_DATA (nid)->node_id = nid;NODE_DATA (nid)->node_start_pfn = start_pfn;NODE_DATA (nid)->node_spanned_pages = end_pfn - start_pfn;
include/linux/numa.h +2 -0
@@ -33,6 +33,8 @@ static inline bool numa_valid_node(int nid)extern struct pglist_data *node_data[];#define NODE_DATA (nid) (node_data[nid]) +void __init alloc_node_data (int nid); +/* Generic implementation available */ int numa_nearest_node (int node,unsigned int state);
mm/numa.c +27 -0
@@ -1,11 +1,38 @@// SPDX-License-Identifier: GPL-2.0-or-later +#include <linux/memblock.h> #include <linux/printk.h> #include <linux/numa.h> struct pglist_data *node_data[MAX_NUMNODES ];EXPORT_SYMBOL (node_data); +/* Allocate NODE_DATA for a node on the local memory */ +void __init alloc_node_data (int nid) +{ +const size_t nd_size =roundup (sizeof (pg_data_t),PAGE_SIZE ); +u64 nd_pa; +void *nd; +int tnid; + +/* Allocate node data. Try node-local memory and then any node. */ + nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); +if (!nd_pa) +panic ("Cannot allocate %zu bytes for node %d data\n" , + nd_size, nid); + nd =__va (nd_pa); + +/* report and initialize */ +pr_info ("NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n" , nid, + nd_pa, nd_pa + nd_size -1 ); + tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); +if (tnid != nid) +pr_info (" NODE_DATA(%d) on node %d\n" , nid, tnid); + + node_data[nid] = nd; +memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); +} +/* Stub functions: */ #ifndef memory_add_physaddr_to_nid
Signature · 1 line
2.43.0
Re: [PATCH 05/17] arch, mm: pull out allocation of NODE_DATA to generic code
Quoted 11 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Architectures that support NUMA duplicate the code that allocates
NODE_DATAon the node-local memory with slight variations in reporting of the addresses where the memory was allocated.Use x86 version as the basis for the generic
alloc_node_data()function and call this function in architecture specific numa initialization.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>---
[...]
Quoted 5 lines
arch/mips/loongson64/numa.c +0
-0
arch/mips/loongson64/numa.c static void __init init_topology_matrix(void) · line 89
Quoted 9 lines
arch/mips/loongson64/numa.c +0
-4@@ -81,12 +81,8 @@ static void __init init_topology_matrix(void)static void __init node_mem_init (unsigned int node) { -struct pglist_data *nd;unsigned long node_addrspace_offset;unsigned long start_pfn, end_pfn; -unsigned long nd_pa; -int tnid; -const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES );
One interesting change is that we now always round up to full pages on architectures where we previously rounded up to SMP_CACHE_BYTES.
I assume we don't really expect a significant growth in memory consumption that we care about, especially because most systems with many nodes also have quite some memory around.
Quoted 37 lines
arch/mips/loongson64/numa.c +0
-33-/* Allocate NODE_DATA for a node on the local memory */ -static void __init alloc_node_data (int nid) -{ -const size_t nd_size =roundup (sizeof (pg_data_t),PAGE_SIZE ); -u64 nd_pa; -void *nd; -int tnid; - -/* -* Allocate node data. Try node-local memory and then any node. -* Never allocate in DMA zone. -*/ - nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); -if (!nd_pa) { -pr_err ("Cannot find %zu bytes in any node (initial node: %d)\n" , - nd_size, nid); -return ; - } - nd =__va (nd_pa); - -/* report and initialize */ -printk (KERN_INFO "NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n" , nid, - nd_pa, nd_pa + nd_size -1 ); - tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); -if (tnid != nid) -printk (KERN_INFO " NODE_DATA(%d) on node %d\n" , nid, tnid); - - node_data[nid] = nd; -memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); - -node_set_online (nid); -} -/** * numa_cleanup_meminfo - Cleanup a numa_meminfo * @mi: numa_meminfo to clean up
arch/mips/loongson64/numa.c static int __init numa_register_memblks(struct numa_meminfo *mi) · line 542
Quoted 5 lines
arch/mips/loongson64/numa.c +1
-0@@ -571,6 +538,7 @@ static int __init numa_register_memblks(struct numa_meminfo *mi)continue ;alloc_node_data (nid); +node_set_online (nid); }
I can spot that we only remove a single node_set_online() call from x86.
What about all the other architectures? Will there be any change in behavior for them? Or do we simply set the nodes online later once more?
Signature · 3 lines
Cheers, David / dhildenb
Mike Rapoport
maintainerRe: [PATCH 05/17] arch, mm: pull out allocation of NODE_DATA to generic code
Quoted 15 lines · David Hildenbrand
Quoted 11 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Architectures that support NUMA duplicate the code that allocates
NODE_DATAon the node-local memory with slight variations in reporting of the addresses where the memory was allocated.Use x86 version as the basis for the generic
alloc_node_data()function and call this function in architecture specific numa initialization.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>---
[...]
Quoted 16 lines
arch/mips/loongson64/numa.c static void __init init_topology_matrix(void) · line 88
Quoted 13 lines
arch/mips/loongson64/numa.c +0
-4@@ -81,12 +81,8 @@ static void __init init_topology_matrix(void)static void __init node_mem_init (unsigned int node) { -struct pglist_data *nd;unsigned long node_addrspace_offset;unsigned long start_pfn, end_pfn; -unsigned long nd_pa; -int tnid; -const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES );One interesting change is that we now always round up to full pages on architectures where we previously rounded up to
SMP_CACHE_BYTES.
On my workstation struct pglist_data take 174400, cachelines: 2725, members: 43 */
Quoted 3 lines
I assume we don't really expect a significant growth in memory consumption that we care about, especially because most systems with many nodes also have quite some memory around.
With Debian kernel configuration for 6.5 struct pglist data takes 174400 bytes so the increase here is below 1%.
For NUMA systems with a lot of nodes that shouldn't be a problem.
Quoted 44 lines
Quoted 37 lines
arch/mips/loongson64/numa.c +0
-33-/* Allocate NODE_DATA for a node on the local memory */ -static void __init alloc_node_data (int nid) -{ -const size_t nd_size =roundup (sizeof (pg_data_t),PAGE_SIZE ); -u64 nd_pa; -void *nd; -int tnid; - -/* -* Allocate node data. Try node-local memory and then any node. -* Never allocate in DMA zone. -*/ - nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); -if (!nd_pa) { -pr_err ("Cannot find %zu bytes in any node (initial node: %d)\n" , - nd_size, nid); -return ; - } - nd =__va (nd_pa); - -/* report and initialize */ -printk (KERN_INFO "NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n" , nid, - nd_pa, nd_pa + nd_size -1 ); - tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); -if (tnid != nid) -printk (KERN_INFO " NODE_DATA(%d) on node %d\n" , nid, tnid); - - node_data[nid] = nd; -memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); - -node_set_online (nid); -} -/** * numa_cleanup_meminfo - Cleanup a numa_meminfo * @mi: numa_meminfo to clean up arch/mips/loongson64/numa.c static int __init numa_register_memblks(struct numa_meminfo *mi) · line 541
Quoted 4 lines
arch/mips/loongson64/numa.c +1
-0@@ -571,6 +538,7 @@ static int __init numa_register_memblks(struct numa_meminfo *mi)continue ;alloc_node_data (nid); +node_set_online (nid); }I can spot that we only remove a single
node_set_online()call from x86.
Quoted 2 lines
What about all the other architectures? Will there be any change in behavior for them? Or do we simply set the nodes online later once more?
On x86 node_set_online() was a part of alloc_node_data() and I moved it outside so it's called right after alloc_node_data(). On other architectures the allocation didn't include that call, so there should be no difference there.
Quoted 6 lines
Signature · 3 lines
Cheers, David / dhildenb
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 05/17] arch, mm: pull out allocation of NODE_DATA to generic code
Quoted 35 lines
Quoted 35 lines
Quoted 28 lines
arch/x86/mm/numa.c +0
-24-* Allocate node data. Try node-local memory and then any node. -* Never allocate in DMA zone. -*/ - nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); -if (!nd_pa) { -pr_err ("Cannot find %zu bytes in any node (initial node: %d)\n" , - nd_size, nid); -return ; - } - nd =__va (nd_pa); - -/* report and initialize */ -printk (KERN_INFO "NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n" , nid, - nd_pa, nd_pa + nd_size -1 ); - tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); -if (tnid != nid) -printk (KERN_INFO " NODE_DATA(%d) on node %d\n" , nid, tnid); - - node_data[nid] = nd; -memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); - -node_set_online (nid); -} -/** * numa_cleanup_meminfo - Cleanup a numa_meminfo * @mi: numa_meminfo to clean up arch/x86/mm/numa.c static int __init numa_register_memblks(struct numa_meminfo *mi) · line 541
Quoted 4 lines
arch/x86/mm/numa.c +1
-0@@ -571,6 +538,7 @@ static int __init numa_register_memblks(struct numa_meminfo *mi)continue ;alloc_node_data (nid); +node_set_online (nid); }I can spot that we only remove a single
node_set_online()call from x86.
Quoted 7 lines
Quoted 2 lines
What about all the other architectures? Will there be any change in behavior for them? Or do we simply set the nodes online later once more?
On x86
node_set_online()was a part ofalloc_node_data()and I moved it outside so it's called right afteralloc_node_data(). On other architectures the allocation didn't include that call, so there should be no difference there.
But won't their arch code try setting the nodes online at a later stage?
And I think, some architectures only set nodes online conditionally (see most other node_set_online() calls).
Sorry if I'm confused here, but with now unconditional node_set_online(), won't we change the behavior of other architectures?
Signature · 3 lines
Cheers, David / dhildenb
Mike Rapoport
maintainerRe: [PATCH 05/17] arch, mm: pull out allocation of NODE_DATA to generic code
Quoted 43 lines · David Hildenbrand
Quoted 35 lines
Quoted 35 lines
Quoted 28 lines
arch/x86/mm/numa.c +0
-24-* Allocate node data. Try node-local memory and then any node. -* Never allocate in DMA zone. -*/ - nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); -if (!nd_pa) { -pr_err ("Cannot find %zu bytes in any node (initial node: %d)\n" , - nd_size, nid); -return ; - } - nd =__va (nd_pa); - -/* report and initialize */ -printk (KERN_INFO "NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n" , nid, - nd_pa, nd_pa + nd_size -1 ); - tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); -if (tnid != nid) -printk (KERN_INFO " NODE_DATA(%d) on node %d\n" , nid, tnid); - - node_data[nid] = nd; -memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); - -node_set_online (nid); -} -/** * numa_cleanup_meminfo - Cleanup a numa_meminfo * @mi: numa_meminfo to clean up arch/x86/mm/numa.c static int __init numa_register_memblks(struct numa_meminfo *mi) · line 541
Quoted 4 lines
arch/x86/mm/numa.c +1
-0@@ -571,6 +538,7 @@ static int __init numa_register_memblks(struct numa_meminfo *mi)continue ;alloc_node_data (nid); +node_set_online (nid); }I can spot that we only remove a single
node_set_online()call from x86.Quoted 7 lines
Quoted 2 lines
What about all the other architectures? Will there be any change in behavior for them? Or do we simply set the nodes online later once more?
On x86
node_set_online()was a part ofalloc_node_data()and I moved it outside so it's called right afteralloc_node_data(). On other architectures the allocation didn't include that call, so there should be no difference there.
Quoted 7 lines
But won't their arch code try setting the nodes online at a later stage?
And I think, some architectures only set nodes online conditionally (see most other
node_set_online()calls).Sorry if I'm confused here, but with now unconditional
node_set_online(), won't we change the behavior of other architectures?
The generic alloc_node_data() does not set the node online:
+/* Allocate NODE_DATA for a node on the local memory */ +void __init alloc_node_data(int nid)
+{
+ const size_t nd_size = roundup(sizeof(pg_data_t), PAGE_SIZE);
+ u64 nd_pa;
+ void *nd;
+ int tnid;
+
+ /* Allocate node data. Try node-local memory and then any node. */
+ nd_pa = memblock_phys_alloc_try_nid(nd_size, SMP_CACHE_BYTES, nid);
+ if (!nd_pa)
+ panic("Cannot allocate %zu bytes for node %d data\n",
+ nd_size, nid);
+ nd = __va(nd_pa);
+
+ /* report and initialize */
+ pr_info("NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n", nid,
+ nd_pa, nd_pa + nd_size - 1);
+ tnid = early_pfn_to_nid(nd_pa >> PAGE_SHIFT);
+ if (tnid != nid)
+ pr_info(" NODE_DATA(%d) on node %d\n", nid, tnid);
+
+ node_data[nid] = nd;
+ memset(NODE_DATA(nid), 0, sizeof(pg_data_t));
+}
I might have missed some architecture except x86 that calls node_set_online() in its alloc_node_data(), but the intention was to leave that call outside the alloc and explicitly add it after the call to alloc_node_data() if needed like in x86.
Quoted 6 lines
Signature · 3 lines
Cheers, David / dhildenb
Signature · 2 lines
Sincerely yours, Mike.
David Hildenbrand
Acked-byRe: [PATCH 05/17] arch, mm: pull out allocation of NODE_DATA to generic code
Quoted 80 lines · Mike Rapoport
Quoted 43 lines · David Hildenbrand
Quoted 35 lines
Quoted 35 lines
Quoted 28 lines
arch/x86/mm/numa.c +0
-24-* Allocate node data. Try node-local memory and then any node. -* Never allocate in DMA zone. -*/ - nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); -if (!nd_pa) { -pr_err ("Cannot find %zu bytes in any node (initial node: %d)\n" , - nd_size, nid); -return ; - } - nd =__va (nd_pa); - -/* report and initialize */ -printk (KERN_INFO "NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n" , nid, - nd_pa, nd_pa + nd_size -1 ); - tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); -if (tnid != nid) -printk (KERN_INFO " NODE_DATA(%d) on node %d\n" , nid, tnid); - - node_data[nid] = nd; -memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); - -node_set_online (nid); -} -/** * numa_cleanup_meminfo - Cleanup a numa_meminfo * @mi: numa_meminfo to clean up arch/x86/mm/numa.c static int __init numa_register_memblks(struct numa_meminfo *mi) · line 541
Quoted 4 lines
arch/x86/mm/numa.c +1
-0@@ -571,6 +538,7 @@ static int __init numa_register_memblks(struct numa_meminfo *mi)continue ;alloc_node_data (nid); +node_set_online (nid); }I can spot that we only remove a single
node_set_online()call from x86.Quoted 7 lines
Quoted 2 lines
What about all the other architectures? Will there be any change in behavior for them? Or do we simply set the nodes online later once more?
On x86
node_set_online()was a part ofalloc_node_data()and I moved it outside so it's called right afteralloc_node_data(). On other architectures the allocation didn't include that call, so there should be no difference there.Quoted 7 lines
But won't their arch code try setting the nodes online at a later stage?
And I think, some architectures only set nodes online conditionally (see most other
node_set_online()calls).Sorry if I'm confused here, but with now unconditional
node_set_online(), won't we change the behavior of other architectures?The generic
alloc_node_data()does not set the node online:mm/numa.c +25
-0+/* Allocate NODE_DATA for a node on the local memory */ +void __init alloc_node_data (int nid) +{ +const size_t nd_size =roundup (sizeof (pg_data_t),PAGE_SIZE ); +u64 nd_pa; +void *nd; +int tnid; + +/* Allocate node data. Try node-local memory and then any node. */ + nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); +if (!nd_pa) +panic ("Cannot allocate %zu bytes for node %d data\n" , + nd_size, nid); + nd =__va (nd_pa); + +/* report and initialize */ +pr_info ("NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n" , nid, + nd_pa, nd_pa + nd_size -1 ); + tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); +if (tnid != nid) +pr_info (" NODE_DATA(%d) on node %d\n" , nid, tnid); + + node_data[nid] = nd; +memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); +}
Quoted 4 lines
I might have missed some architecture except x86 that calls
node_set_online()in itsalloc_node_data(), but the intention was to leave that call outside the alloc and explicitly add it after the call toalloc_node_data()if needed like in x86.
I'm stupid, I didn't realize it is still only called from x86 :(
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH 05/17] arch, mm: pull out allocation of NODE_DATA to generic code
In reply to David HildenbrandQuoted 43 lines · On Fri, 19 Jul 2024 17:07:35 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 35 lines
Quoted 35 lines
Quoted 28 lines
arch/x86/mm/numa.c +0
-24-* Allocate node data. Try node-local memory and then any node. -* Never allocate in DMA zone. -*/ - nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); -if (!nd_pa) { -pr_err ("Cannot find %zu bytes in any node (initial node: %d)\n" , - nd_size, nid); -return ; - } - nd =__va (nd_pa); - -/* report and initialize */ -printk (KERN_INFO "NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n" , nid, - nd_pa, nd_pa + nd_size -1 ); - tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); -if (tnid != nid) -printk (KERN_INFO " NODE_DATA(%d) on node %d\n" , nid, tnid); - - node_data[nid] = nd; -memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); - -node_set_online (nid); -} -/** * numa_cleanup_meminfo - Cleanup a numa_meminfo * @mi: numa_meminfo to clean up arch/x86/mm/numa.c static int __init numa_register_memblks(struct numa_meminfo *mi) · line 541
Quoted 4 lines
arch/x86/mm/numa.c +1
-0@@ -571,6 +538,7 @@ static int __init numa_register_memblks(struct numa_meminfo *mi)continue ;alloc_node_data (nid); +node_set_online (nid); }I can spot that we only remove a single
node_set_online()call from x86.Quoted 7 lines
Quoted 2 lines
What about all the other architectures? Will there be any change in behavior for them? Or do we simply set the nodes online later once more?
On x86
node_set_online()was a part ofalloc_node_data()and I moved it outside so it's called right afteralloc_node_data(). On other architectures the allocation didn't include that call, so there should be no difference there.
Quoted 7 lines
But won't their arch code try setting the nodes online at a later stage?
And I think, some architectures only set nodes online conditionally (see most other
node_set_online()calls).Sorry if I'm confused here, but with now unconditional
node_set_online(), won't we change the behavior of other architectures?
This is moving x86 code to x86 code, not a generic location so how would that affect anyone else? Their onlining should be same as before.
The node onlining difference are a pain (I recall that fun from adding generic initiators) as different ordering on x86 and arm64 at least.
Jonathan
Quoted 1 line
Re: [PATCH 05/17] arch, mm: pull out allocation of NODE_DATA to generic code
Quoted 48 lines · Jonathan Cameron
Quoted 45 lines · On Fri, 19 Jul 2024 17:07:35 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 35 lines
Quoted 35 lines
Quoted 28 lines
arch/x86/mm/numa.c +0
-24-* Allocate node data. Try node-local memory and then any node. -* Never allocate in DMA zone. -*/ - nd_pa =memblock_phys_alloc_try_nid (nd_size,SMP_CACHE_BYTES , nid); -if (!nd_pa) { -pr_err ("Cannot find %zu bytes in any node (initial node: %d)\n" , - nd_size, nid); -return ; - } - nd =__va (nd_pa); - -/* report and initialize */ -printk (KERN_INFO "NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n" , nid, - nd_pa, nd_pa + nd_size -1 ); - tnid =early_pfn_to_nid (nd_pa >>PAGE_SHIFT ); -if (tnid != nid) -printk (KERN_INFO " NODE_DATA(%d) on node %d\n" , nid, tnid); - - node_data[nid] = nd; -memset (NODE_DATA (nid),0 ,sizeof (pg_data_t)); - -node_set_online (nid); -} -/** * numa_cleanup_meminfo - Cleanup a numa_meminfo * @mi: numa_meminfo to clean up arch/x86/mm/numa.c static int __init numa_register_memblks(struct numa_meminfo *mi) · line 541
Quoted 4 lines
arch/x86/mm/numa.c +1
-0@@ -571,6 +538,7 @@ static int __init numa_register_memblks(struct numa_meminfo *mi)continue ;alloc_node_data (nid); +node_set_online (nid); }I can spot that we only remove a single
node_set_online()call from x86.Quoted 7 lines
Quoted 2 lines
What about all the other architectures? Will there be any change in behavior for them? Or do we simply set the nodes online later once more?
On x86
node_set_online()was a part ofalloc_node_data()and I moved it outside so it's called right afteralloc_node_data(). On other architectures the allocation didn't include that call, so there should be no difference there.But won't their arch code try setting the nodes online at a later stage?
Quoted 8 lines
Quoted 5 lines
And I think, some architectures only set nodes online conditionally (see most other
node_set_online()calls).Sorry if I'm confused here, but with now unconditional
node_set_online(), won't we change the behavior of other architectures?This is moving x86 code to x86 code, not a generic location so how would that affect anyone else? Their onlining should be same as before.
Yes, see my reply to Mike.
Quoted 3 lines
The node onlining difference are a pain (I recall that fun from adding generic initiators) as different ordering on x86 and arm64 at least.
That's part of the reason I was confused, because I remember some nasty inconsistency.
Signature · 3 lines
Cheers, David / dhildenb
Mike Rapoport
maintainerRe: [PATCH 05/17] arch, mm: pull out allocation of NODE_DATA to generic code
In reply to David HildenbrandQuoted 15 lines · David Hildenbrand
Quoted 11 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Architectures that support NUMA duplicate the code that allocates
NODE_DATAon the node-local memory with slight variations in reporting of the addresses where the memory was allocated.Use x86 version as the basis for the generic
alloc_node_data()function and call this function in architecture specific numa initialization.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>---
[...]
Quoted 16 lines
arch/mips/loongson64/numa.c static void __init init_topology_matrix(void) · line 88
Quoted 13 lines
arch/mips/loongson64/numa.c +0
-4@@ -81,12 +81,8 @@ static void __init init_topology_matrix(void)static void __init node_mem_init (unsigned int node) { -struct pglist_data *nd;unsigned long node_addrspace_offset;unsigned long start_pfn, end_pfn; -unsigned long nd_pa; -int tnid; -const size_t nd_size =roundup (sizeof (pg_data_t),SMP_CACHE_BYTES );One interesting change is that we now always round up to full pages on architectures where we previously rounded up to
SMP_CACHE_BYTES.
I did some git archaeology and it seems that round up to full pages on x86 backdates to bootmem era when allocation granularity was PAGE_SIZE anyway. I'm going to change that to SMP_CACHE_BYTES in v2.
Quoted 3 lines
I assume we don't really expect a significant growth in memory consumption that we care about, especially because most systems with many nodes also have quite some memory around.
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 05/17] arch, mm: pull out allocation of NODE_DATA to generic code
In reply to Mike RapoportQuoted 10 lines · On Tue, 16 Jul 2024 14:13:34 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Architectures that support NUMA duplicate the code that allocates
NODE_DATAon the node-local memory with slight variations in reporting of the addresses where the memory was allocated.Use x86 version as the basis for the generic
alloc_node_data()function and call this function in architecture specific numa initialization.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
I've no idea what rules are for the sparc prom_printf() calls but given that file already has mix and match of those and normal prints in single functions I assume this change is fine and we'll just see the prints a bit later.
Mike Rapoport
maintainerPATCH 6/17 x86/numa: simplify numa_distance allocation
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Allocation of numa_distance uses memblock_phys_alloc_range() to limit allocation to be below the last mapped page.
But NUMA initializaition runs after the direct map is populated and there is also code in setup_arch() that adjusts memblock limit to reflect how much memory is already mapped in the direct map.
Simplify the allocation of numa_distance and use plain memblock_alloc(). This makes the code clearer and ensures that when numa_distance is not allocated it is always NULL.
--- arch/x86/mm/numa.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
arch/x86/mm/numa.c +3 -9
@@ -319,8 +319,7 @@ void __init numa_reset_distance(void) {size_t size = numa_distance_cnt * numa_distance_cnt *sizeof (numa_distance[0 ]); -/* numa_distance could be 1LU marking allocation failure, test cnt */ -if (numa_distance_cnt) +if (numa_distance)memblock_free (numa_distance, size); numa_distance_cnt =0 ; numa_distance =NULL ;/* enable table creation */
@@ -331,7 +330,6 @@ static int __init numa_alloc_distance(void)nodemask_t nodes_parsed;size_t size;int i, j, cnt =0 ; -u64 phys;/* size the new table and allocate it */ nodes_parsed = numa_nodes_parsed;
@@ -342,16 +340,12 @@ static int __init numa_alloc_distance(void) cnt++; size = cnt * cnt *sizeof (numa_distance[0 ]); - phys =memblock_phys_alloc_range (size,PAGE_SIZE ,0 , -PFN_PHYS (max_pfn_mapped)); -if (!phys) { + numa_distance =memblock_alloc (size,PAGE_SIZE ); +if (!numa_distance) {pr_warn ("Warning: can't allocate distance table!\n" ); -/* don't retry until explicitly reset */ - numa_distance = (void *)1LU ;return -ENOMEM ; } - numa_distance =__va (phys); numa_distance_cnt = cnt;/* fill with the default distances */
Signature · 1 line
2.43.0
Re: [PATCH 06/17] x86/numa: simplify numa_distance allocation
Quoted 6 lines · On Tue, 16 Jul 2024 14:13:35 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Allocation of
numa_distanceusesmemblock_phys_alloc_range()to limit allocation to be below the last mapped page.But NUMA initializaition runs after the direct map is populated and
initialization (one too many 'i's)
Quoted 6 lines
there is also code in
setup_arch()that adjusts memblock limit to reflect how much memory is already mapped in the direct map.Simplify the allocation of
numa_distanceand use plainmemblock_alloc(). This makes the code clearer and ensures that whennuma_distanceis not allocated it is always NULL.
Doesn't this break the comment in numa_set_distance() kernel-doc? "
* If such table cannot be allocated, a warning is printed and further
* calls are ignored until the distance table is reset with
* numa_reset_distance().
"
Superficially that looks to be to avoid repeatedly hitting the singleton bit at the top of numa_set_distance() as SRAT or similar parsing occurs.
Quoted 47 lines
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>--- arch/x86/mm/numa.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)arch/x86/mm/numa.c +3
-9@@ -319,8 +319,7 @@ void __init numa_reset_distance(void) {size_t size = numa_distance_cnt * numa_distance_cnt *sizeof (numa_distance[0 ]); -/* numa_distance could be 1LU marking allocation failure, test cnt */ -if (numa_distance_cnt) +if (numa_distance)memblock_free (numa_distance, size); numa_distance_cnt =0 ; numa_distance =NULL ;/* enable table creation */ @@ -331,7 +330,6 @@ static int __init numa_alloc_distance(void)nodemask_t nodes_parsed;size_t size;int i, j, cnt =0 ; -u64 phys;/* size the new table and allocate it */ nodes_parsed = numa_nodes_parsed;@@ -342,16 +340,12 @@ static int __init numa_alloc_distance(void) cnt++; size = cnt * cnt *sizeof (numa_distance[0 ]); - phys =memblock_phys_alloc_range (size,PAGE_SIZE ,0 , -PFN_PHYS (max_pfn_mapped)); -if (!phys) { + numa_distance =memblock_alloc (size,PAGE_SIZE ); +if (!numa_distance) {pr_warn ("Warning: can't allocate distance table!\n" ); -/* don't retry until explicitly reset */ - numa_distance = (void *)1LU ;return -ENOMEM ; } - numa_distance =__va (phys); numa_distance_cnt = cnt;/* fill with the default distances */
Mike Rapoport
maintainerRe: [PATCH 06/17] x86/numa: simplify numa_distance allocation
Quoted 11 lines · Jonathan Cameron
Quoted 6 lines · On Tue, 16 Jul 2024 14:13:35 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Allocation of
numa_distanceusesmemblock_phys_alloc_range()to limit allocation to be below the last mapped page.But NUMA initializaition runs after the direct map is populated and
initialization (one too many 'i's)
Thanks.
Quoted 13 lines
Quoted 6 lines
there is also code in
setup_arch()that adjusts memblock limit to reflect how much memory is already mapped in the direct map.Simplify the allocation of
numa_distanceand use plainmemblock_alloc(). This makes the code clearer and ensures that whennuma_distanceis not allocated it is always NULL.Doesn't this break the comment in
numa_set_distance()kernel-doc? "
* If such table cannot be allocated, a warning is printed and further
* calls are ignored until the distance table is reset with
*numa_reset_distance().
"
Quoted 3 lines
Superficially that looks to be to avoid repeatedly hitting the singleton bit at the top of
numa_set_distance()as SRAT or similar parsing occurs.
I believe it's there to avoid allocation of numa_distance in the middle of distance parsing (SLIT or DT numa-distance-map).
If the allocation fails for the first element in the table, the numa_distance and numa_distance_cnt remain zero and node_distance() falls back to
return from == to ? LOCAL_DISTANCE : REMOTE_DISTANCE;
It's different from arch_numa that always tries to allocate MAX_NUMNODES * MAX_NUMNODES for numa_distance and treats the allocation failure as a failure to initialize NUMA.
I like the general approach x86 uses more, i.e. in case distance parsing fails in some way NUMA is still initialized with probably suboptimal distances between nodes.
I'm going to restore that "singleton" behavior for now and will look into making this all less cumbersome later.
Quoted 48 lines
Quoted 46 lines
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>--- arch/x86/mm/numa.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)arch/x86/mm/numa.c +3
-9@@ -319,8 +319,7 @@ void __init numa_reset_distance(void) {size_t size = numa_distance_cnt * numa_distance_cnt *sizeof (numa_distance[0 ]); -/* numa_distance could be 1LU marking allocation failure, test cnt */ -if (numa_distance_cnt) +if (numa_distance)memblock_free (numa_distance, size); numa_distance_cnt =0 ; numa_distance =NULL ;/* enable table creation */ @@ -331,7 +330,6 @@ static int __init numa_alloc_distance(void)nodemask_t nodes_parsed;size_t size;int i, j, cnt =0 ; -u64 phys;/* size the new table and allocate it */ nodes_parsed = numa_nodes_parsed;@@ -342,16 +340,12 @@ static int __init numa_alloc_distance(void) cnt++; size = cnt * cnt *sizeof (numa_distance[0 ]); - phys =memblock_phys_alloc_range (size,PAGE_SIZE ,0 , -PFN_PHYS (max_pfn_mapped)); -if (!phys) { + numa_distance =memblock_alloc (size,PAGE_SIZE ); +if (!numa_distance) {pr_warn ("Warning: can't allocate distance table!\n" ); -/* don't retry until explicitly reset */ - numa_distance = (void *)1LU ;return -ENOMEM ; } - numa_distance =__va (phys); numa_distance_cnt = cnt;/* fill with the default distances */
Signature · 2 lines
Sincerely yours, Mike.
Mike Rapoport
maintainerPATCH 7/17 x86/numa: move FAKE_NODE_* defines to numa_emu
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
The definitions of FAKE_NODE_MIN_SIZE and FAKE_NODE_MIN_HASH_MASK are only used by numa emulation code, make them local to arch/x86/mm/numa_emulation.c
--- arch/x86/include/asm/numa.h | 2 -- arch/x86/mm/numa_emulation.c | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-)
arch/x86/include/asm/numa.h +0 -2
@@ -71,8 +71,6 @@ void debug_cpumask_set_cpu(int cpu, int node, bool enable);#endif #ifdef CONFIG_NUMA_EMU -#define FAKE_NODE_MIN_SIZE ((u64)32 << 20) -#define FAKE_NODE_MIN_HASH_MASK (~(FAKE_NODE_MIN_SIZE - 1UL))int numa_emu_cmdline (char *str);#else /* CONFIG_NUMA_EMU */ static inline int numa_emu_cmdline (char *str)
arch/x86/mm/numa_emulation.c +3 -0
@@ -10,6 +10,9 @@#include "numa_internal.h" +#define FAKE_NODE_MIN_SIZE ((u64)32 << 20) +#define FAKE_NODE_MIN_HASH_MASK (~(FAKE_NODE_MIN_SIZE - 1UL)) +static int emu_nid_to_phys[MAX_NUMNODES ];static char *emu_cmdline__initdata ;
Signature · 1 line
2.43.0
Re: [PATCH 07/17] x86/numa: move FAKE_NODE_* defines to numa_emu
Quoted 7 lines · On Tue, 16 Jul 2024 14:13:36 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
The definitions of
FAKE_NODE_MIN_SIZEandFAKE_NODE_MIN_HASH_MASKare only used by numa emulation code, make them local toarch/x86/mm/numa_emulation.cSigned-off-by Mike Rapoport (Microsoft) <[email protected]>
Mike Rapoport
maintainerPATCH 8/17 x86/numa_emu: simplify allocation of phys_dist
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
By the time numa_emulation() is called, all physical memory is already mapped in the direct map and there is no need to define limits for memblock allocation.
Replace memblock_phys_alloc_range() with memblock_alloc().
--- arch/x86/mm/numa_emulation.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
arch/x86/mm/numa_emulation.c +2 -6
@@ -448,15 +448,11 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)/* copy the physical distance table */ if (numa_dist_cnt) { -u64 phys; - - phys =memblock_phys_alloc_range (phys_size,PAGE_SIZE ,0 , -PFN_PHYS (max_pfn_mapped)); -if (!phys) { + phys_dist =memblock_alloc (phys_size,PAGE_SIZE ); +if (!phys_dist) {pr_warn ("NUMA: Warning: can't allocate copy of distance table, disabling emulation\n" ); goto no_emu; } - phys_dist =__va (phys);for (i =0 ; i < numa_dist_cnt; i++)for (j =0 ; j < numa_dist_cnt; j++)
Signature · 1 line
2.43.0
Re: [PATCH 08/17] x86/numa_emu: simplify allocation of phys_dist
Quoted 9 lines · On Tue, 16 Jul 2024 14:13:37 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
By the time
numa_emulation()is called, all physical memory is already mapped in the direct map and there is no need to define limits for memblock allocation.Replace
memblock_phys_alloc_range()withmemblock_alloc().Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Indeed seems to be after mapping physical memory, so this looks fine.
Mike Rapoport
maintainerPATCH 9/17 x86/numa_emu: split __apicid_to_node update to a helper function
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
This is required to make numa emulation code architecture independent so that it can be moved to generic code in following commits.
--- arch/x86/include/asm/numa.h | 2 ++ arch/x86/mm/numa.c | 22 ++++++++++++++++++++++ arch/x86/mm/numa_emulation.c | 14 +------------- 3 files changed, 25 insertions(+), 13 deletions(-)
arch/x86/include/asm/numa.h +2 -0
@@ -72,6 +72,8 @@ void debug_cpumask_set_cpu(int cpu, int node, bool enable);#ifdef CONFIG_NUMA_EMU int numa_emu_cmdline (char *str); +void __init numa_emu_update_cpu_to_node (int *emu_nid_to_phys, +unsigned int nr_emu_nids);#else /* CONFIG_NUMA_EMU */ static inline int numa_emu_cmdline (char *str) {
arch/x86/mm/numa.c +22 -0
@@ -852,6 +852,28 @@ EXPORT_SYMBOL(cpumask_of_node);#endif /* !CONFIG_DEBUG_PER_CPU_MAPS */ +#ifdef CONFIG_NUMA_EMU +void __init numa_emu_update_cpu_to_node (int *emu_nid_to_phys, +unsigned int nr_emu_nids) +{ +int i, j; + +/* +* Transform __apicid_to_node table to use emulated nids by +* reverse-mapping phys_nid. The maps should always exist but fall +* back to zero just in case. +*/ +for (i =0 ; i <ARRAY_SIZE (__apicid_to_node); i++) { +if (__apicid_to_node[i] ==NUMA_NO_NODE ) +continue ; +for (j =0 ; j < nr_emu_nids; j++) +if (__apicid_to_node[i] == emu_nid_to_phys[j]) +break ; + __apicid_to_node[i] = j < nr_emu_nids ? j :0 ; + } +} +#endif /* CONFIG_NUMA_EMU */ +#ifdef CONFIG_NUMA_KEEP_MEMINFO static int meminfo_to_nid (struct numa_meminfo *mi,u64 start) {
arch/x86/mm/numa_emulation.c +1 -13
@@ -476,19 +476,7 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt) ei.blk[i].nid != NUMA_NO_NODE)node_set (ei.blk[i].nid, numa_nodes_parsed); -/* -* Transform __apicid_to_node table to use emulated nids by -* reverse-mapping phys_nid. The maps should always exist but fall -* back to zero just in case. -*/ -for (i =0 ; i <ARRAY_SIZE (__apicid_to_node); i++) { -if (__apicid_to_node[i] ==NUMA_NO_NODE ) -continue ; -for (j =0 ; j <ARRAY_SIZE (emu_nid_to_phys); j++) -if (__apicid_to_node[i] == emu_nid_to_phys[j]) -break ; - __apicid_to_node[i] = j <ARRAY_SIZE (emu_nid_to_phys) ? j :0 ; - } +numa_emu_update_cpu_to_node (emu_nid_to_phys,ARRAY_SIZE (emu_nid_to_phys));/* make sure all emulated nodes are mapped to a physical node */ for (i =0 ; i <ARRAY_SIZE (emu_nid_to_phys); i++)
Signature · 1 line
2.43.0
Re: [PATCH 09/17] x86/numa_emu: split __apicid_to_node update to a helper function
Quoted 6 lines · On Tue, 16 Jul 2024 14:13:38 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
This is required to make numa emulation code architecture independent so that it can be moved to generic code in following commits.
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Not the most intuitive of function names but I can't immediately think of a better one.
Mike Rapoport
maintainerPATCH 10/17 x86/numa_emu: use a helper function to get MAX_DMA32_PFN
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
This is required to make numa emulation code architecture independent s that it can be moved to generic code in following commits.
--- arch/x86/include/asm/numa.h | 1 + arch/x86/mm/numa.c | 5 +++++ arch/x86/mm/numa_emulation.c | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-)
arch/x86/include/asm/numa.h +1 -0
@@ -74,6 +74,7 @@ void debug_cpumask_set_cpu(int cpu, int node, bool enable);int numa_emu_cmdline (char *str);void __init numa_emu_update_cpu_to_node (int *emu_nid_to_phys,unsigned int nr_emu_nids); +u64 __init numa_emu_dma_end (void );#else /* CONFIG_NUMA_EMU */ static inline int numa_emu_cmdline (char *str) {
arch/x86/mm/numa.c +5 -0
@@ -872,6 +872,11 @@ void __init numa_emu_update_cpu_to_node(int *emu_nid_to_phys, __apicid_to_node[i] = j < nr_emu_nids ? j : 0; } } + +u64 __init numa_emu_dma_end (void ) +{ +return PFN_PHYS (MAX_DMA32_PFN ); +}#endif /* CONFIG_NUMA_EMU */ #ifdef CONFIG_NUMA_KEEP_MEMINFO
arch/x86/mm/numa_emulation.c +2 -2
@@ -128,7 +128,7 @@ static int __init split_nodes_interleave(struct numa_meminfo *ei,*/ while (!nodes_empty (physnode_mask)) {for_each_node_mask (i, physnode_mask) { -u64 dma32_end =PFN_PHYS (MAX_DMA32_PFN ); +u64 dma32_end =numa_emu_dma_end ();u64 start, limit, end;int phys_blk;
@@ -275,7 +275,7 @@ static int __init split_nodes_size_interleave_uniform(struct numa_meminfo *ei,*/ while (!nodes_empty (physnode_mask)) {for_each_node_mask (i, physnode_mask) { -u64 dma32_end =PFN_PHYS (MAX_DMA32_PFN ); +u64 dma32_end =numa_emu_dma_end ();u64 start, limit, end;int phys_blk;
Signature · 1 line
2.43.0
Re: [PATCH 10/17] x86/numa_emu: use a helper function to get MAX_DMA32_PFN
Quoted 6 lines · On Tue, 16 Jul 2024 14:13:39 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
This is required to make numa emulation code architecture independent s that it can be moved to generic code in following commits.
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Mike Rapoport
maintainerPATCH 11/17 x86/numa: numa_{add,remove}_cpu: make cpu parameter unsigned
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
CPU id cannot be negative.
Making it unsigned also aligns with declarations in include/asm-generic/numa.h used by arm64 and riscv and allows sharing numa emulation code with these architectures.
--- arch/x86/include/asm/numa.h | 10 +++++----- arch/x86/mm/numa.c | 10 +++++----- arch/x86/mm/numa_emulation.c | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-)
arch/x86/include/asm/numa.h +5 -5
@@ -54,20 +54,20 @@ static inline int numa_cpu_node(int cpu)extern void numa_set_node (int cpu,int node);extern void numa_clear_node (int cpu);extern void __init init_cpu_to_node (void ); -extern void numa_add_cpu (int cpu); -extern void numa_remove_cpu (int cpu); +extern void numa_add_cpu (unsigned int cpu); +extern void numa_remove_cpu (unsigned int cpu);extern void init_gi_nodes (void );#else /* CONFIG_NUMA */ static inline void numa_set_node (int cpu,int node) { }static inline void numa_clear_node (int cpu) { }static inline void init_cpu_to_node (void ) { } -static inline void numa_add_cpu (int cpu) { } -static inline void numa_remove_cpu (int cpu) { } +static inline void numa_add_cpu (unsigned int cpu) { } +static inline void numa_remove_cpu (unsigned int cpu) { }static inline void init_gi_nodes (void ) { }#endif /* CONFIG_NUMA */ #ifdef CONFIG_DEBUG_PER_CPU_MAPS -void debug_cpumask_set_cpu (int cpu,int node,bool enable); +void debug_cpumask_set_cpu (unsigned int cpu,int node,bool enable);#endif #ifdef CONFIG_NUMA_EMU
arch/x86/mm/numa.c +5 -5
@@ -741,12 +741,12 @@ void __init init_cpu_to_node(void)#ifndef CONFIG_DEBUG_PER_CPU_MAPS # ifndef CONFIG_NUMA_EMU -void numa_add_cpu (int cpu) +void numa_add_cpu (unsigned int cpu) {cpumask_set_cpu (cpu, node_to_cpumask_map[early_cpu_to_node (cpu)]); } -void numa_remove_cpu (int cpu) +void numa_remove_cpu (unsigned int cpu) {cpumask_clear_cpu (cpu, node_to_cpumask_map[early_cpu_to_node (cpu)]); }
@@ -784,7 +784,7 @@ int early_cpu_to_node(int cpu)return per_cpu (x86_cpu_to_node_map, cpu); } -void debug_cpumask_set_cpu (int cpu,int node,bool enable) +void debug_cpumask_set_cpu (unsigned int cpu,int node,bool enable) {struct cpumask *mask;
@@ -816,12 +816,12 @@ static void numa_set_cpumask(int cpu, bool enable)debug_cpumask_set_cpu (cpu,early_cpu_to_node (cpu), enable); } -void numa_add_cpu (int cpu) +void numa_add_cpu (unsigned int cpu) {numa_set_cpumask (cpu, true); } -void numa_remove_cpu (int cpu) +void numa_remove_cpu (unsigned int cpu) {numa_set_cpumask (cpu, false); }
arch/x86/mm/numa_emulation.c +5 -5
@@ -514,7 +514,7 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt) }#ifndef CONFIG_DEBUG_PER_CPU_MAPS -void numa_add_cpu (int cpu) +void numa_add_cpu (unsigned int cpu) {int physnid, nid;
@@ -532,7 +532,7 @@ void numa_add_cpu(int cpu)cpumask_set_cpu (cpu, node_to_cpumask_map[nid]); } -void numa_remove_cpu (int cpu) +void numa_remove_cpu (unsigned int cpu) {int i;
@@ -540,7 +540,7 @@ void numa_remove_cpu(int cpu) cpumask_clear_cpu(cpu, node_to_cpumask_map[i]); }#else /* !CONFIG_DEBUG_PER_CPU_MAPS */ -static void numa_set_cpumask (int cpu,bool enable) +static void numa_set_cpumask (unsigned int cpu,bool enable) {int nid, physnid;
@@ -560,12 +560,12 @@ static void numa_set_cpumask(int cpu, bool enable) } } -void numa_add_cpu (int cpu) +void numa_add_cpu (unsigned int cpu) {numa_set_cpumask (cpu, true); } -void numa_remove_cpu (int cpu) +void numa_remove_cpu (unsigned int cpu) {numa_set_cpumask (cpu, false); }
Signature · 1 line
2.43.0
Re: [PATCH 11/17] x86/numa: numa_{add,remove}_cpu: make cpu parameter unsigned
Quoted 9 lines · On Tue, 16 Jul 2024 14:13:40 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
CPU id cannot be negative.
Making it unsigned also aligns with declarations in
include/asm-generic/numa.hused by arm64 and riscv and allows sharing numa emulation code with these architectures.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Makes sense for both reasons. FWIW given how simple it is.
Maybe worth bringing a few more functions inline with this? Probably something for another day given we don't care about the inconsistency for this series.
Mike Rapoport
maintainerPATCH 12/17 mm: introduce numa_memblks
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move code dealing with numa_memblks from arch/x86 to mm/ and add Kconfig options to let x86 select it in its Kconfig.
This code will be later reused by arch_numa.
No functional changes.
--- arch/x86/Kconfig | 1 + arch/x86/include/asm/numa.h | 3 - arch/x86/mm/amdtopology.c | 1 + arch/x86/mm/numa.c | 372 +-------------------------------- arch/x86/mm/numa_emulation.c | 1 + arch/x86/mm/numa_internal.h | 15 +- drivers/acpi/numa/srat.c | 1 + drivers/of/of_numa.c | 1 + include/linux/numa_memblks.h | 35 ++++ mm/Kconfig | 3 + mm/Makefile | 1 + mm/numa_memblks.c | 385 +++++++++++++++++++++++++++++++++++ 12 files changed, 436 insertions(+), 383 deletions(-) create mode 100644 include/linux/numa_memblks.h create mode 100644 mm/numa_memblks.c
arch/x86/Kconfig +1 -0
@@ -295,6 +295,7 @@ config X86 select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK select NEED_SG_DMA_LENGTH + select NUMA_MEMBLKS if NUMA select PCI_DOMAINS if PCI select PCI_LOCKLESS_CONFIG if PCI select PERF_EVENTS
arch/x86/include/asm/numa.h +0 -3
@@ -10,8 +10,6 @@#ifdef CONFIG_NUMA -#define NR_NODE_MEMBLKS (MAX_NUMNODES*2) -extern int numa_off;/*
@@ -25,7 +23,6 @@ extern int numa_off;extern s16 __apicid_to_node[MAX_LOCAL_APIC ];extern nodemask_t numa_nodes_parsed__initdata ; -extern int __init numa_add_memblk (int nodeid,u64 start,u64 end);extern void __init numa_set_distance (int from,int to,int distance);static inline void set_apicid_to_node (int apicid,s16 node)
arch/x86/mm/amdtopology.c +1 -0
@@ -12,6 +12,7 @@#include <linux/string.h> #include <linux/nodemask.h> #include <linux/memblock.h> +#include <linux/numa_memblks.h> #include <asm/io.h> #include <linux/pci_ids.h>
arch/x86/mm/numa.c +5 -367
402 lines not on this page · raw message
arch/x86/mm/numa_emulation.c +1 -0
@@ -6,6 +6,7 @@#include <linux/errno.h> #include <linux/topology.h> #include <linux/memblock.h> +#include <linux/numa_memblks.h> #include <asm/dma.h> #include "numa_internal.h"
arch/x86/mm/numa_internal.h +2 -13
@@ -5,23 +5,12 @@#include <linux/types.h> #include <asm/numa.h> -struct numa_memblk { -u64 start; -u64 end; -int nid; -}; - -struct numa_meminfo { -int nr_blks; -struct numa_memblk blk[NR_NODE_MEMBLKS ]; -}; - -void __init numa_remove_memblk_from (int idx,struct numa_meminfo *mi); -int __init numa_cleanup_meminfo (struct numa_meminfo *mi);void __init numa_reset_distance (void );void __init x86_numa_init (void ); +struct numa_meminfo ; +#ifdef CONFIG_NUMA_EMU void __init numa_emulation (struct numa_meminfo *numa_meminfo,int numa_dist_cnt);
drivers/acpi/numa/srat.c +1 -0
@@ -17,6 +17,7 @@#include <linux/numa.h> #include <linux/nodemask.h> #include <linux/topology.h> +#include <linux/numa_memblks.h> static nodemask_t nodes_found_map =NODE_MASK_NONE ;
drivers/of/of_numa.c +1 -0
@@ -10,6 +10,7 @@#include <linux/of.h> #include <linux/of_address.h> #include <linux/nodemask.h> +#include <linux/numa_memblks.h> #include <asm/numa.h>
include/linux/numa_memblks.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __NUMA_MEMBLKS_H +#define __NUMA_MEMBLKS_H + +#ifdef CONFIG_NUMA_MEMBLKS +#include <linux/types.h> + +#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2) + +struct numa_memblk { +u64 start; +u64 end; +int nid; +}; + +struct numa_meminfo { +int nr_blks; +struct numa_memblk blk[NR_NODE_MEMBLKS ]; +}; + +extern struct numa_meminfo numa_meminfo __initdata_or_meminfo; +extern struct numa_meminfo numa_reserved_meminfo __initdata_or_meminfo; + +int __init numa_add_memblk (int nodeid,u64 start,u64 end); +void __init numa_remove_memblk_from (int idx,struct numa_meminfo *mi); + +int __init numa_cleanup_meminfo (struct numa_meminfo *mi); +int __init numa_register_meminfo (struct numa_meminfo *mi); + +void __init numa_nodemask_from_meminfo (nodemask_t *nodemask, +const struct numa_meminfo *mi); + +#endif /* CONFIG_NUMA_MEMBLKS */ + +#endif /* __NUMA_MEMBLKS_H */
mm/Kconfig +3 -0
@@ -1249,6 +1249,9 @@ config IOMMU_MM_DATA config EXECMEM bool +config NUMA_MEMBLKS + bool + source "mm/damon/Kconfig" endmenu
mm/Makefile +1 -0
@@ -140,3 +140,4 @@ obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o obj-$(CONFIG_EXECMEM) += execmem.o obj-$(CONFIG_NUMA) += numa.o +obj-$(CONFIG_NUMA_MEMBLKS) += numa_memblks.o
mm/numa_memblks.c new file +385 -0
385 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 10 lines · On Tue, 16 Jul 2024 14:13:41 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Move code dealing with
numa_memblksfromarch/x86tomm/and addKconfigoptions to let x86 select it in itsKconfig.This code will be later reused by
arch_numa.No functional changes.
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Hi Mike,
My only real concern in here is there are a few places where the lifted code makes changes to memblocks that are x86 only today. I need to do some more digging to work out if those are safe in all cases.
Jonathan
mm/numa_memblks.c line 97
Quoted 13 lines
mm/numa_memblks.c new file +13
-0+/** +* numa_cleanup_meminfo - Cleanup a numa_meminfo +* @mi: numa_meminfo to clean up +* +* Sanitize @mi by merging and removing unnecessary memblks. Also check for +* conflicts and clear unused memblks. +* +* RETURNS: +* 0 on success, -errno on failure. +*/ +int __init numa_cleanup_meminfo (struct numa_meminfo *mi) +{ +const u64 low =0 ;
Given always zero, why not just use that value inline?
Quoted 90 lines
mm/numa_memblks.c new file +90
-0+const u64 high =PFN_PHYS (max_pfn); +int i, j, k; + +/* first, trim all entries */ +for (i =0 ; i < mi->nr_blks; i++) { +struct numa_memblk *bi = &mi->blk[i]; + +/* move / save reserved memory ranges */ +if (!memblock_overlaps_region (&memblock.memory, + bi->start, bi->end - bi->start)) { +numa_move_tail_memblk (&numa_reserved_meminfo, i--, mi); +continue ; + } + +/* make sure all non-reserved blocks are inside the limits */ + bi->start =max (bi->start, low); + +/* preserve info for non-RAM areas above 'max_pfn': */ +if (bi->end > high) { +numa_add_memblk_to (bi->nid, high, bi->end, + &numa_reserved_meminfo); + bi->end = high; + } + +/* and there's no empty block */ +if (bi->start >= bi->end) +numa_remove_memblk_from (i--, mi); + } + +/* merge neighboring / overlapping entries */ +for (i =0 ; i < mi->nr_blks; i++) { +struct numa_memblk *bi = &mi->blk[i]; + +for (j = i +1 ; j < mi->nr_blks; j++) { +struct numa_memblk *bj = &mi->blk[j]; +u64 start, end; + +/* +* See whether there are overlapping blocks. Whine +* about but allow overlaps of the same nid. They +* will be merged below. +*/ +if (bi->end > bj->start && bi->start < bj->end) { +if (bi->nid != bj->nid) { +pr_err ("node %d [mem %#010Lx-%#010Lx] overlaps with node %d [mem %#010Lx-%#010Lx]\n" , + bi->nid, bi->start, bi->end -1 , + bj->nid, bj->start, bj->end -1 ); +return -EINVAL ; + } +pr_warn ("Warning: node %d [mem %#010Lx-%#010Lx] overlaps with itself [mem %#010Lx-%#010Lx]\n" , + bi->nid, bi->start, bi->end -1 , + bj->start, bj->end -1 ); + } + +/* +* Join together blocks on the same node, holes +* between which don't overlap with memory on other +* nodes. +*/ +if (bi->nid != bj->nid) +continue ; + start =min (bi->start, bj->start); + end =max (bi->end, bj->end); +for (k =0 ; k < mi->nr_blks; k++) { +struct numa_memblk *bk = &mi->blk[k]; + +if (bi->nid == bk->nid) +continue ; +if (start < bk->end && end > bk->start) +break ; + } +if (k < mi->nr_blks) +continue ; +pr_info ("NUMA: Node %d [mem %#010Lx-%#010Lx] + [mem %#010Lx-%#010Lx] -> [mem %#010Lx-%#010Lx]\n" , + bi->nid, bi->start, bi->end -1 , bj->start, + bj->end -1 , start, end -1 ); + bi->start = start; + bi->end = end; +numa_remove_memblk_from (j--, mi); + } + } + +/* clear unused ones */ +for (i = mi->nr_blks; i <ARRAY_SIZE (mi->blk); i++) { + mi->blk[i].start = mi->blk[i].end =0 ; + mi->blk[i].nid =NUMA_NO_NODE ; + } + +return 0 ; +}
...
mm/numa_memblks.c line 207
Quoted 5 lines
mm/numa_memblks.c new file +5
-0+/* +* Mark all currently memblock-reserved physical memory (which covers the +* kernel's own memory ranges) as hot-unswappable. +*/ +static void __init numa_clear_kernel_node_hotplug (void )
This will be a change for non x86 architectures. 'should' be fine but I'm not 100% sure.
Quoted 5 lines
mm/numa_memblks.c new file +5
-0+{ +nodemask_t reserved_nodemask =NODE_MASK_NONE ; +struct memblock_region *mb_region; +int i; +
mm/numa_memblks.c line 222
Quoted 10 lines
mm/numa_memblks.c new file +10
-0+/* +* We have to do some preprocessing of memblock regions, to +* make them suitable for reservation. +* +* At this time, all memory regions reserved by memblock are +* used by the kernel, but those regions are not split up +* along node boundaries yet, and don't necessarily have their +* node ID set yet either. +* +* So iterate over all memory known to the x86 architecture,
Comment needs an update at least given not x86 specific any more.
Quoted 46 lines
mm/numa_memblks.c new file +46
-0+* and use those ranges to set the nid in memblock.reserved. +* This will split up the memblock regions along node +* boundaries and will set the node IDs as well. +*/ +for (i =0 ; i < numa_meminfo.nr_blks; i++) { +struct numa_memblk *mb = numa_meminfo.blk + i; +int ret; + + ret =memblock_set_node (mb->start, mb->end - mb->start, + &memblock.reserved, mb->nid); +WARN_ON_ONCE (ret); + } + +/* +* Now go over all reserved memblock regions, to construct a +* node mask of all kernel reserved memory areas. +* +* [ Note, when booting with mem=nn[kMG] or in a kdump kernel, +* numa_meminfo might not include all memblock.reserved +* memory ranges, because quirks such as trim_snb_memory() +* reserve specific pages for Sandy Bridge graphics. ] +*/ +for_each_reserved_mem_region (mb_region) { +int nid =memblock_get_region_node (mb_region); + +if (nid !=MAX_NUMNODES ) +node_set (nid, reserved_nodemask); + } + +/* +* Finally, clear the MEMBLOCK_HOTPLUG flag for all memory +* belonging to the reserved node mask. +* +* Note that this will include memory regions that reside +* on nodes that contain kernel memory - entire nodes +* become hot-unpluggable: +*/ +for (i =0 ; i < numa_meminfo.nr_blks; i++) { +struct numa_memblk *mb = numa_meminfo.blk + i; + +if (!node_isset (mb->nid, reserved_nodemask)) +continue ; + +memblock_clear_hotplug (mb->start, mb->end - mb->start); + } +}
Mike Rapoport
maintainerQuoted 24 lines · Jonathan Cameron
Quoted 10 lines · On Tue, 16 Jul 2024 14:13:41 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Move code dealing with
numa_memblksfromarch/x86tomm/and addKconfigoptions to let x86 select it in itsKconfig.This code will be later reused by
arch_numa.No functional changes.
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>Hi Mike,
My only real concern in here is there are a few places where the lifted code makes changes to memblocks that are x86 only today. I need to do some more digging to work out if those are safe in all cases.
Jonathan
Quoted 15 lines
mm/numa_memblks.c line 97
Quoted 13 lines
mm/numa_memblks.c new file +13
-0+/** +* numa_cleanup_meminfo - Cleanup a numa_meminfo +* @mi: numa_meminfo to clean up +* +* Sanitize @mi by merging and removing unnecessary memblks. Also check for +* conflicts and clear unused memblks. +* +* RETURNS: +* 0 on success, -errno on failure. +*/ +int __init numa_cleanup_meminfo (struct numa_meminfo *mi) +{ +const u64 low =0 ;Given always zero, why not just use that value inline?
Actually it seems to me that it should be memblock_start_of_DRAM().
The blocks outside system memory are moved to numa_reserved_meminfo, so AFAIU on arm64/riscv such blocks can be below the RAM.
Quoted 94 lines
Quoted 90 lines
mm/numa_memblks.c new file +90
-0+const u64 high =PFN_PHYS (max_pfn); +int i, j, k; + +/* first, trim all entries */ +for (i =0 ; i < mi->nr_blks; i++) { +struct numa_memblk *bi = &mi->blk[i]; + +/* move / save reserved memory ranges */ +if (!memblock_overlaps_region (&memblock.memory, + bi->start, bi->end - bi->start)) { +numa_move_tail_memblk (&numa_reserved_meminfo, i--, mi); +continue ; + } + +/* make sure all non-reserved blocks are inside the limits */ + bi->start =max (bi->start, low); + +/* preserve info for non-RAM areas above 'max_pfn': */ +if (bi->end > high) { +numa_add_memblk_to (bi->nid, high, bi->end, + &numa_reserved_meminfo); + bi->end = high; + } + +/* and there's no empty block */ +if (bi->start >= bi->end) +numa_remove_memblk_from (i--, mi); + } + +/* merge neighboring / overlapping entries */ +for (i =0 ; i < mi->nr_blks; i++) { +struct numa_memblk *bi = &mi->blk[i]; + +for (j = i +1 ; j < mi->nr_blks; j++) { +struct numa_memblk *bj = &mi->blk[j]; +u64 start, end; + +/* +* See whether there are overlapping blocks. Whine +* about but allow overlaps of the same nid. They +* will be merged below. +*/ +if (bi->end > bj->start && bi->start < bj->end) { +if (bi->nid != bj->nid) { +pr_err ("node %d [mem %#010Lx-%#010Lx] overlaps with node %d [mem %#010Lx-%#010Lx]\n" , + bi->nid, bi->start, bi->end -1 , + bj->nid, bj->start, bj->end -1 ); +return -EINVAL ; + } +pr_warn ("Warning: node %d [mem %#010Lx-%#010Lx] overlaps with itself [mem %#010Lx-%#010Lx]\n" , + bi->nid, bi->start, bi->end -1 , + bj->start, bj->end -1 ); + } + +/* +* Join together blocks on the same node, holes +* between which don't overlap with memory on other +* nodes. +*/ +if (bi->nid != bj->nid) +continue ; + start =min (bi->start, bj->start); + end =max (bi->end, bj->end); +for (k =0 ; k < mi->nr_blks; k++) { +struct numa_memblk *bk = &mi->blk[k]; + +if (bi->nid == bk->nid) +continue ; +if (start < bk->end && end > bk->start) +break ; + } +if (k < mi->nr_blks) +continue ; +pr_info ("NUMA: Node %d [mem %#010Lx-%#010Lx] + [mem %#010Lx-%#010Lx] -> [mem %#010Lx-%#010Lx]\n" , + bi->nid, bi->start, bi->end -1 , bj->start, + bj->end -1 , start, end -1 ); + bi->start = start; + bi->end = end; +numa_remove_memblk_from (j--, mi); + } + } + +/* clear unused ones */ +for (i = mi->nr_blks; i <ARRAY_SIZE (mi->blk); i++) { + mi->blk[i].start = mi->blk[i].end =0 ; + mi->blk[i].nid =NUMA_NO_NODE ; + } + +return 0 ; +}...
Quoted 8 lines
mm/numa_memblks.c line 207
Quoted 5 lines
mm/numa_memblks.c new file +5
-0+/* +* Mark all currently memblock-reserved physical memory (which covers the +* kernel's own memory ranges) as hot-unswappable. +*/ +static void __init numa_clear_kernel_node_hotplug (void )This will be a change for non x86 architectures. 'should' be fine but I'm not 100% sure.
This function sets nid to memblock.reserved which does not change anything except the dump in debugfs and then uses the node info in memblock.reserve to clear MEMBLOCK_HOTPLUG from the regions in memblock.memory that contain the reserved memory because they cannot be hot(un)plugged anyway.
Quoted 9 lines
Quoted 9 lines
mm/numa_memblks.c new file +9
-0+{ +nodemask_t reserved_nodemask =NODE_MASK_NONE ; +struct memblock_region *mb_region; +int i; + +/* +* We have to do some preprocessing of memblock regions, to +* make them suitable for reservation. +*
Quoted 8 lines
mm/numa_memblks.c line 222
Quoted 6 lines
mm/numa_memblks.c new file +6
-0+* At this time, all memory regions reserved by memblock are +* used by the kernel, but those regions are not split up +* along node boundaries yet, and don't necessarily have their +* node ID set yet either. +* +* So iterate over all memory known to the x86 architecture, Comment needs an update at least given not x86 specific any more.
Sure, will fix.
Quoted 47 lines
Quoted 46 lines
mm/numa_memblks.c new file +46
-0+* and use those ranges to set the nid in memblock.reserved. +* This will split up the memblock regions along node +* boundaries and will set the node IDs as well. +*/ +for (i =0 ; i < numa_meminfo.nr_blks; i++) { +struct numa_memblk *mb = numa_meminfo.blk + i; +int ret; + + ret =memblock_set_node (mb->start, mb->end - mb->start, + &memblock.reserved, mb->nid); +WARN_ON_ONCE (ret); + } + +/* +* Now go over all reserved memblock regions, to construct a +* node mask of all kernel reserved memory areas. +* +* [ Note, when booting with mem=nn[kMG] or in a kdump kernel, +* numa_meminfo might not include all memblock.reserved +* memory ranges, because quirks such as trim_snb_memory() +* reserve specific pages for Sandy Bridge graphics. ] +*/ +for_each_reserved_mem_region (mb_region) { +int nid =memblock_get_region_node (mb_region); + +if (nid !=MAX_NUMNODES ) +node_set (nid, reserved_nodemask); + } + +/* +* Finally, clear the MEMBLOCK_HOTPLUG flag for all memory +* belonging to the reserved node mask. +* +* Note that this will include memory regions that reside +* on nodes that contain kernel memory - entire nodes +* become hot-unpluggable: +*/ +for (i =0 ; i < numa_meminfo.nr_blks; i++) { +struct numa_memblk *mb = numa_meminfo.blk + i; + +if (!node_isset (mb->nid, reserved_nodemask)) +continue ; + +memblock_clear_hotplug (mb->start, mb->end - mb->start); + } +}
Signature · 2 lines
Sincerely yours, Mike.
Mike Rapoport
maintainerPATCH 13/17 mm: move numa_distance and related code from x86 to numa_memblks
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move code dealing with numa_distance array from arch/x86 to mm/numa_memblks.c
This code will be later reused by arch_numa.
No functional changes.
---
arch/x86/mm/numa.c | 101 ---------------------------
arch/x86/mm/numa_internal.h | 2 -
include/linux/numa_memblks.h | 4 ++
{arch/x86/mm => mm}/numa_emulation.c | 0
mm/numa_memblks.c | 101 +++++++++++++++++++++++++++
5 files changed, 105 insertions(+), 103 deletions(-)
rename {arch/x86/mm => mm}/numa_emulation.c (100%)arch/x86/mm/numa.c +0 -101
@@ -24,9 +24,6 @@int numa_off; -static int numa_distance_cnt; -static u8 *numa_distance; -static __init int numa_setup (char *opt) {if (!opt)
@@ -118,104 +115,6 @@ void __init setup_node_to_cpumask_map(void)pr_debug ("Node to cpumask map for %u nodes\n" , nr_node_ids); } -/** -* numa_reset_distance - Reset NUMA distance table -* -* The current table is freed. The next numa_set_distance() call will -* create a new one. -*/ -void __init numa_reset_distance (void ) -{ -size_t size = numa_distance_cnt * numa_distance_cnt *sizeof (numa_distance[0 ]); - -if (numa_distance) -memblock_free (numa_distance, size); - numa_distance_cnt =0 ; - numa_distance =NULL ;/* enable table creation */ -} - -static int __init numa_alloc_distance (void ) -{ -nodemask_t nodes_parsed; -size_t size; -int i, j, cnt =0 ; - -/* size the new table and allocate it */ - nodes_parsed = numa_nodes_parsed; -numa_nodemask_from_meminfo (&nodes_parsed, &numa_meminfo); - -for_each_node_mask (i, nodes_parsed) - cnt = i; - cnt++; - size = cnt * cnt *sizeof (numa_distance[0 ]); - - numa_distance =memblock_alloc (size,PAGE_SIZE ); -if (!numa_distance) { -pr_warn ("Warning: can't allocate distance table!\n" ); -return -ENOMEM ; - } - - numa_distance_cnt = cnt; - -/* fill with the default distances */ -for (i =0 ; i < cnt; i++) -for (j =0 ; j < cnt; j++) - numa_distance[i * cnt + j] = i == j ? -LOCAL_DISTANCE :REMOTE_DISTANCE ; -printk (KERN_DEBUG "NUMA: Initialized distance table, cnt=%d\n" , cnt); - -return 0 ; -} - -/** -* numa_set_distance - Set NUMA distance from one NUMA to another -* @from: the 'from' node to set distance -* @to: the 'to' node to set distance -* @distance: NUMA distance -* -* Set the distance from node @from to @to to @distance. If distance table -* doesn't exist, one which is large enough to accommodate all the currently -* known nodes will be created. -* -* If such table cannot be allocated, a warning is printed and further -* calls are ignored until the distance table is reset with -* numa_reset_distance(). -* -* If @from or @to is higher than the highest known node or lower than zero -* at the time of table creation or @distance doesn't make sense, the call -* is ignored. -* This is to allow simplification of specific NUMA config implementations. -*/ -void __init numa_set_distance (int from,int to,int distance) -{ -if (!numa_distance &&numa_alloc_distance () <0 ) -return ; - -if (from >= numa_distance_cnt || to >= numa_distance_cnt || - from <0 || to <0 ) { -pr_warn_once ("Warning: node ids are out of bound, from=%d to=%d distance=%d\n" , - from, to, distance); -return ; - } - -if ((u8 )distance != distance || - (from == to && distance !=LOCAL_DISTANCE )) { -pr_warn_once ("Warning: invalid distance parameter, from=%d to=%d distance=%d\n" , - from, to, distance); -return ; - } - - numa_distance[from * numa_distance_cnt + to] = distance; -} - -int __node_distance (int from,int to) -{ -if (from >= numa_distance_cnt || to >= numa_distance_cnt) -return from == to ?LOCAL_DISTANCE :REMOTE_DISTANCE ; -return numa_distance[from * numa_distance_cnt + to]; -} -EXPORT_SYMBOL (__node_distance); -static int __init numa_register_memblks (struct numa_meminfo *mi) {int i, nid, err;
arch/x86/mm/numa_internal.h +0 -2
@@ -5,8 +5,6 @@#include <linux/types.h> #include <asm/numa.h> -void __init numa_reset_distance (void ); -void __init x86_numa_init (void );struct numa_meminfo ;
include/linux/numa_memblks.h +4 -0
@@ -7,6 +7,10 @@#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2) +extern int numa_distance_cnt; +void __init numa_set_distance (int from,int to,int distance); +void __init numa_reset_distance (void ); +struct numa_memblk {u64 start;u64 end;
mm/numa_emulation.c renamed from arch/x86/mm/numa_emulation.c +0 -0
mm/numa_memblks.c +101 -0
112 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 13/17] mm: move numa_distance and related code from x86 to numa_memblks
Quoted 10 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Move code dealing with
numa_distancearray fromarch/x86tomm/numa_memblks.cThis code will be later reused by
arch_numa.No functional changes.
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Quoted 8 lines
---
arch/x86/mm/numa.c | 101 ---------------------------
arch/x86/mm/numa_internal.h | 2 -
include/linux/numa_memblks.h | 4 ++
{arch/x86/mm => mm}/numa_emulation.c | 0
mm/numa_memblks.c | 101 +++++++++++++++++++++++++++
5 files changed, 105 insertions(+), 103 deletions(-)
rename {arch/x86/mm => mm}/numa_emulation.c (100%)The numa_emulation.c rename looks like it should be part of the next commit, not this one.
Mike Rapoport
maintainerRe: [PATCH 13/17] mm: move numa_distance and related code from x86 to numa_memblks
Quoted 20 lines · Samuel Holland
Quoted 10 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Move code dealing with
numa_distancearray fromarch/x86tomm/numa_memblks.cThis code will be later reused by
arch_numa.No functional changes.
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>Quoted 8 lines
--- arch/x86/mm/numa.c | 101 --------------------------- arch/x86/mm/numa_internal.h | 2 - include/linux/numa_memblks.h | 4 ++ {arch/x86/mm => mm}/numa_emulation.c | 0 mm/numa_memblks.c | 101 +++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 103 deletions(-) rename {arch/x86/mm => mm}/numa_emulation.c (100%)
Quoted 2 lines
The
numa_emulation.crename looks like it should be part of the next commit, not this one.
Right, thanks!
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 13/17] mm: move numa_distance and related code from x86 to numa_memblks
In reply to Mike RapoportQuoted 4 lines · On Tue, 16 Jul 2024 14:13:42 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Move code dealing with
numa_distancearray fromarch/x86tomm/numa_memblks.c
It's not really numa memblock related. Is this the best place to put it?
Quoted 6 lines
This code will be later reused by
arch_numa.No functional changes.
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Mike Rapoport
maintainerRe: [PATCH 13/17] mm: move numa_distance and related code from x86 to numa_memblks
Quoted 10 lines · Jonathan Cameron
Quoted 4 lines · On Tue, 16 Jul 2024 14:13:42 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Move code dealing with
numa_distancearray fromarch/x86tomm/numa_memblks.cIt's not really numa memblock related. Is this the best place to put it?
There is a dependency of numa_alloc_distance() on numa_nodemask_from_meminfo() that relies on numa_memblk but I agree that they are not really related.
However, I'd prefer to keep this code in mm/numa_memblks.c because node_distance() definitions and related code are different between architecures and having this code outside numa_memblks in e.g mm/numa.c would be way more involved.
Quoted 6 lines
Quoted 5 lines
This code will be later reused by
arch_numa.No functional changes.
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Signature · 2 lines
Sincerely yours, Mike.
Mike Rapoport
maintainerPATCH 14/17 mm: introduce numa_emulation
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Move numa_emulation codfrom arch/x86 to mm/numa_emulation.c
This code will be later reused by arch_numa.
No functional changes.
--- arch/x86/Kconfig | 8 -------- arch/x86/include/asm/numa.h | 12 ------------ arch/x86/mm/Makefile | 1 - arch/x86/mm/numa_internal.h | 11 ----------- include/linux/numa_memblks.h | 17 +++++++++++++++++ mm/Kconfig | 8 ++++++++ mm/Makefile | 1 + mm/numa_emulation.c | 4 +--- 8 files changed, 27 insertions(+), 35 deletions(-)
arch/x86/Kconfig +0 -8
@@ -1592,14 +1592,6 @@ config X86_64_ACPI_NUMA help Enable ACPI SRAT based node topology detection. -config NUMA_EMU - bool "NUMA emulation" - depends on NUMA - help - Enable NUMA emulation. A flat machine will be split - into virtual nodes when booted with "numa=fake=N", where N is the - number of nodes. This is only useful for debugging. - config NODES_SHIFT int "Maximum NUMA Nodes (as a power of 2)" if !MAXSMP range 1 10
arch/x86/include/asm/numa.h +0 -12
@@ -67,16 +67,4 @@ static inline void init_gi_nodes(void) { }void debug_cpumask_set_cpu (unsigned int cpu,int node,bool enable);#endif -#ifdef CONFIG_NUMA_EMU -int numa_emu_cmdline (char *str); -void __init numa_emu_update_cpu_to_node (int *emu_nid_to_phys, -unsigned int nr_emu_nids); -u64 __init numa_emu_dma_end (void ); -#else /* CONFIG_NUMA_EMU */ -static inline int numa_emu_cmdline (char *str) -{ -return -EINVAL ; -} -#endif /* CONFIG_NUMA_EMU */ -#endif /* _ASM_X86_NUMA_H */
arch/x86/mm/Makefile +0 -1
@@ -57,7 +57,6 @@ obj-$(CONFIG_MMIOTRACE_TEST) += testmmiotrace.o obj-$(CONFIG_NUMA) += numa.o numa_$(BITS).o obj-$(CONFIG_AMD_NUMA) += amdtopology.o obj-$(CONFIG_ACPI_NUMA) += srat.o -obj-$(CONFIG_NUMA_EMU) += numa_emulation.o obj-$(CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS) += pkeys.o obj-$(CONFIG_RANDOMIZE_MEMORY) += kaslr.o
arch/x86/mm/numa_internal.h +0 -11
@@ -7,15 +7,4 @@void __init x86_numa_init (void ); -struct numa_meminfo ; - -#ifdef CONFIG_NUMA_EMU -void __init numa_emulation (struct numa_meminfo *numa_meminfo, -int numa_dist_cnt); -#else -static inline void numa_emulation (struct numa_meminfo *numa_meminfo, -int numa_dist_cnt) -{ } -#endif -#endif /* __X86_MM_NUMA_INTERNAL_H */
include/linux/numa_memblks.h +17 -0
@@ -34,6 +34,23 @@ int __init numa_register_meminfo(struct numa_meminfo *mi);void __init numa_nodemask_from_meminfo (nodemask_t *nodemask,const struct numa_meminfo *mi); +#ifdef CONFIG_NUMA_EMU +int numa_emu_cmdline (char *str); +void __init numa_emu_update_cpu_to_node (int *emu_nid_to_phys, +unsigned int nr_emu_nids); +u64 __init numa_emu_dma_end (void ); +void __init numa_emulation (struct numa_meminfo *numa_meminfo, +int numa_dist_cnt); +#else +static inline void numa_emulation (struct numa_meminfo *numa_meminfo, +int numa_dist_cnt) +{ } +static inline int numa_emu_cmdline (char *str) +{ +return -EINVAL ; +} +#endif /* CONFIG_NUMA_EMU */ +#endif /* CONFIG_NUMA_MEMBLKS */ #endif /* __NUMA_MEMBLKS_H */
mm/Kconfig +8 -0
@@ -1252,6 +1252,14 @@ config EXECMEM config NUMA_MEMBLKS bool +config NUMA_EMU + bool "NUMA emulation" + depends on NUMA_MEMBLKS + help + Enable NUMA emulation. A flat machine will be split + into virtual nodes when booted with "numa=fake=N", where N is the + number of nodes. This is only useful for debugging. + source "mm/damon/Kconfig" endmenu
mm/Makefile +1 -0
@@ -141,3 +141,4 @@ obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o obj-$(CONFIG_EXECMEM) += execmem.o obj-$(CONFIG_NUMA) += numa.o obj-$(CONFIG_NUMA_MEMBLKS) += numa_memblks.o +obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
mm/numa_emulation.c +1 -3
@@ -7,9 +7,7 @@#include <linux/topology.h> #include <linux/memblock.h> #include <linux/numa_memblks.h> -#include <asm/dma.h> - -#include "numa_internal.h" +#include <asm/numa.h> #define FAKE_NODE_MIN_SIZE ((u64)32 << 20)#define FAKE_NODE_MIN_HASH_MASK (~(FAKE_NODE_MIN_SIZE - 1UL))
Signature · 1 line
2.43.0
Re: [PATCH 14/17] mm: introduce numa_emulation
Quoted 9 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Move
numa_emulationcodfromarch/x86tomm/numa_emulation.cThis code will be later reused by
arch_numa.No functional changes.
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Quoted 10 lines
--- arch/x86/Kconfig | 8 -------- arch/x86/include/asm/numa.h | 12 ------------ arch/x86/mm/Makefile | 1 - arch/x86/mm/numa_internal.h | 11 ----------- include/linux/numa_memblks.h | 17 +++++++++++++++++ mm/Kconfig | 8 ++++++++ mm/Makefile | 1 + mm/numa_emulation.c | 4 +--- 8 files changed, 27 insertions(+), 35 deletions(-)
After this code move, the document of numa=fake= should be moved from Documentation/arch/x86/x86_64/boot-options.rst to Documentation/admin-guide/kernel-parameters.txt
too.
Something like:
Documentation/admin-guide/kernel-parameters.txt +12 -0
@@ -4158,6 +4158,18 @@ Disable NUMA, Only set up a single NUMA node spanning all memory. + numa=fake=<size>[MG] + If given as a memory unit, fills all system RAM with nodes of + size interleaved over physical nodes. + + numa=fake=<N> + If given as an integer, fills all system RAM with N fake nodes + interleaved over physical nodes. + + numa=fake=<N>U + If given as an integer followed by 'U', it will divide each + physical node into N emulated nodes. + numa_balancing= [KNL,ARM64,PPC,RISCV,S390,X86] Enable or disable automatic NUMA balancing. Allowed values are enable and disable
Documentation/arch/x86/x86_64/boot-options.rst +0 -12
@@ -170,18 +170,6 @@ NUMA Don't parse the HMAT table for NUMA setup, or soft-reserved memory partitioning. - numa=fake=<size>[MG] - If given as a memory unit, fills all system RAM with nodes of - size interleaved over physical nodes. - - numa=fake=<N> - If given as an integer, fills all system RAM with N fake nodes - interleaved over physical nodes. - - numa=fake=<N>U - If given as an integer followed by 'U', it will divide each - physical node into N emulated nodes. - ACPI ====
Best Regards,
Yan, Zi
Mike Rapoport
maintainerRe: [PATCH 14/17] mm: introduce numa_emulation
Quoted 22 lines · Zi Yan
Quoted 9 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Move
numa_emulationcodfromarch/x86tomm/numa_emulation.cThis code will be later reused by
arch_numa.No functional changes.
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>Quoted 10 lines
--- arch/x86/Kconfig | 8 -------- arch/x86/include/asm/numa.h | 12 ------------ arch/x86/mm/Makefile | 1 - arch/x86/mm/numa_internal.h | 11 ----------- include/linux/numa_memblks.h | 17 +++++++++++++++++ mm/Kconfig | 8 ++++++++ mm/Makefile | 1 + mm/numa_emulation.c | 4 +--- 8 files changed, 27 insertions(+), 35 deletions(-)
Quoted 4 lines
After this code move, the document of numa=fake= should be moved from
Documentation/arch/x86/x86_64/boot-options.rsttoDocumentation/admin-guide/kernel-parameters.txt
too.
I'll add this as a separate commit.
Quoted 50 lines
Something like:
Documentation/admin-guide/kernel-parameters.txt +12
-0@@ -4158,6 +4158,18 @@ Disable NUMA, Only set up a single NUMA node spanning all memory. + numa=fake=<size>[MG] + If given as a memory unit, fills all system RAM with nodes of + size interleaved over physical nodes. + + numa=fake=<N> + If given as an integer, fills all system RAM with N fake nodes + interleaved over physical nodes. + + numa=fake=<N>U + If given as an integer followed by 'U', it will divide each + physical node into N emulated nodes. + numa_balancing= [KNL,ARM64,PPC,RISCV,S390,X86] Enable or disable automatic NUMA balancing. Allowed values are enable and disableDocumentation/arch/x86/x86_64/boot-options.rst +0
-12@@ -170,18 +170,6 @@ NUMA Don't parse the HMAT table for NUMA setup, or soft-reserved memory partitioning. - numa=fake=<size>[MG] - If given as a memory unit, fills all system RAM with nodes of - size interleaved over physical nodes. - - numa=fake=<N> - If given as an integer, fills all system RAM with N fake nodes - interleaved over physical nodes. - - numa=fake=<N>U - If given as an integer followed by 'U', it will divide each - physical node into N emulated nodes. - ACPI ====Best Regards,
Yan, Zi
Signature · 2 lines
Sincerely yours, Mike.
Mike Rapoport
maintainerPATCH 15/17 mm: make numa_memblks more self-contained
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Introduce numa_memblks_init() and move some code around to avoid several global variables in numa_memblks.
--- arch/x86/mm/numa.c | 53 ++++--------------------- include/linux/numa_memblks.h | 9 +---- mm/numa_memblks.c | 77 +++++++++++++++++++++++++++--------- 3 files changed, 68 insertions(+), 71 deletions(-)
arch/x86/mm/numa.c +7 -46
@@ -115,30 +115,19 @@ void __init setup_node_to_cpumask_map(void)pr_debug ("Node to cpumask map for %u nodes\n" , nr_node_ids); } -static int __init numa_register_memblks (struct numa_meminfo *mi) +static int __init numa_register_nodes (void ) { -int i, nid, err; - - err =numa_register_meminfo (mi); -if (err) -return err; +int nid;if (!memblock_validate_numa_coverage (SZ_1M ))return -EINVAL ;/* Finally register nodes. */ for_each_node_mask (nid, node_possible_map) { -u64 start =PFN_PHYS (max_pfn); -u64 end =0 ; - -for (i =0 ; i < mi->nr_blks; i++) { -if (nid != mi->blk[i].nid) -continue ; - start =min (mi->blk[i].start, start); - end =max (mi->blk[i].end, end); - } +unsigned long start_pfn, end_pfn; -if (start >= end) +get_pfn_range_for_nid (nid, &start_pfn, &end_pfn); +if (start_pfn >= end_pfn)continue ;alloc_node_data (nid);
@@ -178,39 +167,11 @@ static int __init numa_init(int (*init_func)(void))for (i =0 ; i <MAX_LOCAL_APIC ; i++)set_apicid_to_node (i,NUMA_NO_NODE ); -nodes_clear (numa_nodes_parsed); -nodes_clear (node_possible_map); -nodes_clear (node_online_map); -memset (&numa_meminfo,0 ,sizeof (numa_meminfo)); -WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.memory, -NUMA_NO_NODE )); -WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.reserved, -NUMA_NO_NODE )); -/* In case that parsing SRAT failed. */ -WARN_ON (memblock_clear_hotplug (0 ,ULLONG_MAX )); -numa_reset_distance (); - - ret =init_func (); -if (ret <0 ) -return ret; - -/* -* We reset memblock back to the top-down direction -* here because if we configured ACPI_NUMA, we have -* parsed SRAT in init_func(). It is ok to have the -* reset here even if we did't configure ACPI_NUMA -* or acpi numa init fails and fallbacks to dummy -* numa init. -*/ -memblock_set_bottom_up (false); - - ret =numa_cleanup_meminfo (&numa_meminfo); + ret =numa_memblks_init (init_func,/* memblock_force_top_down */ true);if (ret <0 )return ret; -numa_emulation (&numa_meminfo, numa_distance_cnt); - - ret =numa_register_memblks (&numa_meminfo); + ret =numa_register_nodes ();if (ret <0 )return ret;
include/linux/numa_memblks.h +2 -7
@@ -7,7 +7,6 @@#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2) -extern int numa_distance_cnt;void __init numa_set_distance (int from,int to,int distance);void __init numa_reset_distance (void );
@@ -22,17 +21,13 @@ struct numa_meminfo {struct numa_memblk blk[NR_NODE_MEMBLKS ]; }; -extern struct numa_meminfo numa_meminfo __initdata_or_meminfo; -extern struct numa_meminfo numa_reserved_meminfo __initdata_or_meminfo; -int __init numa_add_memblk (int nodeid,u64 start,u64 end);void __init numa_remove_memblk_from (int idx,struct numa_meminfo *mi);int __init numa_cleanup_meminfo (struct numa_meminfo *mi); -int __init numa_register_meminfo (struct numa_meminfo *mi); -void __init numa_nodemask_from_meminfo (nodemask_t *nodemask, -const struct numa_meminfo *mi); +int __init numa_memblks_init (int (*init_func)(void ), +bool memblock_force_top_down);#ifdef CONFIG_NUMA_EMU int numa_emu_cmdline (char *str);
mm/numa_memblks.c +59 -18
105 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 15/17] mm: make numa_memblks more self-contained
Quoted 4 lines · On Tue, 16 Jul 2024 14:13:44 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Introduce
numa_memblks_init()and move some code around to avoid several global variables innuma_memblks.
Hi Mike,
Adding the effectively always on memblock_force_top_down deserves a comment on why. I assume because you are going to do something with it later?
There also seems to be more going on in here such as the change to get_pfn_range_for_nid() Perhaps break this up so each change can have an explanation.
Quoted 34 lines
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>--- arch/x86/mm/numa.c | 53 ++++--------------------- include/linux/numa_memblks.h | 9 +---- mm/numa_memblks.c | 77 +++++++++++++++++++++++++++--------- 3 files changed, 68 insertions(+), 71 deletions(-)arch/x86/mm/numa.c +2
-9@@ -115,30 +115,19 @@ void __init setup_node_to_cpumask_map(void)pr_debug ("Node to cpumask map for %u nodes\n" , nr_node_ids); } -static int __init numa_register_memblks (struct numa_meminfo *mi) +static int __init numa_register_nodes (void ) { -int i, nid, err; - - err =numa_register_meminfo (mi); -if (err) -return err; +int nid;if (!memblock_validate_numa_coverage (SZ_1M ))return -EINVAL ;/* Finally register nodes. */ for_each_node_mask (nid, node_possible_map) { -u64 start =PFN_PHYS (max_pfn); -u64 end =0 ; -
arch/x86/mm/numa.c void __init setup_node_to_cpumask_map(void) · line 129
Quoted 10 lines
arch/x86/mm/numa.c +2
-7-for (i =0 ; i < mi->nr_blks; i++) { -if (nid != mi->blk[i].nid) -continue ; - start =min (mi->blk[i].start, start); - end =max (mi->blk[i].end, end); - } +unsigned long start_pfn, end_pfn; -if (start >= end) +get_pfn_range_for_nid (nid, &start_pfn, &end_pfn);
It's not immediately obvious to me that this code is equivalent so I'd prefer it in a separate patch with some description of why it is a valid change.
Quoted 26 lines
arch/x86/mm/numa.c +1
-18+if (start_pfn >= end_pfn)continue ;alloc_node_data (nid);@@ -178,39 +167,11 @@ static int __init numa_init(int (*init_func)(void))for (i =0 ; i <MAX_LOCAL_APIC ; i++)set_apicid_to_node (i,NUMA_NO_NODE ); -nodes_clear (numa_nodes_parsed); -nodes_clear (node_possible_map); -nodes_clear (node_online_map); -memset (&numa_meminfo,0 ,sizeof (numa_meminfo)); -WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.memory, -NUMA_NO_NODE )); -WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.reserved, -NUMA_NO_NODE )); -/* In case that parsing SRAT failed. */ -WARN_ON (memblock_clear_hotplug (0 ,ULLONG_MAX )); -numa_reset_distance (); - - ret =init_func (); -if (ret <0 ) -return ret; - -/* -* We reset memblock back to the top-down direction
arch/x86/mm/numa.c static int __init numa_init(int (*init_func)(void)) · line 170
Quoted 10 lines
arch/x86/mm/numa.c +1
-9-* here because if we configured ACPI_NUMA, we have -* parsed SRAT in init_func(). It is ok to have the -* reset here even if we did't configure ACPI_NUMA -* or acpi numa init fails and fallbacks to dummy -* numa init. -*/ -memblock_set_bottom_up (false); - - ret =numa_cleanup_meminfo (&numa_meminfo); + ret =numa_memblks_init (init_func,/* memblock_force_top_down */ true);
The comment in parameter list seems unnecessary.
Maybe add a comment above the call instead if need to call that out?
Quoted 23 lines
arch/x86/mm/numa.c +1
-3if (ret <0 )return ret; -numa_emulation (&numa_meminfo, numa_distance_cnt); - - ret =numa_register_memblks (&numa_meminfo); + ret =numa_register_nodes ();if (ret <0 )return ret;mm/numa_memblks.c +3
-0@@ -7,13 +7,27 @@#include <linux/numa.h> #include <linux/numa_memblks.h> +/* +* Set nodes, which have memory in @mi, in *@nodemask. +*/
mm/numa_memblks.c line 23
Quoted 10 lines
mm/numa_memblks.c +10
-0+static void __init numa_nodemask_from_meminfo (nodemask_t *nodemask, +const struct numa_meminfo *mi) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (mi->blk); i++) +if (mi->blk[i].start != mi->blk[i].end && + mi->blk[i].nid !=NUMA_NO_NODE ) +node_set (mi->blk[i].nid, *nodemask); +}
The code move doesn't have an obvious purpose. Maybe call that out in the patch description if it is needed for a future patch. Or do it in two goes so first just adds the static, 2nd shuffles the code.
Quoted 81 lines
mm/numa_memblks.c +42
-15/** * numa_reset_distance - Reset NUMA distance table @@ -287,20 +301,6 @@ int __init numa_cleanup_meminfo(struct numa_meminfo *mi)return 0 ; } -/* -* Set nodes, which have memory in @mi, in *@nodemask. -*/ -void __init numa_nodemask_from_meminfo (nodemask_t *nodemask, -const struct numa_meminfo *mi) -{ -int i; - -for (i =0 ; i <ARRAY_SIZE (mi->blk); i++) -if (mi->blk[i].start != mi->blk[i].end && - mi->blk[i].nid !=NUMA_NO_NODE ) -node_set (mi->blk[i].nid, *nodemask); -} -/* * Mark all currently memblock-reserved physical memory (which covers the * kernel's own memory ranges) as hot-unswappable. @@ -368,7 +368,7 @@ static void __init numa_clear_kernel_node_hotplug(void) } } -int __init numa_register_meminfo (struct numa_meminfo *mi) +static int __init numa_register_meminfo (struct numa_meminfo *mi) {int i;@@ -412,6 +412,47 @@ int __init numa_register_meminfo(struct numa_meminfo *mi)return 0 ; } +int __init numa_memblks_init (int (*init_func)(void ), +bool memblock_force_top_down) +{ +int ret; + +nodes_clear (numa_nodes_parsed); +nodes_clear (node_possible_map); +nodes_clear (node_online_map); +memset (&numa_meminfo,0 ,sizeof (numa_meminfo)); +WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.memory, +NUMA_NO_NODE )); +WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.reserved, +NUMA_NO_NODE )); +/* In case that parsing SRAT failed. */ +WARN_ON (memblock_clear_hotplug (0 ,ULLONG_MAX )); +numa_reset_distance (); + + ret =init_func (); +if (ret <0 ) +return ret; + +/* +* We reset memblock back to the top-down direction +* here because if we configured ACPI_NUMA, we have +* parsed SRAT in init_func(). It is ok to have the +* reset here even if we did't configure ACPI_NUMA +* or acpi numa init fails and fallbacks to dummy +* numa init. +*/ +if (memblock_force_top_down) +memblock_set_bottom_up (false); + + ret =numa_cleanup_meminfo (&numa_meminfo); +if (ret <0 ) +return ret; + +numa_emulation (&numa_meminfo, numa_distance_cnt); + +return numa_register_meminfo (&numa_meminfo); +} +static int __init cmp_memblk (const void *a,const void *b) {const struct numa_memblk *ma = *(const struct numa_memblk **)a;
Mike Rapoport
maintainerRe: [PATCH 15/17] mm: make numa_memblks more self-contained
Quoted 5 lines · Jonathan Cameron
Quoted 2 lines · On Tue, 16 Jul 2024 14:13:44 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Quoted 8 lines
Quoted 2 lines
Introduce
numa_memblks_init()and move some code around to avoid several global variables innuma_memblks.Hi Mike,
Adding the effectively always on
memblock_force_top_downdeserves a comment on why. I assume because you are going to do something with it later?
Yes, arch_numa sets it to false. I'll add a note in the changelog.
Quoted 3 lines
There also seems to be more going on in here such as the change to
get_pfn_range_for_nid()Perhaps break this up so each change can have an explanation.
Ok.
Quoted 42 lines
Quoted 42 lines
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>--- arch/x86/mm/numa.c | 53 ++++--------------------- include/linux/numa_memblks.h | 9 +---- mm/numa_memblks.c | 77 +++++++++++++++++++++++++++--------- 3 files changed, 68 insertions(+), 71 deletions(-)arch/x86/mm/numa.c +3
-15@@ -115,30 +115,19 @@ void __init setup_node_to_cpumask_map(void)pr_debug ("Node to cpumask map for %u nodes\n" , nr_node_ids); } -static int __init numa_register_memblks (struct numa_meminfo *mi) +static int __init numa_register_nodes (void ) { -int i, nid, err; - - err =numa_register_meminfo (mi); -if (err) -return err; +int nid;if (!memblock_validate_numa_coverage (SZ_1M ))return -EINVAL ;/* Finally register nodes. */ for_each_node_mask (nid, node_possible_map) { -u64 start =PFN_PHYS (max_pfn); -u64 end =0 ; - -for (i =0 ; i < mi->nr_blks; i++) { -if (nid != mi->blk[i].nid) -continue ; - start =min (mi->blk[i].start, start); - end =max (mi->blk[i].end, end); - } +unsigned long start_pfn, end_pfn;
Quoted 6 lines
arch/x86/mm/numa.c void __init setup_node_to_cpumask_map(void) · line 129
Quoted 2 lines
arch/x86/mm/numa.c +1
-1-if (start >= end) +get_pfn_range_for_nid (nid, &start_pfn, &end_pfn);It's not immediately obvious to me that this code is equivalent so I'd prefer it in a separate patch with some description of why it is a valid change.
Will do.
Quoted 30 lines
Quoted 30 lines
arch/x86/mm/numa.c +1
-22+if (start_pfn >= end_pfn)continue ;alloc_node_data (nid);@@ -178,39 +167,11 @@ static int __init numa_init(int (*init_func)(void))for (i =0 ; i <MAX_LOCAL_APIC ; i++)set_apicid_to_node (i,NUMA_NO_NODE ); -nodes_clear (numa_nodes_parsed); -nodes_clear (node_possible_map); -nodes_clear (node_online_map); -memset (&numa_meminfo,0 ,sizeof (numa_meminfo)); -WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.memory, -NUMA_NO_NODE )); -WARN_ON (memblock_set_node (0 ,ULLONG_MAX , &memblock.reserved, -NUMA_NO_NODE )); -/* In case that parsing SRAT failed. */ -WARN_ON (memblock_clear_hotplug (0 ,ULLONG_MAX )); -numa_reset_distance (); - - ret =init_func (); -if (ret <0 ) -return ret; - -/* -* We reset memblock back to the top-down direction -* here because if we configured ACPI_NUMA, we have -* parsed SRAT in init_func(). It is ok to have the -* reset here even if we did't configure ACPI_NUMA -* or acpi numa init fails and fallbacks to dummy
Quoted 8 lines
arch/x86/mm/numa.c static int __init numa_init(int (*init_func)(void)) · line 170
Quoted 6 lines
arch/x86/mm/numa.c +1
-5-* numa init. -*/ -memblock_set_bottom_up (false); - - ret =numa_cleanup_meminfo (&numa_meminfo); + ret =numa_memblks_init (init_func,/* memblock_force_top_down */ true);The comment in parameter list seems unnecessary.
Maybe add a comment above the call instead if need to call that out?
I'll drop it for now.
Quoted 30 lines
Quoted 30 lines
arch/x86/mm/numa.c +1
-3if (ret <0 )return ret; -numa_emulation (&numa_meminfo, numa_distance_cnt); - - ret =numa_register_memblks (&numa_meminfo); + ret =numa_register_nodes ();if (ret <0 )return ret;mm/numa_memblks.c +10
-0@@ -7,13 +7,27 @@#include <linux/numa.h> #include <linux/numa_memblks.h> +/* +* Set nodes, which have memory in @mi, in *@nodemask. +*/ +static void __init numa_nodemask_from_meminfo (nodemask_t *nodemask, +const struct numa_meminfo *mi) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (mi->blk); i++) + if (mi->blk[i].start != mi->blk[i].end &&
Quoted 8 lines
mm/numa_memblks.c line 30
Quoted 3 lines
mm/numa_memblks.c +3
-0+ mi->blk[i].nid != NUMA_NO_NODE) +node_set (mi->blk[i].nid, *nodemask); +}The code move doesn't have an obvious purpose. Maybe call that out in the patch description if it is needed for a future patch. Or do it in two goes so first just adds the static, 2nd shuffles the code.
Before the move numa_nodemask_from_meminfo() was global so it was ok to define it after its callers.
I'll split this into a separate commit.
Signature · 2 lines
Sincerely yours, Mike.
Mike Rapoport
maintainerRe: [PATCH 15/17] mm: make numa_memblks more self-contained
In reply to Jonathan CameronQuoted 10 lines · Jonathan Cameron
Quoted 4 lines · On Tue, 16 Jul 2024 14:13:44 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Introduce
numa_memblks_init()and move some code around to avoid several global variables innuma_memblks.Hi Mike,
Quoted 7 lines
Adding the effectively always on
memblock_force_top_downdeserves a comment on why. I assume because you are going to do something with it later?There also seems to be more going on in here such as the change to
get_pfn_range_for_nid()Perhaps break this up so each change can have an explanation.
I'll split this into several commits.
Signature · 2 lines
Sincerely yours, Mike.
Mike Rapoport
maintainerPATCH 16/17 arch_numa: switch over to numa_memblks
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Until now arch_numa was directly translating firmware NUMA information to memblock.
Using numa_memblks as an intermediate step has a few advantages:
* alignment with more battle tested x86 implementation
* availability of NUMA emulation
* maintaining node information for not yet populated memory
Replace current functionality related to numa_add_memblk() and __node_distance() with the implementation based on numa_memblks and add functions required by numa_emulation.
--- drivers/base/Kconfig | 1 + drivers/base/arch_numa.c | 200 +++++++++++-------------------------- include/asm-generic/numa.h | 6 +- 3 files changed, 64 insertions(+), 143 deletions(-)
drivers/base/Kconfig +1 -0
@@ -226,6 +226,7 @@ config GENERIC_ARCH_TOPOLOGY config GENERIC_ARCH_NUMA bool + select NUMA_MEMBLKS help Enable support for generic NUMA implementation. Currently, RISC-V and ARM64 use it.
drivers/base/arch_numa.c +59 -141
265 lines not on this page · raw message
include/asm-generic/numa.h +4 -2
@@ -32,8 +32,6 @@ static inline const struct cpumask *cpumask_of_node(int node)void __init arch_numa_init (void );int __init numa_add_memblk (int nodeid,u64 start,u64 end); -void __init numa_set_distance (int from,int to,int distance); -void __init numa_free_distance (void );void __init early_map_cpu_to_node (unsigned int cpu,int nid);int __init early_cpu_to_node (int cpu);void numa_store_cpu_info (unsigned int cpu);
@@ -51,4 +49,8 @@ static inline int early_cpu_to_node(int cpu) { return 0; }#endif /* CONFIG_NUMA */ +#ifdef CONFIG_NUMA_EMU +void debug_cpumask_set_cpu (unsigned int cpu,int node,bool enable); +#endif +#endif /* __ASM_GENERIC_NUMA_H */
Signature · 1 line
2.43.0
Re: [PATCH 16/17] arch_numa: switch over to numa_memblks
Quoted 10 lines · On Tue, 16 Jul 2024 14:13:45 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Until now
arch_numawas directly translating firmware NUMA information to memblock.Using
numa_memblksas an intermediate step has a few advantages:
* alignment with more battle tested x86 implementation
* availability of NUMA emulation
* maintaining node information for not yet populated memory
Quoted 5 lines
Replace current functionality related to
numa_add_memblk()and__node_distance()with the implementation based onnuma_memblksand add functions required bynuma_emulation.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
One trivial comment inline,
Jonathan
Quoted 11 lines
/*
* InitializeNODE_DATAfor a node on the local memory */drivers/base/arch_numa.c +0
-0@@ -226,116 +204,9 @@ static void __init setup_node_data(int nid, u64 start_pfn, u64 end_pfn)NODE_DATA (nid)->node_spanned_pages = end_pfn - start_pfn; }@@ -454,3 +321,54 @@ void __init arch_numa_init(void)numa_init (dummy_numa_init);
drivers/base/arch_numa.c void __init arch_numa_init(void) · line 332
Quoted 10 lines
drivers/base/arch_numa.c +9
-0} + +#ifdef CONFIG_NUMA_EMU +void __init numa_emu_update_cpu_to_node (int *emu_nid_to_phys, +unsigned int nr_emu_nids) +{ +int i, j; + +/* +* Transform __apicid_to_node table to use emulated nids by
Comment needs an update seeing as there is no __apicid_to_node table here.
Quoted 17 lines
drivers/base/arch_numa.c +17
-0+* reverse-mapping phys_nid. The maps should always exist but fall +* back to zero just in case. +*/ +for (i =0 ; i <ARRAY_SIZE (cpu_to_node_map); i++) { +if (cpu_to_node_map[i] ==NUMA_NO_NODE ) +continue ; +for (j =0 ; j < nr_emu_nids; j++) +if (cpu_to_node_map[i] == emu_nid_to_phys[j]) +break ; + cpu_to_node_map[i] = j < nr_emu_nids ? j :0 ; + } +} + +u64 __init numa_emu_dma_end (void ) +{ +return PFN_PHYS (memblock_start_of_DRAM () +SZ_4G ); +}
Mike Rapoport
maintainerPATCH 17/17 mm: make range-to-target_node lookup facility a part of numa_memblks
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
The x86 implementation of range-to-target_node lookup (i.e. phys_to_target_node() and memory_add_physaddr_to_nid()) relies on numa_memblks.
Since numa_memblks are now part of the generic code, move these functions from x86 to mm/numa_memblks.c and select CONFIG_NUMA_KEEP_MEMINFO when CONFIG_NUMA_MEMBLKS=y for dax and cxl.
--- arch/x86/include/asm/sparsemem.h | 9 -------- arch/x86/mm/numa.c | 38 -------------------------------- drivers/cxl/Kconfig | 2 +- drivers/dax/Kconfig | 2 +- include/linux/numa_memblks.h | 7 ++++++ mm/numa.c | 1 + mm/numa_memblks.c | 38 ++++++++++++++++++++++++++++++++ 7 files changed, 48 insertions(+), 49 deletions(-)
arch/x86/include/asm/sparsemem.h +0 -9
@@ -31,13 +31,4 @@#endif /* CONFIG_SPARSEMEM */ -#ifndef __ASSEMBLY__ -#ifdef CONFIG_NUMA_KEEP_MEMINFO -extern int phys_to_target_node (phys_addr_t start); -#define phys_to_target_node phys_to_target_node -extern int memory_add_physaddr_to_nid (u64 start); -#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid -#endif -#endif /* __ASSEMBLY__ */ -#endif /* _ASM_X86_SPARSEMEM_H */
arch/x86/mm/numa.c +0 -38
@@ -449,41 +449,3 @@ u64 __init numa_emu_dma_end(void) return PFN_PHYS(MAX_DMA32_PFN); }#endif /* CONFIG_NUMA_EMU */ - -#ifdef CONFIG_NUMA_KEEP_MEMINFO -static int meminfo_to_nid (struct numa_meminfo *mi,u64 start) -{ -int i; - -for (i =0 ; i < mi->nr_blks; i++) -if (mi->blk[i].start <= start && mi->blk[i].end > start) -return mi->blk[i].nid; -return NUMA_NO_NODE ; -} - -int phys_to_target_node (phys_addr_t start) -{ -int nid =meminfo_to_nid (&numa_meminfo, start); - -/* -* Prefer online nodes, but if reserved memory might be -* hot-added continue the search with reserved ranges. -*/ -if (nid !=NUMA_NO_NODE ) -return nid; - -return meminfo_to_nid (&numa_reserved_meminfo, start); -} -EXPORT_SYMBOL_GPL (phys_to_target_node); - -int memory_add_physaddr_to_nid (u64 start) -{ -int nid =meminfo_to_nid (&numa_meminfo, start); - -if (nid ==NUMA_NO_NODE ) - nid = numa_meminfo.blk[0 ].nid; -return nid; -} -EXPORT_SYMBOL_GPL (memory_add_physaddr_to_nid); - -#endif
drivers/cxl/Kconfig +1 -1
@@ -6,7 +6,7 @@ menuconfig CXL_BUS select FW_UPLOAD select PCI_DOE select FIRMWARE_TABLE - select NUMA_KEEP_MEMINFO if (NUMA && X86) + select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS help CXL is a bus that is electrically compatible with PCI Express, but layers three protocols on that signalling (CXL.io, CXL.cache, and
drivers/dax/Kconfig +1 -1
@@ -30,7 +30,7 @@ config DEV_DAX_PMEM config DEV_DAX_HMEM tristate "HMEM DAX: direct access to 'specific purpose' memory" depends on EFI_SOFT_RESERVE - select NUMA_KEEP_MEMINFO if (NUMA && X86) + select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS default DEV_DAX help EFI 2.8 platforms, and others, may advertise 'specific purpose'
include/linux/numa_memblks.h +7 -0
@@ -46,6 +46,13 @@ static inline int numa_emu_cmdline(char *str) }#endif /* CONFIG_NUMA_EMU */ +#ifdef CONFIG_NUMA_KEEP_MEMINFO +extern int phys_to_target_node (phys_addr_t start); +#define phys_to_target_node phys_to_target_node +extern int memory_add_physaddr_to_nid (u64 start); +#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid +#endif /* CONFIG_NUMA_KEEP_MEMINFO */ +#endif /* CONFIG_NUMA_MEMBLKS */ #endif /* __NUMA_MEMBLKS_H */
mm/numa.c +1 -0
@@ -3,6 +3,7 @@#include <linux/memblock.h> #include <linux/printk.h> #include <linux/numa.h> +#include <linux/numa_memblks.h> struct pglist_data *node_data[MAX_NUMNODES ];EXPORT_SYMBOL (node_data);
mm/numa_memblks.c +38 -0
@@ -525,3 +525,41 @@ int __init numa_fill_memblks(u64 start, u64 end) }return 0 ; } + +#ifdef CONFIG_NUMA_KEEP_MEMINFO +static int meminfo_to_nid (struct numa_meminfo *mi,u64 start) +{ +int i; + +for (i =0 ; i < mi->nr_blks; i++) +if (mi->blk[i].start <= start && mi->blk[i].end > start) +return mi->blk[i].nid; +return NUMA_NO_NODE ; +} + +int phys_to_target_node (phys_addr_t start) +{ +int nid =meminfo_to_nid (&numa_meminfo, start); + +/* +* Prefer online nodes, but if reserved memory might be +* hot-added continue the search with reserved ranges. +*/ +if (nid !=NUMA_NO_NODE ) +return nid; + +return meminfo_to_nid (&numa_reserved_meminfo, start); +} +EXPORT_SYMBOL_GPL (phys_to_target_node); + +int memory_add_physaddr_to_nid (u64 start) +{ +int nid =meminfo_to_nid (&numa_meminfo, start); + +if (nid ==NUMA_NO_NODE ) + nid = numa_meminfo.blk[0 ].nid; +return nid; +} +EXPORT_SYMBOL_GPL (memory_add_physaddr_to_nid); + +#endif /* CONFIG_NUMA_KEEP_MEMINFO */
Signature · 1 line
2.43.0
Re: [PATCH 17/17] mm: make range-to-target_node lookup facility a part of numa_memblks
Quoted 11 lines · On Tue, 16 Jul 2024 14:13:46 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
The x86 implementation of range-to-target_node lookup (i.e.
phys_to_target_node()andmemory_add_physaddr_to_nid()) relies onnuma_memblks.Since
numa_memblksare now part of the generic code, move these functions from x86 tomm/numa_memblks.cand selectCONFIG_NUMA_KEEP_MEMINFOwhenCONFIG_NUMA_MEMBLKS=yfor dax and cxl.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
Thanks. I'll poke around more next week. Have a good weekend.
Jonathan
Quoted 28 lines · On Tue, 16 Jul 2024 14:13:29 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Hi,
Following the discussion about handling of CXL fixed memory windows on arm64 [1] I decided to bite the bullet and move
numa_memblksfrom x86 to the generic code so they will be available on arm64/riscv and maybe on loongarch sometime later.While it could be possible to use memblock to describe CXL memory windows, it currently lacks notion of unpopulated memory ranges and
numa_memblksdoes implement this.Another reason to make
numa_memblksgeneric is that botharch_numa(arm64 and riscv) and loongarch use trimmed copy of x86 code although there is no fundamental reason why the same code cannot be used on all these platforms. Havingnuma_memblksinmm/will make it's interaction with ACPI and FDT more consistent and I believe will reduce maintenance burden.And with generic
numa_memblksit is (almost) straightforward to enable NUMA emulation on arm64 and riscv.The first 5 commits in this series are cleanups that are not strictly related to
numa_memblks.Commits 6-11 slightly reorder code in x86 to allow extracting
numa_memblksand NUMA emulation to the generic code.
Quoted 7 lines
Commits 12-14 actually move the code from
arch/x86/tomm/and commit 15 does some aftermath cleanups.Commit 16 switches
arch_numatonuma_memblks.Commit 17 enables usage of
phys_to_target_node()andmemory_add_physaddr_to_nid()withnuma_memblks.
Hi Mike,
I've lightly tested with emulated CXL + Generic Ports and Generic Initiators as well as more normal cpus and memory via qemu on arm64 and it's looking good.
From my earlier series, patch 4 is probably still needed to avoid presenting nodes with nothing in them at boot (but not if we hotplug memory then remove it again in which case they disappear)
https://lore.kernel.org/all/[email protected]/
However that was broken/inconsistent before your rework so I can send that patch separately.
Thanks for getting this sorted! I should get time to do more extensive testing and review in next week or so.
Jonathan
Quoted 92 lines
[1] https://lore.kernel.org/all/[email protected]/
Mike Rapoport (Microsoft) (17):
mm: movekernel/numa.ctomm/
MIPS: sgi-ip27: makeNODE_DATA()the same as on all other
architectures
MIPS: loongson64: rename__node_datatonode_data
arch, mm: move definition ofnode_datato generic code arch, mm: pull out allocation ofNODE_DATAto generic code x86/numa: simplifynuma_distanceallocation
x86/numa: move FAKE_NODE_* defines tonuma_emux86/numa_emu: simplify allocation ofphys_distx86/numa_emu: split__apicid_to_nodeupdate to a helper function x86/numa_emu: use a helper function to getMAX_DMA32_PFNx86/numa: numa_{add,remove}_cpu: make cpu parameter unsigned
mm: introducenuma_memblks
mm: movenuma_distanceand related code from x86 tonuma_memblks
mm: introducenuma_emulation
mm: makenuma_memblksmore self-contained
arch_numa: switch over tonuma_memblks
mm: make range-to-target_node lookup facility a part ofnuma_memblksarch/arm64/include/asm/Kbuild | 1 + arch/arm64/include/asm/mmzone.h | 13 - arch/arm64/include/asm/topology.h | 1 + arch/loongarch/include/asm/Kbuild | 1 + arch/loongarch/include/asm/mmzone.h | 16 - arch/loongarch/include/asm/topology.h | 1 + arch/loongarch/kernel/numa.c | 21 - arch/mips/include/asm/mach-ip27/mmzone.h | 1 - .../mips/include/asm/mach-loongson64/mmzone.h | 4 - arch/mips/loongson64/numa.c | 20 +- arch/mips/sgi-ip27/ip27-memory.c | 2 +- arch/powerpc/include/asm/mmzone.h | 6 - arch/powerpc/mm/numa.c | 26 +- arch/riscv/include/asm/Kbuild | 1 + arch/riscv/include/asm/mmzone.h | 13 - arch/riscv/include/asm/topology.h | 4 + arch/s390/include/asm/Kbuild | 1 + arch/s390/include/asm/mmzone.h | 17 - arch/s390/kernel/numa.c | 3 - arch/sh/include/asm/mmzone.h | 3 - arch/sh/mm/init.c | 7 +- arch/sh/mm/numa.c | 3 - arch/sparc/include/asm/mmzone.h | 4 - arch/sparc/mm/init_64.c | 11 +- arch/x86/Kconfig | 9 +- arch/x86/include/asm/Kbuild | 1 + arch/x86/include/asm/mmzone.h | 6 - arch/x86/include/asm/mmzone_32.h | 17 - arch/x86/include/asm/mmzone_64.h | 18 - arch/x86/include/asm/numa.h | 24 +- arch/x86/include/asm/sparsemem.h | 9 - arch/x86/mm/Makefile | 1 - arch/x86/mm/amdtopology.c | 1 + arch/x86/mm/numa.c | 618 +----------------- arch/x86/mm/numa_internal.h | 24 - drivers/acpi/numa/srat.c | 1 + drivers/base/Kconfig | 1 + drivers/base/arch_numa.c | 223 ++----- drivers/cxl/Kconfig | 2 +- drivers/dax/Kconfig | 2 +- drivers/of/of_numa.c | 1 + include/asm-generic/mmzone.h | 5 + include/asm-generic/numa.h | 6 +- include/linux/numa.h | 5 + include/linux/numa_memblks.h | 58 ++ kernel/Makefile | 1 - kernel/numa.c | 26 - mm/Kconfig | 11 + mm/Makefile | 3 + mm/numa.c | 57 ++ {arch/x86/mm => mm}/numa_emulation.c | 42 +- mm/numa_memblks.c | 565 ++++++++++++++++ 52 files changed, 847 insertions(+), 1070 deletions(-) delete mode 100644 arch/arm64/include/asm/mmzone.h delete mode 100644 arch/loongarch/include/asm/mmzone.h delete mode 100644 arch/riscv/include/asm/mmzone.h delete mode 100644 arch/s390/include/asm/mmzone.h delete mode 100644 arch/x86/include/asm/mmzone.h delete mode 100644 arch/x86/include/asm/mmzone_32.h delete mode 100644 arch/x86/include/asm/mmzone_64.h create mode 100644 include/asm-generic/mmzone.h create mode 100644 include/linux/numa_memblks.h delete mode 100644 kernel/numa.c create mode 100644 mm/numa.c rename {arch/x86/mm => mm}/numa_emulation.c (94%) create mode 100644 mm/numa_memblks.cbase-commit:
22a40d14b572deb80c0648557f4bd502d7e83826
Mike Rapoport
maintainerQuoted 45 lines · Jonathan Cameron
Quoted 28 lines · On Tue, 16 Jul 2024 14:13:29 +0300 Mike Rapoport <[email protected]> wrote:
From: "Mike Rapoport (Microsoft)" <[email protected]>
Hi,
Following the discussion about handling of CXL fixed memory windows on arm64 [1] I decided to bite the bullet and move
numa_memblksfrom x86 to the generic code so they will be available on arm64/riscv and maybe on loongarch sometime later.While it could be possible to use memblock to describe CXL memory windows, it currently lacks notion of unpopulated memory ranges and
numa_memblksdoes implement this.Another reason to make
numa_memblksgeneric is that botharch_numa(arm64 and riscv) and loongarch use trimmed copy of x86 code although there is no fundamental reason why the same code cannot be used on all these platforms. Havingnuma_memblksinmm/will make it's interaction with ACPI and FDT more consistent and I believe will reduce maintenance burden.And with generic
numa_memblksit is (almost) straightforward to enable NUMA emulation on arm64 and riscv.The first 5 commits in this series are cleanups that are not strictly related to
numa_memblks.Commits 6-11 slightly reorder code in x86 to allow extracting
numa_memblksand NUMA emulation to the generic code.Quoted 7 lines
Commits 12-14 actually move the code from
arch/x86/tomm/and commit 15 does some aftermath cleanups.Commit 16 switches
arch_numatonuma_memblks.Commit 17 enables usage of
phys_to_target_node()andmemory_add_physaddr_to_nid()withnuma_memblks.Hi Mike,
I've lightly tested with emulated CXL + Generic Ports and Generic Initiators as well as more normal cpus and memory via qemu on arm64 and it's looking good.
Quoted 6 lines
From my earlier series, patch 4 is probably still needed to avoid presenting nodes with nothing in them at boot (but not if we hotplug memory then remove it again in which case they disappear)
https://lore.kernel.org/all/[email protected]/
However that was broken/inconsistent before your rework so I can send that patch separately.
I'd appreciate it :)
Quoted 2 lines
Thanks for getting this sorted! I should get time to do more extensive testing and review in next week or so.
Thanks, you may want to wait for v2, I'm planning to send it this week.
Quoted 95 lines
Jonathan
Quoted 92 lines
[1] https://lore.kernel.org/all/[email protected]/
Mike Rapoport (Microsoft) (17):
mm: movekernel/numa.ctomm/
MIPS: sgi-ip27: makeNODE_DATA()the same as on all other
architectures
MIPS: loongson64: rename__node_datatonode_data
arch, mm: move definition ofnode_datato generic code arch, mm: pull out allocation ofNODE_DATAto generic code x86/numa: simplifynuma_distanceallocation
x86/numa: move FAKE_NODE_* defines tonuma_emux86/numa_emu: simplify allocation ofphys_distx86/numa_emu: split__apicid_to_nodeupdate to a helper function x86/numa_emu: use a helper function to getMAX_DMA32_PFNx86/numa: numa_{add,remove}_cpu: make cpu parameter unsigned
mm: introducenuma_memblks
mm: movenuma_distanceand related code from x86 tonuma_memblks
mm: introducenuma_emulation
mm: makenuma_memblksmore self-contained
arch_numa: switch over tonuma_memblks
mm: make range-to-target_node lookup facility a part ofnuma_memblksarch/arm64/include/asm/Kbuild | 1 + arch/arm64/include/asm/mmzone.h | 13 - arch/arm64/include/asm/topology.h | 1 + arch/loongarch/include/asm/Kbuild | 1 + arch/loongarch/include/asm/mmzone.h | 16 - arch/loongarch/include/asm/topology.h | 1 + arch/loongarch/kernel/numa.c | 21 - arch/mips/include/asm/mach-ip27/mmzone.h | 1 - .../mips/include/asm/mach-loongson64/mmzone.h | 4 - arch/mips/loongson64/numa.c | 20 +- arch/mips/sgi-ip27/ip27-memory.c | 2 +- arch/powerpc/include/asm/mmzone.h | 6 - arch/powerpc/mm/numa.c | 26 +- arch/riscv/include/asm/Kbuild | 1 + arch/riscv/include/asm/mmzone.h | 13 - arch/riscv/include/asm/topology.h | 4 + arch/s390/include/asm/Kbuild | 1 + arch/s390/include/asm/mmzone.h | 17 - arch/s390/kernel/numa.c | 3 - arch/sh/include/asm/mmzone.h | 3 - arch/sh/mm/init.c | 7 +- arch/sh/mm/numa.c | 3 - arch/sparc/include/asm/mmzone.h | 4 - arch/sparc/mm/init_64.c | 11 +- arch/x86/Kconfig | 9 +- arch/x86/include/asm/Kbuild | 1 + arch/x86/include/asm/mmzone.h | 6 - arch/x86/include/asm/mmzone_32.h | 17 - arch/x86/include/asm/mmzone_64.h | 18 - arch/x86/include/asm/numa.h | 24 +- arch/x86/include/asm/sparsemem.h | 9 - arch/x86/mm/Makefile | 1 - arch/x86/mm/amdtopology.c | 1 + arch/x86/mm/numa.c | 618 +----------------- arch/x86/mm/numa_internal.h | 24 - drivers/acpi/numa/srat.c | 1 + drivers/base/Kconfig | 1 + drivers/base/arch_numa.c | 223 ++----- drivers/cxl/Kconfig | 2 +- drivers/dax/Kconfig | 2 +- drivers/of/of_numa.c | 1 + include/asm-generic/mmzone.h | 5 + include/asm-generic/numa.h | 6 +- include/linux/numa.h | 5 + include/linux/numa_memblks.h | 58 ++ kernel/Makefile | 1 - kernel/numa.c | 26 - mm/Kconfig | 11 + mm/Makefile | 3 + mm/numa.c | 57 ++ {arch/x86/mm => mm}/numa_emulation.c | 42 +- mm/numa_memblks.c | 565 ++++++++++++++++ 52 files changed, 847 insertions(+), 1070 deletions(-) delete mode 100644 arch/arm64/include/asm/mmzone.h delete mode 100644 arch/loongarch/include/asm/mmzone.h delete mode 100644 arch/riscv/include/asm/mmzone.h delete mode 100644 arch/s390/include/asm/mmzone.h delete mode 100644 arch/x86/include/asm/mmzone.h delete mode 100644 arch/x86/include/asm/mmzone_32.h delete mode 100644 arch/x86/include/asm/mmzone_64.h create mode 100644 include/asm-generic/mmzone.h create mode 100644 include/linux/numa_memblks.h delete mode 100644 kernel/numa.c create mode 100644 mm/numa.c rename {arch/x86/mm => mm}/numa_emulation.c (94%) create mode 100644 mm/numa_memblks.cbase-commit:
22a40d14b572deb80c0648557f4bd502d7e83826
Signature · 2 lines
Sincerely yours, Mike.