numa: allocate CPUs masks dynamically
cover numa: allocate CPUs masks dynamically
This series removes global MAX_CPUMASK_BITS constant so that it won't inderectly influence maximum CPUs count supported by different targets.
It replaces statically allocated bitmasks with dynamically allocated ones using '-smp maxcpus' value for setting bitmasks size.
That would allocate just enough memory to handle all CPUs indexes that a QEMU instance would ever have.
Igor Mammedov (2):
add bitmap_free() wrapper
numa: make -numa parser dynamically allocate CPUs masks
include/qemu/bitmap.h | 5 +++++ include/sysemu/numa.h | 2 +- include/sysemu/sysemu.h | 7 ------- numa.c | 19 ++++++++++++------- vl.c | 5 ----- 5 files changed, 18 insertions(+), 20 deletions(-)
Signature · 1 line
2.7.4
RFC PATCH 1/2 add bitmap_free() wrapper
it will be used for freeing bitmaps allocated with bitmap_[try]_new()
--- include/qemu/bitmap.h | 5 +++++ 1 file changed, 5 insertions(+)
include/qemu/bitmap.h +5 -0
@@ -98,6 +98,11 @@ static inline unsigned long *bitmap_new(long nbits)return ptr; } +static inline void bitmap_free (unsigned long *bitmap) +{ +g_free (bitmap); +} +static inline void bitmap_zero (unsigned long *dst,long nbits) {if (small_nbits (nbits)) {
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH RFC 1/2] add bitmap_free() wrapper
Quoted 3 lines · Igor Mammedov
it will be used for freeing bitmaps allocated with bitmap_[try]_new()
Signed-off-by Igor Mammedov <[email protected]>
We need to change all code using g_free() for bitmaps to use bitmap_free(), as people in the future might assume that changing bitmap_free() is safe (and it won't be).
Personally, I think g_free() is good enough and we don't need bitmap_free(). The assumption that bitmap_new() returns g_free()-able memory is part of the API.
Quoted 23 lines
--- include/qemu/bitmap.h | 5 +++++ 1 file changed, 5 insertions(+)include/qemu/bitmap.h +5
-0@@ -98,6 +98,11 @@ static inline unsigned long *bitmap_new(long nbits)return ptr; } +static inline void bitmap_free (unsigned long *bitmap) +{ +g_free (bitmap); +} +static inline void bitmap_zero (unsigned long *dst,long nbits) {if (small_nbits (nbits)) {Signature · 1 line
2.7.4
Signature · 1 line
Eduardo
RFC PATCH 2/2 numa: make -numa parser dynamically allocate CPUs masks
In reply to Igor Mammedovso it won't impose an additional limits on max_cpus limits supported by different targets.
It removes global MAX_CPUMASK_BITS constant and need to bump it up whenever max_cpus is being increased for a target above MAX_CPUMASK_BITS value.
Use runtime max_cpus value instead to allocate sufficiently sized node_cpu bitmasks in numa parser.
--- include/sysemu/numa.h | 2 +- include/sysemu/sysemu.h | 7 ------- numa.c | 19 ++++++++++++------- vl.c | 5 ----- 4 files changed, 13 insertions(+), 20 deletions(-)
include/sysemu/numa.h +1 -1
@@ -17,7 +17,7 @@ struct numa_addr_range { typedef struct node_info { uint64_t node_mem; - DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); + unsigned long *node_cpu; struct HostMemoryBackend *node_memdev; bool present; QLIST_HEAD(, numa_addr_range) addr; /* List to store address ranges */
include/sysemu/sysemu.h +0 -7
@@ -168,13 +168,6 @@ extern int mem_prealloc;#define MAX_NODES 128#define NUMA_NODE_UNASSIGNED MAX_NODES -/* The following shall be true for all CPUs: -* cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS -* -* Note that cpu->get_arch_id() may be larger than MAX_CPUMASK_BITS. -*/ -#define MAX_CPUMASK_BITS 288 -#define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { const char *name;
numa.c +12 -7
@@ -266,20 +266,20 @@ static char *enumerate_cpus(unsigned long *cpus, int max_cpus)static void validate_numa_cpus (void ) {int i; -DECLARE_BITMAP (seen_cpus,MAX_CPUMASK_BITS ); +unsigned long *seen_cpus =bitmap_new (max_cpus); -bitmap_zero (seen_cpus,MAX_CPUMASK_BITS ); +bitmap_zero (seen_cpus, max_cpus);for (i =0 ; i < nb_numa_nodes; i++) { -if (bitmap_intersects (seen_cpus, numa_info[i].node_cpu, -MAX_CPUMASK_BITS )) { +if (bitmap_intersects (seen_cpus, numa_info[i].node_cpu, max_cpus)) {bitmap_and (seen_cpus, seen_cpus, - numa_info[i].node_cpu,MAX_CPUMASK_BITS ); + numa_info[i].node_cpu, max_cpus);error_report ("CPU(s) present in multiple NUMA nodes: %s" ,enumerate_cpus (seen_cpus, max_cpus)); +bitmap_free (seen_cpus);exit (EXIT_FAILURE ); }bitmap_or (seen_cpus, seen_cpus, - numa_info[i].node_cpu,MAX_CPUMASK_BITS ); + numa_info[i].node_cpu, max_cpus); }if (!bitmap_full (seen_cpus, max_cpus)) {
@@ -291,12 +291,17 @@ static void validate_numa_cpus(void) "in NUMA config");g_free (msg); } +bitmap_free (seen_cpus); }void parse_numa_opts (MachineClass *mc) {int i; +for (i =0 ; i <MAX_NODES ; i++) { + numa_info[i].node_cpu =bitmap_new (max_cpus); + } +if (qemu_opts_foreach (qemu_find_opts ("numa" ), parse_numa,NULL ,NULL )) {exit (1 ); }
@@ -362,7 +367,7 @@ void parse_numa_opts(MachineClass *mc)numa_set_mem_ranges ();for (i =0 ; i < nb_numa_nodes; i++) { -if (!bitmap_empty (numa_info[i].node_cpu,MAX_CPUMASK_BITS )) { +if (!bitmap_empty (numa_info[i].node_cpu, max_cpus)) {break ; } }
vl.c +0 -5
@@ -1277,11 +1277,6 @@ static void smp_parse(QemuOpts *opts) max_cpus =qemu_opt_get_number (opts,"maxcpus" , cpus); -if (max_cpus >MAX_CPUMASK_BITS ) { -error_report ("unsupported number of maxcpus" ); -exit (1 ); - } -if (max_cpus < cpus) {error_report ("maxcpus must be equal to or greater than smp" );exit (1 );
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH RFC 2/2] numa: make -numa parser dynamically allocate CPUs masks
Quoted 36 lines · Igor Mammedov
so it won't impose an additional limits on
max_cpuslimits supported by different targets.It removes global
MAX_CPUMASK_BITSconstant and need to bump it up whenevermax_cpusis being increased for a target aboveMAX_CPUMASK_BITSvalue.Use runtime
max_cpusvalue instead to allocate sufficiently sizednode_cpubitmasks in numa parser.Signed-off-by Igor Mammedov <[email protected]>--- include/sysemu/numa.h | 2 +- include/sysemu/sysemu.h | 7 ------- numa.c | 19 ++++++++++++------- vl.c | 5 ----- 4 files changed, 13 insertions(+), 20 deletions(-)include/sysemu/numa.h +1
-1@@ -17,7 +17,7 @@ struct numa_addr_range { typedef struct node_info { uint64_t node_mem; - DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); + unsigned long *node_cpu; struct HostMemoryBackend *node_memdev; bool present; QLIST_HEAD(, numa_addr_range) addr; /* List to store address ranges */include/sysemu/sysemu.h +0
-0
include/sysemu/sysemu.h extern int mem_prealloc; · line 177
Quoted 10 lines
include/sysemu/sysemu.h +0
-7@@ -168,13 +168,6 @@ extern int mem_prealloc;#define MAX_NODES 128#define NUMA_NODE_UNASSIGNED MAX_NODES -/* The following shall be true for all CPUs: -* cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS -* -* Note that cpu->get_arch_id() may be larger than MAX_CPUMASK_BITS. -*/ -#define MAX_CPUMASK_BITS 288 -
Nice!
Quoted 8 lines
include/sysemu/sysemu.h +0
-0#define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { const char *name;numa.c +0
-0
numa.c static char *enumerate_cpus(unsigned long *cpus, int max_cpus) · line 271
Quoted 8 lines
numa.c +2
-2@@ -266,20 +266,20 @@ static char *enumerate_cpus(unsigned long *cpus, int max_cpus)static void validate_numa_cpus (void ) {int i; -DECLARE_BITMAP (seen_cpus,MAX_CPUMASK_BITS ); +unsigned long *seen_cpus =bitmap_new (max_cpus); -bitmap_zero (seen_cpus,MAX_CPUMASK_BITS ); +bitmap_zero (seen_cpus, max_cpus);
bitmap_new() already returns a zeroed bitmap.
Quoted 19 lines
numa.c +4
-4for (i =0 ; i < nb_numa_nodes; i++) { -if (bitmap_intersects (seen_cpus, numa_info[i].node_cpu, -MAX_CPUMASK_BITS )) { +if (bitmap_intersects (seen_cpus, numa_info[i].node_cpu, max_cpus)) {bitmap_and (seen_cpus, seen_cpus, - numa_info[i].node_cpu,MAX_CPUMASK_BITS ); + numa_info[i].node_cpu, max_cpus);error_report ("CPU(s) present in multiple NUMA nodes: %s" ,enumerate_cpus (seen_cpus, max_cpus)); +bitmap_free (seen_cpus);exit (EXIT_FAILURE ); }bitmap_or (seen_cpus, seen_cpus, - numa_info[i].node_cpu,MAX_CPUMASK_BITS ); + numa_info[i].node_cpu, max_cpus); }if (!bitmap_full (seen_cpus, max_cpus)) {
numa.c static void validate_numa_cpus(void) · line 294
Quoted 4 lines
numa.c +1
-0@@ -291,12 +291,17 @@ static void validate_numa_cpus(void) "in NUMA config");g_free (msg); } +bitmap_free (seen_cpus);
See comment about bitmap_free() on patch 1/2. I think g_free() is good enough (unless you really want to review all callers of bitmap_[try_]new()).
Quoted 41 lines
numa.c +5
-1}void parse_numa_opts (MachineClass *mc) {int i; +for (i =0 ; i <MAX_NODES ; i++) { + numa_info[i].node_cpu =bitmap_new (max_cpus); + } +if (qemu_opts_foreach (qemu_find_opts ("numa" ), parse_numa,NULL ,NULL )) {exit (1 ); }@@ -362,7 +367,7 @@ void parse_numa_opts(MachineClass *mc)numa_set_mem_ranges ();for (i =0 ; i < nb_numa_nodes; i++) { -if (!bitmap_empty (numa_info[i].node_cpu,MAX_CPUMASK_BITS )) { +if (!bitmap_empty (numa_info[i].node_cpu, max_cpus)) {break ; } }vl.c +0
-5@@ -1277,11 +1277,6 @@ static void smp_parse(QemuOpts *opts) max_cpus =qemu_opt_get_number (opts,"maxcpus" , cpus); -if (max_cpus >MAX_CPUMASK_BITS ) { -error_report ("unsupported number of maxcpus" ); -exit (1 ); - } -if (max_cpus < cpus) {error_report ("maxcpus must be equal to or greater than smp" );exit (1 );Signature · 1 line
2.7.4
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH RFC 2/2] numa: make -numa parser dynamically allocate CPUs masks
Quoted 86 lines · On Wed, 16 Nov 2016 15:08:26 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 36 lines · Igor Mammedov
so it won't impose an additional limits on
max_cpuslimits supported by different targets.It removes global
MAX_CPUMASK_BITSconstant and need to bump it up whenevermax_cpusis being increased for a target aboveMAX_CPUMASK_BITSvalue.Use runtime
max_cpusvalue instead to allocate sufficiently sizednode_cpubitmasks in numa parser.Signed-off-by Igor Mammedov <[email protected]>--- include/sysemu/numa.h | 2 +- include/sysemu/sysemu.h | 7 ------- numa.c | 19 ++++++++++++------- vl.c | 5 ----- 4 files changed, 13 insertions(+), 20 deletions(-)include/sysemu/numa.h +1
-1@@ -17,7 +17,7 @@ struct numa_addr_range { typedef struct node_info { uint64_t node_mem; - DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); + unsigned long *node_cpu; struct HostMemoryBackend *node_memdev; bool present; QLIST_HEAD(, numa_addr_range) addr; /* List to store address ranges */include/sysemu/sysemu.h +0
-0include/sysemu/sysemu.h extern int mem_prealloc; · line 177
Quoted 10 lines
include/sysemu/sysemu.h +0
-7@@ -168,13 +168,6 @@ extern int mem_prealloc;#define MAX_NODES 128#define NUMA_NODE_UNASSIGNED MAX_NODES -/* The following shall be true for all CPUs: -* cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS -* -* Note that cpu->get_arch_id() may be larger than MAX_CPUMASK_BITS. -*/ -#define MAX_CPUMASK_BITS 288 -Nice!
Quoted 8 lines
include/sysemu/sysemu.h +0
-0#define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { const char *name;numa.c +0
-0numa.c static char *enumerate_cpus(unsigned long *cpus, int max_cpus) · line 271
Quoted 8 lines
numa.c +2
-2@@ -266,20 +266,20 @@ static char *enumerate_cpus(unsigned long *cpus, int max_cpus)static void validate_numa_cpus (void ) {int i; -DECLARE_BITMAP (seen_cpus,MAX_CPUMASK_BITS ); +unsigned long *seen_cpus =bitmap_new (max_cpus); -bitmap_zero (seen_cpus,MAX_CPUMASK_BITS ); +bitmap_zero (seen_cpus, max_cpus);
bitmap_new()already returns a zeroed bitmap.Quoted 17 lines
numa.c +4
-4for (i =0 ; i < nb_numa_nodes; i++) { -if (bitmap_intersects (seen_cpus, numa_info[i].node_cpu, -MAX_CPUMASK_BITS )) { +if (bitmap_intersects (seen_cpus, numa_info[i].node_cpu, max_cpus)) {bitmap_and (seen_cpus, seen_cpus, - numa_info[i].node_cpu,MAX_CPUMASK_BITS ); + numa_info[i].node_cpu, max_cpus);error_report ("CPU(s) present in multiple NUMA nodes: %s" ,enumerate_cpus (seen_cpus, max_cpus)); +bitmap_free (seen_cpus);exit (EXIT_FAILURE ); }bitmap_or (seen_cpus, seen_cpus, - numa_info[i].node_cpu,MAX_CPUMASK_BITS ); + numa_info[i].node_cpu, max_cpus); }
Quoted 10 lines
numa.c static void validate_numa_cpus(void) · line 294
Quoted 6 lines
numa.c +1
-0if (!bitmap_full (seen_cpus, max_cpus)) {@@ -291,12 +291,17 @@ static void validate_numa_cpus(void) "in NUMA config");g_free (msg); } +bitmap_free (seen_cpus);See comment about
bitmap_free()on patch 1/2. I thinkg_free()is good enough (unless you really want to review all callers of bitmap_[try_]new()).
ok, I'll replace bitmap_free() with g_free() and respin.
Quoted 43 lines
Quoted 42 lines
numa.c +5
-1}void parse_numa_opts (MachineClass *mc) {int i; +for (i =0 ; i <MAX_NODES ; i++) { + numa_info[i].node_cpu =bitmap_new (max_cpus); + } +if (qemu_opts_foreach (qemu_find_opts ("numa" ), parse_numa,NULL ,NULL )) {exit (1 ); }@@ -362,7 +367,7 @@ void parse_numa_opts(MachineClass *mc)numa_set_mem_ranges ();for (i =0 ; i < nb_numa_nodes; i++) { -if (!bitmap_empty (numa_info[i].node_cpu,MAX_CPUMASK_BITS )) { +if (!bitmap_empty (numa_info[i].node_cpu, max_cpus)) {break ; } }vl.c +0
-5@@ -1277,11 +1277,6 @@ static void smp_parse(QemuOpts *opts) max_cpus =qemu_opt_get_number (opts,"maxcpus" , cpus); -if (max_cpus >MAX_CPUMASK_BITS ) { -error_report ("unsupported number of maxcpus" ); -exit (1 ); - } -if (max_cpus < cpus) {error_report ("maxcpus must be equal to or greater than smp" );exit (1 );Signature · 1 line
2.7.4
Quoted 17 lines · Igor Mammedov
This series removes global
MAX_CPUMASK_BITSconstant so that it won't inderectly influence maximum CPUs count supported by different targets.It replaces statically allocated bitmasks with dynamically allocated ones using '-smp maxcpus' value for setting bitmasks size.
That would allocate just enough memory to handle all CPUs indexes that a QEMU instance would ever have.CC Alexey Kardashevskiy <[email protected]>CC Greg Kurz <[email protected]>CC David Gibson <[email protected]>CC Eduardo Habkost <[email protected]>CC Paolo Bonzini <[email protected]>
Quoted 3 lines
Igor Mammedov (2):
addbitmap_free()wrapper
numa: make -numa parser dynamically allocate CPUs masks
Nice, with "ulimit -n 3072", guest kernel with CONFIG_NR_CPUS=2048, "mc->max_cpus = 2048;" in hw/ppc/spapr.c, and "-smp 2048,threads=8" in QEMU cmdline, I get all 2048 CPUs in the guest.
Quoted 8 lines
include/qemu/bitmap.h | 5 +++++ include/sysemu/numa.h | 2 +- include/sysemu/sysemu.h | 7 ------- numa.c | 19 ++++++++++++------- vl.c | 5 ----- 5 files changed, 18 insertions(+), 20 deletions(-)
Signature · 1 line
Alexey
Quoted 18 lines · On Thu, 17 Nov 2016 17:27:20 +1100 Alexey Kardashevskiy <[email protected]> wrote:
Quoted 17 lines · Igor Mammedov
This series removes global
MAX_CPUMASK_BITSconstant so that it won't inderectly influence maximum CPUs count supported by different targets.It replaces statically allocated bitmasks with dynamically allocated ones using '-smp maxcpus' value for setting bitmasks size.
That would allocate just enough memory to handle all CPUs indexes that a QEMU instance would ever have.CC Alexey Kardashevskiy <[email protected]>CC Greg Kurz <[email protected]>CC David Gibson <[email protected]>CC Eduardo Habkost <[email protected]>CC Paolo Bonzini <[email protected]>
Quoted 8 lines
Quoted 3 lines
Igor Mammedov (2):
addbitmap_free()wrapper
numa: make -numa parser dynamically allocate CPUs masksNice, with "ulimit -n 3072", guest kernel with
CONFIG_NR_CPUS=2048, "mc->max_cpus= 2048;" inhw/ppc/spapr.c, and "-smp 2048,threads=8" in QEMU cmdline, I get all 2048 CPUs in the guest.
Nice ! And mc->max_cpus in hw/ppc/spapr.c no longer depends on MAX_CPUMASK_BITS since commit 079019f2e319b, so it is already possible to bump that value (1024 ? 2048 ?).
Will you send a patch ?
Quoted 14 lines
Tested-by Alexey Kardashevskiy <[email protected]>Quoted 8 lines
include/qemu/bitmap.h | 5 +++++ include/sysemu/numa.h | 2 +- include/sysemu/sysemu.h | 7 ------- numa.c | 19 ++++++++++++------- vl.c | 5 ----- 5 files changed, 18 insertions(+), 20 deletions(-)
Quoted 30 lines · Greg Kurz
Quoted 18 lines · On Thu, 17 Nov 2016 17:27:20 +1100 Alexey Kardashevskiy <[email protected]> wrote:
Quoted 17 lines · Igor Mammedov
This series removes global
MAX_CPUMASK_BITSconstant so that it won't inderectly influence maximum CPUs count supported by different targets.It replaces statically allocated bitmasks with dynamically allocated ones using '-smp maxcpus' value for setting bitmasks size.
That would allocate just enough memory to handle all CPUs indexes that a QEMU instance would ever have.CC Alexey Kardashevskiy <[email protected]>CC Greg Kurz <[email protected]>CC David Gibson <[email protected]>CC Eduardo Habkost <[email protected]>CC Paolo Bonzini <[email protected]>Quoted 8 lines
Quoted 3 lines
Igor Mammedov (2):
addbitmap_free()wrapper
numa: make -numa parser dynamically allocate CPUs masksNice, with "ulimit -n 3072", guest kernel with
CONFIG_NR_CPUS=2048, "mc->max_cpus= 2048;" inhw/ppc/spapr.c, and "-smp 2048,threads=8" in QEMU cmdline, I get all 2048 CPUs in the guest.
Quoted 5 lines
Nice ! And
mc->max_cpusinhw/ppc/spapr.cno longer depends onMAX_CPUMASK_BITSsince commit079019f2e319b, so it is already possible to bump that value (1024 ? 2048 ?).Will you send a patch ?
Sure, when these two hit upstream.
Quoted 16 lines
Quoted 15 lines
Tested-by Alexey Kardashevskiy <[email protected]>Quoted 8 lines
include/qemu/bitmap.h | 5 +++++ include/sysemu/numa.h | 2 +- include/sysemu/sysemu.h | 7 ------- numa.c | 19 ++++++++++++------- vl.c | 5 ----- 5 files changed, 18 insertions(+), 20 deletions(-)
Signature · 1 line
Alexey