]> git.proxmox.com Git - mirror_qemu.git/blame - hw/core/numa.c
Include migration/vmstate.h less
[mirror_qemu.git] / hw / core / numa.c
CommitLineData
96d0e26c
WG
1/*
2 * NUMA parameter parsing routines
3 *
4 * Copyright (c) 2014 Fujitsu Ltd.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
d38ea87a 25#include "qemu/osdep.h"
e35704ba 26#include "sysemu/numa.h"
96d0e26c 27#include "exec/cpu-common.h"
0987d735 28#include "exec/ramlist.h"
96d0e26c 29#include "qemu/bitmap.h"
2b631ec2 30#include "qemu/error-report.h"
e688df6b 31#include "qapi/error.h"
0042109a 32#include "qapi/opts-visitor.h"
8ac25c84 33#include "qapi/qapi-visit-machine.h"
f8123f22 34#include "sysemu/qtest.h"
5b009e40 35#include "hw/mem/pc-dimm.h"
d6454270 36#include "migration/vmstate.h"
2cc0e2e8 37#include "hw/mem/memory-device.h"
7dcd1d70
EH
38#include "qemu/option.h"
39#include "qemu/config-file.h"
cc001888 40#include "qemu/cutils.h"
0042109a
WG
41
42QemuOptsList qemu_numa_opts = {
43 .name = "numa",
44 .implied_opt_name = "type",
45 .head = QTAILQ_HEAD_INITIALIZER(qemu_numa_opts.head),
46 .desc = { { 0 } } /* validated with OptsVisitor */
47};
48
b69239e0
IM
49static int have_memdevs;
50static int have_mem;
25712ffe
EH
51static int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
52 * For all nodes, nodeid < max_numa_nodeid
53 */
de1a7c84 54int nb_numa_nodes;
0f203430 55bool have_numa_distance;
de1a7c84 56NodeInfo numa_info[MAX_NODES];
7febe36f 57
e75e2a14 58
64c2a8f6 59static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
cc001888 60 Error **errp)
96d0e26c 61{
a22528b9 62 Error *err = NULL;
0042109a
WG
63 uint16_t nodenr;
64 uint16List *cpus = NULL;
64c2a8f6 65 MachineClass *mc = MACHINE_GET_CLASS(ms);
5cc8767d 66 unsigned int max_cpus = ms->smp.max_cpus;
96d0e26c 67
0042109a
WG
68 if (node->has_nodeid) {
69 nodenr = node->nodeid;
96d0e26c 70 } else {
0042109a 71 nodenr = nb_numa_nodes;
96d0e26c
WG
72 }
73
0042109a
WG
74 if (nodenr >= MAX_NODES) {
75 error_setg(errp, "Max number of NUMA nodes reached: %"
01bbbcf4 76 PRIu16 "", nodenr);
0042109a 77 return;
96d0e26c
WG
78 }
79
1945b9d8
EH
80 if (numa_info[nodenr].present) {
81 error_setg(errp, "Duplicate NUMA nodeid: %" PRIu16, nodenr);
82 return;
83 }
84
81ce6aa5 85 if (!mc->cpu_index_to_instance_props || !mc->get_default_cpu_node_id) {
a22528b9
MA
86 error_setg(errp, "NUMA is not supported by this machine-type");
87 return;
64c2a8f6 88 }
0042109a 89 for (cpus = node->cpus; cpus; cpus = cpus->next) {
7c88e65d 90 CpuInstanceProperties props;
8979c945
EH
91 if (cpus->value >= max_cpus) {
92 error_setg(errp,
93 "CPU index (%" PRIu16 ")"
94 " should be smaller than maxcpus (%d)",
95 cpus->value, max_cpus);
0042109a
WG
96 return;
97 }
7c88e65d
IM
98 props = mc->cpu_index_to_instance_props(ms, cpus->value);
99 props.node_id = nodenr;
100 props.has_node_id = true;
a22528b9
MA
101 machine_set_cpu_numa_node(ms, &props, &err);
102 if (err) {
103 error_propagate(errp, err);
104 return;
105 }
96d0e26c
WG
106 }
107
b69239e0
IM
108 have_memdevs = have_memdevs ? : node->has_memdev;
109 have_mem = have_mem ? : node->has_mem;
110 if ((node->has_mem && have_memdevs) || (node->has_memdev && have_mem)) {
111 error_setg(errp, "numa configuration should use either mem= or memdev=,"
112 "mixing both is not allowed");
7febe36f
PB
113 return;
114 }
115
0042109a 116 if (node->has_mem) {
cc001888 117 numa_info[nodenr].node_mem = node->mem;
f8123f22
EH
118 if (!qtest_enabled()) {
119 warn_report("Parameter -numa node,mem is deprecated,"
120 " use -numa node,memdev instead");
121 }
0042109a 122 }
7febe36f
PB
123 if (node->has_memdev) {
124 Object *o;
125 o = object_resolve_path_type(node->memdev, TYPE_MEMORY_BACKEND, NULL);
126 if (!o) {
127 error_setg(errp, "memdev=%s is ambiguous", node->memdev);
128 return;
129 }
130
131 object_ref(o);
61d7c144 132 numa_info[nodenr].node_mem = object_property_get_uint(o, "size", NULL);
7febe36f
PB
133 numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
134 }
1af878e0
EH
135 numa_info[nodenr].present = true;
136 max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);
7b8be49d 137 nb_numa_nodes++;
96d0e26c
WG
138}
139
0f203430
HC
140static void parse_numa_distance(NumaDistOptions *dist, Error **errp)
141{
142 uint16_t src = dist->src;
143 uint16_t dst = dist->dst;
144 uint8_t val = dist->val;
145
146 if (src >= MAX_NODES || dst >= MAX_NODES) {
74f38e96
IM
147 error_setg(errp, "Parameter '%s' expects an integer between 0 and %d",
148 src >= MAX_NODES ? "src" : "dst", MAX_NODES - 1);
0f203430
HC
149 return;
150 }
151
152 if (!numa_info[src].present || !numa_info[dst].present) {
153 error_setg(errp, "Source/Destination NUMA node is missing. "
154 "Please use '-numa node' option to declare it first.");
155 return;
156 }
157
158 if (val < NUMA_DISTANCE_MIN) {
159 error_setg(errp, "NUMA distance (%" PRIu8 ") is invalid, "
160 "it shouldn't be less than %d.",
161 val, NUMA_DISTANCE_MIN);
162 return;
163 }
164
165 if (src == dst && val != NUMA_DISTANCE_MIN) {
166 error_setg(errp, "Local distance of node %d should be %d.",
167 src, NUMA_DISTANCE_MIN);
168 return;
169 }
170
171 numa_info[src].distance[dst] = val;
172 have_numa_distance = true;
173}
174
3319b4ef 175void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp)
96d0e26c 176{
0042109a 177 Error *err = NULL;
96d0e26c 178
1fd5d4fe 179 switch (object->type) {
d081a49a 180 case NUMA_OPTIONS_TYPE_NODE:
cc001888 181 parse_numa_node(ms, &object->u.node, &err);
0042109a 182 if (err) {
157e94e8 183 goto end;
96d0e26c 184 }
0042109a 185 break;
0f203430
HC
186 case NUMA_OPTIONS_TYPE_DIST:
187 parse_numa_distance(&object->u.dist, &err);
188 if (err) {
189 goto end;
190 }
191 break;
419fcdec
IM
192 case NUMA_OPTIONS_TYPE_CPU:
193 if (!object->u.cpu.has_node_id) {
194 error_setg(&err, "Missing mandatory node-id property");
195 goto end;
196 }
197 if (!numa_info[object->u.cpu.node_id].present) {
198 error_setg(&err, "Invalid node-id=%" PRId64 ", NUMA node must be "
199 "defined with -numa node,nodeid=ID before it's used with "
200 "-numa cpu,node-id=ID", object->u.cpu.node_id);
201 goto end;
202 }
203
204 machine_set_cpu_numa_node(ms, qapi_NumaCpuOptions_base(&object->u.cpu),
205 &err);
206 break;
0042109a
WG
207 default:
208 abort();
209 }
96d0e26c 210
3319b4ef
IM
211end:
212 error_propagate(errp, err);
213}
214
4f7ec696 215static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
3319b4ef
IM
216{
217 NumaOptions *object = NULL;
218 MachineState *ms = MACHINE(opaque);
219 Error *err = NULL;
220 Visitor *v = opts_visitor_new(opts);
221
222 visit_type_NumaOptions(v, NULL, &object, &err);
223 visit_free(v);
224 if (err) {
225 goto end;
226 }
227
228 /* Fix up legacy suffix-less format */
229 if ((object->type == NUMA_OPTIONS_TYPE_NODE) && object->u.node.has_mem) {
230 const char *mem_str = qemu_opt_get(opts, "mem");
231 qemu_strtosz_MiB(mem_str, NULL, &object->u.node.mem);
232 }
233
234 set_numa_options(ms, object, &err);
235
157e94e8 236end:
96a1616c 237 qapi_free_NumaOptions(object);
157e94e8 238 if (err) {
4f7ec696 239 error_propagate(errp, err);
157e94e8
MAL
240 return -1;
241 }
0042109a 242
157e94e8 243 return 0;
96d0e26c
WG
244}
245
0f203430
HC
246/* If all node pair distances are symmetric, then only distances
247 * in one direction are enough. If there is even one asymmetric
248 * pair, though, then all distances must be provided. The
249 * distance from a node to itself is always NUMA_DISTANCE_MIN,
250 * so providing it is never necessary.
251 */
252static void validate_numa_distance(void)
3ef71975 253{
0f203430
HC
254 int src, dst;
255 bool is_asymmetrical = false;
256
257 for (src = 0; src < nb_numa_nodes; src++) {
258 for (dst = src; dst < nb_numa_nodes; dst++) {
259 if (numa_info[src].distance[dst] == 0 &&
260 numa_info[dst].distance[src] == 0) {
261 if (src != dst) {
262 error_report("The distance between node %d and %d is "
263 "missing, at least one distance value "
264 "between each nodes should be provided.",
265 src, dst);
266 exit(EXIT_FAILURE);
267 }
268 }
3ef71975 269
0f203430
HC
270 if (numa_info[src].distance[dst] != 0 &&
271 numa_info[dst].distance[src] != 0 &&
272 numa_info[src].distance[dst] !=
273 numa_info[dst].distance[src]) {
274 is_asymmetrical = true;
275 }
276 }
277 }
278
279 if (is_asymmetrical) {
280 for (src = 0; src < nb_numa_nodes; src++) {
281 for (dst = 0; dst < nb_numa_nodes; dst++) {
282 if (src != dst && numa_info[src].distance[dst] == 0) {
283 error_report("At least one asymmetrical pair of "
284 "distances is given, please provide distances "
285 "for both directions of all node pairs.");
286 exit(EXIT_FAILURE);
287 }
288 }
289 }
3ef71975 290 }
3ef71975
EH
291}
292
0f203430 293static void complete_init_numa_distance(void)
3ef71975 294{
0f203430 295 int src, dst;
3ef71975 296
0f203430
HC
297 /* Fixup NUMA distance by symmetric policy because if it is an
298 * asymmetric distance table, it should be a complete table and
299 * there would not be any missing distance except local node, which
300 * is verified by validate_numa_distance above.
301 */
302 for (src = 0; src < nb_numa_nodes; src++) {
303 for (dst = 0; dst < nb_numa_nodes; dst++) {
304 if (numa_info[src].distance[dst] == 0) {
305 if (src == dst) {
306 numa_info[src].distance[dst] = NUMA_DISTANCE_MIN;
307 } else {
308 numa_info[src].distance[dst] = numa_info[dst].distance[src];
309 }
310 }
3ef71975 311 }
3ef71975 312 }
0f203430 313}
549fc54b 314
3bfe5716
LV
315void numa_legacy_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
316 int nb_nodes, ram_addr_t size)
317{
318 int i;
319 uint64_t usedmem = 0;
320
321 /* Align each node according to the alignment
322 * requirements of the machine class
323 */
324
325 for (i = 0; i < nb_nodes - 1; i++) {
326 nodes[i].node_mem = (size / nb_nodes) &
327 ~((1 << mc->numa_mem_align_shift) - 1);
328 usedmem += nodes[i].node_mem;
549fc54b 329 }
3bfe5716 330 nodes[i].node_mem = size - usedmem;
3ef71975
EH
331}
332
3bfe5716
LV
333void numa_default_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
334 int nb_nodes, ram_addr_t size)
96d0e26c 335{
12d6e464 336 int i;
3bfe5716
LV
337 uint64_t usedmem = 0, node_mem;
338 uint64_t granularity = size / nb_nodes;
339 uint64_t propagate = 0;
340
341 for (i = 0; i < nb_nodes - 1; i++) {
342 node_mem = (granularity + propagate) &
343 ~((1 << mc->numa_mem_align_shift) - 1);
344 propagate = granularity + propagate - node_mem;
345 nodes[i].node_mem = node_mem;
346 usedmem += node_mem;
347 }
348 nodes[i].node_mem = size - usedmem;
349}
12d6e464 350
7a3099fc 351void numa_complete_configuration(MachineState *ms)
96d0e26c 352{
12d6e464 353 int i;
ea089eeb 354 MachineClass *mc = MACHINE_GET_CLASS(ms);
cdda2018 355
7b8be49d
DL
356 /*
357 * If memory hotplug is enabled (slots > 0) but without '-numa'
358 * options explicitly on CLI, guestes will break.
359 *
360 * Windows: won't enable memory hotplug without SRAT table at all
361 *
362 * Linux: if QEMU is started with initial memory all below 4Gb
363 * and no SRAT table present, guest kernel will use nommu DMA ops,
364 * which breaks 32bit hw drivers when memory is hotplugged and
365 * guest tries to use it with that drivers.
366 *
367 * Enable NUMA implicitly by adding a new NUMA node automatically.
368 */
369 if (ms->ram_slots > 0 && nb_numa_nodes == 0 &&
370 mc->auto_enable_numa_with_memhp) {
371 NumaNodeOptions node = { };
a22528b9 372 parse_numa_node(ms, &node, &error_abort);
7b8be49d
DL
373 }
374
12d6e464
EH
375 assert(max_numa_nodeid <= MAX_NODES);
376
377 /* No support for sparse NUMA node IDs yet: */
378 for (i = max_numa_nodeid - 1; i >= 0; i--) {
379 /* Report large node IDs first, to make mistakes easier to spot */
380 if (!numa_info[i].present) {
381 error_report("numa: Node ID missing: %d", i);
382 exit(1);
383 }
384 }
385
386 /* This must be always true if all nodes are present: */
387 assert(nb_numa_nodes == max_numa_nodeid);
388
96d0e26c 389 if (nb_numa_nodes > 0) {
2b631ec2 390 uint64_t numa_total;
96d0e26c
WG
391
392 if (nb_numa_nodes > MAX_NODES) {
393 nb_numa_nodes = MAX_NODES;
394 }
395
9851d0fe 396 /* If no memory size is given for any node, assume the default case
96d0e26c
WG
397 * and distribute the available memory equally across all nodes
398 */
399 for (i = 0; i < nb_numa_nodes; i++) {
8c85901e 400 if (numa_info[i].node_mem != 0) {
96d0e26c
WG
401 break;
402 }
403 }
404 if (i == nb_numa_nodes) {
3bfe5716
LV
405 assert(mc->numa_auto_assign_ram);
406 mc->numa_auto_assign_ram(mc, numa_info, nb_numa_nodes, ram_size);
f8123f22
EH
407 if (!qtest_enabled()) {
408 warn_report("Default splitting of RAM between nodes is deprecated,"
409 " Use '-numa node,memdev' to explictly define RAM"
410 " allocation per node");
411 }
96d0e26c
WG
412 }
413
2b631ec2
WG
414 numa_total = 0;
415 for (i = 0; i < nb_numa_nodes; i++) {
8c85901e 416 numa_total += numa_info[i].node_mem;
2b631ec2
WG
417 }
418 if (numa_total != ram_size) {
c68233ae
HT
419 error_report("total memory for NUMA nodes (0x%" PRIx64 ")"
420 " should equal RAM size (0x" RAM_ADDR_FMT ")",
2b631ec2
WG
421 numa_total, ram_size);
422 exit(1);
423 }
424
0f203430
HC
425 /* QEMU needs at least all unique node pair distances to build
426 * the whole NUMA distance table. QEMU treats the distance table
427 * as symmetric by default, i.e. distance A->B == distance B->A.
428 * Thus, QEMU is able to complete the distance table
429 * initialization even though only distance A->B is provided and
430 * distance B->A is not. QEMU knows the distance of a node to
431 * itself is always 10, so A->A distances may be omitted. When
432 * the distances of two nodes of a pair differ, i.e. distance
433 * A->B != distance B->A, then that means the distance table is
434 * asymmetric. In this case, the distances for both directions
435 * of all node pairs are required.
436 */
437 if (have_numa_distance) {
438 /* Validate enough NUMA distance information was provided. */
439 validate_numa_distance();
96d0e26c 440
0f203430
HC
441 /* Validation succeeded, now fill in any missing distances. */
442 complete_init_numa_distance();
96d0e26c
WG
443 }
444 }
445}
dfabb8b9 446
7a3099fc
IM
447void parse_numa_opts(MachineState *ms)
448{
4f7ec696 449 qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, ms, &error_fatal);
7a3099fc
IM
450}
451
a0ceb640
IM
452void numa_cpu_pre_plug(const CPUArchId *slot, DeviceState *dev, Error **errp)
453{
a0ceb640
IM
454 int node_id = object_property_get_int(OBJECT(dev), "node-id", &error_abort);
455
a0ceb640
IM
456 if (node_id == CPU_UNSET_NUMA_NODE_ID) {
457 /* due to bug in libvirt, it doesn't pass node-id from props on
458 * device_add as expected, so we have to fix it up here */
d41f3e75
IM
459 if (slot->props.has_node_id) {
460 object_property_set_int(OBJECT(dev), slot->props.node_id,
461 "node-id", errp);
462 }
463 } else if (node_id != slot->props.node_id) {
a5bf9fbc
LV
464 error_setg(errp, "invalid node-id, must be %"PRId64,
465 slot->props.node_id);
a0ceb640
IM
466 }
467}
468
7febe36f
PB
469static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
470 const char *name,
471 uint64_t ram_size)
472{
0b183fc8
PB
473 if (mem_path) {
474#ifdef __linux__
7f56e740 475 Error *err = NULL;
cbfc0171 476 memory_region_init_ram_from_file(mr, owner, name, ram_size, 0, 0,
7f56e740 477 mem_path, &err);
c3ba3095 478 if (err) {
29b762f5 479 error_report_err(err);
fae947b0
LC
480 if (mem_prealloc) {
481 exit(1);
482 }
cb79224b
IM
483 warn_report("falling back to regular RAM allocation");
484 error_printf("This is deprecated. Make sure that -mem-path "
485 " specified path has sufficient resources to allocate"
486 " -m specified RAM amount");
fae947b0
LC
487 /* Legacy behavior: if allocation failed, fall back to
488 * regular RAM allocation.
489 */
6233b679 490 mem_path = NULL;
1cfe48c1 491 memory_region_init_ram_nomigrate(mr, owner, name, ram_size, &error_fatal);
7f56e740 492 }
0b183fc8
PB
493#else
494 fprintf(stderr, "-mem-path not supported on this host\n");
495 exit(1);
496#endif
497 } else {
1cfe48c1 498 memory_region_init_ram_nomigrate(mr, owner, name, ram_size, &error_fatal);
0b183fc8 499 }
7febe36f
PB
500 vmstate_register_ram_global(mr);
501}
502
dfabb8b9
PB
503void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
504 const char *name,
505 uint64_t ram_size)
506{
7febe36f
PB
507 uint64_t addr = 0;
508 int i;
509
510 if (nb_numa_nodes == 0 || !have_memdevs) {
511 allocate_system_memory_nonnuma(mr, owner, name, ram_size);
512 return;
513 }
514
515 memory_region_init(mr, owner, name, ram_size);
f51878ba 516 for (i = 0; i < nb_numa_nodes; i++) {
7febe36f
PB
517 uint64_t size = numa_info[i].node_mem;
518 HostMemoryBackend *backend = numa_info[i].node_memdev;
519 if (!backend) {
520 continue;
521 }
7943e97b 522 MemoryRegion *seg = host_memory_backend_get_memory(backend);
7febe36f 523
0462faee
HT
524 if (memory_region_is_mapped(seg)) {
525 char *path = object_get_canonical_path_component(OBJECT(backend));
526 error_report("memory backend %s is used multiple times. Each "
527 "-numa option must use a different memdev value.",
528 path);
2920bd64 529 g_free(path);
0462faee
HT
530 exit(1);
531 }
532
0b217571 533 host_memory_backend_set_mapped(backend, true);
7febe36f
PB
534 memory_region_add_subregion(mr, addr, seg);
535 vmstate_register_ram_global(seg);
536 addr += size;
537 }
dfabb8b9 538}
76b5d850 539
31959e82 540static void numa_stat_memory_devices(NumaNodeMem node_mem[])
5b009e40 541{
2cc0e2e8 542 MemoryDeviceInfoList *info_list = qmp_memory_device_list();
5b009e40 543 MemoryDeviceInfoList *info;
31959e82 544 PCDIMMDeviceInfo *pcdimm_info;
cae02c34 545 VirtioPMEMDeviceInfo *vpi;
5b009e40 546
5b009e40
HZ
547 for (info = info_list; info; info = info->next) {
548 MemoryDeviceInfo *value = info->value;
549
550 if (value) {
1fd5d4fe 551 switch (value->type) {
6388e18d 552 case MEMORY_DEVICE_INFO_KIND_DIMM:
6388e18d 553 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
cae02c34
DH
554 pcdimm_info = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
555 value->u.dimm.data : value->u.nvdimm.data;
31959e82 556 node_mem[pcdimm_info->node].node_mem += pcdimm_info->size;
178003ea
DH
557 node_mem[pcdimm_info->node].node_plugged_mem +=
558 pcdimm_info->size;
cae02c34
DH
559 break;
560 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
561 vpi = value->u.virtio_pmem.data;
562 /* TODO: once we support numa, assign to right node */
563 node_mem[0].node_mem += vpi->size;
564 node_mem[0].node_plugged_mem += vpi->size;
565 break;
566 default:
567 g_assert_not_reached();
5b009e40
HZ
568 }
569 }
570 }
571 qapi_free_MemoryDeviceInfoList(info_list);
572}
573
31959e82 574void query_numa_node_mem(NumaNodeMem node_mem[])
5b009e40
HZ
575{
576 int i;
577
578 if (nb_numa_nodes <= 0) {
579 return;
580 }
581
582 numa_stat_memory_devices(node_mem);
583 for (i = 0; i < nb_numa_nodes; i++) {
31959e82 584 node_mem[i].node_mem += numa_info[i].node_mem;
5b009e40
HZ
585 }
586}
587
0987d735
PB
588void ram_block_notifier_add(RAMBlockNotifier *n)
589{
590 QLIST_INSERT_HEAD(&ram_list.ramblock_notifiers, n, next);
591}
592
593void ram_block_notifier_remove(RAMBlockNotifier *n)
594{
595 QLIST_REMOVE(n, next);
596}
597
598void ram_block_notify_add(void *host, size_t size)
599{
600 RAMBlockNotifier *notifier;
601
602 QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) {
603 notifier->ram_block_added(notifier, host, size);
604 }
605}
606
607void ram_block_notify_remove(void *host, size_t size)
608{
609 RAMBlockNotifier *notifier;
610
611 QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) {
612 notifier->ram_block_removed(notifier, host, size);
613 }
614}