memory-hotplug.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. QEMU memory hotplug
  2. ===================
  3. This document explains how to use the memory hotplug feature in QEMU,
  4. which is present since v2.1.0.
  5. Guest support is required for memory hotplug to work.
  6. Basic RAM hotplug
  7. -----------------
  8. In order to be able to hotplug memory, QEMU has to be told how many
  9. hotpluggable memory slots to create and what is the maximum amount of
  10. memory the guest can grow. This is done at startup time by means of
  11. the -m command-line option, which has the following format:
  12. -m [size=]megs[,slots=n,maxmem=size]
  13. Where,
  14. - "megs" is the startup RAM. It is the RAM the guest will boot with
  15. - "slots" is the number of hotpluggable memory slots
  16. - "maxmem" is the maximum RAM size the guest can have
  17. For example, the following command-line:
  18. qemu [...] -m 1G,slots=3,maxmem=4G
  19. Creates a guest with 1GB of memory and three hotpluggable memory slots.
  20. The hotpluggable memory slots are empty when the guest is booted, so all
  21. memory the guest will see after boot is 1GB. The maximum memory the
  22. guest can reach is 4GB. This means that three additional gigabytes can be
  23. hotplugged by using any combination of the available memory slots.
  24. Two monitor commands are used to hotplug memory:
  25. - "object_add": creates a memory backend object
  26. - "device_add": creates a front-end pc-dimm device and inserts it
  27. into the first empty slot
  28. For example, the following commands add another 1GB to the guest
  29. discussed earlier:
  30. (qemu) object_add memory-backend-ram,id=mem1,size=1G
  31. (qemu) device_add pc-dimm,id=dimm1,memdev=mem1
  32. Using the file backend
  33. ----------------------
  34. Besides basic RAM hotplug, QEMU also supports using files as a memory
  35. backend. This is useful for using hugetlbfs in Linux, which provides
  36. access to bigger page sizes.
  37. For example, assuming that the host has 1GB hugepages available in
  38. the /mnt/hugepages-1GB directory, a 1GB hugepage could be hotplugged
  39. into the guest from the previous section with the following commands:
  40. (qemu) object_add memory-backend-file,id=mem1,size=1G,mem-path=/mnt/hugepages-1GB
  41. (qemu) device_add pc-dimm,id=dimm1,memdev=mem1
  42. It's also possible to start a guest with memory cold-plugged into the
  43. hotpluggable memory slots. This might seem counterintuitive at first,
  44. but this allows for a lot of flexibility when using the file backend.
  45. In the following command-line example, an 8GB guest is created where 6GB
  46. comes from regular RAM, 1GB is a 1GB hugepage page and 256MB is from
  47. 2MB pages. Also, the guest has additional memory slots to hotplug more
  48. 2GB if needed:
  49. qemu [...] -m 6GB,slots=4,maxmem=10G \
  50. -object memory-backend-file,id=mem1,size=1G,mem-path=/mnt/hugepages-1G \
  51. -device pc-dimm,id=dimm1,memdev=mem1 \
  52. -object memory-backend-file,id=mem2,size=256M,mem-path=/mnt/hugepages-2MB \
  53. -device pc-dimm,id=dimm2,memdev=mem2
  54. RAM hot-unplug
  55. ---------------
  56. In order to be able to hot unplug pc-dimm device, QEMU has to be told the ids
  57. of pc-dimm device and memory backend object. The ids were assigned when you hot
  58. plugged memory.
  59. Two monitor commands are used to hot unplug memory:
  60. - "device_del": deletes a front-end pc-dimm device
  61. - "object_del": deletes a memory backend object
  62. For example, assuming that the pc-dimm device with id "dimm1" exists, and its memory
  63. backend is "mem1", the following commands tries to remove it.
  64. (qemu) device_del dimm1
  65. (qemu) object_del mem1