Skip to contentSkip to conversation

Common base for memory hotplug and NUMA policy work

RFC PATCH In review Paolo Bonzini 4 participants 23 messages Dec 11, 2013 – Dec 12, 2013

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

cover Common base for memory hotplug and NUMA policy work

Hi,

this is a proposal for a common tree for memory hotplug and NUMA policy patches.

The common base for these tree is Igor's "memory device" QOM hierarchy, that subsumes and improves on the "-numa mem" concept that I had proposed. These patches include a basic conversion of his QOM hierarchy to -object. Stefan and Igor are looking at improving -object, but this is not required to build on this series.

Thanks to the memory device object, NUMA nodes' memory allocation be expressed easily via a new suboption "-numa node,memdev=ID". For example:

  -object memory-ram,size=1024M,id=ram-node0 \
  -numa node,nodeid=0,cpus=0,memdev=ram-node0 \
  -object memory-ram,size=1024M,id=ram-node1 \
  -numa node,nodeid=1,cpus=1,memdev=ram-node1 \
  -m 2048

memdev=ID is alternative to mem=SIZE: if you use memdev for one node, you must use it for all of them. When memdev is in use, the single large RAM memory region is replaced by a container region, with all memdevs layed out one after another.

The integration between boards and the NUMA subsystem is done by a new function in numa.c, memory_region_allocate_system_memory. Thus, boards have to request NUMA-aware allocation explicitly. This however is not a change compared to Wanlong's patches: both the early ones that hardcoded the "pc.ram" memory region name, and the latest version that similarly introduced a function for boards to call (memory_region_set_mem_policy in his patches).

Wanlong can then proceed to add policy properties (hostnode, policy) to backends/hostmem-ram.c, and these will be automatically applicable to hotpluggable memory as well.

I'm quite happy with the design of both series. It took quite a long time, but it shows the power of the host/guest separation that is already present in -blockdev/-chardev/-netdev.

You can find this at refs/heads/numa in my github repository, where I included also the monitor object-add/object-del patches.

Paolo

Igor Mammedov (3):
qapi: add SIZE type parser to string_input_visitor
vl: convert -m to QemuOpts
add memdev backend infrastructure

Paolo Bonzini (6):
QemuOpts: introduce qemu_find_opts_singleton
qom: fix leak for objects created with -object
qom: catch errors in object_property_add_child
pc: pass QEMUMachineInitArgs to pc_memory_init
numa: introduce memory_region_allocate_system_memory
numa: add -numa node,memdev= option

Wanlong Gao (5):
NUMA: move numa related code to new file numa.c
NUMA: check if the total numa memory size is equal to ram_size
NUMA: Add numa_info structure to contain numa nodes info
NUMA: convert -numa option to use OptsVisitor
NUMA: expand MAX_NODES from 64 to 128

 Makefile.target             |   2 +-
 backends/Makefile.objs      |   2 +
 backends/hostmem-ram.c      |  46 ++++++++
 backends/hostmem.c          | 116 ++++++++++++++++++++
 cpus.c                      |  14 ---
 hw/i386/pc.c                |  27 ++---
 hw/i386/pc_piix.c           |   8 +-
 hw/i386/pc_q35.c            |   4 +-
 include/hw/i386/pc.h        |   7 +-
 include/qemu/config-file.h  |   2 +
 include/sysemu/cpus.h       |   1 -
 include/sysemu/hostmem.h    |  63 +++++++++++
 include/sysemu/sysemu.h     |  21 +++-
 monitor.c                   |   2 +-
 numa.c                      | 259 ++++++++++++++++++++++++++++++++++++++++++++
 qapi-schema.json            |  34 ++++++
 qapi/string-input-visitor.c |  18 +++
 qemu-options.hx             |   7 +-
 qom/object.c                |   9 +-
 util/qemu-config.c          |  14 +++
 vl.c                        | 221 ++++++++++---------------------------
 21 files changed, 664 insertions(+), 213 deletions(-)
 create mode 100644 backends/hostmem-ram.c
 create mode 100644 backends/hostmem.c
 create mode 100644 include/sysemu/hostmem.h
 create mode 100644 numa.c
Signature · 1 line
1.8.4.2
#1 lore raw

RFC PATCH 1/14 NUMA: move numa related code to new file numa.c

From: Wanlong Gao <[email protected]>

---
 Makefile.target         |   2 +-
 cpus.c                  |  14 ----
 include/sysemu/cpus.h   |   1 -
 include/sysemu/sysemu.h |   3 +
 numa.c                  | 182 ++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c                    | 139 +-----------------------------------
 6 files changed, 187 insertions(+), 154 deletions(-)
 create mode 100644 numa.c
Makefile.target +1 -1
index af6ac7e..0197c17 100644
@@ -109,7 +109,7 @@ endif #CONFIG_BSD_USER
 #########################################################
 # System emulator target
 ifdef CONFIG_SOFTMMU
-obj-y += arch_init.o cpus.o monitor.o gdbstub.o balloon.o ioport.o
+obj-y += arch_init.o cpus.o monitor.o gdbstub.o balloon.o ioport.o numa.o
 obj-y += qtest.o
 obj-y += hw/
 obj-$(CONFIG_FDT) += device_tree.o
cpus.c +0 -14
index 01d128d..53360b0 100644
@@ -1297,20 +1297,6 @@ static void tcg_exec_all(void)
     exit_request = 0;
 }
 
-void set_numa_modes(void)
-{
-    CPUState *cpu;
-    int i;
-
-    CPU_FOREACH(cpu) {
-        for (i = 0; i < nb_numa_nodes; i++) {
-            if (test_bit(cpu->cpu_index, node_cpumask[i])) {
-                cpu->numa_node = i;
-            }
-        }
-    }
-}
-
 void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg)
 {
     /* XXX: implement xxx_cpu_list for targets that still miss it */
include/sysemu/cpus.h +0 -1
index 6502488..4f79081 100644
@@ -23,7 +23,6 @@ extern int smp_threads;
 #define smp_threads 1
 #endif
 
-void set_numa_modes(void);
 void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg);
 
 #endif
include/sysemu/sysemu.h +3 -0
index 495dae8..2509649 100644
@@ -136,6 +136,9 @@ extern QEMUClockType rtc_clock;
 extern int nb_numa_nodes;
 extern uint64_t node_mem[MAX_NODES];
 extern unsigned long *node_cpumask[MAX_NODES];
+void numa_add(const char *optarg);
+void set_numa_nodes(void);
+void set_numa_modes(void);
 
 #define MAX_OPTION_ROMS 16
 typedef struct QEMUOptionRom {
numa.c new file +182 -0

182 lines not on this page · raw message

vl.c +1 -138

151 lines not on this page · raw message

Signature · 1 line
1.8.4.2
#2 lore raw

RFC PATCH 2/14 NUMA: check if the total numa memory size is equal to ram_size

In reply to Paolo Bonzini

From: Wanlong Gao <[email protected]>

If the total number of the assigned numa nodes memory is not equal to the assigned ram size, it will write the wrong data to ACPI talb, then the guest will ignore the wrong ACPI table and recognize all memory to one node. It's buggy, we should check it to ensure that we write the right data to ACPI table.

---
 numa.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
numa.c +10 -0
index ce7736a..beda80e 100644
@@ -150,6 +150,16 @@ void set_numa_nodes(void)
             node_mem[i] = ram_size - usedmem;
         }
 
+        uint64_t numa_total = 0;
+        for (i = 0; i < nb_numa_nodes; i++) {
+            numa_total += node_mem[i];
+        }
+        if (numa_total != ram_size) {
+            fprintf(stderr, "qemu: numa nodes total memory size "
+                            "should equal to ram_size\n");
+            exit(1);
+        }
+
         for (i = 0; i < nb_numa_nodes; i++) {
             if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) {
                 break;
Signature · 1 line
1.8.4.2
#3 lore raw

Re: [Qemu-devel] [RFC PATCH 02/14] NUMA: check if the total numa memory size is equal to ram_size

Quoted 5 lines · Paolo Bonzini

From: Wanlong Gao <[email protected]>

If the total number of the assigned numa nodes memory is not equal to the assigned ram size, it will write the wrong data to ACPI talb, then the guest will ignore the wrong ACPI table

s/talb/table/

numa.c void set_numa_nodes(void) · line 159

Quoted 13 lines

and recognize all memory to one node. It's buggy, we should check it to ensure that we write the right data to ACPI table.

---
 numa.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
numa.c +4 -0
+        }
+        if (numa_total != ram_size) {
+            fprintf(stderr, "qemu: numa nodes total memory size "
+                            "should equal to ram_size\n");

s/to //

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw

RFC PATCH 3/14 NUMA: Add numa_info structure to contain numa nodes info

In reply to Paolo Bonzini

From: Wanlong Gao <[email protected]>

Add the numa_info structure to contain the numa nodes memory, VCPUs information and the future added numa nodes host memory policies.

---
 hw/i386/pc.c            | 12 ++++++++----
 include/sysemu/sysemu.h |  8 ++++++--
 monitor.c               |  2 +-
 numa.c                  | 23 ++++++++++++-----------
 vl.c                    |  7 +++----
 5 files changed, 30 insertions(+), 22 deletions(-)
hw/i386/pc.c +8 -4
index 12c436e..74c1f16 100644
@@ -670,14 +670,14 @@ static FWCfgState *bochs_bios_init(void)
         unsigned int apic_id = x86_cpu_apic_id_from_index(i);
         assert(apic_id < apic_id_limit);
         for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, node_cpumask[j])) {
+            if (test_bit(i, numa_info[j].node_cpu)) {
                 numa_fw_cfg[apic_id + 1] = cpu_to_le64(j);
                 break;
             }
         }
     }
     for (i = 0; i < nb_numa_nodes; i++) {
-        numa_fw_cfg[apic_id_limit + 1 + i] = cpu_to_le64(node_mem[i]);
+        numa_fw_cfg[apic_id_limit + 1 + i] = cpu_to_le64(numa_info[i].node_mem);
     }
     fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, numa_fw_cfg,
                      (1 + apic_id_limit + nb_numa_nodes) *
@@ -1072,8 +1072,12 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
     guest_info->apic_id_limit = pc_apic_id_limit(max_cpus);
     guest_info->apic_xrupt_override = kvm_allows_irq0_override();
     guest_info->numa_nodes = nb_numa_nodes;
-    guest_info->node_mem = g_memdup(node_mem, guest_info->numa_nodes *
+    guest_info->node_mem = g_malloc0(guest_info->numa_nodes *
                                     sizeof *guest_info->node_mem);
+    for (i = 0; i < nb_numa_nodes; i++) {
+        guest_info->node_mem[i] = numa_info[i].node_mem;
+    }
+
     guest_info->node_cpu = g_malloc0(guest_info->apic_id_limit *
                                      sizeof *guest_info->node_cpu);
 
@@ -1081,7 +1085,7 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
         unsigned int apic_id = x86_cpu_apic_id_from_index(i);
         assert(apic_id < guest_info->apic_id_limit);
         for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, node_cpumask[j])) {
+            if (test_bit(i, numa_info[j].node_cpu)) {
                 guest_info->node_cpu[apic_id] = j;
                 break;
             }
include/sysemu/sysemu.h +6 -2
index 2509649..d873b42 100644
@@ -9,6 +9,7 @@
 #include "qapi-types.h"
 #include "qemu/notify.h"
 #include "qemu/main-loop.h"
+#include "qemu/bitmap.h"
 
 /* vl.c */
 
@@ -134,8 +135,11 @@ extern QEMUClockType rtc_clock;
 #define MAX_NODES 64
 #define MAX_CPUMASK_BITS 255
 extern int nb_numa_nodes;
-extern uint64_t node_mem[MAX_NODES];
-extern unsigned long *node_cpumask[MAX_NODES];
+typedef struct node_info {
+    uint64_t node_mem;
+    DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
+} NodeInfo;
+extern NodeInfo numa_info[MAX_NODES];
 void numa_add(const char *optarg);
 void set_numa_nodes(void);
 void set_numa_modes(void);
monitor.c +1 -1
index 845f608..b97b7d3 100644
@@ -2004,7 +2004,7 @@ static void do_info_numa(Monitor *mon, const QDict *qdict)
         }
         monitor_printf(mon, "\n");
         monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i,
-            node_mem[i] >> 20);
+            numa_info[i].node_mem >> 20);
     }
 }
 
numa.c +12 -11
index beda80e..1bc0fad 100644
@@ -61,7 +61,7 @@ static void numa_node_parse_cpus(int nodenr, const char *cpus)
         goto error;
     }
 
-    bitmap_set(node_cpumask[nodenr], value, endvalue-value+1);
+    bitmap_set(numa_info[nodenr].node_cpu, value, endvalue-value+1);
     return;
 
 error:
@@ -101,7 +101,7 @@ void numa_add(const char *optarg)
         }
 
         if (get_param_value(option, 128, "mem", optarg) == 0) {
-            node_mem[nodenr] = 0;
+            numa_info[nodenr].node_mem = 0;
         } else {
             int64_t sval;
             sval = strtosz(option, &endptr);
@@ -109,7 +109,7 @@ void numa_add(const char *optarg)
                 fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg);
                 exit(1);
             }
-            node_mem[nodenr] = sval;
+            numa_info[nodenr].node_mem = sval;
         }
         if (get_param_value(option, 128, "cpus", optarg) != 0) {
             numa_node_parse_cpus(nodenr, option);
@@ -134,7 +134,7 @@ void set_numa_nodes(void)
          * and distribute the available memory equally across all nodes
          */
         for (i = 0; i < nb_numa_nodes; i++) {
-            if (node_mem[i] != 0)
+            if (numa_info[i].node_mem != 0)
                 break;
         }
         if (i == nb_numa_nodes) {
@@ -144,15 +144,16 @@ void set_numa_nodes(void)
              * the final node gets the rest.
              */
             for (i = 0; i < nb_numa_nodes - 1; i++) {
-                node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
-                usedmem += node_mem[i];
+                numa_info[i].node_mem = (ram_size / nb_numa_nodes) &
+                                        ~((1 << 23UL) - 1);
+                usedmem += numa_info[i].node_mem;
             }
-            node_mem[i] = ram_size - usedmem;
+            numa_info[i].node_mem = ram_size - usedmem;
         }
 
         uint64_t numa_total = 0;
         for (i = 0; i < nb_numa_nodes; i++) {
-            numa_total += node_mem[i];
+            numa_total += numa_info[i].node_mem;
         }
         if (numa_total != ram_size) {
             fprintf(stderr, "qemu: numa nodes total memory size "
@@ -161,7 +162,7 @@ void set_numa_nodes(void)
         }
 
         for (i = 0; i < nb_numa_nodes; i++) {
-            if (!bitmap_empty(node_cpumask[i], MAX_CPUMASK_BITS)) {
+            if (!bitmap_empty(numa_info[i].node_cpu, MAX_CPUMASK_BITS)) {
                 break;
             }
         }
@@ -171,7 +172,7 @@ void set_numa_nodes(void)
          */
         if (i == nb_numa_nodes) {
             for (i = 0; i < max_cpus; i++) {
-                set_bit(i, node_cpumask[i % nb_numa_nodes]);
+                set_bit(i, numa_info[i % nb_numa_nodes].node_cpu);
             }
         }
     }
@@ -184,7 +185,7 @@ void set_numa_modes(void)
 
     CPU_FOREACH(cpu) {
         for (i = 0; i < nb_numa_nodes; i++) {
-            if (test_bit(cpu->cpu_index, node_cpumask[i])) {
+            if (test_bit(cpu->cpu_index, numa_info[i].node_cpu)) {
                 cpu->numa_node = i;
             }
         }
vl.c +3 -4
index a5c6f17..53a412f 100644
@@ -248,8 +248,7 @@ static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
     QTAILQ_HEAD_INITIALIZER(fw_boot_order);
 
 int nb_numa_nodes;
-uint64_t node_mem[MAX_NODES];
-unsigned long *node_cpumask[MAX_NODES];
+NodeInfo numa_info[MAX_NODES];
 
 uint8_t qemu_uuid[16];
 bool qemu_uuid_set;
@@ -2815,8 +2814,8 @@ int main(int argc, char **argv, char **envp)
     translation = BIOS_ATA_TRANSLATION_AUTO;
 
     for (i = 0; i < MAX_NODES; i++) {
-        node_mem[i] = 0;
-        node_cpumask[i] = bitmap_new(MAX_CPUMASK_BITS);
+        numa_info[i].node_mem = 0;
+        bitmap_zero(numa_info[i].node_cpu, MAX_CPUMASK_BITS);
     }
 
     nb_numa_nodes = 0;
Signature · 1 line
1.8.4.2
#5 lore raw

RFC PATCH 4/14 NUMA: convert -numa option to use OptsVisitor

In reply to Paolo Bonzini

From: Wanlong Gao <[email protected]>

---
 include/sysemu/sysemu.h |   3 +-
 numa.c                  | 148 +++++++++++++++++++++++-------------------------
 qapi-schema.json        |  30 ++++++++++
 vl.c                    |  11 +++-
 4 files changed, 114 insertions(+), 78 deletions(-)
include/sysemu/sysemu.h +2 -1
index d873b42..20b05a3 100644
@@ -140,9 +140,10 @@ typedef struct node_info {
     DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
 } NodeInfo;
 extern NodeInfo numa_info[MAX_NODES];
-void numa_add(const char *optarg);
 void set_numa_nodes(void);
 void set_numa_modes(void);
+extern QemuOptsList qemu_numa_opts;
+int numa_init_func(QemuOpts *opts, void *opaque);
 
 #define MAX_OPTION_ROMS 16
 typedef struct QEMUOptionRom {
numa.c +72 -76

173 lines not on this page · raw message

qapi-schema.json +30 -0
index d6f8615..d99e39d 100644
@@ -4235,3 +4235,33 @@
 # Since: 1.7
 ##
 { 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }
+
+##
+# @NumaOptions
+#
+# A discriminated record of NUMA options. (for OptsVisitor)
+#
+# Since 2.0
+##
+{ 'union': 'NumaOptions',
+  'data': {
+    'node': 'NumaNodeOptions' }}
+
+##
+# @NumaNodeOptions
+#
+# Create a guest NUMA node. (for OptsVisitor)
+#
+# @nodeid: #optional NUMA node ID
+#
+# @cpus: #optional VCPUs belong to this node
+#
+# @mem: #optional memory size of this node
+#
+# Since: 2.0
+##
+{ 'type': 'NumaNodeOptions',
+  'data': {
+   '*nodeid': 'uint16',
+   '*cpus':   ['uint16'],
+   '*mem':    'str' }}
vl.c +10 -1
index 53a412f..95181e0 100644
@@ -2793,6 +2793,7 @@ int main(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_tpmdev_opts);
     qemu_add_opts(&qemu_realtime_opts);
     qemu_add_opts(&qemu_msg_opts);
+    qemu_add_opts(&qemu_numa_opts);
 
     runstate_init();
 
@@ -2980,7 +2981,10 @@ int main(int argc, char **argv, char **envp)
                 }
                 break;
             case QEMU_OPTION_numa:
-                numa_add(optarg);
+                opts = qemu_opts_parse(qemu_find_opts("numa"), optarg, 1);
+                if (!opts) {
+                    exit(1);
+                }
                 break;
             case QEMU_OPTION_display:
                 display_type = select_display(optarg);
@@ -4060,6 +4064,11 @@ int main(int argc, char **argv, char **envp)
 
     register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL);
 
+    if (qemu_opts_foreach(qemu_find_opts("numa"), numa_init_func,
+                          NULL, 1) != 0) {
+        exit(1);
+    }
+
     set_numa_nodes();
 
     if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {
Signature · 1 line
1.8.4.2
#6 lore raw

Re: [Qemu-devel] [RFC PATCH 04/14] NUMA: convert -numa option to use OptsVisitor

Quoted 12 lines · Paolo Bonzini

From: Wanlong Gao <[email protected]>

---

+++ b/qapi-schema.json

qapi-schema.json +1 -0
@@ -4235,3 +4235,33 @@
 # Since: 1.7
 ##
 { 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }
+

qapi-schema.json line 4248

Quoted 10 lines
qapi-schema.json +10 -0
+##
+# @NumaOptions
+#
+# A discriminated record of NUMA options. (for OptsVisitor)
+#
+# Since 2.0
+##
+{ 'union': 'NumaOptions',
+  'data': {
+    'node': 'NumaNodeOptions' }}

Why do we need a union, if there's no alternative, and since nothing else in the series adds an alternative?

qapi-schema.json line 4257

Quoted 9 lines
qapi-schema.json +9 -0
+
+##
+# @NumaNodeOptions
+#
+# Create a guest NUMA node. (for OptsVisitor)
+#
+# @nodeid: #optional NUMA node ID
+#
+# @cpus: #optional VCPUs belong to this node

What are the defaults if these fields are omitted?

Review line 4259

Quoted 2 lines
(quoted diff) +2 -0
+#
+# @mem: #optional memory size of this node

In bytes? Why is this field a string instead of an integer?

Quoted 8 lines
qapi-schema.json +8 -0
+#
+# Since: 2.0
+##
+{ 'type': 'NumaNodeOptions',
+  'data': {
+   '*nodeid': 'uint16',
+   '*cpus':   ['uint16'],
+   '*mem':    'str' }}
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#7 lore raw

Re: [Qemu-devel] [RFC PATCH 04/14] NUMA: convert -numa option to use OptsVisitor

Il 11/12/2013 19:51, Eric Blake ha scritto:

Quoted 5 lines
Quoted 3 lines

qapi-schema.json line 4248

Quoted 3 lines
qapi-schema.json +3 -0
+{ 'union': 'NumaOptions',
+  'data': {
+    'node': 'NumaNodeOptions' }}

Why do we need a union, if there's no alternative, and since nothing else in the series adds an alternative?

Because these structures are used to parse command-line options and follow somewhat special rules. The "node" in "-numa node,..." is present for forwards-extensibility. Another alternative, "mem", was added in previous versions of the NUMA policy patches but is made obsolete by Igor's memory object.

Quoted 10 lines
Quoted 9 lines

qapi-schema.json line 4257

Quoted 9 lines
qapi-schema.json +9 -0
+
+##
+# @NumaNodeOptions
+#
+# Create a guest NUMA node. (for OptsVisitor)
+#
+# @nodeid: #optional NUMA node ID
+#
+# @cpus: #optional VCPUs belong to this node

What are the defaults if these fields are omitted?

Wanlong, can you fill this out when you resubmit?

Quoted 3 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+#
+# @mem: #optional memory size of this node

In bytes? Why is this field a string instead of an integer?

It was like this because it is a command-line option and thus is never used via QMP. However, it can and should indeed be a 'size', handled like Igor did for '-m mem=' in patch 8 of the series.

Paolo

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
qapi-schema.json +8 -0
+#
+# Since: 2.0
+##
+{ 'type': 'NumaNodeOptions',
+  'data': {
+   '*nodeid': 'uint16',
+   '*cpus':   ['uint16'],
+   '*mem':    'str' }}
#8 lore raw

RFC PATCH 5/14 NUMA: expand MAX_NODES from 64 to 128

In reply to Paolo Bonzini

From: Wanlong Gao <[email protected]>

libnuma choosed 128 for MAX_NODES, so we follow libnuma here.

---
 include/sysemu/sysemu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/sysemu/sysemu.h +1 -1
index 20b05a3..4c94cf5 100644
@@ -132,7 +132,7 @@ extern size_t boot_splash_filedata_size;
 extern uint8_t qemu_extra_params_fw[2];
 extern QEMUClockType rtc_clock;
 
-#define MAX_NODES 64
+#define MAX_NODES 128
 #define MAX_CPUMASK_BITS 255
 extern int nb_numa_nodes;
 typedef struct node_info {
Signature · 1 line
1.8.4.2
#9 lore raw

RFC PATCH 6/14 qapi: add SIZE type parser to string_input_visitor

In reply to Paolo Bonzini

From: Igor Mammedov <[email protected]>

---
 qapi/string-input-visitor.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
qapi/string-input-visitor.c +18 -0
index 8f1bc41..a152f5d 100644
@@ -97,6 +97,23 @@ static void parse_type_number(Visitor *v, double *obj, const char *name,
     *obj = val;
 }
 
+static void parse_type_size(Visitor *v, uint64_t *obj, const char *name,
+                            Error **errp)
+{
+    StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
+    int64_t val;
+    char *endp;
+
+    val = strtosz_suffix(siv->string ? siv->string : "", &endp,
+                         STRTOSZ_DEFSUFFIX_B);
+    if (val < 0 || *endp != '\0') {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, name,
+                  "a size value representible as a non-negative int64");
+        return;
+    }
+    *obj = val;
+}
+
 static void parse_start_optional(Visitor *v, bool *present,
                                  const char *name, Error **errp)
 {
@@ -131,6 +148,7 @@ StringInputVisitor *string_input_visitor_new(const char *str)
     v->visitor.type_bool = parse_type_bool;
     v->visitor.type_str = parse_type_str;
     v->visitor.type_number = parse_type_number;
+    v->visitor.type_size = parse_type_size;
     v->visitor.start_optional = parse_start_optional;
 
     v->string = str;
Signature · 1 line
1.8.4.2
#10 lore raw

RFC PATCH 7/14 QemuOpts: introduce qemu_find_opts_singleton

In reply to Paolo Bonzini
---
 include/qemu/config-file.h |  2 ++
 util/qemu-config.c         | 14 ++++++++++++++
 vl.c                       | 11 +----------
 3 files changed, 17 insertions(+), 10 deletions(-)
include/qemu/config-file.h +2 -0
index 508428f..699c3a1 100644
@@ -7,6 +7,8 @@
 
 QemuOptsList *qemu_find_opts(const char *group);
 QemuOptsList *qemu_find_opts_err(const char *group, Error **errp);
+QemuOpts *qemu_find_opts_singleton(const char *group);
+
 void qemu_add_opts(QemuOptsList *list);
 void qemu_add_drive_opts(QemuOptsList *list);
 int qemu_set_option(const char *str);
util/qemu-config.c +14 -0
index 04da942..c6ac589 100644
@@ -39,6 +39,20 @@ QemuOptsList *qemu_find_opts(const char *group)
     return ret;
 }
 
+QemuOpts *qemu_find_opts_singleton(const char *group)
+{
+    QemuOptsList *list;
+    QemuOpts *opts;
+
+    list = qemu_find_opts(group);
+    assert(list);
+    opts = qemu_opts_find(list, NULL);
+    if (!opts) {
+        opts = qemu_opts_create_nofail(list);
+    }
+    return opts;
+}
+
 static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
 {
     CommandLineParameterInfoList *param_list = NULL, *entry;
vl.c +1 -10
index 95181e0..ecda5ad 100644
@@ -537,16 +537,7 @@ static QemuOptsList qemu_msg_opts = {
  */
 QemuOpts *qemu_get_machine_opts(void)
 {
-    QemuOptsList *list;
-    QemuOpts *opts;
-
-    list = qemu_find_opts("machine");
-    assert(list);
-    opts = qemu_opts_find(list, NULL);
-    if (!opts) {
-        opts = qemu_opts_create_nofail(list);
-    }
-    return opts;
+    return qemu_find_opts_singleton("machine");
 }
 
 const char *qemu_get_vm_name(void)
Signature · 1 line
1.8.4.2
#11 lore raw

RFC PATCH 8/14 vl: convert -m to QemuOpts

In reply to Paolo Bonzini

From: Igor Mammedov <[email protected]>

Adds option to -m
"mem" - startup memory amount

For compatibility with legacy CLI if suffix-less number is passed, it assumes amount in Mb.

Otherwise user is free to use suffixed number using suffixes b,k/K,M,G

---
 qemu-options.hx |  7 +++++--
 vl.c            | 52 +++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 46 insertions(+), 13 deletions(-)
qemu-options.hx +5 -2
index af34483..416f8e4 100644
@@ -210,8 +210,11 @@ use is discouraged as it may be removed from future versions.
 ETEXI
 
 DEF("m", HAS_ARG, QEMU_OPTION_m,
-    "-m megs         set virtual RAM size to megs MB [default="
-    stringify(DEFAULT_RAM_SIZE) "]\n", QEMU_ARCH_ALL)
+    "-m [mem=]megs\n"
+    "                configure guest RAM\n"
+    "                mem: initial amount of guest memory (default: "
+    stringify(DEFAULT_RAM_SIZE) "Mb)\n",
+    QEMU_ARCH_ALL)
 STEXI
 @item -m @var{megs}
 @findex -m
vl.c +41 -11

92 lines not on this page · raw message

Signature · 1 line
1.8.4.2
#12 lore raw

RFC PATCH 9/14 qom: fix leak for objects created with -object

In reply to Paolo Bonzini

The object must be unref-ed when its variable goes out of scope.

---
 vl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
vl.c +2 -1
index 68ba565..086a062 100644
@@ -2717,12 +2717,13 @@ static int object_create(QemuOpts *opts, void *opaque)
 
     obj = object_new(type);
     if (qemu_opt_foreach(opts, object_set_property, obj, 1) < 0) {
+        object_unref(obj);
         return -1;
     }
 
     object_property_add_child(container_get(object_get_root(), "/objects"),
                               id, obj, NULL);
-
+    object_unref(obj);
     return 0;
 }
 
Signature · 1 line
1.8.4.2
#14 lore raw

RFC PATCH 10/14 qom: catch errors in object_property_add_child

In reply to Paolo Bonzini
---
 qom/object.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
qom/object.c +7 -2
index fc19cf6..68fe07a 100644
@@ -988,17 +988,22 @@ static void object_finalize_child_property(Object *obj, const char *name,
 void object_property_add_child(Object *obj, const char *name,
                                Object *child, Error **errp)
 {
+    Error *local_err = NULL;
     gchar *type;
 
     type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child)));
 
     object_property_add(obj, name, type, object_get_child_property,
-                        NULL, object_finalize_child_property, child, errp);
-
+                        NULL, object_finalize_child_property, child, &local_err);
+    if (error_is_set(&local_err)) {
+        error_propagate(errp, local_err);
+        goto out;
+    }
     object_ref(child);
     g_assert(child->parent == NULL);
     child->parent = obj;
 
+out:
     g_free(type);
 }
 
Signature · 1 line
1.8.4.2
Reviewed-by on v1 10/14
#15 lore raw

Re: [Qemu-devel] [RFC PATCH 10/14] qom: catch errors in object_property_add_child

Quoted 39 lines · On Wed, 11 Dec 2013 13:19:17 +0100 Paolo Bonzini <[email protected]> wrote:
---
 qom/object.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
qom/object.c +7 -2
index fc19cf6..68fe07a 100644
@@ -988,17 +988,22 @@ static void object_finalize_child_property(Object *obj, const char *name,
 void object_property_add_child(Object *obj, const char *name,
                                Object *child, Error **errp)
 {
+    Error *local_err = NULL;
     gchar *type;
 
     type = g_strdup_printf("child<%s>", object_get_typename(OBJECT(child)));
 
     object_property_add(obj, name, type, object_get_child_property,
-                        NULL, object_finalize_child_property, child, errp);
-
+                        NULL, object_finalize_child_property, child, &local_err);
+    if (error_is_set(&local_err)) {
+        error_propagate(errp, local_err);
+        goto out;
+    }
     object_ref(child);
     g_assert(child->parent == NULL);
     child->parent = obj;
 
+out:
     g_free(type);
 }
 
Signature · 1 line
1.8.4.2
Signature · 2 lines
Regards,
  Igor
#17 lore raw

RFC PATCH 11/14 pc: pass QEMUMachineInitArgs to pc_memory_init

In reply to Paolo Bonzini
---
 hw/i386/pc.c         | 11 +++++------
 hw/i386/pc_piix.c    |  8 +++-----
 hw/i386/pc_q35.c     |  4 +---
 include/hw/i386/pc.h |  7 +++----
 4 files changed, 12 insertions(+), 18 deletions(-)
hw/i386/pc.c +5 -6
index 74c1f16..76c47a9 100644
@@ -1148,10 +1148,8 @@ void pc_acpi_init(const char *default_dsdt)
     }
 }
 
-FWCfgState *pc_memory_init(MemoryRegion *system_memory,
-                           const char *kernel_filename,
-                           const char *kernel_cmdline,
-                           const char *initrd_filename,
+FWCfgState *pc_memory_init(QEMUMachineInitArgs *args,
+                           MemoryRegion *system_memory,
                            ram_addr_t below_4g_mem_size,
                            ram_addr_t above_4g_mem_size,
                            MemoryRegion *rom_memory,
@@ -1163,7 +1161,7 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,
     MemoryRegion *ram_below_4g, *ram_above_4g;
     FWCfgState *fw_cfg;
 
-    linux_boot = (kernel_filename != NULL);
+    linux_boot = (args->kernel_filename != NULL);
 
     /* Allocate RAM.  We allocate it as a single memory region and use
      * aliases to address portions of it, mostly for backwards compatibility
@@ -1204,7 +1202,8 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,
     rom_set_fw(fw_cfg);
 
     if (linux_boot) {
-        load_linux(fw_cfg, kernel_filename, initrd_filename, kernel_cmdline, below_4g_mem_size);
+        load_linux(fw_cfg, args->kernel_filename, args->initrd_filename,
+                   args->kernel_cmdline, below_4g_mem_size);
     }
 
     for (i = 0; i < nb_option_roms; i++) {
hw/i386/pc_piix.c +3 -5
index ab56285..cd3eda1 100644
@@ -130,11 +130,9 @@ static void pc_init1(QEMUMachineInitArgs *args,
 
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
-        fw_cfg = pc_memory_init(system_memory,
-                       args->kernel_filename, args->kernel_cmdline,
-                       args->initrd_filename,
-                       below_4g_mem_size, above_4g_mem_size,
-                       rom_memory, &ram_memory, guest_info);
+        fw_cfg = pc_memory_init(args, system_memory,
+                                below_4g_mem_size, above_4g_mem_size,
+                                rom_memory, &ram_memory, guest_info);
     }
 
     gsi_state = g_malloc0(sizeof(*gsi_state));
hw/i386/pc_q35.c +1 -3
index 97aa842..c2dcbae 100644
@@ -115,9 +115,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
-        pc_memory_init(get_system_memory(),
-                       args->kernel_filename, args->kernel_cmdline,
-                       args->initrd_filename,
+        pc_memory_init(args, get_system_memory(),
                        below_4g_mem_size, above_4g_mem_size,
                        rom_memory, &ram_memory, guest_info);
     }
include/hw/i386/pc.h +3 -4
index 09652fb..7dda9a6 100644
@@ -3,6 +3,7 @@
 
 #include "qemu-common.h"
 #include "exec/memory.h"
+#include "hw/boards.h"
 #include "hw/isa/isa.h"
 #include "hw/block/fdc.h"
 #include "net/net.h"
@@ -140,10 +141,8 @@ static inline uint64_t pci_host_get_hole64_size(uint64_t pci_hole64_size)
 void pc_init_pci64_hole(PcPciInfo *pci_info, uint64_t pci_hole64_start,
                         uint64_t pci_hole64_size);
 
-FWCfgState *pc_memory_init(MemoryRegion *system_memory,
-                           const char *kernel_filename,
-                           const char *kernel_cmdline,
-                           const char *initrd_filename,
+FWCfgState *pc_memory_init(QEMUMachineInitArgs *args,
+                           MemoryRegion *system_memory,
                            ram_addr_t below_4g_mem_size,
                            ram_addr_t above_4g_mem_size,
                            MemoryRegion *rom_memory,
Signature · 1 line
1.8.4.2
#18 lore raw

RFC PATCH 12/14 numa: introduce memory_region_allocate_system_memory

In reply to Paolo Bonzini
---
 hw/i386/pc.c            |  4 +---
 include/sysemu/sysemu.h |  5 +++++
 numa.c                  | 10 ++++++++++
 3 files changed, 16 insertions(+), 3 deletions(-)
hw/i386/pc.c +1 -3
index 76c47a9..61df5d4 100644
@@ -1168,9 +1168,7 @@ FWCfgState *pc_memory_init(QEMUMachineInitArgs *args,
      * with older qemus that used qemu_ram_alloc().
      */
     ram = g_malloc(sizeof(*ram));
-    memory_region_init_ram(ram, NULL, "pc.ram",
-                           below_4g_mem_size + above_4g_mem_size);
-    vmstate_register_ram_global(ram);
+    memory_region_allocate_system_memory(ram, NULL, "pc.ram", args);
     *ram_memory = ram;
     ram_below_4g = g_malloc(sizeof(*ram_below_4g));
     memory_region_init_alias(ram_below_4g, NULL, "ram-below-4g", ram,
include/sysemu/sysemu.h +5 -0
index 4c94cf5..e9da760 100644
@@ -10,6 +10,8 @@
 #include "qemu/notify.h"
 #include "qemu/main-loop.h"
 #include "qemu/bitmap.h"
+#include "qom/object.h"
+#include "hw/boards.h"
 
 /* vl.c */
 
@@ -144,6 +146,9 @@ void set_numa_nodes(void);
 void set_numa_modes(void);
 extern QemuOptsList qemu_numa_opts;
 int numa_init_func(QemuOpts *opts, void *opaque);
+void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
+                                          const char *name,
+                                          QEMUMachineInitArgs *args);
 
 #define MAX_OPTION_ROMS 16
 typedef struct QEMUOptionRom {
numa.c +10 -0
index c4fa665..f903b9e 100644
@@ -187,3 +187,13 @@ void set_numa_modes(void)
         }
     }
 }
+
+void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
+                                          const char *name,
+                                          QEMUMachineInitArgs *args)
+{
+    uint64_t ram_size = args->ram_size;
+
+    memory_region_init_ram(mr, owner, name, ram_size);
+    vmstate_register_ram_global(mr);
+}
Signature · 1 line
1.8.4.2
#19 lore raw

RFC PATCH 13/14 add memdev backend infrastructure

In reply to Paolo Bonzini

From: Igor Mammedov <[email protected]>

Provides framework for splitting host RAM allocation/ policies into a separate backend that could be used by devices.

Initially only legacy RAM backend is provided, which uses memory_region_init_ram() allocator and compatible with every CLI option that affects memory_region_init_ram().

---
 backends/Makefile.objs   |   2 +
 backends/hostmem-ram.c   |  46 +++++++++++++++++++
 backends/hostmem.c       | 116 +++++++++++++++++++++++++++++++++++++++++++++++
 include/sysemu/hostmem.h |  63 +++++++++++++++++++++++++
 4 files changed, 227 insertions(+)
 create mode 100644 backends/hostmem-ram.c
 create mode 100644 backends/hostmem.c
 create mode 100644 include/sysemu/hostmem.h
backends/Makefile.objs +2 -0
index 42557d5..e6bdc11 100644
@@ -6,3 +6,5 @@ common-obj-$(CONFIG_BRLAPI) += baum.o
 $(obj)/baum.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
 
 common-obj-$(CONFIG_TPM) += tpm.o
+
+common-obj-y += hostmem.o hostmem-ram.o
backends/hostmem-ram.c new file +46 -0

46 lines not on this page · raw message

backends/hostmem.c new file +116 -0

116 lines not on this page · raw message

include/sysemu/hostmem.h new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
1.8.4.2
#20 lore raw

RFC PATCH 14/14 numa: add -numa node, memdev= option

In reply to Paolo Bonzini

This option provides the infrastructure for binding guest NUMA nodes to host NUMA nodes. For example:

-object memory-ram,size=1024M,policy=membind,host-nodes=0,id=ram-node0 \
-numa node,nodeid=0,cpus=0,memdev=ram-node0 \
-object memory-ram,size=1024M,policy=interleave,host-nodes=1-3,id=ram-node1 \
-numa node,nodeid=1,cpus=1,memdev=ram-node1

The option replaces "-numa mem".

---
 include/sysemu/sysemu.h |  2 ++
 numa.c                  | 64 +++++++++++++++++++++++++++++++++++++++++++++++--
 qapi-schema.json        |  6 ++++-
 3 files changed, 69 insertions(+), 3 deletions(-)
include/sysemu/sysemu.h +2 -0
index e9da760..acfc0c7 100644
@@ -12,6 +12,7 @@
 #include "qemu/bitmap.h"
 #include "qom/object.h"
 #include "hw/boards.h"
+#include "sysemu/hostmem.h"
 
 /* vl.c */
 
@@ -140,6 +141,7 @@ extern int nb_numa_nodes;
 typedef struct node_info {
     uint64_t node_mem;
     DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
+    HostMemoryBackend *node_memdev;
 } NodeInfo;
 extern NodeInfo numa_info[MAX_NODES];
 void set_numa_nodes(void);
numa.c +62 -2

103 lines not on this page · raw message

qapi-schema.json +5 -1
index d99e39d..e449316 100644
@@ -4256,7 +4256,10 @@
 #
 # @cpus: #optional VCPUs belong to this node
 #
-# @mem: #optional memory size of this node
+# @memdev: #optional memory backend object.  If specified for one node,
+#          it must be specified for all nodes.
+#
+# @mem: #optional memory size of this node; mutually exclusive with @memdev.
 #
 # Since: 2.0
 ##
@@ -4264,4 +4267,5 @@
   'data': {
    '*nodeid': 'uint16',
    '*cpus':   ['uint16'],
+   '*memdev': 'str',
    '*mem':    'str' }}
Signature · 1 line
1.8.4.2
#21 lore raw

Re: [Qemu-devel] [RFC PATCH 14/14] numa: add -numa node, memdev= option

Quoted 7 lines · On Wed, 11 Dec 2013 13:19:21 +0100 Paolo Bonzini <[email protected]> wrote:

This option provides the infrastructure for binding guest NUMA nodes to host NUMA nodes. For example:

-object memory-ram,size=1024M,policy=membind,host-nodes=0,id=ram-node0 \
-numa node,nodeid=0,cpus=0,memdev=ram-node0 \
-object memory-ram,size=1024M,policy=interleave,host-nodes=1-3,id=ram-node1 \
-numa node,nodeid=1,cpus=1,memdev=ram-node1

I was thinking about a bit more radical change:
-object memory-ram,size=1024M,policy=membind,host-nodes=0,id=ram-node0 -device dimm,memdev=ram-node0,node=0
-object memory-ram,size=1024M,policy=membind,host-nodes=1,id=ram-node1 -device dimm,memdev=ram-node1,node=1

that would allow to avoid synthetic -numa option but would require conversion of initial RAM to dimms. That would be more flexible for example allowing bind several backends to one node (like: 1Gb_hugepage + 2Mb_hugepage ones)

Quoted 84 lines

The option replaces "-numa mem".

---
 include/sysemu/sysemu.h |  2 ++
 numa.c                  | 64 +++++++++++++++++++++++++++++++++++++++++++++++--
 qapi-schema.json        |  6 ++++-
 3 files changed, 69 insertions(+), 3 deletions(-)
include/sysemu/sysemu.h +2 -0
index e9da760..acfc0c7 100644
@@ -12,6 +12,7 @@
 #include "qemu/bitmap.h"
 #include "qom/object.h"
 #include "hw/boards.h"
+#include "sysemu/hostmem.h"
 
 /* vl.c */
 
@@ -140,6 +141,7 @@ extern int nb_numa_nodes;
 typedef struct node_info {
     uint64_t node_mem;
     DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
+    HostMemoryBackend *node_memdev;
 } NodeInfo;
 extern NodeInfo numa_info[MAX_NODES];
 void set_numa_nodes(void);
numa.c +21 -0
index f903b9e..686dbfa 100644
@@ -27,6 +27,8 @@
 #include "qapi-visit.h"
 #include "qapi/opts-visitor.h"
 #include "qapi/dealloc-visitor.h"
+#include "qapi/qmp/qerror.h"
+
 QemuOptsList qemu_numa_opts = {
     .name = "numa",
     .implied_opt_name = "type",
@@ -34,10 +36,13 @@ QemuOptsList qemu_numa_opts = {
     .desc = { { 0 } } /* validated with OptsVisitor */
 };
 
+static int have_memdevs = -1;
+
 static int numa_node_parse(NumaNodeOptions *opts)
 {
     uint16_t nodenr;
     uint16List *cpus = NULL;
+    Error *local_err = NULL;
 
     if (opts->has_nodeid) {
         nodenr = opts->nodeid;
@@ -60,6 +65,19 @@ static int numa_node_parse(NumaNodeOptions *opts)
         bitmap_set(numa_info[nodenr].node_cpu, cpus->value, 1);
     }
 
+    if (opts->has_mem && opts->has_memdev) {
+        fprintf(stderr, "qemu: cannot specify both mem= and memdev=\n");
+        return -1;
+    }
+
+    if (have_memdevs == -1) {
+        have_memdevs = opts->has_memdev;
+    }
+    if (opts->has_memdev != have_memdevs) {
+        fprintf(stderr, "qemu: memdev option must be specified for either "
+                "all or no nodes\n");
+    }
+
     if (opts->has_mem) {
         int64_t mem_size;
         char *endptr;
@@ -70,7 +88,19 @@ static int numa_node_parse(NumaNodeOptions *opts)
         }
         numa_info[nodenr].node_mem = mem_size;
     }
+    if (opts->has_memdev) {
+        Object *o;
+        o = object_resolve_path_type(opts->memdev, TYPE_MEMORY_BACKEND, NULL);

numa.c static int numa_node_parse(NumaNodeOptions *opts) · line 103

Quoted 10 lines
numa.c +9 -0
+        if (!o) {
+            error_setg(&local_err, "memdev=%s is ambiguous", opts->memdev);
+            qerror_report_err(local_err);
+            return -1;
+        }
 
+        object_ref(o);
+        numa_info[nodenr].node_mem = object_property_get_int(o, "size", NULL);
+        numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
+    }

there wouldn't be any need for keeping numa mappings in separate structure, if we use node property of dimm device.
acpi_build then could build SRAT directly enumerating present dimm devices.

Quoted 23 lines
numa.c +11 -0
     return 0;
 }
 
@@ -188,12 +218,42 @@ void set_numa_modes(void)
     }
 }
 
+static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
+                                           const char *name,
+                                           QEMUMachineInitArgs *args)
+{
+    uint64_t ram_size = args->ram_size;
+
+    memory_region_init_ram(mr, owner, name, ram_size);
+    vmstate_register_ram_global(mr);
+}
+
 void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
                                           const char *name,
                                           QEMUMachineInitArgs *args)
 {
     uint64_t ram_size = args->ram_size;
+    uint64_t addr = 0;

numa.c void set_numa_modes(void) · line 244

Quoted 10 lines
numa.c +7 -2
+    int i;
 
-    memory_region_init_ram(mr, owner, name, ram_size);
-    vmstate_register_ram_global(mr);
+    if (nb_numa_nodes == 0 || !have_memdevs) {
+        allocate_system_memory_nonnuma(mr, owner, name, args);
+        return;
+    }
+
+    memory_region_init(mr, owner, name, ram_size);

container might clip subregions due to presence of hole, it's size should be ram_size + hole_size.

Quoted 40 lines
numa.c +14 -0
+    for (i = 0; i < nb_numa_nodes; i++) {
+        Error *local_err = NULL;
+        uint64_t size = numa_info[i].node_mem;
+        HostMemoryBackend *backend = numa_info[i].node_memdev;
+        MemoryRegion *seg = host_memory_backend_get_memory(backend, &local_err);
+        if (local_err) {
+            qerror_report_err(local_err);
+            exit(1);
+        }
+
+        memory_region_add_subregion(mr, addr, seg);
+        vmstate_register_ram_global(seg);
+        addr += size;
+    }
 }
qapi-schema.json +5 -1
index d99e39d..e449316 100644
@@ -4256,7 +4256,10 @@
 #
 # @cpus: #optional VCPUs belong to this node
 #
-# @mem: #optional memory size of this node
+# @memdev: #optional memory backend object.  If specified for one node,
+#          it must be specified for all nodes.
+#
+# @mem: #optional memory size of this node; mutually exclusive with @memdev.
 #
 # Since: 2.0
 ##
@@ -4264,4 +4267,5 @@
   'data': {
    '*nodeid': 'uint16',
    '*cpus':   ['uint16'],
+   '*memdev': 'str',
    '*mem':    'str' }}
Signature · 1 line
1.8.4.2
Signature · 2 lines
Regards,
  Igor
#22 lore raw

Re: [Qemu-devel] [RFC PATCH 14/14] numa: add -numa node, memdev= option

Il 11/12/2013 16:36, Igor Mammedov ha scritto:

Quoted 11 lines
Quoted 4 lines
Quoted 4 lines

-object memory-ram,size=1024M,policy=membind,host-nodes=0,id=ram-node0 \
-numa node,nodeid=0,cpus=0,memdev=ram-node0 \
-object memory-ram,size=1024M,policy=interleave,host-nodes=1-3,id=ram-node1 \
-numa node,nodeid=1,cpus=1,memdev=ram-node1

I was thinking about a bit more radical change:

(quoted diff) +0 -4
-object memory-ram,size=1024M,policy=membind,host-nodes=0,id=ram-node0
-device dimm,memdev=ram-node0,node=0
-object memory-ram,size=1024M,policy=membind,host-nodes=1,id=ram-node1
-device dimm,memdev=ram-node1,node=1
Quoted 1 line

that would allow to avoid synthetic -numa option

You still need -numa for cpus, at least in the short/medium-term.

Quoted 3 lines

but would require conversion
of initial RAM to dimms. That would be more flexible for example allowing bind several backends to one node (like: 1Gb_hugepage + 2Mb_hugepage ones)

Yes, that's another possibility, perhaps even cleaner.

With "-numa node,memdev=", your board only needs to use memory_region_allocate_system_memory in order to apply a NUMA policy to guest RAM; it also works with guests or boards that are not themselves NUMA-aware.

Doing the same with "-device dimm" requires changing the board to support RAM-as-dimms; do you have any idea how easy/hard that would be?

Paolo