On 5/4/26 14:30, Marc-André Lureau wrote:
> Refactor the RamDiscardManager interface into two distinct components:
> - RamDiscardSource: An interface that state providers (virtio-mem,
> RamBlockAttributes) implement to provide discard state information
> (granularity, populated/discarded ranges, replay callbacks).
> - RamDiscardManager: A concrete QOM object that wraps a source, owns
> the listener list, and handles listener registration/unregistration
> and notifications.
>
> This separation moves the listener management logic from individual
> source implementations into the central RamDiscardManager, reducing
> code duplication between virtio-mem and RamBlockAttributes.
>
> The change prepares for future work where a RamDiscardManager could
> aggregate multiple sources.
>
> Note, the original virtio-mem code had conditions before discard:
> if (vmem->size) {
> rdl->notify_discard(rdl, rdl->section);
> }
> however, the new code calls discard unconditionally. This is considered
> safe, since the populate/discard of sections are already asymmetrical
> (unplug & unregister all listener section unconditionally).
>
> Reviewed-by: Peter Xu <[email protected]>
> Signed-off-by: Marc-André Lureau <[email protected]>
> ---
[...]
>
> /* @offset: the offset within the RAMBlock */
> +
Unrelated?
> int ram_block_discard_range(RAMBlock *rb, uint64_t offset, size_t length);
> /* @offset: the offset within the RAMBlock */
> int ram_block_discard_guest_memfd_range(RAMBlock *rb, uint64_t offset,
> diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
> index a4b71974a1c..be149ee9441 100644
> --- a/hw/virtio/virtio-mem.c
> +++ b/hw/virtio/virtio-mem.c
> @@ -16,6 +16,7 @@
> #include "qemu/error-report.h"
> #include "qemu/units.h"
> #include "qemu/target-info-qapi.h"
> +#include "system/memory.h"
> #include "system/numa.h"
> #include "system/system.h"
> #include "system/ramblock.h"
> @@ -324,74 +325,31 @@ static int virtio_mem_for_each_unplugged_section(const
> VirtIOMEM *vmem,
> return ret;
> }
>
LGTM
Acked-by: David Hildenbrand <[email protected]>
--
Cheers,
David