From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH v4 06/13] system/ram-discard-manager: drop replay from source interface
Date: Mon, 04 May 2026 16:30:12 +0400 [thread overview]
Message-ID: <20260504-rdm5-v4-6-bdf61e57c1e1@redhat.com> (raw)
In-Reply-To: <20260504-rdm5-v4-0-bdf61e57c1e1@redhat.com>
Remove replay_populated and replay_discarded from RamDiscardSourceClass
now that the RamDiscardManager handles replay iteration internally via
is_populated.
Remove the now-dead replay methods, helpers, and
for_each_populated/discarded_section() from ram-block-attributes, which
was the last source still carrying this code.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
include/system/ram-discard-manager.h | 52 +++-----------
system/ram-block-attributes.c | 130 -----------------------------------
2 files changed, 10 insertions(+), 172 deletions(-)
diff --git a/include/system/ram-discard-manager.h b/include/system/ram-discard-manager.h
index b188e09a30f..b5dbcb4a82d 100644
--- a/include/system/ram-discard-manager.h
+++ b/include/system/ram-discard-manager.h
@@ -77,8 +77,8 @@ static inline void ram_discard_listener_init(RamDiscardListener *rdl,
/**
* typedef ReplayRamDiscardState:
*
- * The callback handler for #RamDiscardSourceClass.replay_populated/
- * #RamDiscardSourceClass.replay_discarded to invoke on populated/discarded
+ * The callback handler used by ram_discard_manager_replay_populated() and
+ * ram_discard_manager_replay_discarded() to invoke on populated/discarded
* parts.
*
* @section: the #MemoryRegionSection of populated/discarded part
@@ -134,42 +134,6 @@ struct RamDiscardSourceClass {
*/
bool (*is_populated)(const RamDiscardSource *rds,
const MemoryRegionSection *section);
-
- /**
- * @replay_populated:
- *
- * Call the #ReplayRamDiscardState callback for all populated parts within
- * the #MemoryRegionSection via the #RamDiscardSource.
- *
- * In case any call fails, no further calls are made.
- *
- * @rds: the #RamDiscardSource
- * @section: the #MemoryRegionSection
- * @replay_fn: the #ReplayRamDiscardState callback
- * @opaque: pointer to forward to the callback
- *
- * Returns 0 on success, or a negative error if any notification failed.
- */
- int (*replay_populated)(const RamDiscardSource *rds,
- const MemoryRegionSection *section,
- ReplayRamDiscardState replay_fn, void *opaque);
-
- /**
- * @replay_discarded:
- *
- * Call the #ReplayRamDiscardState callback for all discarded parts within
- * the #MemoryRegionSection via the #RamDiscardSource.
- *
- * @rds: the #RamDiscardSource
- * @section: the #MemoryRegionSection
- * @replay_fn: the #ReplayRamDiscardState callback
- * @opaque: pointer to forward to the callback
- *
- * Returns 0 on success, or a negative error if any notification failed.
- */
- int (*replay_discarded)(const RamDiscardSource *rds,
- const MemoryRegionSection *section,
- ReplayRamDiscardState replay_fn, void *opaque);
};
/**
@@ -226,8 +190,10 @@ bool ram_discard_manager_is_populated(const RamDiscardManager *rdm,
/**
* ram_discard_manager_replay_populated:
*
- * A wrapper to call the #RamDiscardSourceClass.replay_populated callback
- * of the #RamDiscardSource sources.
+ * Iterate the given #MemoryRegionSection at minimum granularity, calling
+ * #RamDiscardSourceClass.is_populated for each chunk, and invoke @replay_fn
+ * for each contiguous populated range. In case any call fails, no further
+ * calls are made.
*
* @rdm: the #RamDiscardManager
* @section: the #MemoryRegionSection
@@ -244,8 +210,10 @@ int ram_discard_manager_replay_populated(const RamDiscardManager *rdm,
/**
* ram_discard_manager_replay_discarded:
*
- * A wrapper to call the #RamDiscardSourceClass.replay_discarded callback
- * of the #RamDiscardSource sources.
+ * Iterate the given #MemoryRegionSection at minimum granularity, calling
+ * #RamDiscardSourceClass.is_populated for each chunk, and invoke @replay_fn
+ * for each contiguous discarded range. In case any call fails, no further
+ * calls are made.
*
* @rdm: the #RamDiscardManager
* @section: the #MemoryRegionSection
diff --git a/system/ram-block-attributes.c b/system/ram-block-attributes.c
index 79c7e97d9a1..718c7075cec 100644
--- a/system/ram-block-attributes.c
+++ b/system/ram-block-attributes.c
@@ -32,106 +32,6 @@ ram_block_attributes_get_block_size(void)
return qemu_real_host_page_size();
}
-typedef int (*ram_block_attributes_section_cb)(MemoryRegionSection *s,
- void *arg);
-
-static int
-ram_block_attributes_for_each_populated_section(const RamBlockAttributes *attr,
- const MemoryRegionSection *section,
- void *arg,
- ram_block_attributes_section_cb cb)
-{
- unsigned long first_bit, last_bit;
- uint64_t offset, size;
- const size_t block_size = ram_block_attributes_get_block_size();
- int ret = 0;
-
- first_bit = section->offset_within_region / block_size;
- first_bit = find_next_bit(attr->bitmap, attr->bitmap_size,
- first_bit);
-
- while (first_bit < attr->bitmap_size) {
- MemoryRegionSection tmp = *section;
-
- offset = first_bit * block_size;
- last_bit = find_next_zero_bit(attr->bitmap, attr->bitmap_size,
- first_bit + 1) - 1;
- size = (last_bit - first_bit + 1) * block_size;
-
- if (!memory_region_section_intersect_range(&tmp, offset, size)) {
- break;
- }
-
- ret = cb(&tmp, arg);
- if (ret) {
- error_report("%s: Failed to notify RAM discard listener: %s",
- __func__, strerror(-ret));
- break;
- }
-
- first_bit = find_next_bit(attr->bitmap, attr->bitmap_size,
- last_bit + 2);
- }
-
- return ret;
-}
-
-static int
-ram_block_attributes_for_each_discarded_section(const RamBlockAttributes *attr,
- const MemoryRegionSection *section,
- void *arg,
- ram_block_attributes_section_cb cb)
-{
- unsigned long first_bit, last_bit;
- uint64_t offset, size;
- const size_t block_size = ram_block_attributes_get_block_size();
- int ret = 0;
-
- first_bit = section->offset_within_region / block_size;
- first_bit = find_next_zero_bit(attr->bitmap, attr->bitmap_size,
- first_bit);
-
- while (first_bit < attr->bitmap_size) {
- MemoryRegionSection tmp = *section;
-
- offset = first_bit * block_size;
- last_bit = find_next_bit(attr->bitmap, attr->bitmap_size,
- first_bit + 1) - 1;
- size = (last_bit - first_bit + 1) * block_size;
-
- if (!memory_region_section_intersect_range(&tmp, offset, size)) {
- break;
- }
-
- ret = cb(&tmp, arg);
- if (ret) {
- error_report("%s: Failed to notify RAM discard listener: %s",
- __func__, strerror(-ret));
- break;
- }
-
- first_bit = find_next_zero_bit(attr->bitmap,
- attr->bitmap_size,
- last_bit + 2);
- }
-
- return ret;
-}
-
-
-typedef struct RamBlockAttributesReplayData {
- ReplayRamDiscardState fn;
- void *opaque;
-} RamBlockAttributesReplayData;
-
-static int ram_block_attributes_rds_replay_cb(MemoryRegionSection *section,
- void *arg)
-{
- RamBlockAttributesReplayData *data = arg;
-
- return data->fn(section, data->opaque);
-}
-
/* RamDiscardSource interface implementation */
static uint64_t
ram_block_attributes_rds_get_min_granularity(const RamDiscardSource *rds,
@@ -159,34 +59,6 @@ ram_block_attributes_rds_is_populated(const RamDiscardSource *rds,
return first_discarded_bit > last_bit;
}
-static int
-ram_block_attributes_rds_replay_populated(const RamDiscardSource *rds,
- const MemoryRegionSection *section,
- ReplayRamDiscardState replay_fn,
- void *opaque)
-{
- RamBlockAttributes *attr = RAM_BLOCK_ATTRIBUTES(rds);
- RamBlockAttributesReplayData data = { .fn = replay_fn, .opaque = opaque };
-
- g_assert(section->mr == attr->ram_block->mr);
- return ram_block_attributes_for_each_populated_section(attr, section, &data,
- ram_block_attributes_rds_replay_cb);
-}
-
-static int
-ram_block_attributes_rds_replay_discarded(const RamDiscardSource *rds,
- const MemoryRegionSection *section,
- ReplayRamDiscardState replay_fn,
- void *opaque)
-{
- RamBlockAttributes *attr = RAM_BLOCK_ATTRIBUTES(rds);
- RamBlockAttributesReplayData data = { .fn = replay_fn, .opaque = opaque };
-
- g_assert(section->mr == attr->ram_block->mr);
- return ram_block_attributes_for_each_discarded_section(attr, section, &data,
- ram_block_attributes_rds_replay_cb);
-}
-
static bool
ram_block_attributes_is_valid_range(RamBlockAttributes *attr, uint64_t offset,
uint64_t size)
@@ -346,6 +218,4 @@ static void ram_block_attributes_class_init(ObjectClass *klass,
rdsc->get_min_granularity = ram_block_attributes_rds_get_min_granularity;
rdsc->is_populated = ram_block_attributes_rds_is_populated;
- rdsc->replay_populated = ram_block_attributes_rds_replay_populated;
- rdsc->replay_discarded = ram_block_attributes_rds_replay_discarded;
}
--
2.54.0
next prev parent reply other threads:[~2026-05-04 12:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 12:30 [PATCH v4 00/13] Make RamDiscardManager work with multiple sources & virtio-mem Marc-André Lureau
2026-05-04 12:30 ` [PATCH v4 01/13] system/memory: split RamDiscardManager into source and manager Marc-André Lureau
2026-05-04 12:30 ` [PATCH v4 02/13] system/memory: move RamDiscardManager to separate compilation unit Marc-André Lureau
2026-05-04 12:30 ` [PATCH v4 03/13] system/memory: constify section arguments Marc-André Lureau
2026-05-04 12:30 ` [PATCH v4 04/13] system/ram-discard-manager: implement replay via is_populated iteration Marc-André Lureau
2026-05-13 20:40 ` Peter Xu
2026-05-04 12:30 ` [PATCH v4 05/13] virtio-mem: remove replay_populated/replay_discarded implementation Marc-André Lureau
2026-05-13 20:40 ` Peter Xu
2026-05-04 12:30 ` Marc-André Lureau [this message]
2026-05-13 20:40 ` [PATCH v4 06/13] system/ram-discard-manager: drop replay from source interface Peter Xu
2026-05-04 12:30 ` [PATCH v4 07/13] system/memory: implement RamDiscardManager multi-source aggregation Marc-André Lureau
2026-05-04 12:30 ` [PATCH v4 08/13] system/physmem: destroy ram block attributes before RCU-deferred reclaim Marc-André Lureau
2026-05-04 12:30 ` [PATCH v4 09/13] system/memory: add RamDiscardManager reference counting and cleanup Marc-André Lureau
2026-05-04 12:30 ` [PATCH v4 10/13] tests: add unit tests for RamDiscardManager multi-source aggregation Marc-André Lureau
2026-05-04 12:30 ` [PATCH v4 11/13] system/physmem: make ram_block_discard_range() handle guest_memfd Marc-André Lureau
2026-05-13 20:37 ` Peter Xu
2026-05-04 12:30 ` [PATCH v4 12/13] monitor: add 'info ramblock-attributes' command Marc-André Lureau
2026-05-13 20:39 ` Peter Xu
2026-05-04 12:30 ` [PATCH v4 13/13] RFC: hw/virtio: start virtio-mem guest_memfd regions as shared Marc-André Lureau
2026-05-13 20:47 ` Peter Xu
2026-05-14 7:32 ` Chenyi Qiang
2026-05-13 20:53 ` [PATCH v4 00/13] Make RamDiscardManager work with multiple sources & virtio-mem Peter Xu
2026-05-14 5:15 ` Chenyi Qiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260504-rdm5-v4-6-bdf61e57c1e1@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.