system/ram-discard-manager: drop replay from source interface
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. Reviewed-by: Peter Xu <peterx@redhat.com> Acked-by: David Hildenbrand <david@kernel.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Link: https://lore.kernel.org/r/20260604-rdm5-v5-6-5768e6a0943d@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com>
This commit is contained in:
committed by
Peter Xu
parent
4d65b12d2e
commit
f46a11c563
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user