You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

numa.c 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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. #include "qemu/osdep.h"
  25. #include "sysemu/numa.h"
  26. #include "exec/cpu-common.h"
  27. #include "exec/ramlist.h"
  28. #include "qemu/bitmap.h"
  29. #include "qom/cpu.h"
  30. #include "qemu/error-report.h"
  31. #include "qapi/error.h"
  32. #include "qapi/opts-visitor.h"
  33. #include "qapi/qapi-commands-misc.h"
  34. #include "qapi/qapi-visit-misc.h"
  35. #include "hw/boards.h"
  36. #include "sysemu/hostmem.h"
  37. #include "hw/mem/pc-dimm.h"
  38. #include "hw/mem/memory-device.h"
  39. #include "qemu/option.h"
  40. #include "qemu/config-file.h"
  41. #include "qemu/cutils.h"
  42. QemuOptsList 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. static int have_memdevs = -1;
  49. static int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
  50. * For all nodes, nodeid < max_numa_nodeid
  51. */
  52. int nb_numa_nodes;
  53. bool have_numa_distance;
  54. NodeInfo numa_info[MAX_NODES];
  55. static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
  56. Error **errp)
  57. {
  58. Error *err = NULL;
  59. uint16_t nodenr;
  60. uint16List *cpus = NULL;
  61. MachineClass *mc = MACHINE_GET_CLASS(ms);
  62. if (node->has_nodeid) {
  63. nodenr = node->nodeid;
  64. } else {
  65. nodenr = nb_numa_nodes;
  66. }
  67. if (nodenr >= MAX_NODES) {
  68. error_setg(errp, "Max number of NUMA nodes reached: %"
  69. PRIu16 "", nodenr);
  70. return;
  71. }
  72. if (numa_info[nodenr].present) {
  73. error_setg(errp, "Duplicate NUMA nodeid: %" PRIu16, nodenr);
  74. return;
  75. }
  76. if (!mc->cpu_index_to_instance_props || !mc->get_default_cpu_node_id) {
  77. error_setg(errp, "NUMA is not supported by this machine-type");
  78. return;
  79. }
  80. for (cpus = node->cpus; cpus; cpus = cpus->next) {
  81. CpuInstanceProperties props;
  82. if (cpus->value >= max_cpus) {
  83. error_setg(errp,
  84. "CPU index (%" PRIu16 ")"
  85. " should be smaller than maxcpus (%d)",
  86. cpus->value, max_cpus);
  87. return;
  88. }
  89. props = mc->cpu_index_to_instance_props(ms, cpus->value);
  90. props.node_id = nodenr;
  91. props.has_node_id = true;
  92. machine_set_cpu_numa_node(ms, &props, &err);
  93. if (err) {
  94. error_propagate(errp, err);
  95. return;
  96. }
  97. }
  98. if (node->has_mem && node->has_memdev) {
  99. error_setg(errp, "cannot specify both mem= and memdev=");
  100. return;
  101. }
  102. if (have_memdevs == -1) {
  103. have_memdevs = node->has_memdev;
  104. }
  105. if (node->has_memdev != have_memdevs) {
  106. error_setg(errp, "memdev option must be specified for either "
  107. "all or no nodes");
  108. return;
  109. }
  110. if (node->has_mem) {
  111. numa_info[nodenr].node_mem = node->mem;
  112. }
  113. if (node->has_memdev) {
  114. Object *o;
  115. o = object_resolve_path_type(node->memdev, TYPE_MEMORY_BACKEND, NULL);
  116. if (!o) {
  117. error_setg(errp, "memdev=%s is ambiguous", node->memdev);
  118. return;
  119. }
  120. object_ref(o);
  121. numa_info[nodenr].node_mem = object_property_get_uint(o, "size", NULL);
  122. numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
  123. }
  124. numa_info[nodenr].present = true;
  125. max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);
  126. nb_numa_nodes++;
  127. }
  128. static void parse_numa_distance(NumaDistOptions *dist, Error **errp)
  129. {
  130. uint16_t src = dist->src;
  131. uint16_t dst = dist->dst;
  132. uint8_t val = dist->val;
  133. if (src >= MAX_NODES || dst >= MAX_NODES) {
  134. error_setg(errp, "Parameter '%s' expects an integer between 0 and %d",
  135. src >= MAX_NODES ? "src" : "dst", MAX_NODES - 1);
  136. return;
  137. }
  138. if (!numa_info[src].present || !numa_info[dst].present) {
  139. error_setg(errp, "Source/Destination NUMA node is missing. "
  140. "Please use '-numa node' option to declare it first.");
  141. return;
  142. }
  143. if (val < NUMA_DISTANCE_MIN) {
  144. error_setg(errp, "NUMA distance (%" PRIu8 ") is invalid, "
  145. "it shouldn't be less than %d.",
  146. val, NUMA_DISTANCE_MIN);
  147. return;
  148. }
  149. if (src == dst && val != NUMA_DISTANCE_MIN) {
  150. error_setg(errp, "Local distance of node %d should be %d.",
  151. src, NUMA_DISTANCE_MIN);
  152. return;
  153. }
  154. numa_info[src].distance[dst] = val;
  155. have_numa_distance = true;
  156. }
  157. static
  158. void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp)
  159. {
  160. Error *err = NULL;
  161. switch (object->type) {
  162. case NUMA_OPTIONS_TYPE_NODE:
  163. parse_numa_node(ms, &object->u.node, &err);
  164. if (err) {
  165. goto end;
  166. }
  167. break;
  168. case NUMA_OPTIONS_TYPE_DIST:
  169. parse_numa_distance(&object->u.dist, &err);
  170. if (err) {
  171. goto end;
  172. }
  173. break;
  174. case NUMA_OPTIONS_TYPE_CPU:
  175. if (!object->u.cpu.has_node_id) {
  176. error_setg(&err, "Missing mandatory node-id property");
  177. goto end;
  178. }
  179. if (!numa_info[object->u.cpu.node_id].present) {
  180. error_setg(&err, "Invalid node-id=%" PRId64 ", NUMA node must be "
  181. "defined with -numa node,nodeid=ID before it's used with "
  182. "-numa cpu,node-id=ID", object->u.cpu.node_id);
  183. goto end;
  184. }
  185. machine_set_cpu_numa_node(ms, qapi_NumaCpuOptions_base(&object->u.cpu),
  186. &err);
  187. break;
  188. default:
  189. abort();
  190. }
  191. end:
  192. error_propagate(errp, err);
  193. }
  194. static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
  195. {
  196. NumaOptions *object = NULL;
  197. MachineState *ms = MACHINE(opaque);
  198. Error *err = NULL;
  199. Visitor *v = opts_visitor_new(opts);
  200. visit_type_NumaOptions(v, NULL, &object, &err);
  201. visit_free(v);
  202. if (err) {
  203. goto end;
  204. }
  205. /* Fix up legacy suffix-less format */
  206. if ((object->type == NUMA_OPTIONS_TYPE_NODE) && object->u.node.has_mem) {
  207. const char *mem_str = qemu_opt_get(opts, "mem");
  208. qemu_strtosz_MiB(mem_str, NULL, &object->u.node.mem);
  209. }
  210. set_numa_options(ms, object, &err);
  211. end:
  212. qapi_free_NumaOptions(object);
  213. if (err) {
  214. error_propagate(errp, err);
  215. return -1;
  216. }
  217. return 0;
  218. }
  219. /* If all node pair distances are symmetric, then only distances
  220. * in one direction are enough. If there is even one asymmetric
  221. * pair, though, then all distances must be provided. The
  222. * distance from a node to itself is always NUMA_DISTANCE_MIN,
  223. * so providing it is never necessary.
  224. */
  225. static void validate_numa_distance(void)
  226. {
  227. int src, dst;
  228. bool is_asymmetrical = false;
  229. for (src = 0; src < nb_numa_nodes; src++) {
  230. for (dst = src; dst < nb_numa_nodes; dst++) {
  231. if (numa_info[src].distance[dst] == 0 &&
  232. numa_info[dst].distance[src] == 0) {
  233. if (src != dst) {
  234. error_report("The distance between node %d and %d is "
  235. "missing, at least one distance value "
  236. "between each nodes should be provided.",
  237. src, dst);
  238. exit(EXIT_FAILURE);
  239. }
  240. }
  241. if (numa_info[src].distance[dst] != 0 &&
  242. numa_info[dst].distance[src] != 0 &&
  243. numa_info[src].distance[dst] !=
  244. numa_info[dst].distance[src]) {
  245. is_asymmetrical = true;
  246. }
  247. }
  248. }
  249. if (is_asymmetrical) {
  250. for (src = 0; src < nb_numa_nodes; src++) {
  251. for (dst = 0; dst < nb_numa_nodes; dst++) {
  252. if (src != dst && numa_info[src].distance[dst] == 0) {
  253. error_report("At least one asymmetrical pair of "
  254. "distances is given, please provide distances "
  255. "for both directions of all node pairs.");
  256. exit(EXIT_FAILURE);
  257. }
  258. }
  259. }
  260. }
  261. }
  262. static void complete_init_numa_distance(void)
  263. {
  264. int src, dst;
  265. /* Fixup NUMA distance by symmetric policy because if it is an
  266. * asymmetric distance table, it should be a complete table and
  267. * there would not be any missing distance except local node, which
  268. * is verified by validate_numa_distance above.
  269. */
  270. for (src = 0; src < nb_numa_nodes; src++) {
  271. for (dst = 0; dst < nb_numa_nodes; dst++) {
  272. if (numa_info[src].distance[dst] == 0) {
  273. if (src == dst) {
  274. numa_info[src].distance[dst] = NUMA_DISTANCE_MIN;
  275. } else {
  276. numa_info[src].distance[dst] = numa_info[dst].distance[src];
  277. }
  278. }
  279. }
  280. }
  281. }
  282. void numa_legacy_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
  283. int nb_nodes, ram_addr_t size)
  284. {
  285. int i;
  286. uint64_t usedmem = 0;
  287. /* Align each node according to the alignment
  288. * requirements of the machine class
  289. */
  290. for (i = 0; i < nb_nodes - 1; i++) {
  291. nodes[i].node_mem = (size / nb_nodes) &
  292. ~((1 << mc->numa_mem_align_shift) - 1);
  293. usedmem += nodes[i].node_mem;
  294. }
  295. nodes[i].node_mem = size - usedmem;
  296. }
  297. void numa_default_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
  298. int nb_nodes, ram_addr_t size)
  299. {
  300. int i;
  301. uint64_t usedmem = 0, node_mem;
  302. uint64_t granularity = size / nb_nodes;
  303. uint64_t propagate = 0;
  304. for (i = 0; i < nb_nodes - 1; i++) {
  305. node_mem = (granularity + propagate) &
  306. ~((1 << mc->numa_mem_align_shift) - 1);
  307. propagate = granularity + propagate - node_mem;
  308. nodes[i].node_mem = node_mem;
  309. usedmem += node_mem;
  310. }
  311. nodes[i].node_mem = size - usedmem;
  312. }
  313. void numa_complete_configuration(MachineState *ms)
  314. {
  315. int i;
  316. MachineClass *mc = MACHINE_GET_CLASS(ms);
  317. /*
  318. * If memory hotplug is enabled (slots > 0) but without '-numa'
  319. * options explicitly on CLI, guestes will break.
  320. *
  321. * Windows: won't enable memory hotplug without SRAT table at all
  322. *
  323. * Linux: if QEMU is started with initial memory all below 4Gb
  324. * and no SRAT table present, guest kernel will use nommu DMA ops,
  325. * which breaks 32bit hw drivers when memory is hotplugged and
  326. * guest tries to use it with that drivers.
  327. *
  328. * Enable NUMA implicitly by adding a new NUMA node automatically.
  329. */
  330. if (ms->ram_slots > 0 && nb_numa_nodes == 0 &&
  331. mc->auto_enable_numa_with_memhp) {
  332. NumaNodeOptions node = { };
  333. parse_numa_node(ms, &node, &error_abort);
  334. }
  335. assert(max_numa_nodeid <= MAX_NODES);
  336. /* No support for sparse NUMA node IDs yet: */
  337. for (i = max_numa_nodeid - 1; i >= 0; i--) {
  338. /* Report large node IDs first, to make mistakes easier to spot */
  339. if (!numa_info[i].present) {
  340. error_report("numa: Node ID missing: %d", i);
  341. exit(1);
  342. }
  343. }
  344. /* This must be always true if all nodes are present: */
  345. assert(nb_numa_nodes == max_numa_nodeid);
  346. if (nb_numa_nodes > 0) {
  347. uint64_t numa_total;
  348. if (nb_numa_nodes > MAX_NODES) {
  349. nb_numa_nodes = MAX_NODES;
  350. }
  351. /* If no memory size is given for any node, assume the default case
  352. * and distribute the available memory equally across all nodes
  353. */
  354. for (i = 0; i < nb_numa_nodes; i++) {
  355. if (numa_info[i].node_mem != 0) {
  356. break;
  357. }
  358. }
  359. if (i == nb_numa_nodes) {
  360. assert(mc->numa_auto_assign_ram);
  361. mc->numa_auto_assign_ram(mc, numa_info, nb_numa_nodes, ram_size);
  362. }
  363. numa_total = 0;
  364. for (i = 0; i < nb_numa_nodes; i++) {
  365. numa_total += numa_info[i].node_mem;
  366. }
  367. if (numa_total != ram_size) {
  368. error_report("total memory for NUMA nodes (0x%" PRIx64 ")"
  369. " should equal RAM size (0x" RAM_ADDR_FMT ")",
  370. numa_total, ram_size);
  371. exit(1);
  372. }
  373. /* QEMU needs at least all unique node pair distances to build
  374. * the whole NUMA distance table. QEMU treats the distance table
  375. * as symmetric by default, i.e. distance A->B == distance B->A.
  376. * Thus, QEMU is able to complete the distance table
  377. * initialization even though only distance A->B is provided and
  378. * distance B->A is not. QEMU knows the distance of a node to
  379. * itself is always 10, so A->A distances may be omitted. When
  380. * the distances of two nodes of a pair differ, i.e. distance
  381. * A->B != distance B->A, then that means the distance table is
  382. * asymmetric. In this case, the distances for both directions
  383. * of all node pairs are required.
  384. */
  385. if (have_numa_distance) {
  386. /* Validate enough NUMA distance information was provided. */
  387. validate_numa_distance();
  388. /* Validation succeeded, now fill in any missing distances. */
  389. complete_init_numa_distance();
  390. }
  391. }
  392. }
  393. void parse_numa_opts(MachineState *ms)
  394. {
  395. qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, ms, &error_fatal);
  396. }
  397. void qmp_set_numa_node(NumaOptions *cmd, Error **errp)
  398. {
  399. if (!runstate_check(RUN_STATE_PRECONFIG)) {
  400. error_setg(errp, "The command is permitted only in '%s' state",
  401. RunState_str(RUN_STATE_PRECONFIG));
  402. return;
  403. }
  404. set_numa_options(MACHINE(qdev_get_machine()), cmd, errp);
  405. }
  406. void numa_cpu_pre_plug(const CPUArchId *slot, DeviceState *dev, Error **errp)
  407. {
  408. int node_id = object_property_get_int(OBJECT(dev), "node-id", &error_abort);
  409. if (node_id == CPU_UNSET_NUMA_NODE_ID) {
  410. /* due to bug in libvirt, it doesn't pass node-id from props on
  411. * device_add as expected, so we have to fix it up here */
  412. if (slot->props.has_node_id) {
  413. object_property_set_int(OBJECT(dev), slot->props.node_id,
  414. "node-id", errp);
  415. }
  416. } else if (node_id != slot->props.node_id) {
  417. error_setg(errp, "invalid node-id, must be %"PRId64,
  418. slot->props.node_id);
  419. }
  420. }
  421. static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
  422. const char *name,
  423. uint64_t ram_size)
  424. {
  425. if (mem_path) {
  426. #ifdef __linux__
  427. Error *err = NULL;
  428. memory_region_init_ram_from_file(mr, owner, name, ram_size, 0, 0,
  429. mem_path, &err);
  430. if (err) {
  431. error_report_err(err);
  432. if (mem_prealloc) {
  433. exit(1);
  434. }
  435. error_report("falling back to regular RAM allocation.");
  436. /* Legacy behavior: if allocation failed, fall back to
  437. * regular RAM allocation.
  438. */
  439. mem_path = NULL;
  440. memory_region_init_ram_nomigrate(mr, owner, name, ram_size, &error_fatal);
  441. }
  442. #else
  443. fprintf(stderr, "-mem-path not supported on this host\n");
  444. exit(1);
  445. #endif
  446. } else {
  447. memory_region_init_ram_nomigrate(mr, owner, name, ram_size, &error_fatal);
  448. }
  449. vmstate_register_ram_global(mr);
  450. }
  451. void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
  452. const char *name,
  453. uint64_t ram_size)
  454. {
  455. uint64_t addr = 0;
  456. int i;
  457. if (nb_numa_nodes == 0 || !have_memdevs) {
  458. allocate_system_memory_nonnuma(mr, owner, name, ram_size);
  459. return;
  460. }
  461. memory_region_init(mr, owner, name, ram_size);
  462. for (i = 0; i < nb_numa_nodes; i++) {
  463. uint64_t size = numa_info[i].node_mem;
  464. HostMemoryBackend *backend = numa_info[i].node_memdev;
  465. if (!backend) {
  466. continue;
  467. }
  468. MemoryRegion *seg = host_memory_backend_get_memory(backend);
  469. if (memory_region_is_mapped(seg)) {
  470. char *path = object_get_canonical_path_component(OBJECT(backend));
  471. error_report("memory backend %s is used multiple times. Each "
  472. "-numa option must use a different memdev value.",
  473. path);
  474. g_free(path);
  475. exit(1);
  476. }
  477. host_memory_backend_set_mapped(backend, true);
  478. memory_region_add_subregion(mr, addr, seg);
  479. vmstate_register_ram_global(seg);
  480. addr += size;
  481. }
  482. }
  483. static void numa_stat_memory_devices(NumaNodeMem node_mem[])
  484. {
  485. MemoryDeviceInfoList *info_list = qmp_memory_device_list();
  486. MemoryDeviceInfoList *info;
  487. PCDIMMDeviceInfo *pcdimm_info;
  488. for (info = info_list; info; info = info->next) {
  489. MemoryDeviceInfo *value = info->value;
  490. if (value) {
  491. switch (value->type) {
  492. case MEMORY_DEVICE_INFO_KIND_DIMM:
  493. pcdimm_info = value->u.dimm.data;
  494. break;
  495. case MEMORY_DEVICE_INFO_KIND_NVDIMM:
  496. pcdimm_info = value->u.nvdimm.data;
  497. break;
  498. default:
  499. pcdimm_info = NULL;
  500. break;
  501. }
  502. if (pcdimm_info) {
  503. node_mem[pcdimm_info->node].node_mem += pcdimm_info->size;
  504. node_mem[pcdimm_info->node].node_plugged_mem +=
  505. pcdimm_info->size;
  506. }
  507. }
  508. }
  509. qapi_free_MemoryDeviceInfoList(info_list);
  510. }
  511. void query_numa_node_mem(NumaNodeMem node_mem[])
  512. {
  513. int i;
  514. if (nb_numa_nodes <= 0) {
  515. return;
  516. }
  517. numa_stat_memory_devices(node_mem);
  518. for (i = 0; i < nb_numa_nodes; i++) {
  519. node_mem[i].node_mem += numa_info[i].node_mem;
  520. }
  521. }
  522. static int query_memdev(Object *obj, void *opaque)
  523. {
  524. MemdevList **list = opaque;
  525. MemdevList *m = NULL;
  526. if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
  527. m = g_malloc0(sizeof(*m));
  528. m->value = g_malloc0(sizeof(*m->value));
  529. m->value->id = object_get_canonical_path_component(obj);
  530. m->value->has_id = !!m->value->id;
  531. m->value->size = object_property_get_uint(obj, "size",
  532. &error_abort);
  533. m->value->merge = object_property_get_bool(obj, "merge",
  534. &error_abort);
  535. m->value->dump = object_property_get_bool(obj, "dump",
  536. &error_abort);
  537. m->value->prealloc = object_property_get_bool(obj,
  538. "prealloc",
  539. &error_abort);
  540. m->value->policy = object_property_get_enum(obj,
  541. "policy",
  542. "HostMemPolicy",
  543. &error_abort);
  544. object_property_get_uint16List(obj, "host-nodes",
  545. &m->value->host_nodes,
  546. &error_abort);
  547. m->next = *list;
  548. *list = m;
  549. }
  550. return 0;
  551. }
  552. MemdevList *qmp_query_memdev(Error **errp)
  553. {
  554. Object *obj = object_get_objects_root();
  555. MemdevList *list = NULL;
  556. object_child_foreach(obj, query_memdev, &list);
  557. return list;
  558. }
  559. void ram_block_notifier_add(RAMBlockNotifier *n)
  560. {
  561. QLIST_INSERT_HEAD(&ram_list.ramblock_notifiers, n, next);
  562. }
  563. void ram_block_notifier_remove(RAMBlockNotifier *n)
  564. {
  565. QLIST_REMOVE(n, next);
  566. }
  567. void ram_block_notify_add(void *host, size_t size)
  568. {
  569. RAMBlockNotifier *notifier;
  570. QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) {
  571. notifier->ram_block_added(notifier, host, size);
  572. }
  573. }
  574. void ram_block_notify_remove(void *host, size_t size)
  575. {
  576. RAMBlockNotifier *notifier;
  577. QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) {
  578. notifier->ram_block_removed(notifier, host, size);
  579. }
  580. }