[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC 10/15] virtio-mem: Set the RamDiscardManager for the RAM memo
From: |
David Hildenbrand |
Subject: |
[PATCH RFC 10/15] virtio-mem: Set the RamDiscardManager for the RAM memory region earlier |
Date: |
Wed, 13 Oct 2021 12:33:25 +0200 |
Let's set the RamDiscardManager earlier, logically before we expose the
RAM memory region to the system. This is a preparation for further changes
and is logically cleaner: before we expose the RAM memory region to
migration code, make sure we have the RamDiscardManager setup.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
hw/virtio/virtio-mem.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
index d5a578142b..b2ad27ed7f 100644
--- a/hw/virtio/virtio-mem.c
+++ b/hw/virtio/virtio-mem.c
@@ -773,16 +773,17 @@ static void virtio_mem_device_realize(DeviceState *dev,
Error **errp)
sizeof(struct virtio_mem_config));
vmem->vq = virtio_add_queue(vdev, 128, virtio_mem_handle_request);
- host_memory_backend_set_mapped(vmem->memdev, true);
- vmstate_register_ram(&vmem->memdev->mr, DEVICE(vmem));
- qemu_register_reset(virtio_mem_system_reset, vmem);
-
/*
- * Set ourselves as RamDiscardManager before the plug handler maps the
- * memory region and exposes it via an address space.
+ * Set ourselves as RamDiscardManager before we expose the memory region
+ * to the system (e.g., marking the RAMBlock migratable, mapping the
+ * region).
*/
memory_region_set_ram_discard_manager(&vmem->memdev->mr,
RAM_DISCARD_MANAGER(vmem));
+
+ host_memory_backend_set_mapped(vmem->memdev, true);
+ vmstate_register_ram(&vmem->memdev->mr, DEVICE(vmem));
+ qemu_register_reset(virtio_mem_system_reset, vmem);
}
static void virtio_mem_device_unrealize(DeviceState *dev)
@@ -790,14 +791,10 @@ static void virtio_mem_device_unrealize(DeviceState *dev)
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VirtIOMEM *vmem = VIRTIO_MEM(dev);
- /*
- * The unplug handler unmapped the memory region, it cannot be
- * found via an address space anymore. Unset ourselves.
- */
- memory_region_set_ram_discard_manager(&vmem->memdev->mr, NULL);
qemu_unregister_reset(virtio_mem_system_reset, vmem);
vmstate_unregister_ram(&vmem->memdev->mr, DEVICE(vmem));
host_memory_backend_set_mapped(vmem->memdev, false);
+ memory_region_set_ram_discard_manager(&vmem->memdev->mr, NULL);
virtio_del_queue(vdev, 0);
virtio_cleanup(vdev);
g_free(vmem->bitmap);
--
2.31.1
- [PATCH RFC 00/15] virtio-mem: Expose device memory via separate memslots, David Hildenbrand, 2021/10/13
- [PATCH RFC 01/15] memory: Drop mapping check from memory_region_get_ram_discard_manager(), David Hildenbrand, 2021/10/13
- [PATCH RFC 02/15] kvm: Return number of free memslots, David Hildenbrand, 2021/10/13
- [PATCH RFC 03/15] vhost: Return number of free memslots, David Hildenbrand, 2021/10/13
- [PATCH RFC 04/15] memory: Allow for marking memory region aliases unmergeable, David Hildenbrand, 2021/10/13
- [PATCH RFC 05/15] vhost: Don't merge unmergeable memory sections, David Hildenbrand, 2021/10/13
- [PATCH RFC 06/15] memory-device: Move memory_device_check_addable() directly into memory_device_pre_plug(), David Hildenbrand, 2021/10/13
- [PATCH RFC 07/15] memory-device: Generalize memory_device_used_region_size(), David Hildenbrand, 2021/10/13
- [PATCH RFC 08/15] memory-device: Support memory devices that consume a variable number of memslots, David Hildenbrand, 2021/10/13
- [PATCH RFC 09/15] vhost: Respect reserved memslots for memory devices when realizing a vhost device, David Hildenbrand, 2021/10/13
- [PATCH RFC 10/15] virtio-mem: Set the RamDiscardManager for the RAM memory region earlier,
David Hildenbrand <=
- [PATCH RFC 11/15] virtio-mem: Fix typo in virito_mem_intersect_memory_section() function name, David Hildenbrand, 2021/10/13
- [PATCH RFC 12/15] virtio-mem: Expose device memory via separate memslots, David Hildenbrand, 2021/10/13
- [PATCH RFC 13/15] vhost-user: Increase VHOST_USER_MAX_RAM_SLOTS to 496 with CONFIG_VIRTIO_MEM, David Hildenbrand, 2021/10/13
- [PATCH RFC 14/15] libvhost-user: Increase VHOST_USER_MAX_RAM_SLOTS to 4096, David Hildenbrand, 2021/10/13
- [PATCH RFC 15/15] virtio-mem: Set "max-memslots" to 0 (auto) for the 6.2 machine, David Hildenbrand, 2021/10/13
- Re: [PATCH RFC 00/15] virtio-mem: Expose device memory via separate memslots, Dr. David Alan Gilbert, 2021/10/13