Skip to content

Commit 5f1f79b

Browse files
davidhildenbrandmstsirkin
authored andcommitted
virtio-mem: Paravirtualized memory hotplug
Each virtio-mem device owns exactly one memory region. It is responsible for adding/removing memory from that memory region on request. When the device driver starts up, the requested amount of memory is queried and then plugged to Linux. On request, further memory can be plugged or unplugged. This patch only implements the plugging part. On x86-64, memory can currently be plugged in 4MB ("subblock") granularity. When required, a new memory block will be added (e.g., usually 128MB on x86-64) in order to plug more subblocks. Only x86-64 was tested for now. The online_page callback is used to keep unplugged subblocks offline when onlining memory - similar to the Hyper-V balloon driver. Unplugged pages are marked PG_offline, to tell dump tools (e.g., makedumpfile) to skip them. User space is usually responsible for onlining the added memory. The memory hotplug notifier is used to synchronize virtio-mem activity against memory onlining/offlining. Each virtio-mem device can belong to a NUMA node, which allows us to easily add/remove small chunks of memory to/from a specific NUMA node by using multiple virtio-mem devices. Something that works even when the guest has no idea about the NUMA topology. One way to view virtio-mem is as a "resizable DIMM" or a DIMM with many "sub-DIMMS". This patch directly introduces the basic infrastructure to implement memory unplug. Especially the memory block states and subblock bitmaps will be heavily used there. Notes: - In case memory is to be onlined by user space, we limit the amount of offline memory blocks, to not run out of memory. This is esp. an issue if memory is added faster than it is getting onlined. - Suspend/Hibernate is not supported due to the way virtio-mem devices behave. Limited support might be possible in the future. - Reloading the device driver is not supported. Reviewed-by: Pankaj Gupta <[email protected]> Tested-by: Pankaj Gupta <[email protected]> Cc: "Michael S. Tsirkin" <[email protected]> Cc: Jason Wang <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Igor Mammedov <[email protected]> Cc: Dave Young <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Dan Williams <[email protected]> Cc: Pavel Tatashin <[email protected]> Cc: Stefan Hajnoczi <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: "Rafael J. Wysocki" <[email protected]> Cc: Len Brown <[email protected]> Cc: [email protected] Signed-off-by: David Hildenbrand <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 18e643c commit 5f1f79b

File tree

5 files changed

+1751
-0
lines changed

5 files changed

+1751
-0
lines changed

drivers/virtio/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ config VIRTIO_BALLOON
7878

7979
If unsure, say M.
8080

81+
config VIRTIO_MEM
82+
tristate "Virtio mem driver"
83+
default m
84+
depends on X86_64
85+
depends on VIRTIO
86+
depends on MEMORY_HOTPLUG_SPARSE
87+
depends on MEMORY_HOTREMOVE
88+
help
89+
This driver provides access to virtio-mem paravirtualized memory
90+
devices, allowing to hotplug and hotunplug memory.
91+
92+
This driver was only tested under x86-64, but should theoretically
93+
work on all architectures that support memory hotplug and hotremove.
94+
95+
If unsure, say M.
96+
8197
config VIRTIO_INPUT
8298
tristate "Virtio input driver"
8399
depends on VIRTIO

drivers/virtio/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ virtio_pci-$(CONFIG_VIRTIO_PCI_LEGACY) += virtio_pci_legacy.o
77
obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
88
obj-$(CONFIG_VIRTIO_INPUT) += virtio_input.o
99
obj-$(CONFIG_VIRTIO_VDPA) += virtio_vdpa.o
10+
obj-$(CONFIG_VIRTIO_MEM) += virtio_mem.o

0 commit comments

Comments
 (0)