Skip to contentSkip to conversation

support NUMA emulation for arm64

RFC PATCH In review Rongwei Wang 5 participants 22 messages Oct 12, 2023 – Feb 29, 2024

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

cover support NUMA emulation for arm64

A brief introduction
====================

The NUMA emulation can fake more node base on a single node system, e.g.

one node system:

[root@localhost ~]# numactl -H
available: 1 nodes (0)
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 31788 MB
node 0 free: 31446 MB
node distances:
node 0
0: 10

add numa=fake=2 (fake 2 node on each origin node):

[root@localhost ~]# numactl -H
available: 2 nodes (0-1)
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 15806 MB
node 0 free: 15451 MB
node 1 cpus: 0 1 2 3 4 5 6 7
node 1 size: 16029 MB
node 1 free: 15989 MB
node distances:
node 0 1

  0:  10  10
  1:  10  10

As above shown, a new node has been faked. As cpus, the realization of x86 NUMA emulation is kept. Maybe each node should has 4 cores is better (not sure, next to do if so).

Why do this
===========

It seems has following reasons:
(1) In x86 host, apply NUMA emulation can fake more nodes environment to test or verify some performance stuff, but arm64 only has one method that modify ACPI table to do this. It's troublesome more or less.
(2) Reduce competition for some locks. Here an example we found:

      will-it-scale/tlb_flush1_processes -t 96 -s 10, it shows obvious
      hotspot on lruvec->lock when test in single environment. What's
      more, The performance improved greatly if test in two more nodes
      system. The data shows below (more is better):

      ---------------------------------------------------------------------
      threads/process |   1     |     12   |     24   |   48     |   96
      ---------------------------------------------------------------------
      one node        | 14 1122 | 110 5372 | 111 2615 | 79 7084  | 72 4516
      ---------------------------------------------------------------------
      numa=fake=2     | 14 1168 | 144 4848 | 215 9070 | 157 0412 | 142 3968
      ---------------------------------------------------------------------
                      | For concurrency 12, no lruvec->lock hotspot. For 24,
      hotspot         | one node has 24% hotspot on lruvec->lock, but
                      | two nodes env hasn't.
      ---------------------------------------------------------------------

As for risks (e.g. numa balance...), they need to be discussed here.

Lastly, this just is a draft, I can improve next if it's acceptable.

Thanks!

Rongwei Wang (5):
mm/numa: move numa emulation APIs into generic files
mm: percpu: fix variable type of cpu
arch_numa: remove __init in early_cpu_to_node() mm/numa: support CONFIG_NUMA_EMU for arm64 mm/numa: migrate leftover numa emulation into mm/numa.c

 arch/x86/Kconfig                          |   8 -
 arch/x86/include/asm/numa.h               |   3 -
 arch/x86/mm/Makefile                      |   1 -
 arch/x86/mm/numa.c                        | 216 +-------------
 arch/x86/mm/numa_internal.h               |  14 +-
 drivers/base/arch_numa.c                  |   7 +-
 include/asm-generic/numa.h                |  33 +++
 include/linux/percpu.h                    |   2 +-
 mm/Kconfig                                |   8 +
 mm/Makefile                               |   1 +
 arch/x86/mm/numa_emulation.c => mm/numa.c | 333 +++++++++++++++++++++-
 11 files changed, 373 insertions(+), 253 deletions(-)
 rename arch/x86/mm/numa_emulation.c => mm/numa.c (63%)
Signature · 1 line
2.32.0.3.gf3a3e56d6
#1 lore raw

RFC PATCH 1/5 mm/numa: move numa emulation APIs into generic files

In order to support NUMA EMU for other arch, some functions that used by numa_meminfo should be moved out x86 arch. mm/numa.c created to place above API.

CONFIG_NUMA_EMU will be handled later.

---
 arch/x86/include/asm/numa.h |   3 -
 arch/x86/mm/numa.c          | 216 +-------------------------
 arch/x86/mm/numa_internal.h |  14 +-
 include/asm-generic/numa.h  |  18 +++
 mm/Makefile                 |   1 +
 mm/numa.c                   | 298 ++++++++++++++++++++++++++++++++++++
 6 files changed, 323 insertions(+), 227 deletions(-)
 create mode 100644 mm/numa.c
arch/x86/include/asm/numa.h +0 -3
index e3bae2b60a0d..8d79be8095d5 100644
@@ -9,9 +9,6 @@
 #include <asm/apicdef.h>
 
 #ifdef CONFIG_NUMA
-
-#define NR_NODE_MEMBLKS		(MAX_NUMNODES*2)
-
 /*
  * Too small node sizes may confuse the VM badly. Usually they
  * result from BIOS bugs. So dont recognize nodes as standalone
arch/x86/mm/numa.c +2 -214

240 lines not on this page · raw message

arch/x86/mm/numa_internal.h +4 -10
index 86860f279662..b6053beb81b1 100644
@@ -16,19 +16,13 @@ struct numa_meminfo {
 	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);
+extern int __init numa_cleanup_meminfo(struct numa_meminfo *mi);
 void __init numa_reset_distance(void);
 
 void __init x86_numa_init(void);
 
-#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
+extern void __init numa_emulation(struct numa_meminfo *numa_meminfo,
+				  int numa_dist_cnt);
+
 
 #endif	/* __X86_MM_NUMA_INTERNAL_H */
include/asm-generic/numa.h +18 -0
index 1a3ad6d29833..929d7c582a73 100644
@@ -39,6 +39,24 @@ void numa_store_cpu_info(unsigned int cpu);
 void numa_add_cpu(unsigned int cpu);
 void numa_remove_cpu(unsigned int cpu);
 
+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;
+
+int __init numa_register_memblks(struct numa_meminfo *mi);
+int __init numa_cleanup_meminfo(struct numa_meminfo *mi);
+void __init numa_emulation(struct numa_meminfo *numa_meminfo,
+			   int numa_dist_cnt);
+
 #else	/* CONFIG_NUMA */
 
 static inline void numa_store_cpu_info(unsigned int cpu) { }
mm/Makefile +1 -0
index ec65984e2ade..6fc1bd7c9f5b 100644
@@ -138,3 +138,4 @@ obj-$(CONFIG_IO_MAPPING) += io-mapping.o
 obj-$(CONFIG_HAVE_BOOTMEM_INFO_NODE) += bootmem_info.o
 obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o
 obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o
+obj-$(CONFIG_NUMA) += numa.o
mm/numa.c new file +298 -0

298 lines not on this page · raw message

Signature · 1 line
2.32.0.3.gf3a3e56d6
Acked-by on v1 1/5
#2 lore raw

Re: [PATCH RFC 1/5] mm/numa: move numa emulation APIs into generic files

Quoted 8 lines · Rongwei Wang

In order to support NUMA EMU for other arch, some functions that used by numa_meminfo should be moved out x86 arch. mm/numa.c created to place above API.

CONFIG_NUMA_EMU will be handled later.

Quoted 9 lines
---
 arch/x86/include/asm/numa.h |   3 -
 arch/x86/mm/numa.c          | 216 +-------------------------
 arch/x86/mm/numa_internal.h |  14 +-
 include/asm-generic/numa.h  |  18 +++
 mm/Makefile                 |   1 +
 mm/numa.c                   | 298 ++++++++++++++++++++++++++++++++++++
 6 files changed, 323 insertions(+), 227 deletions(-)
 create mode 100644 mm/numa.c

No objections to moving the x86 NUMA emulation code to mm/numa.c, as long as it stays similarly functional:

Thanks,

Ingo

#3 lore raw

Re: [PATCH RFC 1/5] mm/numa: move numa emulation APIs into generic files

In reply to Rongwei Wang
kernel test robot noticed the following build warnings:

Hi Rongwei,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on driver-core/driver-core-testing]
[also build test WARNING on driver-core/driver-core-next driver-core/driver-core-linus tip/x86/mm linus/master v6.6-rc6] [cannot apply to akpm-mm/mm-everything next-20231017]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rongwei-Wang/mm-percpu-fix-variable-type-of-cpu/20231017-102250
base:   driver-core/driver-core-testing
patch link:    https://lore.kernel.org/r/20231012024842.99703-2-rongwei.wang%40linux.alibaba.com
patch subject: [PATCH RFC 1/5] mm/numa: move numa emulation APIs into generic files
config: sparc-allyesconfig (https://download.01.org/0day-ci/archive/20231017/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231017/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> mm/numa.c:22:13: warning: no previous prototype for 'numa_nodemask_from_meminfo' [-Wmissing-prototypes]
      22 | void __init numa_nodemask_from_meminfo(nodemask_t *nodemask,
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~
   In file included from include/linux/cpumask.h:10,
                    from include/linux/smp.h:13,
                    from include/linux/lockdep.h:14,
                    from include/linux/spinlock.h:63,
                    from include/linux/mmzone.h:8,
                    from include/linux/gfp.h:7,
                    from include/linux/slab.h:16,
                    from include/linux/resource_ext.h:11,
                    from include/linux/acpi.h:13,
                    from mm/numa.c:2:
   mm/numa.c: In function 'numa_nodemask_from_meminfo':
   mm/numa.c:27:38: error: invalid use of undefined type 'const struct numa_meminfo'
      27 |         for (i = 0; i < ARRAY_SIZE(mi->blk); i++)
         |                                      ^~
   include/linux/kernel.h:57:33: note: in definition of macro 'ARRAY_SIZE'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                 ^~~
   mm/numa.c:27:38: error: invalid use of undefined type 'const struct numa_meminfo'
      27 |         for (i = 0; i < ARRAY_SIZE(mi->blk); i++)
         |                                      ^~
   include/linux/kernel.h:57:48: note: in definition of macro 'ARRAY_SIZE'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                ^~~
   In file included from include/linux/bits.h:21,
                    from include/linux/ioport.h:13,
                    from include/linux/acpi.h:12:
   mm/numa.c:27:38: error: invalid use of undefined type 'const struct numa_meminfo'
      27 |         for (i = 0; i < ARRAY_SIZE(mi->blk); i++)
         |                                      ^~
   include/linux/build_bug.h:16:62: note: in definition of macro 'BUILD_BUG_ON_ZERO'
      16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
         |                                                              ^
   include/linux/compiler.h:231:51: note: in expansion of macro '__same_type'
     231 | #define __must_be_array(a)      BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
         |                                                   ^~~~~~~~~~~
   include/linux/kernel.h:57:59: note: in expansion of macro '__must_be_array'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                           ^~~~~~~~~~~~~~~
   mm/numa.c:27:25: note: in expansion of macro 'ARRAY_SIZE'
      27 |         for (i = 0; i < ARRAY_SIZE(mi->blk); i++)
         |                         ^~~~~~~~~~
   mm/numa.c:27:38: error: invalid use of undefined type 'const struct numa_meminfo'
      27 |         for (i = 0; i < ARRAY_SIZE(mi->blk); i++)
         |                                      ^~
   include/linux/build_bug.h:16:62: note: in definition of macro 'BUILD_BUG_ON_ZERO'
      16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
         |                                                              ^
   include/linux/compiler.h:231:51: note: in expansion of macro '__same_type'
     231 | #define __must_be_array(a)      BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
         |                                                   ^~~~~~~~~~~
   include/linux/kernel.h:57:59: note: in expansion of macro '__must_be_array'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                           ^~~~~~~~~~~~~~~
   mm/numa.c:27:25: note: in expansion of macro 'ARRAY_SIZE'
      27 |         for (i = 0; i < ARRAY_SIZE(mi->blk); i++)
         |                         ^~~~~~~~~~
   include/linux/build_bug.h:16:51: error: bit-field '<anonymous>' width not an integer constant
      16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
         |                                                   ^
   include/linux/compiler.h:231:33: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
     231 | #define __must_be_array(a)      BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
         |                                 ^~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:59: note: in expansion of macro '__must_be_array'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                           ^~~~~~~~~~~~~~~
   mm/numa.c:27:25: note: in expansion of macro 'ARRAY_SIZE'
      27 |         for (i = 0; i < ARRAY_SIZE(mi->blk); i++)
         |                         ^~~~~~~~~~
   mm/numa.c:28:23: error: invalid use of undefined type 'const struct numa_meminfo'
      28 |                 if (mi->blk[i].start != mi->blk[i].end &&
         |                       ^~
   mm/numa.c:28:43: error: invalid use of undefined type 'const struct numa_meminfo'
      28 |                 if (mi->blk[i].start != mi->blk[i].end &&
         |                                           ^~
   mm/numa.c:29:23: error: invalid use of undefined type 'const struct numa_meminfo'
      29 |                     mi->blk[i].nid != NUMA_NO_NODE)
         |                       ^~
   In file included from include/linux/mmzone.h:18:
   mm/numa.c:30:36: error: invalid use of undefined type 'const struct numa_meminfo'
      30 |                         node_set(mi->blk[i].nid, *nodemask);
         |                                    ^~
   include/linux/nodemask.h:128:41: note: in definition of macro 'node_set'
     128 | #define node_set(node, dst) __node_set((node), &(dst))
         |                                         ^~~~
   mm/numa.c: In function 'numa_remove_memblk_from':
   mm/numa.c:43:11: error: invalid use of undefined type 'struct numa_meminfo'
      43 |         mi->nr_blks--;
         |           ^~
   mm/numa.c:44:20: error: invalid use of undefined type 'struct numa_meminfo'
      44 |         memmove(&mi->blk[idx], &mi->blk[idx + 1],
         |                    ^~
   mm/numa.c:44:35: error: invalid use of undefined type 'struct numa_meminfo'
      44 |         memmove(&mi->blk[idx], &mi->blk[idx + 1],
         |                                   ^~
   mm/numa.c:45:20: error: invalid use of undefined type 'struct numa_meminfo'
      45 |                 (mi->nr_blks - idx) * sizeof(mi->blk[0]));
         |                    ^~
   mm/numa.c:45:48: error: invalid use of undefined type 'struct numa_meminfo'
      45 |                 (mi->nr_blks - idx) * sizeof(mi->blk[0]));
         |                                                ^~
   mm/numa.c: In function 'numa_move_tail_memblk':
   mm/numa.c:57:12: error: invalid use of undefined type 'struct numa_meminfo'
      57 |         dst->blk[dst->nr_blks++] = src->blk[idx];
         |            ^~
   mm/numa.c:57:21: error: invalid use of undefined type 'struct numa_meminfo'
      57 |         dst->blk[dst->nr_blks++] = src->blk[idx];
         |                     ^~
   mm/numa.c:57:39: error: invalid use of undefined type 'struct numa_meminfo'
      57 |         dst->blk[dst->nr_blks++] = src->blk[idx];
         |                                       ^~
   mm/numa.c: At top level:
>> mm/numa.c:61:12: warning: no previous prototype for 'numa_add_memblk_to' [-Wmissing-prototypes]
      61 | int __init numa_add_memblk_to(int nid, u64 start, u64 end,
         |            ^~~~~~~~~~~~~~~~~~
   mm/numa.c: In function 'numa_add_memblk_to':
   mm/numa.c:75:15: error: invalid use of undefined type 'struct numa_meminfo'
      75 |         if (mi->nr_blks >= NR_NODE_MEMBLKS) {
         |               ^~
   mm/numa.c:75:28: error: 'NR_NODE_MEMBLKS' undeclared (first use in this function)
      75 |         if (mi->nr_blks >= NR_NODE_MEMBLKS) {
         |                            ^~~~~~~~~~~~~~~
   mm/numa.c:75:28: note: each undeclared identifier is reported only once for each function it appears in
   mm/numa.c:80:11: error: invalid use of undefined type 'struct numa_meminfo'
      80 |         mi->blk[mi->nr_blks].start = start;
         |           ^~
   mm/numa.c:80:19: error: invalid use of undefined type 'struct numa_meminfo'
      80 |         mi->blk[mi->nr_blks].start = start;
         |                   ^~
   mm/numa.c:81:11: error: invalid use of undefined type 'struct numa_meminfo'
      81 |         mi->blk[mi->nr_blks].end = end;
         |           ^~
   mm/numa.c:81:19: error: invalid use of undefined type 'struct numa_meminfo'
      81 |         mi->blk[mi->nr_blks].end = end;
         |                   ^~
   mm/numa.c:82:11: error: invalid use of undefined type 'struct numa_meminfo'
      82 |         mi->blk[mi->nr_blks].nid = nid;
         |           ^~
   mm/numa.c:82:19: error: invalid use of undefined type 'struct numa_meminfo'
      82 |         mi->blk[mi->nr_blks].nid = nid;
         |                   ^~
   mm/numa.c:83:11: error: invalid use of undefined type 'struct numa_meminfo'
      83 |         mi->nr_blks++;
         |           ^~
   mm/numa.c: At top level:
>> mm/numa.c:97:12: warning: no previous prototype for 'numa_cleanup_meminfo' [-Wmissing-prototypes]
      97 | int __init numa_cleanup_meminfo(struct numa_meminfo *mi)
         |            ^~~~~~~~~~~~~~~~~~~~
   mm/numa.c: In function 'numa_cleanup_meminfo':
   mm/numa.c:104:27: error: invalid use of undefined type 'struct numa_meminfo'
     104 |         for (i = 0; i < mi->nr_blks; i++) {
         |                           ^~
   mm/numa.c:105:45: error: invalid use of undefined type 'struct numa_meminfo'
     105 |                 struct numa_memblk *bi = &mi->blk[i];
         |                                             ^~
   mm/numa.c:109:43: error: invalid use of undefined type 'struct numa_memblk'
     109 |                                         bi->start, bi->end - bi->start)) {
         |                                           ^~
   mm/numa.c:109:54: error: invalid use of undefined type 'struct numa_memblk'
     109 |                                         bi->start, bi->end - bi->start)) {
         |                                                      ^~
   mm/numa.c:109:64: error: invalid use of undefined type 'struct numa_memblk'
     109 |                                         bi->start, bi->end - bi->start)) {
         |                                                                ^~
   mm/numa.c:115:19: error: invalid use of undefined type 'struct numa_memblk'
     115 |                 bi->start = max(bi->start, low);
         |                   ^~
   In file included from include/linux/ioport.h:15:
   mm/numa.c:115:35: error: invalid use of undefined type 'struct numa_memblk'
     115 |                 bi->start = max(bi->start, low);
         |                                   ^~
   include/linux/minmax.h:21:28: note: in definition of macro '__typecheck'
      21 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
         |                            ^
   include/linux/minmax.h:37:31: note: in expansion of macro '__safe_cmp'
      37 |         __builtin_choose_expr(__safe_cmp(x, y), \
         |                               ^~~~~~~~~~
   include/linux/minmax.h:75:25: note: in expansion of macro '__careful_cmp'
      75 | #define max(x, y)       __careful_cmp(x, y, >)
         |                         ^~~~~~~~~~~~~
   mm/numa.c:115:29: note: in expansion of macro 'max'
     115 |                 bi->start = max(bi->start, low);
         |                             ^~~
   In file included from include/linux/bits.h:5:
   mm/numa.c:115:35: error: invalid use of undefined type 'struct numa_memblk'
     115 |                 bi->start = max(bi->start, low);
         |                                   ^~
   include/linux/const.h:12:55: note: in definition of macro '__is_constexpr'
      12 |         (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
         |                                                       ^
   include/linux/minmax.h:27:39: note: in expansion of macro '__no_side_effects'
      27 |                 (__typecheck(x, y) && __no_side_effects(x, y))
         |                                       ^~~~~~~~~~~~~~~~~
   include/linux/minmax.h:37:31: note: in expansion of macro '__safe_cmp'
      37 |         __builtin_choose_expr(__safe_cmp(x, y), \
         |                               ^~~~~~~~~~
   include/linux/minmax.h:75:25: note: in expansion of macro '__careful_cmp'
      75 | #define max(x, y)       __careful_cmp(x, y, >)
         |                         ^~~~~~~~~~~~~
   mm/numa.c:115:29: note: in expansion of macro 'max'
     115 |                 bi->start = max(bi->start, low);
         |                             ^~~
   mm/numa.c:115:35: error: invalid use of undefined type 'struct numa_memblk'
     115 |                 bi->start = max(bi->start, low);
         |                                   ^~
   include/linux/minmax.h:29:27: note: in definition of macro '__cmp'
      29 | #define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
         |                           ^
   include/linux/minmax.h:75:25: note: in expansion of macro '__careful_cmp'
      75 | #define max(x, y)       __careful_cmp(x, y, >)
         |                         ^~~~~~~~~~~~~
   mm/numa.c:115:29: note: in expansion of macro 'max'
     115 |                 bi->start = max(bi->start, low);
         |                             ^~~
   mm/numa.c:115:35: error: invalid use of undefined type 'struct numa_memblk'
     115 |                 bi->start = max(bi->start, low);
         |                                   ^~
   include/linux/minmax.h:29:40: note: in definition of macro '__cmp'
      29 | #define __cmp(x, y, op) ((x) op (y) ? (x) : (y))
         |                                        ^
   include/linux/minmax.h:75:25: note: in expansion of macro '__careful_cmp'
      75 | #define max(x, y)       __careful_cmp(x, y, >)
         |                         ^~~~~~~~~~~~~
   mm/numa.c:115:29: note: in expansion of macro 'max'
     115 |                 bi->start = max(bi->start, low);
         |                             ^~~
   mm/numa.c:115:35: error: invalid use of undefined type 'struct numa_memblk'
     115 |                 bi->start = max(bi->start, low);
         |                                   ^~
   include/linux/minmax.h:32:24: note: in definition of macro '__cmp_once'
      32 |                 typeof(x) unique_x = (x);               \
         |                        ^
   include/linux/minmax.h:75:25: note: in expansion of macro '__careful_cmp'
      75 | #define max(x, y)       __careful_cmp(x, y, >)
         |                         ^~~~~~~~~~~~~
   mm/numa.c:115:29: note: in expansion of macro 'max'
     115 |                 bi->start = max(bi->start, low);
         |                             ^~~
   mm/numa.c:115:35: error: invalid use of undefined type 'struct numa_memblk'
     115 |                 bi->start = max(bi->start, low);
         |                                   ^~
   include/linux/minmax.h:32:39: note: in definition of macro '__cmp_once'
      32 |                 typeof(x) unique_x = (x);               \
         |                                       ^
   include/linux/minmax.h:75:25: note: in expansion of macro '__careful_cmp'
      75 | #define max(x, y)       __careful_cmp(x, y, >)
--
         |                                                   ^~~~~~~~~~~
   include/linux/kernel.h:57:59: note: in expansion of macro '__must_be_array'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                           ^~~~~~~~~~~~~~~
   mm/numa.c:183:35: note: in expansion of macro 'ARRAY_SIZE'
     183 |         for (i = mi->nr_blks; i < ARRAY_SIZE(mi->blk); i++) {
         |                                   ^~~~~~~~~~
   include/linux/build_bug.h:16:51: error: bit-field '<anonymous>' width not an integer constant
      16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
         |                                                   ^
   include/linux/compiler.h:231:33: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
     231 | #define __must_be_array(a)      BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
         |                                 ^~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:59: note: in expansion of macro '__must_be_array'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                           ^~~~~~~~~~~~~~~
   mm/numa.c:183:35: note: in expansion of macro 'ARRAY_SIZE'
     183 |         for (i = mi->nr_blks; i < ARRAY_SIZE(mi->blk); i++) {
         |                                   ^~~~~~~~~~
   mm/numa.c:184:19: error: invalid use of undefined type 'struct numa_meminfo'
     184 |                 mi->blk[i].start = mi->blk[i].end = 0;
         |                   ^~
   mm/numa.c:184:38: error: invalid use of undefined type 'struct numa_meminfo'
     184 |                 mi->blk[i].start = mi->blk[i].end = 0;
         |                                      ^~
   mm/numa.c:185:19: error: invalid use of undefined type 'struct numa_meminfo'
     185 |                 mi->blk[i].nid = NUMA_NO_NODE;
         |                   ^~
   mm/numa.c: In function 'numa_clear_kernel_node_hotplug':
   mm/numa.c:215:37: error: invalid use of undefined type 'struct numa_meminfo'
     215 |         for (i = 0; i < numa_meminfo.nr_blks; i++) {
         |                                     ^
   mm/numa.c:216:54: error: invalid use of undefined type 'struct numa_meminfo'
     216 |                 struct numa_memblk *mb = numa_meminfo.blk + i;
         |                                                      ^
   mm/numa.c:219:43: error: invalid use of undefined type 'struct numa_memblk'
     219 |                 ret = memblock_set_node(mb->start, mb->end - mb->start, &memblock.reserved, mb->nid);
         |                                           ^~
   mm/numa.c:219:54: error: invalid use of undefined type 'struct numa_memblk'
     219 |                 ret = memblock_set_node(mb->start, mb->end - mb->start, &memblock.reserved, mb->nid);
         |                                                      ^~
   mm/numa.c:219:64: error: invalid use of undefined type 'struct numa_memblk'
     219 |                 ret = memblock_set_node(mb->start, mb->end - mb->start, &memblock.reserved, mb->nid);
         |                                                                ^~
   mm/numa.c:219:95: error: invalid use of undefined type 'struct numa_memblk'
     219 |                 ret = memblock_set_node(mb->start, mb->end - mb->start, &memblock.reserved, mb->nid);
         |                                                                                               ^~
   mm/numa.c:247:37: error: invalid use of undefined type 'struct numa_meminfo'
     247 |         for (i = 0; i < numa_meminfo.nr_blks; i++) {
         |                                     ^
   mm/numa.c:248:54: error: invalid use of undefined type 'struct numa_meminfo'
     248 |                 struct numa_memblk *mb = numa_meminfo.blk + i;
         |                                                      ^
   In file included from include/linux/thread_info.h:27:
   mm/numa.c:250:35: error: invalid use of undefined type 'struct numa_memblk'
     250 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                                   ^~
   include/linux/bitops.h:49:32: note: in definition of macro 'bitop'
      49 |         ((__builtin_constant_p(nr) &&                                   \
         |                                ^~
   include/linux/nodemask.h:153:36: note: in expansion of macro 'test_bit'
     153 | #define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
         |                                    ^~~~~~~~
   mm/numa.c:250:22: note: in expansion of macro 'node_isset'
     250 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                      ^~~~~~~~~~
   mm/numa.c:250:35: error: invalid use of undefined type 'struct numa_memblk'
     250 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                                   ^~
   include/linux/bitops.h:53:20: note: in definition of macro 'bitop'
      53 |          const##op(nr, addr) : op(nr, addr))
         |                    ^~
   include/linux/nodemask.h:153:36: note: in expansion of macro 'test_bit'
     153 | #define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
         |                                    ^~~~~~~~
   mm/numa.c:250:22: note: in expansion of macro 'node_isset'
     250 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                      ^~~~~~~~~~
   mm/numa.c:250:35: error: invalid use of undefined type 'struct numa_memblk'
     250 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                                   ^~
   include/linux/bitops.h:53:35: note: in definition of macro 'bitop'
      53 |          const##op(nr, addr) : op(nr, addr))
         |                                   ^~
   include/linux/nodemask.h:153:36: note: in expansion of macro 'test_bit'
     153 | #define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
         |                                    ^~~~~~~~
   mm/numa.c:250:22: note: in expansion of macro 'node_isset'
     250 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                      ^~~~~~~~~~
   mm/numa.c:253:42: error: invalid use of undefined type 'struct numa_memblk'
     253 |                 memblock_clear_hotplug(mb->start, mb->end - mb->start);
         |                                          ^~
   mm/numa.c:253:53: error: invalid use of undefined type 'struct numa_memblk'
     253 |                 memblock_clear_hotplug(mb->start, mb->end - mb->start);
         |                                                     ^~
   mm/numa.c:253:63: error: invalid use of undefined type 'struct numa_memblk'
     253 |                 memblock_clear_hotplug(mb->start, mb->end - mb->start);
         |                                                               ^~
   mm/numa.c: At top level:
>> mm/numa.c:257:19: warning: no previous prototype for 'numa_register_memblks' [-Wmissing-prototypes]
     257 | int __weak __init numa_register_memblks(struct numa_meminfo *mi)
         |                   ^~~~~~~~~~~~~~~~~~~~~
   mm/numa.c: In function 'numa_register_memblks':
   mm/numa.c:262:29: error: 'numa_nodes_parsed' undeclared (first use in this function); did you mean 'numa_node_id'?
     262 |         node_possible_map = numa_nodes_parsed;
         |                             ^~~~~~~~~~~~~~~~~
         |                             numa_node_id
   mm/numa.c:267:27: error: invalid use of undefined type 'struct numa_meminfo'
     267 |         for (i = 0; i < mi->nr_blks; i++) {
         |                           ^~
   mm/numa.c:268:45: error: invalid use of undefined type 'struct numa_meminfo'
     268 |                 struct numa_memblk *mb = &mi->blk[i];
         |                                             ^~
   mm/numa.c:269:37: error: invalid use of undefined type 'struct numa_memblk'
     269 |                 memblock_set_node(mb->start, mb->end - mb->start,
         |                                     ^~
   mm/numa.c:269:48: error: invalid use of undefined type 'struct numa_memblk'
     269 |                 memblock_set_node(mb->start, mb->end - mb->start,
         |                                                ^~
   mm/numa.c:269:58: error: invalid use of undefined type 'struct numa_memblk'
     269 |                 memblock_set_node(mb->start, mb->end - mb->start,
         |                                                          ^~
   mm/numa.c:270:55: error: invalid use of undefined type 'struct numa_memblk'
     270 |                                   &memblock.memory, mb->nid);
         |                                                       ^~
   mm/numa.c: At top level:
   mm/numa.c:16:21: error: storage size of 'numa_meminfo' isn't known
      16 | struct numa_meminfo numa_meminfo __initdata_or_meminfo;
         |                     ^~~~~~~~~~~~
   mm/numa.c:17:21: error: storage size of 'numa_reserved_meminfo' isn't known
      17 | struct numa_meminfo numa_reserved_meminfo __initdata_or_meminfo;
         |                     ^~~~~~~~~~~~~~~~~~~~~

vim +/numa_nodemask_from_meminfo +22 mm/numa.c

    18	
    19	/*
    20	 * Set nodes, which have memory in @mi, in *@nodemask.
    21	 */
  > 22	void __init numa_nodemask_from_meminfo(nodemask_t *nodemask,
    23						      const struct numa_meminfo *mi)
    24	{
    25		int i;
    26	
    27		for (i = 0; i < ARRAY_SIZE(mi->blk); i++)
    28			if (mi->blk[i].start != mi->blk[i].end &&
    29			    mi->blk[i].nid != NUMA_NO_NODE)
    30				node_set(mi->blk[i].nid, *nodemask);
    31	}
    32	
    33	/**
    34	 * numa_remove_memblk_from - Remove one numa_memblk from a numa_meminfo
    35	 * @idx: Index of memblk to remove
    36	 * @mi: numa_meminfo to remove memblk from
    37	 *
    38	 * Remove @idx'th numa_memblk from @mi by shifting @mi->blk[] and
    39	 * decrementing @mi->nr_blks.
    40	 */
    41	static void __init numa_remove_memblk_from(int idx, struct numa_meminfo *mi)
    42	{
    43		mi->nr_blks--;
    44		memmove(&mi->blk[idx], &mi->blk[idx + 1],
    45			(mi->nr_blks - idx) * sizeof(mi->blk[0]));
    46	}
    47	
    48	/**
    49	 * numa_move_tail_memblk - Move a numa_memblk from one numa_meminfo to another
    50	 * @dst: numa_meminfo to append block to
    51	 * @idx: Index of memblk to remove
    52	 * @src: numa_meminfo to remove memblk from
    53	 */
    54	static void __init numa_move_tail_memblk(struct numa_meminfo *dst, int idx,
    55						 struct numa_meminfo *src)
    56	{
    57		dst->blk[dst->nr_blks++] = src->blk[idx];
    58		numa_remove_memblk_from(idx, src);
    59	}
    60	
  > 61	int __init numa_add_memblk_to(int nid, u64 start, u64 end,
    62					     struct numa_meminfo *mi)
    63	{
    64		/* ignore zero length blks */
    65		if (start == end)
    66			return 0;
    67	
    68		/* whine about and ignore invalid blks */
    69		if (start > end || nid < 0 || nid >= MAX_NUMNODES) {
    70			pr_warn("Warning: invalid memblk node %d [mem %#010Lx-%#010Lx]\n",
    71				nid, start, end - 1);
    72			return 0;
    73		}
    74	
    75		if (mi->nr_blks >= NR_NODE_MEMBLKS) {
    76			pr_err("too many memblk ranges\n");
    77			return -EINVAL;
    78		}
    79	
    80		mi->blk[mi->nr_blks].start = start;
    81		mi->blk[mi->nr_blks].end = end;
    82		mi->blk[mi->nr_blks].nid = nid;
    83		mi->nr_blks++;
    84		return 0;
    85	}
    86	
    87	/**
    88	 * numa_cleanup_meminfo - Cleanup a numa_meminfo
    89	 * @mi: numa_meminfo to clean up
    90	 *
    91	 * Sanitize @mi by merging and removing unnecessary memblks.  Also check for
    92	 * conflicts and clear unused memblks.
    93	 *
    94	 * RETURNS:
    95	 * 0 on success, -errno on failure.
    96	 */
  > 97	int __init numa_cleanup_meminfo(struct numa_meminfo *mi)
    98	{
    99		const u64 low = 0;

100 const u64 high = PFN_PHYS(max_pfn);
101 int i, j, k;
102
103 /* first, trim all entries */
104 for (i = 0; i < mi->nr_blks; i++) {
105 struct numa_memblk *bi = &mi->blk[i];
106
107 /* move / save reserved memory ranges */
108 if (!memblock_overlaps_region(&memblock.memory,
109 bi->start, bi->end - bi->start)) {
110 numa_move_tail_memblk(&numa_reserved_meminfo, i--, mi);
111 continue;
112 }
113
114 /* make sure all non-reserved blocks are inside the limits */
115 bi->start = max(bi->start, low);
116
117 /* preserve info for non-RAM areas above 'max_pfn': */
118 if (bi->end > high) {
119 numa_add_memblk_to(bi->nid, high, bi->end,
120 &numa_reserved_meminfo);
121 bi->end = high;
122 }
123
124 /* and there's no empty block */
125 if (bi->start >= bi->end)
126 numa_remove_memblk_from(i--, mi);
127 }
128
129 /* merge neighboring / overlapping entries */
130 for (i = 0; i < mi->nr_blks; i++) {
131 struct numa_memblk *bi = &mi->blk[i];
132
133 for (j = i + 1; j < mi->nr_blks; j++) {
134 struct numa_memblk *bj = &mi->blk[j];
135 u64 start, end;
136
137 /*
138 * See whether there are overlapping blocks. Whine
139 * about but allow overlaps of the same nid. They
140 * will be merged below.
141 */
142 if (bi->end > bj->start && bi->start < bj->end) {
143 if (bi->nid != bj->nid) {
144 pr_err("node %d [mem %#010Lx-%#010Lx] overlaps with node %d [mem %#010Lx-%#010Lx]\n",
145 bi->nid, bi->start, bi->end - 1,
146 bj->nid, bj->start, bj->end - 1);
147 return -EINVAL;
148 }
149 pr_warn("Warning: node %d [mem %#010Lx-%#010Lx] overlaps with itself [mem %#010Lx-%#010Lx]\n",
150 bi->nid, bi->start, bi->end - 1,
151 bj->start, bj->end - 1);
152 }
153
154 /*
155 * Join together blocks on the same node, holes
156 * between which don't overlap with memory on other
157 * nodes.
158 */
159 if (bi->nid != bj->nid)
160 continue;
161 start = min(bi->start, bj->start);
162 end = max(bi->end, bj->end);
163 for (k = 0; k < mi->nr_blks; k++) {
164 struct numa_memblk *bk = &mi->blk[k];
165
166 if (bi->nid == bk->nid)
167 continue;
168 if (start < bk->end && end > bk->start)
169 break;
170 }
171 if (k < mi->nr_blks)
172 continue;
173 printk(KERN_INFO "NUMA: Node %d [mem %#010Lx-%#010Lx] + [mem %#010Lx-%#010Lx] -> [mem %#010Lx-%#010Lx]\n",
174 bi->nid, bi->start, bi->end - 1, bj->start,
175 bj->end - 1, start, end - 1);
176 bi->start = start;
177 bi->end = end;
178 numa_remove_memblk_from(j--, mi);
179 }
180 }
181
182 /* clear unused ones */
183 for (i = mi->nr_blks; i < ARRAY_SIZE(mi->blk); i++) {
184 mi->blk[i].start = mi->blk[i].end = 0;
185 mi->blk[i].nid = NUMA_NO_NODE;
186 }
187
188 return 0;
189 }
190

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

Re: [PATCH RFC 1/5] mm/numa: move numa emulation APIs into generic files

In reply to Rongwei Wang
kernel test robot noticed the following build warnings:

Hi Rongwei,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on driver-core/driver-core-testing]
[also build test WARNING on driver-core/driver-core-next driver-core/driver-core-linus tip/x86/mm linus/master v6.6-rc6] [cannot apply to akpm-mm/mm-everything next-20231018]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rongwei-Wang/mm-percpu-fix-variable-type-of-cpu/20231017-102250
base:   driver-core/driver-core-testing
patch link:    https://lore.kernel.org/r/20231012024842.99703-2-rongwei.wang%40linux.alibaba.com
patch subject: [PATCH RFC 1/5] mm/numa: move numa emulation APIs into generic files
config: sh-defconfig (https://download.01.org/0day-ci/archive/20231019/[email protected]/config)
compiler: sh4-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231019/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

     216 |                 struct numa_memblk *mb = numa_meminfo.blk + i;
         |                                                      ^
   mm/numa.c:219:43: error: invalid use of undefined type 'struct numa_memblk'
     219 |                 ret = memblock_set_node(mb->start, mb->end - mb->start, &memblock.reserved, mb->nid);
         |                                           ^~
   mm/numa.c:219:54: error: invalid use of undefined type 'struct numa_memblk'
     219 |                 ret = memblock_set_node(mb->start, mb->end - mb->start, &memblock.reserved, mb->nid);
         |                                                      ^~
   mm/numa.c:219:64: error: invalid use of undefined type 'struct numa_memblk'
     219 |                 ret = memblock_set_node(mb->start, mb->end - mb->start, &memblock.reserved, mb->nid);
         |                                                                ^~
   mm/numa.c:219:95: error: invalid use of undefined type 'struct numa_memblk'
     219 |                 ret = memblock_set_node(mb->start, mb->end - mb->start, &memblock.reserved, mb->nid);
         |                                                                                               ^~
   mm/numa.c:247:37: error: invalid use of undefined type 'struct numa_meminfo'
     247 |         for (i = 0; i < numa_meminfo.nr_blks; i++) {
         |                                     ^
   mm/numa.c:248:54: error: invalid use of undefined type 'struct numa_meminfo'
     248 |                 struct numa_memblk *mb = numa_meminfo.blk + i;
         |                                                      ^
   In file included from include/linux/log2.h:12,
                    from include/asm-generic/div64.h:55,
                    from ./arch/sh/include/generated/asm/div64.h:1,
                    from include/linux/math.h:6,
                    from include/linux/math64.h:6,
                    from include/linux/time64.h:5,
                    from include/linux/restart_block.h:10,
                    from include/linux/thread_info.h:14:
   mm/numa.c:250:35: error: invalid use of undefined type 'struct numa_memblk'
     250 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                                   ^~
   include/linux/bitops.h:49:32: note: in definition of macro 'bitop'
      49 |         ((__builtin_constant_p(nr) &&                                   \
         |                                ^~
   include/linux/nodemask.h:153:36: note: in expansion of macro 'test_bit'
     153 | #define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
         |                                    ^~~~~~~~
   mm/numa.c:250:22: note: in expansion of macro 'node_isset'
     250 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                      ^~~~~~~~~~
   mm/numa.c:250:35: error: invalid use of undefined type 'struct numa_memblk'
     250 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                                   ^~
   include/linux/bitops.h:53:20: note: in definition of macro 'bitop'
      53 |          const##op(nr, addr) : op(nr, addr))
         |                    ^~
   include/linux/nodemask.h:153:36: note: in expansion of macro 'test_bit'
     153 | #define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
         |                                    ^~~~~~~~
   mm/numa.c:250:22: note: in expansion of macro 'node_isset'
     250 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                      ^~~~~~~~~~
   mm/numa.c:250:35: error: invalid use of undefined type 'struct numa_memblk'
     250 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                                   ^~
   include/linux/bitops.h:53:35: note: in definition of macro 'bitop'
      53 |          const##op(nr, addr) : op(nr, addr))
         |                                   ^~
   include/linux/nodemask.h:153:36: note: in expansion of macro 'test_bit'
     153 | #define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
         |                                    ^~~~~~~~
   mm/numa.c:250:22: note: in expansion of macro 'node_isset'
     250 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                      ^~~~~~~~~~
   mm/numa.c:253:42: error: invalid use of undefined type 'struct numa_memblk'
     253 |                 memblock_clear_hotplug(mb->start, mb->end - mb->start);
         |                                          ^~
   mm/numa.c:253:53: error: invalid use of undefined type 'struct numa_memblk'
     253 |                 memblock_clear_hotplug(mb->start, mb->end - mb->start);
         |                                                     ^~
   mm/numa.c:253:63: error: invalid use of undefined type 'struct numa_memblk'
     253 |                 memblock_clear_hotplug(mb->start, mb->end - mb->start);
         |                                                               ^~
   mm/numa.c: At top level:
   mm/numa.c:257:19: warning: no previous prototype for 'numa_register_memblks' [-Wmissing-prototypes]
     257 | int __weak __init numa_register_memblks(struct numa_meminfo *mi)
         |                   ^~~~~~~~~~~~~~~~~~~~~
   mm/numa.c: In function 'numa_register_memblks':
   mm/numa.c:262:29: error: 'numa_nodes_parsed' undeclared (first use in this function); did you mean 'numa_node_id'?
     262 |         node_possible_map = numa_nodes_parsed;
         |                             ^~~~~~~~~~~~~~~~~
         |                             numa_node_id
   mm/numa.c:267:27: error: invalid use of undefined type 'struct numa_meminfo'
     267 |         for (i = 0; i < mi->nr_blks; i++) {
         |                           ^~
   mm/numa.c:268:45: error: invalid use of undefined type 'struct numa_meminfo'
     268 |                 struct numa_memblk *mb = &mi->blk[i];
         |                                             ^~
   mm/numa.c:269:37: error: invalid use of undefined type 'struct numa_memblk'
     269 |                 memblock_set_node(mb->start, mb->end - mb->start,
         |                                     ^~
   mm/numa.c:269:48: error: invalid use of undefined type 'struct numa_memblk'
     269 |                 memblock_set_node(mb->start, mb->end - mb->start,
         |                                                ^~
   mm/numa.c:269:58: error: invalid use of undefined type 'struct numa_memblk'
     269 |                 memblock_set_node(mb->start, mb->end - mb->start,
         |                                                          ^~
   mm/numa.c:270:55: error: invalid use of undefined type 'struct numa_memblk'
     270 |                                   &memblock.memory, mb->nid);
         |                                                       ^~
>> include/linux/kern_levels.h:5:25: warning: format '%Lu' expects argument of type 'long long unsigned int', but argument 2 has type 'unsigned int' [-Wformat=]
       5 | #define KERN_SOH        "\001"          /* ASCII Start Of Header */
         |                         ^~~~~~
   include/linux/printk.h:427:25: note: in definition of macro 'printk_index_wrap'
     427 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                         ^~~~
   include/linux/printk.h:508:9: note: in expansion of macro 'printk'
     508 |         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~
   include/linux/kern_levels.h:12:25: note: in expansion of macro 'KERN_SOH'
      12 | #define KERN_WARNING    KERN_SOH "4"    /* warning conditions */
         |                         ^~~~~~~~
   include/linux/printk.h:508:16: note: in expansion of macro 'KERN_WARNING'
     508 |         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
         |                ^~~~~~~~~~~~
   mm/numa.c:290:25: note: in expansion of macro 'pr_warn'
     290 |                         pr_warn("Node alignment %LuMB < min %LuMB, rejecting NUMA config\n",
         |                         ^~~~~~~
   include/linux/kern_levels.h:5:25: warning: format '%Lu' expects argument of type 'long long unsigned int', but argument 3 has type 'unsigned int' [-Wformat=]
       5 | #define KERN_SOH        "\001"          /* ASCII Start Of Header */
         |                         ^~~~~~
   include/linux/printk.h:427:25: note: in definition of macro 'printk_index_wrap'
     427 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                         ^~~~
   include/linux/printk.h:508:9: note: in expansion of macro 'printk'
     508 |         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~
   include/linux/kern_levels.h:12:25: note: in expansion of macro 'KERN_SOH'
      12 | #define KERN_WARNING    KERN_SOH "4"    /* warning conditions */
         |                         ^~~~~~~~
   include/linux/printk.h:508:16: note: in expansion of macro 'KERN_WARNING'
     508 |         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
         |                ^~~~~~~~~~~~
   mm/numa.c:290:25: note: in expansion of macro 'pr_warn'
     290 |                         pr_warn("Node alignment %LuMB < min %LuMB, rejecting NUMA config\n",
         |                         ^~~~~~~
   mm/numa.c: At top level:
   mm/numa.c:16:21: error: storage size of 'numa_meminfo' isn't known
      16 | struct numa_meminfo numa_meminfo __initdata_or_meminfo;
         |                     ^~~~~~~~~~~~
   mm/numa.c:17:21: error: storage size of 'numa_reserved_meminfo' isn't known
      17 | struct numa_meminfo numa_reserved_meminfo __initdata_or_meminfo;
         |                     ^~~~~~~~~~~~~~~~~~~~~

vim +5 include/linux/kern_levels.h

314ba3520e513a Joe Perches 2012-07-30 4
04d2c8c83d0e3a Joe Perches 2012-07-30 @5 #define KERN_SOH "\001" /* ASCII Start Of Header */
04d2c8c83d0e3a Joe Perches 2012-07-30 6 #define KERN_SOH_ASCII '\001'
04d2c8c83d0e3a Joe Perches 2012-07-30 7

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

RFC PATCH 2/5 mm: percpu: fix variable type of cpu

In reply to Rongwei Wang

Almost all places declare 'cpu' as 'unsigned int'
type, but early_cpu_to_nod() not. So correct it
in this patch.

---
 drivers/base/arch_numa.c | 2 +-
 include/linux/percpu.h   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/base/arch_numa.c +1 -1
index eaa31e567d1e..db0bb8b8fd67 100644
@@ -144,7 +144,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid)
 unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
 EXPORT_SYMBOL(__per_cpu_offset);
 
-static int __init early_cpu_to_node(int cpu)
+static int __init early_cpu_to_node(unsigned int cpu)
 {
 	return cpu_to_node_map[cpu];
 }
include/linux/percpu.h +1 -1
index 68fac2e7cbe6..4aee8400af54 100644
@@ -100,7 +100,7 @@ extern const char * const pcpu_fc_names[PCPU_FC_NR];
 
 extern enum pcpu_fc pcpu_chosen_fc;
 
-typedef int (pcpu_fc_cpu_to_node_fn_t)(int cpu);
+typedef int (pcpu_fc_cpu_to_node_fn_t)(unsigned int cpu);
 typedef int (pcpu_fc_cpu_distance_fn_t)(unsigned int from, unsigned int to);
 
 extern struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int nr_groups,
Signature · 1 line
2.32.0.3.gf3a3e56d6
#6 lore raw

Re: [PATCH RFC 2/5] mm: percpu: fix variable type of cpu

kernel test robot noticed the following build errors:

Hi Rongwei,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on driver-core/driver-core-testing]
[also build test ERROR on driver-core/driver-core-next driver-core/driver-core-linus tip/x86/mm linus/master v6.6-rc6] [cannot apply to akpm-mm/mm-everything next-20231018]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rongwei-Wang/mm-percpu-fix-variable-type-of-cpu/20231017-102250
base:   driver-core/driver-core-testing
patch link:    https://lore.kernel.org/r/20231012024842.99703-3-rongwei.wang%40linux.alibaba.com
patch subject: [PATCH RFC 2/5] mm: percpu: fix variable type of cpu
config: loongarch-randconfig-001-20231018 (https://download.01.org/0day-ci/archive/20231018/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231018/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

arch/loongarch/kernel/numa.c: In function 'setup_per_cpu_areas':

>> arch/loongarch/kernel/numa.c:93:64: error: passing argument 5 of 'pcpu_embed_first_chunk' from incompatible pointer type [-Werror=incompatible-pointer-types]
      93 |                                             pcpu_cpu_distance, pcpu_cpu_to_node);
         |                                                                ^~~~~~~~~~~~~~~~
         |                                                                |
         |                                                                int (*)(int)
   In file included from include/linux/prandom.h:13,
                    from include/linux/random.h:153,
                    from include/linux/nodemask.h:97,
                    from include/linux/mmzone.h:18,
                    from include/linux/gfp.h:7,
                    from include/linux/mm.h:7,
                    from arch/loongarch/kernel/numa.c:10:
   include/linux/percpu.h:116:58: note: expected 'int (*)(unsigned int)' but argument is of type 'int (*)(int)'
     116 |                                 pcpu_fc_cpu_to_node_fn_t cpu_to_nd_fn);
         |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
>> arch/loongarch/kernel/numa.c:99:67: error: passing argument 2 of 'pcpu_page_first_chunk' from incompatible pointer type [-Werror=incompatible-pointer-types]
      99 |                 rc = pcpu_page_first_chunk(PERCPU_MODULE_RESERVE, pcpu_cpu_to_node);
         |                                                                   ^~~~~~~~~~~~~~~~
         |                                                                   |
         |                                                                   int (*)(int)
   include/linux/percpu.h:121:58: note: expected 'int (*)(unsigned int)' but argument is of type 'int (*)(int)'
     121 |                                 pcpu_fc_cpu_to_node_fn_t cpu_to_nd_fn);
         |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +/pcpu_embed_first_chunk +93 arch/loongarch/kernel/numa.c

d4b6f1562a3c32 Huacai Chen 2022-05-31   72  
d4b6f1562a3c32 Huacai Chen 2022-05-31   73  void __init setup_per_cpu_areas(void)
d4b6f1562a3c32 Huacai Chen 2022-05-31   74  {
d4b6f1562a3c32 Huacai Chen 2022-05-31   75  	unsigned long delta;
d4b6f1562a3c32 Huacai Chen 2022-05-31   76  	unsigned int cpu;
d4b6f1562a3c32 Huacai Chen 2022-05-31   77  	int rc = -EINVAL;
d4b6f1562a3c32 Huacai Chen 2022-05-31   78  
d4b6f1562a3c32 Huacai Chen 2022-05-31   79  	if (pcpu_chosen_fc == PCPU_FC_AUTO) {
d4b6f1562a3c32 Huacai Chen 2022-05-31   80  		if (nr_node_ids >= 8)
d4b6f1562a3c32 Huacai Chen 2022-05-31   81  			pcpu_chosen_fc = PCPU_FC_PAGE;
d4b6f1562a3c32 Huacai Chen 2022-05-31   82  		else
d4b6f1562a3c32 Huacai Chen 2022-05-31   83  			pcpu_chosen_fc = PCPU_FC_EMBED;
d4b6f1562a3c32 Huacai Chen 2022-05-31   84  	}
d4b6f1562a3c32 Huacai Chen 2022-05-31   85  
d4b6f1562a3c32 Huacai Chen 2022-05-31   86  	/*
d4b6f1562a3c32 Huacai Chen 2022-05-31   87  	 * Always reserve area for module percpu variables.  That's
d4b6f1562a3c32 Huacai Chen 2022-05-31   88  	 * what the legacy allocator did.
d4b6f1562a3c32 Huacai Chen 2022-05-31   89  	 */
d4b6f1562a3c32 Huacai Chen 2022-05-31   90  	if (pcpu_chosen_fc != PCPU_FC_PAGE) {
d4b6f1562a3c32 Huacai Chen 2022-05-31   91  		rc = pcpu_embed_first_chunk(PERCPU_MODULE_RESERVE,
d4b6f1562a3c32 Huacai Chen 2022-05-31   92  					    PERCPU_DYNAMIC_RESERVE, PMD_SIZE,
d4b6f1562a3c32 Huacai Chen 2022-05-31  @93  					    pcpu_cpu_distance, pcpu_cpu_to_node);
d4b6f1562a3c32 Huacai Chen 2022-05-31   94  		if (rc < 0)
d4b6f1562a3c32 Huacai Chen 2022-05-31   95  			pr_warn("%s allocator failed (%d), falling back to page size\n",
d4b6f1562a3c32 Huacai Chen 2022-05-31   96  				pcpu_fc_names[pcpu_chosen_fc], rc);
d4b6f1562a3c32 Huacai Chen 2022-05-31   97  	}
d4b6f1562a3c32 Huacai Chen 2022-05-31   98  	if (rc < 0)
d4b6f1562a3c32 Huacai Chen 2022-05-31  @99  		rc = pcpu_page_first_chunk(PERCPU_MODULE_RESERVE, pcpu_cpu_to_node);
d4b6f1562a3c32 Huacai Chen 2022-05-31  100  	if (rc < 0)
d4b6f1562a3c32 Huacai Chen 2022-05-31  101  		panic("cannot initialize percpu area (err=%d)", rc);
d4b6f1562a3c32 Huacai Chen 2022-05-31  102  
d4b6f1562a3c32 Huacai Chen 2022-05-31  103  	delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
d4b6f1562a3c32 Huacai Chen 2022-05-31  104  	for_each_possible_cpu(cpu)
d4b6f1562a3c32 Huacai Chen 2022-05-31  105  		__per_cpu_offset[cpu] = delta + pcpu_unit_offsets[cpu];
d4b6f1562a3c32 Huacai Chen 2022-05-31  106  }
d4b6f1562a3c32 Huacai Chen 2022-05-31  107  #endif
d4b6f1562a3c32 Huacai Chen 2022-05-31  108  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#7 lore raw

RFC PATCH 3/5 arch_numa: remove __init in early_cpu_to_node()

In reply to Rongwei Wang

Most of arch does not stick '__init' for
early_cpu_to_node(). And it's safe to
delete this attribute here, ready for
later numa emulation.

---
 drivers/base/arch_numa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/arch_numa.c +1 -1
index db0bb8b8fd67..5df0ad5cb09d 100644
@@ -144,7 +144,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid)
 unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
 EXPORT_SYMBOL(__per_cpu_offset);
 
-static int __init early_cpu_to_node(unsigned int cpu)
+int early_cpu_to_node(unsigned int cpu)
 {
 	return cpu_to_node_map[cpu];
 }
Signature · 1 line
2.32.0.3.gf3a3e56d6
#8 lore raw

RFC PATCH 4/5 mm/numa: support CONFIG_NUMA_EMU for arm64

In reply to Rongwei Wang

The CONFIG_NUMA_EMU migrates from x86/Kconfig
to mm/Kconfig. Now x86 and arm64 support it.

---
 arch/x86/Kconfig             |   8 -
 arch/x86/mm/Makefile         |   1 -
 arch/x86/mm/numa_emulation.c | 585 -----------------------------------
 drivers/base/arch_numa.c     |   3 +
 include/asm-generic/numa.h   |  12 +
 mm/Kconfig                   |   8 +
 mm/numa.c                    |  12 +
 7 files changed, 35 insertions(+), 594 deletions(-)
 delete mode 100644 arch/x86/mm/numa_emulation.c
arch/x86/Kconfig +0 -8
index 66bfabae8814..13438bfe2ec1 100644
@@ -1568,14 +1568,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/mm/Makefile +0 -1
index c80febc44cd2..1581f17e5de4 100644
@@ -56,7 +56,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_emulation.c deleted +0 -585

585 lines not on this page · raw message

drivers/base/arch_numa.c +3 -0
index 5df0ad5cb09d..67bdbcd0caf9 100644
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/of.h>
 
+#include <asm-generic/numa.h>
 #include <asm/sections.h>
 
 struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
@@ -30,6 +31,8 @@ static __init int numa_parse_early_param(char *opt)
 		return -EINVAL;
 	if (str_has_prefix(opt, "off"))
 		numa_off = true;
+	if (!strncmp(opt, "fake=", 5))
+		return numa_emu_cmdline(opt + 5);
 
 	return 0;
 }
include/asm-generic/numa.h +12 -0
index 929d7c582a73..4658155a070a 100644
@@ -50,12 +50,24 @@ struct numa_meminfo {
 	struct numa_memblk	blk[NR_NODE_MEMBLKS];
 };
 
+#ifdef CONFIG_NUMA_EMU
+#define FAKE_NODE_MIN_SIZE	((u64)32 << 20)
+#define FAKE_NODE_MIN_HASH_MASK	(~(FAKE_NODE_MIN_SIZE - 1UL))
+
 extern struct numa_meminfo numa_meminfo;
+extern char *emu_cmdline __initdata;
 
+int numa_emu_cmdline(char *str);
 int __init numa_register_memblks(struct numa_meminfo *mi);
 int __init numa_cleanup_meminfo(struct numa_meminfo *mi);
 void __init numa_emulation(struct numa_meminfo *numa_meminfo,
 			   int numa_dist_cnt);
+#else
+static inline int numa_emu_cmdline(char *str)
+{
+	return -EINVAL;
+}
+#endif
 
 #else	/* CONFIG_NUMA */
 
mm/Kconfig +8 -0
index 264a2df5ecf5..22bead675ee6 100644
@@ -549,6 +549,14 @@ config ARCH_ENABLE_MEMORY_HOTPLUG
 config ARCH_ENABLE_MEMORY_HOTREMOVE
 	bool
 
+config NUMA_EMU
+	bool "NUMA emulation (EXPERIMENTAL)"
+	depends on NUMA && (X86 || ARM64)
+	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.
+
 # eventually, we can have this option just 'select SPARSEMEM'
 menuconfig MEMORY_HOTPLUG
 	bool "Memory hotplug"
mm/numa.c +12 -0
index 88277e8404f0..3cc01f06a2a6 100644
@@ -16,6 +16,10 @@
 struct numa_meminfo numa_meminfo __initdata_or_meminfo;
 struct numa_meminfo numa_reserved_meminfo __initdata_or_meminfo;
 
+#ifdef CONFIG_NUMA_EMU
+char *emu_cmdline __initdata;
+#endif
+
 /*
  * Set nodes, which have memory in @mi, in *@nodemask.
  */
@@ -296,3 +300,11 @@ int __weak __init numa_register_memblks(struct numa_meminfo *mi)
 
 	return 0;
 }
+
+#ifdef CONFIG_NUMA_EMU
+int __init numa_emu_cmdline(char *str)
+{
+	emu_cmdline = str;
+	return 0;
+}
+#endif
Signature · 1 line
2.32.0.3.gf3a3e56d6
#9 lore raw

Re: [PATCH RFC 4/5] mm/numa: support CONFIG_NUMA_EMU for arm64

kernel test robot noticed the following build warnings:

Hi Rongwei,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on driver-core/driver-core-testing]
[also build test WARNING on driver-core/driver-core-next driver-core/driver-core-linus linus/master v6.6-rc6] [cannot apply to akpm-mm/mm-everything tip/x86/mm next-20231020]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rongwei-Wang/mm-numa-move-numa-emulation-APIs-into-generic-files/20231017-143037
base:   driver-core/driver-core-testing
patch link:    https://lore.kernel.org/r/20231012024842.99703-5-rongwei.wang%40linux.alibaba.com
patch subject: [PATCH RFC 4/5] mm/numa: support CONFIG_NUMA_EMU for arm64
config: x86_64-buildonly-randconfig-002-20231020 (https://download.01.org/0day-ci/archive/20231020/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231020/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

| ^~
mm/numa.c: In function 'numa_clear_kernel_node_hotplug':
mm/numa.c:219:37: error: invalid use of undefined type 'struct numa_meminfo'

     219 |         for (i = 0; i < numa_meminfo.nr_blks; i++) {
         |                                     ^
   mm/numa.c:220:54: error: invalid use of undefined type 'struct numa_meminfo'
     220 |                 struct numa_memblk *mb = numa_meminfo.blk + i;
         |                                                      ^
   mm/numa.c:223:43: error: invalid use of undefined type 'struct numa_memblk'
     223 |                 ret = memblock_set_node(mb->start, mb->end - mb->start, &memblock.reserved, mb->nid);
         |                                           ^~
   mm/numa.c:223:54: error: invalid use of undefined type 'struct numa_memblk'
     223 |                 ret = memblock_set_node(mb->start, mb->end - mb->start, &memblock.reserved, mb->nid);
         |                                                      ^~
   mm/numa.c:223:64: error: invalid use of undefined type 'struct numa_memblk'
     223 |                 ret = memblock_set_node(mb->start, mb->end - mb->start, &memblock.reserved, mb->nid);
         |                                                                ^~
   mm/numa.c:223:95: error: invalid use of undefined type 'struct numa_memblk'
     223 |                 ret = memblock_set_node(mb->start, mb->end - mb->start, &memblock.reserved, mb->nid);
         |                                                                                               ^~
   mm/numa.c:251:37: error: invalid use of undefined type 'struct numa_meminfo'
     251 |         for (i = 0; i < numa_meminfo.nr_blks; i++) {
         |                                     ^
   mm/numa.c:252:54: error: invalid use of undefined type 'struct numa_meminfo'
     252 |                 struct numa_memblk *mb = numa_meminfo.blk + i;
         |                                                      ^
   In file included from include/linux/kernel.h:22:
   mm/numa.c:254:35: error: invalid use of undefined type 'struct numa_memblk'
     254 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                                   ^~
   include/linux/bitops.h:49:32: note: in definition of macro 'bitop'
      49 |         ((__builtin_constant_p(nr) &&                                   \
         |                                ^~
   include/linux/nodemask.h:153:36: note: in expansion of macro 'test_bit'
     153 | #define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
         |                                    ^~~~~~~~
   mm/numa.c:254:22: note: in expansion of macro 'node_isset'
     254 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                      ^~~~~~~~~~
   mm/numa.c:254:35: error: invalid use of undefined type 'struct numa_memblk'
     254 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                                   ^~
   include/linux/bitops.h:53:20: note: in definition of macro 'bitop'
      53 |          const##op(nr, addr) : op(nr, addr))
         |                    ^~
   include/linux/nodemask.h:153:36: note: in expansion of macro 'test_bit'
     153 | #define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
         |                                    ^~~~~~~~
   mm/numa.c:254:22: note: in expansion of macro 'node_isset'
     254 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                      ^~~~~~~~~~
   mm/numa.c:254:35: error: invalid use of undefined type 'struct numa_memblk'
     254 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                                   ^~
   include/linux/bitops.h:53:35: note: in definition of macro 'bitop'
      53 |          const##op(nr, addr) : op(nr, addr))
         |                                   ^~
   include/linux/nodemask.h:153:36: note: in expansion of macro 'test_bit'
     153 | #define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
         |                                    ^~~~~~~~
   mm/numa.c:254:22: note: in expansion of macro 'node_isset'
     254 |                 if (!node_isset(mb->nid, reserved_nodemask))
         |                      ^~~~~~~~~~
   mm/numa.c:257:42: error: invalid use of undefined type 'struct numa_memblk'
     257 |                 memblock_clear_hotplug(mb->start, mb->end - mb->start);
         |                                          ^~
   mm/numa.c:257:53: error: invalid use of undefined type 'struct numa_memblk'
     257 |                 memblock_clear_hotplug(mb->start, mb->end - mb->start);
         |                                                     ^~
   mm/numa.c:257:63: error: invalid use of undefined type 'struct numa_memblk'
     257 |                 memblock_clear_hotplug(mb->start, mb->end - mb->start);
         |                                                               ^~
   mm/numa.c: At top level:
   mm/numa.c:261:19: warning: no previous prototype for 'numa_register_memblks' [-Wmissing-prototypes]
     261 | int __weak __init numa_register_memblks(struct numa_meminfo *mi)
         |                   ^~~~~~~~~~~~~~~~~~~~~
   mm/numa.c: In function 'numa_register_memblks':
   mm/numa.c:266:29: error: 'numa_nodes_parsed' undeclared (first use in this function); did you mean 'numa_node_id'?
     266 |         node_possible_map = numa_nodes_parsed;
         |                             ^~~~~~~~~~~~~~~~~
         |                             numa_node_id
   mm/numa.c:271:27: error: invalid use of undefined type 'struct numa_meminfo'
     271 |         for (i = 0; i < mi->nr_blks; i++) {
         |                           ^~
   mm/numa.c:272:45: error: invalid use of undefined type 'struct numa_meminfo'
     272 |                 struct numa_memblk *mb = &mi->blk[i];
         |                                             ^~
   mm/numa.c:273:37: error: invalid use of undefined type 'struct numa_memblk'
     273 |                 memblock_set_node(mb->start, mb->end - mb->start,
         |                                     ^~
   mm/numa.c:273:48: error: invalid use of undefined type 'struct numa_memblk'
     273 |                 memblock_set_node(mb->start, mb->end - mb->start,
         |                                                ^~
   mm/numa.c:273:58: error: invalid use of undefined type 'struct numa_memblk'
     273 |                 memblock_set_node(mb->start, mb->end - mb->start,
         |                                                          ^~
   mm/numa.c:274:55: error: invalid use of undefined type 'struct numa_memblk'
     274 |                                   &memblock.memory, mb->nid);
         |                                                       ^~
   mm/numa.c: At top level:
>> mm/numa.c:305:12: warning: no previous prototype for 'numa_emu_cmdline' [-Wmissing-prototypes]
     305 | int __init numa_emu_cmdline(char *str)
         |            ^~~~~~~~~~~~~~~~
   mm/numa.c:16:21: error: storage size of 'numa_meminfo' isn't known
      16 | struct numa_meminfo numa_meminfo __initdata_or_meminfo;
         |                     ^~~~~~~~~~~~
   mm/numa.c:17:21: error: storage size of 'numa_reserved_meminfo' isn't known
      17 | struct numa_meminfo numa_reserved_meminfo __initdata_or_meminfo;
         |                     ^~~~~~~~~~~~~~~~~~~~~

vim +/numa_emu_cmdline +305 mm/numa.c

303
304 #ifdef CONFIG_NUMA_EMU

 > 305	int __init numa_emu_cmdline(char *str)
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#10 lore raw

RFC PATCH 5/5 mm/numa: migrate leftover numa emulation into mm/numa.c

In reply to Rongwei Wang

Here moving original x86/mm/numa_emulation.c into
mm/numa.c. And next to enable it for arm64.

---
 drivers/base/arch_numa.c   |   2 +
 include/asm-generic/numa.h |   3 +
 mm/numa.c                  | 586 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 587 insertions(+), 4 deletions(-)
drivers/base/arch_numa.c +2 -0
index 67bdbcd0caf9..c6f5ceadb9e1 100644
@@ -64,6 +64,7 @@ EXPORT_SYMBOL(cpumask_of_node);
 
 #endif
 
+#ifndef CONFIG_NUMA_EMU
 static void numa_update_cpu(unsigned int cpu, bool remove)
 {
 	int nid = cpu_to_node(cpu);
@@ -92,6 +93,7 @@ void numa_clear_node(unsigned int cpu)
 	numa_remove_cpu(cpu);
 	set_cpu_numa_node(cpu, NUMA_NO_NODE);
 }
+#endif
 
 /*
  * Allocate node_to_cpumask_map based on number of available nodes
include/asm-generic/numa.h +3 -0
index 4658155a070a..9969ec7f59a4 100644
@@ -55,6 +55,7 @@ struct numa_meminfo {
 #define FAKE_NODE_MIN_HASH_MASK	(~(FAKE_NODE_MIN_SIZE - 1UL))
 
 extern struct numa_meminfo numa_meminfo;
+extern int emu_nid_to_phys[MAX_NUMNODES];
 extern char *emu_cmdline __initdata;
 
 int numa_emu_cmdline(char *str);
@@ -62,6 +63,8 @@ int __init numa_register_memblks(struct numa_meminfo *mi);
 int __init numa_cleanup_meminfo(struct numa_meminfo *mi);
 void __init numa_emulation(struct numa_meminfo *numa_meminfo,
 			   int numa_dist_cnt);
+int __init numa_add_memblk_to(int nid, u64 start, u64 end,
+			      struct numa_meminfo *mi);
 #else
 static inline int numa_emu_cmdline(char *str)
 {
mm/numa.c +582 -4

605 lines not on this page · raw message

Signature · 1 line
2.32.0.3.gf3a3e56d6
#11 lore raw

Re: [PATCH RFC 5/5] mm/numa: migrate leftover numa emulation into mm/numa.c

kernel test robot noticed the following build errors:

Hi Rongwei,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on driver-core/driver-core-testing]
[also build test ERROR on driver-core/driver-core-next driver-core/driver-core-linus linus/master v6.6-rc6] [cannot apply to akpm-mm/mm-everything tip/x86/mm next-20231020]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rongwei-Wang/mm-numa-move-numa-emulation-APIs-into-generic-files/20231017-143037
base:   driver-core/driver-core-testing
patch link:    https://lore.kernel.org/r/20231012024842.99703-6-rongwei.wang%40linux.alibaba.com
patch subject: [PATCH RFC 5/5] mm/numa: migrate leftover numa emulation into mm/numa.c
config: x86_64-buildonly-randconfig-002-20231020 (https://download.01.org/0day-ci/archive/20231021/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231021/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

     339 |         struct numa_memblk *eb = &ei->blk[ei->nr_blks];
         |                                     ^~
   mm/numa.c:339:45: error: invalid use of undefined type 'struct numa_meminfo'
     339 |         struct numa_memblk *eb = &ei->blk[ei->nr_blks];
         |                                             ^~
   mm/numa.c:340:37: error: invalid use of undefined type 'struct numa_meminfo'
     340 |         struct numa_memblk *pb = &pi->blk[phys_blk];
         |                                     ^~
   mm/numa.c:342:15: error: invalid use of undefined type 'struct numa_meminfo'
     342 |         if (ei->nr_blks >= NR_NODE_MEMBLKS) {
         |               ^~
   mm/numa.c:342:28: error: 'NR_NODE_MEMBLKS' undeclared (first use in this function)
     342 |         if (ei->nr_blks >= NR_NODE_MEMBLKS) {
         |                            ^~~~~~~~~~~~~~~
   mm/numa.c:347:11: error: invalid use of undefined type 'struct numa_meminfo'
     347 |         ei->nr_blks++;
         |           ^~
   mm/numa.c:348:11: error: invalid use of undefined type 'struct numa_memblk'
     348 |         eb->start = pb->start;
         |           ^~
   mm/numa.c:348:23: error: invalid use of undefined type 'struct numa_memblk'
     348 |         eb->start = pb->start;
         |                       ^~
   mm/numa.c:349:11: error: invalid use of undefined type 'struct numa_memblk'
     349 |         eb->end = pb->start + size;
         |           ^~
   mm/numa.c:349:21: error: invalid use of undefined type 'struct numa_memblk'
     349 |         eb->end = pb->start + size;
         |                     ^~
   mm/numa.c:350:11: error: invalid use of undefined type 'struct numa_memblk'
     350 |         eb->nid = nid;
         |           ^~
   mm/numa.c:353:42: error: invalid use of undefined type 'struct numa_memblk'
     353 |                 emu_nid_to_phys[nid] = pb->nid;
         |                                          ^~
   mm/numa.c:355:11: error: invalid use of undefined type 'struct numa_memblk'
     355 |         pb->start += size;
         |           ^~
   mm/numa.c:356:15: error: invalid use of undefined type 'struct numa_memblk'
     356 |         if (pb->start >= pb->end) {
         |               ^~
   mm/numa.c:356:28: error: invalid use of undefined type 'struct numa_memblk'
     356 |         if (pb->start >= pb->end) {
         |                            ^~
   In file included from arch/x86/include/asm/bug.h:87,
                    from include/linux/bug.h:5,
                    from include/linux/thread_info.h:13:
   mm/numa.c:357:32: error: invalid use of undefined type 'struct numa_memblk'
     357 |                 WARN_ON_ONCE(pb->start > pb->end);
         |                                ^~
   include/asm-generic/bug.h:111:32: note: in definition of macro 'WARN_ON_ONCE'
     111 |         int __ret_warn_on = !!(condition);                      \
         |                                ^~~~~~~~~
   mm/numa.c:357:44: error: invalid use of undefined type 'struct numa_memblk'
     357 |                 WARN_ON_ONCE(pb->start > pb->end);
         |                                            ^~
   include/asm-generic/bug.h:111:32: note: in definition of macro 'WARN_ON_ONCE'
     111 |         int __ret_warn_on = !!(condition);                      \
         |                                ^~~~~~~~~
   mm/numa.c:362:23: error: invalid use of undefined type 'struct numa_memblk'
     362 |                nid, eb->start, eb->end - 1, (eb->end - eb->start) >> 20);
         |                       ^~
   include/linux/printk.h:427:33: note: in definition of macro 'printk_index_wrap'
     427 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                                 ^~~~~~~~~~~
   mm/numa.c:361:9: note: in expansion of macro 'printk'
     361 |         printk(KERN_INFO "Faking node %d at [mem %#018Lx-%#018Lx] (%LuMB)\n",
         |         ^~~~~~
   mm/numa.c:362:34: error: invalid use of undefined type 'struct numa_memblk'
     362 |                nid, eb->start, eb->end - 1, (eb->end - eb->start) >> 20);
         |                                  ^~
   include/linux/printk.h:427:33: note: in definition of macro 'printk_index_wrap'
     427 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                                 ^~~~~~~~~~~
   mm/numa.c:361:9: note: in expansion of macro 'printk'
     361 |         printk(KERN_INFO "Faking node %d at [mem %#018Lx-%#018Lx] (%LuMB)\n",
         |         ^~~~~~
   mm/numa.c:362:48: error: invalid use of undefined type 'struct numa_memblk'
     362 |                nid, eb->start, eb->end - 1, (eb->end - eb->start) >> 20);
         |                                                ^~
   include/linux/printk.h:427:33: note: in definition of macro 'printk_index_wrap'
     427 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                                 ^~~~~~~~~~~
   mm/numa.c:361:9: note: in expansion of macro 'printk'
     361 |         printk(KERN_INFO "Faking node %d at [mem %#018Lx-%#018Lx] (%LuMB)\n",
         |         ^~~~~~
   mm/numa.c:362:58: error: invalid use of undefined type 'struct numa_memblk'
     362 |                nid, eb->start, eb->end - 1, (eb->end - eb->start) >> 20);
         |                                                          ^~
   include/linux/printk.h:427:33: note: in definition of macro 'printk_index_wrap'
     427 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                                 ^~~~~~~~~~~
   mm/numa.c:361:9: note: in expansion of macro 'printk'
     361 |         printk(KERN_INFO "Faking node %d at [mem %#018Lx-%#018Lx] (%LuMB)\n",
         |         ^~~~~~
   mm/numa.c: In function 'split_nodes_interleave':
   mm/numa.c:376:36: error: 'numa_nodes_parsed' undeclared (first use in this function); did you mean 'numa_node_id'?
     376 |         nodemask_t physnode_mask = numa_nodes_parsed;
         |                                    ^~~~~~~~~~~~~~~~~
         |                                    numa_node_id
>> mm/numa.c:401:25: error: 'FAKE_NODE_MIN_HASH_MASK' undeclared (first use in this function)
     401 |         big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * nr_nodes) /
         |                         ^~~~~~~~~~~~~~~~~~~~~~~
>> mm/numa.c:402:17: error: 'FAKE_NODE_MIN_SIZE' undeclared (first use in this function)
     402 |                 FAKE_NODE_MIN_SIZE;
         |                 ^~~~~~~~~~~~~~~~~~
   mm/numa.c:428:35: error: invalid use of undefined type 'struct numa_meminfo'
     428 |                         start = pi->blk[phys_blk].start;
         |                                   ^~
   mm/numa.c:429:35: error: invalid use of undefined type 'struct numa_meminfo'
     429 |                         limit = pi->blk[phys_blk].end;
         |                                   ^~
   mm/numa.c: In function 'find_end_of_node':
   mm/numa.c:485:24: error: 'FAKE_NODE_MIN_SIZE' undeclared (first use in this function)
     485 |                 end += FAKE_NODE_MIN_SIZE;
         |                        ^~~~~~~~~~~~~~~~~~
   mm/numa.c: At top level:
   mm/numa.c:512:68: warning: 'struct numa_memblk' declared inside parameter list will not be visible outside of this definition or declaration
     512 |                                               int nr_nodes, struct numa_memblk *pblk,
         |                                                                    ^~~~~~~~~~~
   mm/numa.c: In function 'split_nodes_size_interleave_uniform':
   mm/numa.c:515:36: error: 'numa_nodes_parsed' undeclared (first use in this function); did you mean 'numa_node_id'?
     515 |         nodemask_t physnode_mask = numa_nodes_parsed;
         |                                    ^~~~~~~~~~~~~~~~~
         |                                    numa_node_id
   mm/numa.c:536:30: error: invalid use of undefined type 'struct numa_memblk'
     536 |                 node_set(pblk->nid, physnode_mask);
         |                              ^~
   include/linux/nodemask.h:128:41: note: in definition of macro 'node_set'
     128 | #define node_set(node, dst) __node_set((node), &(dst))
         |                                         ^~~~
   In file included from include/vdso/const.h:5,
                    from include/linux/const.h:4:
   mm/numa.c:554:40: error: 'FAKE_NODE_MIN_SIZE' undeclared (first use in this function)
     554 |         min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
         |                                        ^~~~~~~~~~~~~~~~~~
   include/uapi/linux/const.h:32:44: note: in definition of macro '__ALIGN_KERNEL_MASK'
      32 | #define __ALIGN_KERNEL_MASK(x, mask)    (((x) + (mask)) & ~(mask))
         |                                            ^
   include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
       8 | #define ALIGN(x, a)             __ALIGN_KERNEL((x), (a))
         |                                 ^~~~~~~~~~~~~~
   mm/numa.c:554:20: note: in expansion of macro 'ALIGN'
     554 |         min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
         |                    ^~~~~
   include/linux/minmax.h:27:18: note: in expansion of macro '__typecheck'
      27 |                 (__typecheck(x, y) && __no_side_effects(x, y))
         |                  ^~~~~~~~~~~
   include/linux/minmax.h:37:31: note: in expansion of macro '__safe_cmp'
      37 |         __builtin_choose_expr(__safe_cmp(x, y), \
         |                               ^~~~~~~~~~
   include/linux/minmax.h:75:25: note: in expansion of macro '__careful_cmp'
      75 | #define max(x, y)       __careful_cmp(x, y, >)
         |                         ^~~~~~~~~~~~~
   mm/numa.c:554:26: note: in expansion of macro 'max'
     554 |         min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
         |                          ^~~
   include/linux/minmax.h:37:9: error: first argument to '__builtin_choose_expr' not a constant
      37 |         __builtin_choose_expr(__safe_cmp(x, y), \
         |         ^~~~~~~~~~~~~~~~~~~~~
   include/uapi/linux/const.h:32:44: note: in definition of macro '__ALIGN_KERNEL_MASK'
      32 | #define __ALIGN_KERNEL_MASK(x, mask)    (((x) + (mask)) & ~(mask))
         |                                            ^
   include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
       8 | #define ALIGN(x, a)             __ALIGN_KERNEL((x), (a))
         |                                 ^~~~~~~~~~~~~~
   mm/numa.c:554:20: note: in expansion of macro 'ALIGN'
     554 |         min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
         |                    ^~~~~
   include/linux/minmax.h:75:25: note: in expansion of macro '__careful_cmp'
      75 | #define max(x, y)       __careful_cmp(x, y, >)
         |                         ^~~~~~~~~~~~~
   mm/numa.c:554:26: note: in expansion of macro 'max'
     554 |         min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
         |                          ^~~
   include/linux/minmax.h:37:9: error: first argument to '__builtin_choose_expr' not a constant
      37 |         __builtin_choose_expr(__safe_cmp(x, y), \
         |         ^~~~~~~~~~~~~~~~~~~~~
   include/uapi/linux/const.h:32:50: note: in definition of macro '__ALIGN_KERNEL_MASK'
      32 | #define __ALIGN_KERNEL_MASK(x, mask)    (((x) + (mask)) & ~(mask))
         |                                                  ^~~~
   include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
       8 | #define ALIGN(x, a)             __ALIGN_KERNEL((x), (a))
         |                                 ^~~~~~~~~~~~~~
   mm/numa.c:554:20: note: in expansion of macro 'ALIGN'
     554 |         min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
         |                    ^~~~~
   include/linux/minmax.h:75:25: note: in expansion of macro '__careful_cmp'
      75 | #define max(x, y)       __careful_cmp(x, y, >)
         |                         ^~~~~~~~~~~~~
   mm/numa.c:554:26: note: in expansion of macro 'max'
     554 |         min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
         |                          ^~~
   include/linux/minmax.h:37:9: error: first argument to '__builtin_choose_expr' not a constant
      37 |         __builtin_choose_expr(__safe_cmp(x, y), \
         |         ^~~~~~~~~~~~~~~~~~~~~
   include/uapi/linux/const.h:32:61: note: in definition of macro '__ALIGN_KERNEL_MASK'
      32 | #define __ALIGN_KERNEL_MASK(x, mask)    (((x) + (mask)) & ~(mask))
         |                                                             ^~~~
   include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
       8 | #define ALIGN(x, a)             __ALIGN_KERNEL((x), (a))
         |                                 ^~~~~~~~~~~~~~
   mm/numa.c:554:20: note: in expansion of macro 'ALIGN'
     554 |         min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
         |                    ^~~~~
   include/linux/minmax.h:75:25: note: in expansion of macro '__careful_cmp'
      75 | #define max(x, y)       __careful_cmp(x, y, >)
         |                         ^~~~~~~~~~~~~
   mm/numa.c:554:26: note: in expansion of macro 'max'
     554 |         min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
         |                          ^~~
   mm/numa.c:580:35: error: invalid use of undefined type 'struct numa_meminfo'
     580 |                         start = pi->blk[phys_blk].start;
         |                                   ^~
   mm/numa.c:581:35: error: invalid use of undefined type 'struct numa_meminfo'
     581 |                         limit = pi->blk[phys_blk].end;
         |                                   ^~
   mm/numa.c: At top level:
   mm/numa.c:669:13: warning: no previous prototype for 'numa_emulation' [-Wmissing-prototypes]
     669 | void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
         |             ^~~~~~~~~~~~~~
   mm/numa.c: In function 'numa_emulation':
   mm/numa.c:671:36: error: storage size of 'ei' isn't known
     671 |         static struct numa_meminfo ei __initdata;
         |                                    ^~
   mm/numa.c:672:36: error: storage size of 'pi' isn't known
     672 |         static struct numa_meminfo pi __initdata;
         |                                    ^~
   include/linux/fortify-string.h:515:65: warning: left-hand operand of comma expression has no effect [-Wunused-value]
     515 |         fortify_memset_chk(__fortify_size, p_size, p_size_field),       \
         |                                                                 ^
   include/linux/fortify-string.h:524:25: note: in expansion of macro '__fortify_memset_chk'
     524 | #define memset(p, c, s) __fortify_memset_chk(p, c, s,                   \
         |                         ^~~~~~~~~~~~~~~~~~~~
   mm/numa.c:682:9: note: in expansion of macro 'memset'
     682 |         memset(&ei, 0, sizeof(ei));
         |         ^~~~~~
   mm/numa.c:683:14: error: invalid use of undefined type 'struct numa_meminfo'
     683 |         pi = *numa_meminfo;
         |              ^
   mm/numa.c:694:44: error: 'numa_nodes_parsed' undeclared (first use in this function); did you mean 'numa_node_id'?
     694 |                 nodemask_t physnode_mask = numa_nodes_parsed;
         |                                            ^~~~~~~~~~~~~~~~~
         |                                            numa_node_id
   mm/numa.c:769:23: error: invalid use of undefined type 'struct numa_meminfo'
     769 |         *numa_meminfo = ei;
         |                       ^
   include/linux/build_bug.h:16:51: error: bit-field '<anonymous>' width not an integer constant
      16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
         |                                                   ^
   include/linux/compiler.h:231:33: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
     231 | #define __must_be_array(a)      BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
         |                                 ^~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:59: note: in expansion of macro '__must_be_array'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                           ^~~~~~~~~~~~~~~
   mm/numa.c:773:25: note: in expansion of macro 'ARRAY_SIZE'
     773 |         for (i = 0; i < ARRAY_SIZE(ei.blk); i++)
         |                         ^~~~~~~~~~
>> mm/numa.c:784:36: error: '__apicid_to_node' undeclared (first use in this function)
     784 |         for (i = 0; i < ARRAY_SIZE(__apicid_to_node); i++) {
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:33: note: in definition of macro 'ARRAY_SIZE'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                 ^~~
   include/linux/build_bug.h:16:51: error: bit-field '<anonymous>' width not an integer constant
      16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
         |                                                   ^
   include/linux/compiler.h:231:33: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
     231 | #define __must_be_array(a)      BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
         |                                 ^~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:59: note: in expansion of macro '__must_be_array'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                           ^~~~~~~~~~~~~~~
   mm/numa.c:784:25: note: in expansion of macro 'ARRAY_SIZE'
     784 |         for (i = 0; i < ARRAY_SIZE(__apicid_to_node); i++) {
         |                         ^~~~~~~~~~
   mm/numa.c:800:9: error: implicit declaration of function 'numa_free_distance' [-Werror=implicit-function-declaration]
     800 |         numa_free_distance();
         |         ^~~~~~~~~~~~~~~~~~
>> mm/numa.c:815:25: error: implicit declaration of function 'numa_set_distance'; did you mean 'node_distance'? [-Werror=implicit-function-declaration]
     815 |                         numa_set_distance(i, j, dist);
         |                         ^~~~~~~~~~~~~~~~~
         |                         node_distance
   mm/numa.c:672:36: warning: unused variable 'pi' [-Wunused-variable]
     672 |         static struct numa_meminfo pi __initdata;
         |                                    ^~
   mm/numa.c:671:36: warning: unused variable 'ei' [-Wunused-variable]
     671 |         static struct numa_meminfo ei __initdata;
         |                                    ^~
   mm/numa.c: At top level:
   mm/numa.c:830:12: error: conflicting types for 'early_cpu_to_node'; have 'int(unsigned int)'
     830 | extern int early_cpu_to_node(unsigned int cpu);
         |            ^~~~~~~~~~~~~~~~~
   In file included from include/linux/topology.h:36,
                    from include/linux/gfp.h:8:
   arch/x86/include/asm/topology.h:56:19: note: previous definition of 'early_cpu_to_node' with type 'int(int)'
      56 | static inline int early_cpu_to_node(int cpu)
         |                   ^~~~~~~~~~~~~~~~~
>> mm/numa.c:832:6: warning: no previous prototype for 'numa_add_cpu' [-Wmissing-prototypes]
     832 | void numa_add_cpu(unsigned int cpu)
         |      ^~~~~~~~~~~~
>> mm/numa.c:850:6: warning: no previous prototype for 'numa_remove_cpu' [-Wmissing-prototypes]
     850 | void numa_remove_cpu(unsigned int cpu)
         |      ^~~~~~~~~~~~~~~
   mm/numa.c:17:21: error: storage size of 'numa_meminfo' isn't known
      17 | struct numa_meminfo numa_meminfo __initdata_or_meminfo;
         |                     ^~~~~~~~~~~~
   mm/numa.c:18:21: error: storage size of 'numa_reserved_meminfo' isn't known
      18 | struct numa_meminfo numa_reserved_meminfo __initdata_or_meminfo;
         |                     ^~~~~~~~~~~~~~~~~~~~~
   mm/numa.c:672:36: warning: 'pi' defined but not used [-Wunused-variable]
     672 |         static struct numa_meminfo pi __initdata;
         |                                    ^~
   mm/numa.c:671:36: warning: 'ei' defined but not used [-Wunused-variable]
     671 |         static struct numa_meminfo ei __initdata;
         |                                    ^~

cc1: some warnings being treated as errors

vim +/FAKE_NODE_MIN_HASH_MASK +401 mm/numa.c

365
366 /*
367 * Sets up nr_nodes fake nodes interleaved over physical nodes ranging from addr
368 * to max_addr.
369 *
370 * Returns zero on success or negative on error.
371 */
372 static int __init split_nodes_interleave(struct numa_meminfo *ei,
373 struct numa_meminfo *pi,
374 u64 addr, u64 max_addr, int nr_nodes)
375 {
376 nodemask_t physnode_mask = numa_nodes_parsed;
377 u64 size;
378 int big;
379 int nid = 0;
380 int i, ret;
381
382 if (nr_nodes <= 0)
383 return -1;
384 if (nr_nodes > MAX_NUMNODES) {
385 pr_info("numa=fake=%d too large, reducing to %d\n",
386 nr_nodes, MAX_NUMNODES);
387 nr_nodes = MAX_NUMNODES;
388 }
389
390 /*
391 * Calculate target node size. x86_32 freaks on __udivdi3() so do
392 * the division in ulong number of pages and convert back.
393 */
394 size = max_addr - addr - mem_hole_size(addr, max_addr);
395 size = PFN_PHYS((unsigned long)(size >> PAGE_SHIFT) / nr_nodes);
396
397 /*
398 * Calculate the number of big nodes that can be allocated as a result
399 * of consolidating the remainder.
400 */

 > 401		big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * nr_nodes) /
 > 402			FAKE_NODE_MIN_SIZE;

403
404 size &= FAKE_NODE_MIN_HASH_MASK;
405 if (!size) {
406 pr_err("Not enough memory for each node. "
407 "NUMA emulation disabled.\n");
408 return -1;
409 }
410
411 /*
412 * Continue to fill physical nodes with fake nodes until there is no
413 * memory left on any of them.
414 */
415 while (!nodes_empty(physnode_mask)) {
416 for_each_node_mask(i, physnode_mask) {
417 #ifdef CONFIG_X86
418 u64 dma32_end = PFN_PHYS(MAX_DMA32_PFN);
419 #endif
420 u64 start, limit, end;
421 int phys_blk;
422
423 phys_blk = emu_find_memblk_by_nid(i, pi);
424 if (phys_blk < 0) {
425 node_clear(i, physnode_mask);
426 continue;
427 }
428 start = pi->blk[phys_blk].start;
429 limit = pi->blk[phys_blk].end;
430 end = start + size;
431
432 if (nid < big)
433 end += FAKE_NODE_MIN_SIZE;
434
435 /*
436 * Continue to add memory to this fake node if its
437 * non-reserved memory is less than the per-node size.
438 */
439 while (end - start - mem_hole_size(start, end) < size) {
440 end += FAKE_NODE_MIN_SIZE;
441 if (end > limit) {
442 end = limit;
443 break;
444 }
445 }
446

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#12 lore raw

Re: [PATCH RFC 5/5] mm/numa: migrate leftover numa emulation into mm/numa.c

In reply to Rongwei Wang
kernel test robot noticed the following build errors:

Hi Rongwei,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on driver-core/driver-core-testing]
[also build test ERROR on driver-core/driver-core-next driver-core/driver-core-linus linus/master v6.6-rc6] [cannot apply to akpm-mm/mm-everything tip/x86/mm next-20231020]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rongwei-Wang/mm-numa-move-numa-emulation-APIs-into-generic-files/20231017-143037
base:   driver-core/driver-core-testing
patch link:    https://lore.kernel.org/r/20231012024842.99703-6-rongwei.wang%40linux.alibaba.com
patch subject: [PATCH RFC 5/5] mm/numa: migrate leftover numa emulation into mm/numa.c
config: x86_64-buildonly-randconfig-005-20231020 (https://download.01.org/0day-ci/archive/20231021/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231021/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

     554 |         min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
         |                          ^~~
   include/linux/minmax.h:37:9: error: first argument to '__builtin_choose_expr' not a constant
      37 |         __builtin_choose_expr(__safe_cmp(x, y), \
         |         ^~~~~~~~~~~~~~~~~~~~~
   include/uapi/linux/const.h:32:61: note: in definition of macro '__ALIGN_KERNEL_MASK'
      32 | #define __ALIGN_KERNEL_MASK(x, mask)    (((x) + (mask)) & ~(mask))
         |                                                             ^~~~
   include/linux/align.h:8:33: note: in expansion of macro '__ALIGN_KERNEL'
       8 | #define ALIGN(x, a)             __ALIGN_KERNEL((x), (a))
         |                                 ^~~~~~~~~~~~~~
   mm/numa.c:554:20: note: in expansion of macro 'ALIGN'
     554 |         min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
         |                    ^~~~~
   include/linux/minmax.h:75:25: note: in expansion of macro '__careful_cmp'
      75 | #define max(x, y)       __careful_cmp(x, y, >)
         |                         ^~~~~~~~~~~~~
   mm/numa.c:554:26: note: in expansion of macro 'max'
     554 |         min_size = ALIGN(max(min_size, FAKE_NODE_MIN_SIZE), FAKE_NODE_MIN_SIZE);
         |                          ^~~
   mm/numa.c:580:35: error: invalid use of undefined type 'struct numa_meminfo'
     580 |                         start = pi->blk[phys_blk].start;
         |                                   ^~
   mm/numa.c:581:35: error: invalid use of undefined type 'struct numa_meminfo'
     581 |                         limit = pi->blk[phys_blk].end;
         |                                   ^~
   mm/numa.c: At top level:
   mm/numa.c:669:13: warning: no previous prototype for 'numa_emulation' [-Wmissing-prototypes]
     669 | void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
         |             ^~~~~~~~~~~~~~
   mm/numa.c: In function 'numa_emulation':
   mm/numa.c:671:36: error: storage size of 'ei' isn't known
     671 |         static struct numa_meminfo ei __initdata;
         |                                    ^~
   mm/numa.c:672:36: error: storage size of 'pi' isn't known
     672 |         static struct numa_meminfo pi __initdata;
         |                                    ^~
   include/linux/fortify-string.h:515:65: warning: left-hand operand of comma expression has no effect [-Wunused-value]
     515 |         fortify_memset_chk(__fortify_size, p_size, p_size_field),       \
         |                                                                 ^
   include/linux/fortify-string.h:524:25: note: in expansion of macro '__fortify_memset_chk'
     524 | #define memset(p, c, s) __fortify_memset_chk(p, c, s,                   \
         |                         ^~~~~~~~~~~~~~~~~~~~
   mm/numa.c:682:9: note: in expansion of macro 'memset'
     682 |         memset(&ei, 0, sizeof(ei));
         |         ^~~~~~
   mm/numa.c:683:14: error: invalid use of undefined type 'struct numa_meminfo'
     683 |         pi = *numa_meminfo;
         |              ^
   mm/numa.c:694:44: error: 'numa_nodes_parsed' undeclared (first use in this function); did you mean 'numa_node_id'?
     694 |                 nodemask_t physnode_mask = numa_nodes_parsed;
         |                                            ^~~~~~~~~~~~~~~~~
         |                                            numa_node_id
   mm/numa.c:769:23: error: invalid use of undefined type 'struct numa_meminfo'
     769 |         *numa_meminfo = ei;
         |                       ^
   include/linux/build_bug.h:16:51: error: bit-field '<anonymous>' width not an integer constant
      16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
         |                                                   ^
   include/linux/compiler.h:231:33: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
     231 | #define __must_be_array(a)      BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
         |                                 ^~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:59: note: in expansion of macro '__must_be_array'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                           ^~~~~~~~~~~~~~~
   mm/numa.c:773:25: note: in expansion of macro 'ARRAY_SIZE'
     773 |         for (i = 0; i < ARRAY_SIZE(ei.blk); i++)
         |                         ^~~~~~~~~~
   mm/numa.c:784:36: error: '__apicid_to_node' undeclared (first use in this function); did you mean '__cpu_to_node'?
     784 |         for (i = 0; i < ARRAY_SIZE(__apicid_to_node); i++) {
         |                                    ^~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:33: note: in definition of macro 'ARRAY_SIZE'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                 ^~~
   include/linux/build_bug.h:16:51: error: bit-field '<anonymous>' width not an integer constant
      16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
         |                                                   ^
   include/linux/compiler.h:231:33: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
     231 | #define __must_be_array(a)      BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
         |                                 ^~~~~~~~~~~~~~~~~
   include/linux/kernel.h:57:59: note: in expansion of macro '__must_be_array'
      57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                           ^~~~~~~~~~~~~~~
   mm/numa.c:784:25: note: in expansion of macro 'ARRAY_SIZE'
     784 |         for (i = 0; i < ARRAY_SIZE(__apicid_to_node); i++) {
         |                         ^~~~~~~~~~
   mm/numa.c:800:9: error: implicit declaration of function 'numa_free_distance' [-Werror=implicit-function-declaration]
     800 |         numa_free_distance();
         |         ^~~~~~~~~~~~~~~~~~
   mm/numa.c:815:25: error: implicit declaration of function 'numa_set_distance'; did you mean 'node_distance'? [-Werror=implicit-function-declaration]
     815 |                         numa_set_distance(i, j, dist);
         |                         ^~~~~~~~~~~~~~~~~
         |                         node_distance
   mm/numa.c:672:36: warning: unused variable 'pi' [-Wunused-variable]
     672 |         static struct numa_meminfo pi __initdata;
         |                                    ^~
   mm/numa.c:671:36: warning: unused variable 'ei' [-Wunused-variable]
     671 |         static struct numa_meminfo ei __initdata;
         |                                    ^~
   mm/numa.c: In function 'numa_set_cpumask':
>> mm/numa.c:874:17: error: implicit declaration of function 'debug_cpumask_set_cpu'; did you mean 'cpumask_set_cpu'? [-Werror=implicit-function-declaration]
     874 |                 debug_cpumask_set_cpu(cpu, nid, enable);
         |                 ^~~~~~~~~~~~~~~~~~~~~
         |                 cpumask_set_cpu
   mm/numa.c: At top level:
   mm/numa.c:878:6: warning: no previous prototype for 'numa_add_cpu' [-Wmissing-prototypes]
     878 | void numa_add_cpu(unsigned int cpu)
         |      ^~~~~~~~~~~~
   mm/numa.c:883:6: warning: no previous prototype for 'numa_remove_cpu' [-Wmissing-prototypes]
     883 | void numa_remove_cpu(unsigned int cpu)
         |      ^~~~~~~~~~~~~~~
   mm/numa.c:17:21: error: storage size of 'numa_meminfo' isn't known
      17 | struct numa_meminfo numa_meminfo __initdata_or_meminfo;
         |                     ^~~~~~~~~~~~
   mm/numa.c:18:21: error: storage size of 'numa_reserved_meminfo' isn't known
      18 | struct numa_meminfo numa_reserved_meminfo __initdata_or_meminfo;
         |                     ^~~~~~~~~~~~~~~~~~~~~
   mm/numa.c:672:36: warning: 'pi' defined but not used [-Wunused-variable]
     672 |         static struct numa_meminfo pi __initdata;
         |                                    ^~
   mm/numa.c:671:36: warning: 'ei' defined but not used [-Wunused-variable]
     671 |         static struct numa_meminfo ei __initdata;
         |                                    ^~

cc1: some warnings being treated as errors

vim +874 mm/numa.c

849
850 void numa_remove_cpu(unsigned int cpu)
851 {
852 int i;
853
854 for_each_online_node(i)
855 cpumask_clear_cpu(cpu, node_to_cpumask_map[i]);
856 }
857 #else /* !CONFIG_DEBUG_PER_CPU_MAPS */
858 static void numa_set_cpumask(int cpu, bool enable)
859 {
860 int nid, physnid;
861
862 nid = early_cpu_to_node(cpu);
863 if (nid == NUMA_NO_NODE) {
864 /* early_cpu_to_node() already emits a warning and trace */
865 return;
866 }
867
868 physnid = emu_nid_to_phys[nid];
869
870 for_each_online_node(nid) {
871 if (emu_nid_to_phys[nid] != physnid)
872 continue;
873

 > 874			debug_cpumask_set_cpu(cpu, nid, enable);

875 }
876 }
877

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#13 lore raw
In reply to Rongwei Wang

Hello Rongwei,

Quoted 62 lines · Rongwei Wang

A brief introduction
====================

The NUMA emulation can fake more node base on a single node system, e.g.

one node system:

[root@localhost ~]# numactl -H
available: 1 nodes (0)
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 31788 MB
node 0 free: 31446 MB
node distances:
node 0
0: 10

add numa=fake=2 (fake 2 node on each origin node):

[root@localhost ~]# numactl -H
available: 2 nodes (0-1)
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 15806 MB
node 0 free: 15451 MB
node 1 cpus: 0 1 2 3 4 5 6 7
node 1 size: 16029 MB
node 1 free: 15989 MB
node distances:

node   0   1
   0:  10  10
   1:  10  10

As above shown, a new node has been faked. As cpus, the realization of x86 NUMA emulation is kept. Maybe each node should has 4 cores is better (not sure, next to do if so).

Why do this
===========

It seems has following reasons:
(1) In x86 host, apply NUMA emulation can fake more nodes environment to test or verify some performance stuff, but arm64 only has one method that modify ACPI table to do this. It's troublesome more or less.
(2) Reduce competition for some locks. Here an example we found:

       will-it-scale/tlb_flush1_processes -t 96 -s 10, it shows obvious
       hotspot on lruvec->lock when test in single environment. What's
       more, The performance improved greatly if test in two more nodes
       system. The data shows below (more is better):

       ---------------------------------------------------------------------
       threads/process |   1     |     12   |     24   |   48     |   96
       ---------------------------------------------------------------------
       one node        | 14 1122 | 110 5372 | 111 2615 | 79 7084  | 72 4516
       ---------------------------------------------------------------------
       numa=fake=2     | 14 1168 | 144 4848 | 215 9070 | 157 0412 | 142 3968
       ---------------------------------------------------------------------
                       | For concurrency 12, no lruvec->lock hotspot. For 24,
       hotspot         | one node has 24% hotspot on lruvec->lock, but
                       | two nodes env hasn't.
       ---------------------------------------------------------------------
Quoted 3 lines

As for risks (e.g. numa balance...), they need to be discussed here.

Lastly, this just is a draft, I can improve next if it's acceptable.

I'm not engaging on the utility/relevance of the patch-set, but I tried them on an arm64 system with the 'numa=fake=2' parameter and could not see 2 nodes being created under:
/sys/devices/system/node/
Indeed it seems that even though numa_emulation() is moved to a generic mm/numa.c file, the function is only called from:
arch/x86/mm/numa.c:numa_init()
(or maybe I'm misinterpreting the intent of the patches).

Also I had the following errors when building (still for arm64):
mm/numa.c:862:8: error: implicit declaration of function 'early_cpu_to_node' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

        nid = early_cpu_to_node(cpu);
              ^
mm/numa.c:862:8: note: did you mean 'early_map_cpu_to_node'?
./include/asm-generic/numa.h:37:13: note: 'early_map_cpu_to_node' declared here
void __init early_map_cpu_to_node(unsigned int cpu, int nid);
            ^
mm/numa.c:874:3: error: implicit declaration of function 'debug_cpumask_set_cpu' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                debug_cpumask_set_cpu(cpu, nid, enable);
                ^
mm/numa.c:874:3: note: did you mean '__cpumask_set_cpu'?
./include/linux/cpumask.h:474:29: note: '__cpumask_set_cpu' declared here
static __always_inline void __cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
                            ^

2 errors generated.

Regards,
Pierre

Quoted 24 lines

Thanks!

Rongwei Wang (5):
mm/numa: move numa emulation APIs into generic files
mm: percpu: fix variable type of cpu
arch_numa: remove __init in early_cpu_to_node() mm/numa: support CONFIG_NUMA_EMU for arm64 mm/numa: migrate leftover numa emulation into mm/numa.c

  arch/x86/Kconfig                          |   8 -
  arch/x86/include/asm/numa.h               |   3 -
  arch/x86/mm/Makefile                      |   1 -
  arch/x86/mm/numa.c                        | 216 +-------------
  arch/x86/mm/numa_internal.h               |  14 +-
  drivers/base/arch_numa.c                  |   7 +-
  include/asm-generic/numa.h                |  33 +++
  include/linux/percpu.h                    |   2 +-
  mm/Kconfig                                |   8 +
  mm/Makefile                               |   1 +
  arch/x86/mm/numa_emulation.c => mm/numa.c | 333 +++++++++++++++++++++-
  11 files changed, 373 insertions(+), 253 deletions(-)

rename arch/x86/mm/numa_emulation.c => mm/numa.c (63%)

#14 lore raw
Quoted 65 lines · Pierre Gondois

Hello Rongwei,

Quoted 62 lines · Rongwei Wang

A brief introduction
====================

The NUMA emulation can fake more node base on a single node system, e.g.

one node system:

[root@localhost ~]# numactl -H
available: 1 nodes (0)
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 31788 MB
node 0 free: 31446 MB
node distances:
node   0
   0:  10

add numa=fake=2 (fake 2 node on each origin node):

[root@localhost ~]# numactl -H
available: 2 nodes (0-1)
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 15806 MB
node 0 free: 15451 MB
node 1 cpus: 0 1 2 3 4 5 6 7
node 1 size: 16029 MB
node 1 free: 15989 MB
node distances:
node   0   1
   0:  10  10
   1:  10  10

As above shown, a new node has been faked. As cpus, the realization of x86 NUMA emulation is kept. Maybe each node should has 4 cores is better (not sure, next to do if so).

Why do this
===========

It seems has following reasons:
   (1) In x86 host, apply NUMA emulation can fake more nodes environment to test or verify some performance stuff, but arm64 only has one method that modify ACPI table to do this. It's troublesome more or less.
   (2) Reduce competition for some locks. Here an example we found:
       will-it-scale/tlb_flush1_processes -t 96 -s 10, it shows obvious hotspot on lruvec->lock when test in single environment. What's more, The performance improved greatly if test in two more nodes system. The data shows below (more is better):

---------------------------------------------------------------------
       threads/process |   1     |     12   |     24   | 48     |   96
---------------------------------------------------------------------
       one node        | 14 1122 | 110 5372 | 111 2615 | 79 7084  | 72 4516
---------------------------------------------------------------------
       numa=fake=2     | 14 1168 | 144 4848 | 215 9070 | 157 0412 | 142 3968
---------------------------------------------------------------------
                       | For concurrency 12, no lruvec->lock hotspot. For 24, hotspot         | one node has 24% hotspot on lruvec->lock, but | two nodes env hasn't.
---------------------------------------------------------------------

Quoted 6 lines
Quoted 3 lines

As for risks (e.g. numa balance...), they need to be discussed here.

Lastly, this just is a draft, I can improve next if it's acceptable.

I'm not engaging on the utility/relevance of the patch-set, but I tried them on an arm64 system with the 'numa=fake=2' parameter and could not

Sorry, my fault.

I should mention this in previous brief introduction: acpi=on numa=fake=2.

The default patch of arm64 numa initialize is numa_init() -> dummy_numa_init() if turn off acpi (this path has not been taken into account yet in this patch, next will to do).

What's more, if you test these patchset in qemu-kvm, you should add below parameters in the script.

object memory-backend-ram,id=mem0,size=32G \
numa node,memdev=mem0,cpus=0-7,nodeid=0 \

(Above parameters just make sure SRAT table has NUMA configure, avoiding path of numa_init() -> dummy_numa_init())

Quoted 6 lines

see 2 nodes being created under:
  /sys/devices/system/node/
Indeed it seems that even though numa_emulation() is moved to a generic mm/numa.c file, the function is only called from:
  arch/x86/mm/numa.c:numa_init()
(or maybe I'm misinterpreting the intent of the patches).

Here drivers/base/arch_numa.c:numa_init() has called numa_emulation() (I guess it works if you add acpi=on :-)).

Quoted 4 lines

Also I had the following errors when building (still for arm64):
mm/numa.c:862:8: error: implicit declaration of function 'early_cpu_to_node' is invalid in C99 [-Werror,-Wimplicit-function-declaration] nid = early_cpu_to_node(cpu);

It seems CONFIG_DEBUG_PER_CPU_MAPS enabled in your environment? You can disable CONFIG_DEBUG_PER_CPU_MAPS and test it again.

I have not test it with CONFIG_DEBUG_PER_CPU_MAPS enabled. It's very helpful, I will fix it next time.

If you have any questions, please let me know.

Regards,

-wrw

Quoted 41 lines

^
mm/numa.c:862:8: note: did you mean 'early_map_cpu_to_node'?
./include/asm-generic/numa.h:37:13: note: 'early_map_cpu_to_node' declared here
void __init early_map_cpu_to_node(unsigned int cpu, int nid);
            ^
mm/numa.c:874:3: error: implicit declaration of function 'debug_cpumask_set_cpu' is invalid in C99 [-Werror,-Wimplicit-function-declaration] debug_cpumask_set_cpu(cpu, nid, enable);
                ^
mm/numa.c:874:3: note: did you mean '__cpumask_set_cpu'?
./include/linux/cpumask.h:474:29: note: '__cpumask_set_cpu' declared here
static __always_inline void __cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
                            ^
2 errors generated.

Regards,
Pierre

Quoted 24 lines

Thanks!

Rongwei Wang (5):
   mm/numa: move numa emulation APIs into generic files
   mm: percpu: fix variable type of cpu
   arch_numa: remove __init in early_cpu_to_node() mm/numa: support CONFIG_NUMA_EMU for arm64 mm/numa: migrate leftover numa emulation into mm/numa.c

  arch/x86/Kconfig                          |   8 - arch/x86/include/asm/numa.h               |   3 - arch/x86/mm/Makefile                      |   1 - arch/x86/mm/numa.c                        | 216 +------------- arch/x86/mm/numa_internal.h               |  14 +- drivers/base/arch_numa.c                  |   7 +- include/asm-generic/numa.h                |  33 +++ include/linux/percpu.h                    |   2 +- mm/Kconfig                                |   8 + mm/Makefile                               |   1 + arch/x86/mm/numa_emulation.c => mm/numa.c | 333 +++++++++++++++++++++-

  11 files changed, 373 insertions(+), 253 deletions(-)

  rename arch/x86/mm/numa_emulation.c => mm/numa.c (63%)

#15 lore raw

Hello Rongwei,

Quoted 101 lines · Rongwei Wang
Quoted 68 lines · Pierre Gondois

Hello Rongwei,

Quoted 65 lines · Rongwei Wang

A brief introduction
====================

The NUMA emulation can fake more node base on a single node system, e.g.

one node system:

[root@localhost ~]# numactl -H
available: 1 nodes (0)
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 31788 MB
node 0 free: 31446 MB
node distances:
node   0
   0:  10

add numa=fake=2 (fake 2 node on each origin node):

[root@localhost ~]# numactl -H
available: 2 nodes (0-1)
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 15806 MB
node 0 free: 15451 MB
node 1 cpus: 0 1 2 3 4 5 6 7
node 1 size: 16029 MB
node 1 free: 15989 MB
node distances:
node   0   1
   0:  10  10
   1:  10  10

As above shown, a new node has been faked. As cpus, the realization of x86 NUMA emulation is kept. Maybe each node should has 4 cores is better (not sure, next to do if so).

Why do this
===========

It seems has following reasons:
   (1) In x86 host, apply NUMA emulation can fake more nodes environment to test or verify some performance stuff, but arm64 only has one method that modify ACPI table to do this. It's troublesome more or less.
   (2) Reduce competition for some locks. Here an example we found:
       will-it-scale/tlb_flush1_processes -t 96 -s 10, it shows obvious hotspot on lruvec->lock when test in single environment. What's more, The performance improved greatly if test in two more nodes system. The data shows below (more is better):

---------------------------------------------------------------------

        threads/process |   1     |     12   |     24   | 48     |   96

---------------------------------------------------------------------
       one node        | 14 1122 | 110 5372 | 111 2615 | 79 7084  |
72 4516
---------------------------------------------------------------------
       numa=fake=2     | 14 1168 | 144 4848 | 215 9070 | 157 0412 |
142 3968
---------------------------------------------------------------------
                       | For concurrency 12, no lruvec->lock hotspot.
For 24,
       hotspot         | one node has 24% hotspot on lruvec->lock, but | two nodes env hasn't.
---------------------------------------------------------------------

Quoted 6 lines
Quoted 3 lines

As for risks (e.g. numa balance...), they need to be discussed here.

Lastly, this just is a draft, I can improve next if it's acceptable.

I'm not engaging on the utility/relevance of the patch-set, but I tried them on an arm64 system with the 'numa=fake=2' parameter and could not

Sorry, my fault.

I should mention this in previous brief introduction: acpi=on numa=fake=2.

The default patch of arm64 numa initialize is numa_init() -> dummy_numa_init() if turn off acpi (this path has not been taken into account yet in this patch, next will to do).

What's more, if you test these patchset in qemu-kvm, you should add below parameters in the script.

object memory-backend-ram,id=mem0,size=32G \
numa node,memdev=mem0,cpus=0-7,nodeid=0 \

(Above parameters just make sure SRAT table has NUMA configure, avoiding path of numa_init() -> dummy_numa_init())

Quoted 6 lines

see 2 nodes being created under:
  /sys/devices/system/node/
Indeed it seems that even though numa_emulation() is moved to a generic mm/numa.c file, the function is only called from:
  arch/x86/mm/numa.c:numa_init()
(or maybe I'm misinterpreting the intent of the patches).

Quoted 2 lines

Here drivers/base/arch_numa.c:numa_init() has called numa_emulation() (I guess it works if you add acpi=on :-)).

I don't see numa_emulation() being called from drivers/base/arch_numa.c:numa_init()

I have:

  $ git grep numa_emulation
  arch/x86/mm/numa.c:     numa_emulation(&numa_meminfo, numa_distance_cnt);
  arch/x86/mm/numa_internal.h:extern void __init numa_emulation(struct numa_meminfo *numa_meminfo,
  include/asm-generic/numa.h:void __init numa_emulation(struct numa_meminfo *numa_meminfo,
  mm/numa.c:/* Most of this file comes from x86/numa_emulation.c */
  mm/numa.c: * numa_emulation - Emulate NUMA nodes
  mm/numa.c:void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
so from this, an arm64-based platform should not be able to call numa_emulation().

Is it possible to add a call to dump_stack() in numa_emulation() to see the call stack ?

The branch I'm using is based on v6.6-rc5 and has the 5 patches applied:
2af398a87cc7 mm/numa: migrate leftover numa emulation into mm/numa.c c8e314fb23be mm/numa: support CONFIG_NUMA_EMU for arm64 335b7219d40e arch_numa: remove __init in early_cpu_to_node() d9358adf1cdc mm: percpu: fix variable type of cpu 1ffbe40a00f5 mm/numa: move numa emulation APIs into generic files 94f6f0550c62 (tag: v6.6-rc5) Linux 6.6-rc5

Regards,
Pierre

Quoted 66 lines
Quoted 8 lines

Also I had the following errors when building (still for arm64):
mm/numa.c:862:8: error: implicit declaration of function 'early_cpu_to_node' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        nid = early_cpu_to_node(cpu);

It seems CONFIG_DEBUG_PER_CPU_MAPS enabled in your environment? You can disable CONFIG_DEBUG_PER_CPU_MAPS and test it again.

I have not test it with CONFIG_DEBUG_PER_CPU_MAPS enabled. It's very helpful, I will fix it next time.

If you have any questions, please let me know.

Regards,

-wrw

Quoted 45 lines

^
mm/numa.c:862:8: note: did you mean 'early_map_cpu_to_node'? ./include/asm-generic/numa.h:37:13: note: 'early_map_cpu_to_node' declared here
void __init early_map_cpu_to_node(unsigned int cpu, int nid);
            ^
mm/numa.c:874:3: error: implicit declaration of function 'debug_cpumask_set_cpu' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                debug_cpumask_set_cpu(cpu, nid, enable);
                ^
mm/numa.c:874:3: note: did you mean '__cpumask_set_cpu'? ./include/linux/cpumask.h:474:29: note: '__cpumask_set_cpu' declared here static __always_inline void __cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
                            ^
2 errors generated.

Regards,
Pierre

Quoted 24 lines

Thanks!

Rongwei Wang (5):
   mm/numa: move numa emulation APIs into generic files
   mm: percpu: fix variable type of cpu
   arch_numa: remove __init in early_cpu_to_node() mm/numa: support CONFIG_NUMA_EMU for arm64 mm/numa: migrate leftover numa emulation into mm/numa.c

   arch/x86/Kconfig                          |   8 -
   arch/x86/include/asm/numa.h               |   3 -
   arch/x86/mm/Makefile                      |   1 -
   arch/x86/mm/numa.c                        | 216 +-------------
   arch/x86/mm/numa_internal.h               |  14 +-
   drivers/base/arch_numa.c                  |   7 +-
   include/asm-generic/numa.h                |  33 +++
   include/linux/percpu.h                    |   2 +-
   mm/Kconfig                                |   8 +
   mm/Makefile                               |   1 +
   arch/x86/mm/numa_emulation.c => mm/numa.c | 333 +++++++++++++++++++++-
   11 files changed, 373 insertions(+), 253 deletions(-)

  rename arch/x86/mm/numa_emulation.c => mm/numa.c (63%)

#16 lore raw

cover support NUMA emulation for genertic arch

In reply to Rongwei Wang

A brief introduction
====================

The NUMA emulation can fake more node base on a single node system, e.g.

one node system:

[root@localhost ~]# numactl -H
available: 1 nodes (0)
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 31788 MB
node 0 free: 31446 MB
node distances:
node 0
0: 10

add numa=fake=2 (fake 2 node on each origin node):

[root@localhost ~]# numactl -H
available: 2 nodes (0-1)
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 15806 MB
node 0 free: 15451 MB
node 1 cpus: 0 1 2 3 4 5 6 7
node 1 size: 16029 MB
node 1 free: 15989 MB
node distances:
node 0 1

  0:  10  10
  1:  10  10

As above shown, a new node has been faked. As cpus, the realization of x86 NUMA emulation is kept. Maybe each node should has 4 cores is better (not sure, next to do if so).

Why do this
===========

It seems has following reasons:
(1) In x86 host, apply NUMA emulation can fake more nodes environment to test or verify some performance stuff, but arm64 only has one method that modify ACPI table to do this. It's troublesome more or less.
(2) Reduce competition for some locks. Here an example we found:

      will-it-scale/tlb_flush1_processes -t 96 -s 10, it shows obvious
      hotspot on lruvec->lock when test in single environment. What's
      more, The performance improved greatly if test in two more nodes
      system. The data shows below (more is better):

      ---------------------------------------------------------------------
      threads/process |   1     |     12   |     24   |   48     |   96
      ---------------------------------------------------------------------
      one node        | 14 1122 | 110 5372 | 111 2615 | 79 7084  | 72 4516
      ---------------------------------------------------------------------
      numa=fake=2     | 14 1168 | 144 4848 | 215 9070 | 157 0412 | 142 3968
      ---------------------------------------------------------------------
                      | For concurrency 12, no lruvec->lock hotspot. For 24,
      hotspot         | one node has 24% hotspot on lruvec->lock, but
                      | two nodes env hasn't.
      ---------------------------------------------------------------------

As for risks (e.g. numa balance...), they need to be discussed here.

Lastly, it seems not a good choice to realize x86 and other genertic archs separately. But it can indeed avoid some architecture related APIs adjustments and alleviate future maintenance. The previous RFC link see [1].

Any advice are welcome, Thanks!

Change log
==========

RFC v1 -> v1
* add new CONFIG_NUMA_FAKE for genertic archs.
* keep x86 implementation, realize numa emulation in driver/base/ for genertic arch, e.g, arm64.

[1] RFC v1: https://patchwork.kernel.org/project/linux-arm-kernel/cover/[email protected]/

Rongwei Wang (2):
arch_numa: remove __init for early_cpu_to_node
numa: introduce numa emulation for genertic arch

 drivers/base/Kconfig          |   9 +
 drivers/base/Makefile         |   1 +
 drivers/base/arch_numa.c      |  32 +-
 drivers/base/numa_emulation.c | 909 ++++++++++++++++++++++++++++++++++
 drivers/base/numa_emulation.h |  41 ++
 include/asm-generic/numa.h    |   2 +-
 6 files changed, 992 insertions(+), 2 deletions(-)
 create mode 100644 drivers/base/numa_emulation.c
 create mode 100644 drivers/base/numa_emulation.h
Signature · 1 line
2.32.0.3.gf3a3e56d6
#17 lore raw

PATCH 1/2 arch_numa: remove __init for early_cpu_to_node

Next, in order to support other arch, early_cpu_to_node() will be called in a general function. We have to delete '__init' to avoid warning messages during compiling.

---
 drivers/base/arch_numa.c   | 2 +-
 include/asm-generic/numa.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/base/arch_numa.c +1 -1
index 5b59d133b6af..90519d981471 100644
@@ -144,7 +144,7 @@ void __init early_map_cpu_to_node(unsigned int cpu, int nid)
 unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
 EXPORT_SYMBOL(__per_cpu_offset);
 
-int __init early_cpu_to_node(int cpu)
+int early_cpu_to_node(int cpu)
 {
 	return cpu_to_node_map[cpu];
 }
include/asm-generic/numa.h +1 -1
index c32e0cf23c90..16073111bffc 100644
@@ -35,7 +35,7 @@ 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);
+int early_cpu_to_node(int cpu);
 void numa_store_cpu_info(unsigned int cpu);
 void numa_add_cpu(unsigned int cpu);
 void numa_remove_cpu(unsigned int cpu);
Signature · 1 line
2.32.0.3.gf3a3e56d6
#18 lore raw

PATCH 2/2 numa: introduce numa emulation for genertic arch

In reply to Rongwei Wang

Currently, x86 has already support numa
emulation for a long time. That's enabled
by CONFIG_NUMA_EMU. This patch mainly to
introduce numa emulation for genertic
arch (refer to x86 implementation).

In order to avoid changing APIs (especially
related to NUMA), and more coupling, maintaining
x86 and other genertic archs separately
would be a better choice. So a new configure
CONFIG_NUMA_FAKE used to enable it, also avoid
some conflicts with CONFIG_NUMA_EMU.

---
 drivers/base/Kconfig          |   9 +
 drivers/base/Makefile         |   1 +
 drivers/base/arch_numa.c      |  30 ++
 drivers/base/numa_emulation.c | 909 ++++++++++++++++++++++++++++++++++
 drivers/base/numa_emulation.h |  41 ++
 5 files changed, 990 insertions(+)
 create mode 100644 drivers/base/numa_emulation.c
 create mode 100644 drivers/base/numa_emulation.h
drivers/base/Kconfig +9 -0
index 2b8fd6bb7da0..c162aedf1458 100644
@@ -230,6 +230,15 @@ config GENERIC_ARCH_NUMA
 	  Enable support for generic NUMA implementation. Currently, RISC-V
 	  and ARM64 use it.
 
+config NUMA_FAKE
+	bool "NUMA emulation"
+	depends on NUMA
+	depends on GENERIC_ARCH_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 FW_DEVLINK_SYNC_STATE_TIMEOUT
 	bool "sync_state() behavior defaults to timeout instead of strict"
 	help
drivers/base/Makefile +1 -0
index 3079bfe53d04..23976a1babae 100644
@@ -34,3 +34,4 @@ ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o		:= -I$(src)
 obj-$(CONFIG_TRACING)	+= trace.o
+obj-$(CONFIG_NUMA_FAKE)	+=  numa_emulation.o
drivers/base/arch_numa.c +30 -0
index 90519d981471..77ea423e2bf9 100644
@@ -24,12 +24,25 @@ static int numa_distance_cnt;
 static u8 *numa_distance;
 bool numa_off;
 
+#ifdef CONFIG_NUMA_FAKE
+extern struct numa_meminfo numa_meminfo;
+
+extern void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt);
+extern int __init numa_cleanup_meminfo(struct numa_meminfo *mi);
+extern int __init numa_register_memblks(struct numa_meminfo *mi);
+extern int __init numa_add_memblk_to(int nid, u64 start, u64 end,
+				     struct numa_meminfo *mi);
+extern int __init numa_emu_cmdline(char *str);
+#endif
+
 static __init int numa_parse_early_param(char *opt)
 {
 	if (!opt)
 		return -EINVAL;
 	if (str_has_prefix(opt, "off"))
 		numa_off = true;
+	if (!strncmp(opt, "fake=", 5))
+		return numa_emu_cmdline(opt + 5);
 
 	return 0;
 }
@@ -61,6 +74,7 @@ EXPORT_SYMBOL(cpumask_of_node);
 
 #endif
 
+#ifndef CONFIG_NUMA_FAKE
 static void numa_update_cpu(unsigned int cpu, bool remove)
 {
 	int nid = cpu_to_node(cpu);
@@ -89,6 +103,7 @@ void numa_clear_node(unsigned int cpu)
 	numa_remove_cpu(cpu);
 	set_cpu_numa_node(cpu, NUMA_NO_NODE);
 }
+#endif
 
 /*
  * Allocate node_to_cpumask_map based on number of available nodes
@@ -202,6 +217,9 @@ int __init numa_add_memblk(int nid, u64 start, u64 end)
 {
 	int ret;
 
+	if (IS_ENABLED(CONFIG_NUMA_FAKE))
+		return numa_add_memblk_to(nid, start, end, &numa_meminfo);
+
 	ret = memblock_set_node(start, (end - start), &memblock.memory, nid);
 	if (ret < 0) {
 		pr_err("memblock [0x%llx - 0x%llx] failed to add on node %d\n",
@@ -395,6 +413,18 @@ static int __init numa_init(int (*init_func)(void))
 		goto out_free_distance;
 	}
 
+#ifdef CONFIG_NUMA_FAKE
+	ret = numa_cleanup_meminfo(&numa_meminfo);
+	if (ret < 0)
+		return ret;
+
+	numa_emulation(&numa_meminfo, numa_distance_cnt);
+
+	ret = numa_register_memblks(&numa_meminfo);
+	if (ret < 0)
+		return ret;
+#endif
+
 	ret = numa_register_nodes();
 	if (ret < 0)
 		goto out_free_distance;
drivers/base/numa_emulation.c new file +909 -0

909 lines not on this page · raw message

drivers/base/numa_emulation.h new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.32.0.3.gf3a3e56d6
maintainer
#19 lore raw

Re: [PATCH v1 0/2] support NUMA emulation for genertic arch

In reply to Rongwei Wang
Quoted 5 lines · Rongwei Wang

A brief introduction
====================

The NUMA emulation can fake more node base on a single node system, e.g.

...

Quoted 3 lines

Lastly, it seems not a good choice to realize x86 and other genertic archs separately. But it can indeed avoid some architecture related APIs adjustments and alleviate future maintenance.

Why is it a good choice? Copying 1k lines from x86 to a new place and having to maintain two copies does not sound like a good choice to me.

Quoted 32 lines

The previous RFC link see [1].

Any advice are welcome, Thanks!

Change log
==========

RFC v1 -> v1
* add new CONFIG_NUMA_FAKE for genertic archs.
* keep x86 implementation, realize numa emulation in driver/base/ for genertic arch, e.g, arm64.

[1] RFC v1: https://patchwork.kernel.org/project/linux-arm-kernel/cover/[email protected]/

Rongwei Wang (2):
arch_numa: remove __init for early_cpu_to_node
numa: introduce numa emulation for genertic arch

 drivers/base/Kconfig          |   9 +
 drivers/base/Makefile         |   1 +
 drivers/base/arch_numa.c      |  32 +-
 drivers/base/numa_emulation.c | 909 ++++++++++++++++++++++++++++++++++
 drivers/base/numa_emulation.h |  41 ++
 include/asm-generic/numa.h    |   2 +-
 6 files changed, 992 insertions(+), 2 deletions(-)
 create mode 100644 drivers/base/numa_emulation.c
 create mode 100644 drivers/base/numa_emulation.h
Signature · 1 line
2.32.0.3.gf3a3e56d6
Signature · 2 lines
Sincerely yours,
Mike.
#20 lore raw

Re: [PATCH v1 0/2] support NUMA emulation for genertic arch

Quoted 7 lines · Mike Rapoport
Quoted 5 lines · Rongwei Wang

A brief introduction
====================

The NUMA emulation can fake more node base on a single node system, e.g.

Quoted 8 lines

...

Quoted 3 lines

Lastly, it seems not a good choice to realize x86 and other genertic archs separately. But it can indeed avoid some architecture related APIs adjustments and alleviate future maintenance.

Why is it a good choice? Copying 1k lines from x86 to a new place and having to maintain two copies does not sound like a good choice to me.

I agree it would be better to avoid duplication and extract the common code from the original x86 implementation. The RFC seemed to go more in this direction.
Also NITs:
- genertic -> generic
- there is a 'ifdef CONFIG_X86' in drivers/base/numa_emulation.c, but the file should not be used by x86 as the arch doesn't set CONFIG_GENERIC_ARCH_NUMA

Regards,
Pierre

Quoted 34 lines
Quoted 33 lines

The previous RFC link see [1].

Any advice are welcome, Thanks!

Change log
==========

RFC v1 -> v1
* add new CONFIG_NUMA_FAKE for genertic archs.
* keep x86 implementation, realize numa emulation in driver/base/ for genertic arch, e.g, arm64.

[1] RFC v1: https://patchwork.kernel.org/project/linux-arm-kernel/cover/[email protected]/

Rongwei Wang (2):
arch_numa: remove __init for early_cpu_to_node
numa: introduce numa emulation for genertic arch

  drivers/base/Kconfig          |   9 +
  drivers/base/Makefile         |   1 +
  drivers/base/arch_numa.c      |  32 +-
  drivers/base/numa_emulation.c | 909 ++++++++++++++++++++++++++++++++++
  drivers/base/numa_emulation.h |  41 ++
  include/asm-generic/numa.h    |   2 +-
  6 files changed, 992 insertions(+), 2 deletions(-)

create mode 100644 drivers/base/numa_emulation.c create mode 100644 drivers/base/numa_emulation.h

Signature · 1 line
2.32.0.3.gf3a3e56d6
#21 lore raw

Re: [PATCH v1 0/2] support NUMA emulation for genertic arch

Quoted 10 lines · Pierre Gondois
Quoted 7 lines · Mike Rapoport
Quoted 5 lines · Rongwei Wang

A brief introduction
====================

The NUMA emulation can fake more node base on a single node system, e.g.

Quoted 7 lines
Quoted 7 lines

...

Quoted 3 lines

Lastly, it seems not a good choice to realize x86 and other genertic archs separately. But it can indeed avoid some architecture related APIs adjustments and alleviate future maintenance.

Why is it a good choice? Copying 1k lines from x86 to a new place and having to maintain two copies does not sound like a good choice to me.

Hi Pierre

Quoted 5 lines

I agree it would be better to avoid duplication and extract the common code from the original x86 implementation. The RFC seemed to go more in this direction.
Also NITs:
- genertic -> generic

Thanks, my fault, zhaoyu also found this (thanks).

Quoted 4 lines

- there is a 'ifdef CONFIG_X86' in drivers/base/numa_emulation.c, but the file should not be used by x86 as the arch doesn't set CONFIG_GENERIC_ARCH_NUMA

Actually, I have not think about how to ask the question. I'm also try to original direction like RFC version, but found much APIs need to be updated, and there are many APIs are similar but a little difference. That seems much modification needed in more than one arch if go in original direction.

But if all think original method is right, I will continue it in RFC version.

Thanks for your time to review.

Quoted 38 lines

Regards,
Pierre

Quoted 35 lines
Quoted 34 lines

The previous RFC link see [1].

Any advice are welcome, Thanks!

Change log
==========

RFC v1 -> v1
* add new CONFIG_NUMA_FAKE for genertic archs.
* keep x86 implementation, realize numa emulation in driver/base/ for genertic arch, e.g, arm64.

[1] RFC v1: https://patchwork.kernel.org/project/linux-arm-kernel/cover/[email protected]/

Rongwei Wang (2):
   arch_numa: remove __init for early_cpu_to_node
   numa: introduce numa emulation for genertic arch

  drivers/base/Kconfig          |   9 +
  drivers/base/Makefile         |   1 +
  drivers/base/arch_numa.c      |  32 +-
  drivers/base/numa_emulation.c | 909
++++++++++++++++++++++++++++++++++
  drivers/base/numa_emulation.h |  41 ++
  include/asm-generic/numa.h    |   2 +-

  6 files changed, 992 insertions(+), 2 deletions(-)

  create mode 100644 drivers/base/numa_emulation.c create mode 100644 drivers/base/numa_emulation.h

Signature · 1 line
2.32.0.3.gf3a3e56d6
Signature · 2 lines
Thanks,
-wrw