Skip to content

Commit cb83ba8

Browse files
davidhildenbrandbonzini
authored andcommitted
softmmu/memory_mapping: optimize for RamDiscardManager sections
virtio-mem logically plugs/unplugs memory within a sparse memory region and notifies via the RamDiscardManager interface when parts become plugged (populated) or unplugged (discarded). Currently, we end up (via the two users) 1) zeroing all logically unplugged/discarded memory during TPM resets. 2) reading all logically unplugged/discarded memory when dumping, to figure out the content is zero. 1) is always bad, because we assume unplugged memory stays discarded (and is already implicitly zero). 2) isn't that bad with anonymous memory, we end up reading the zero page (slow and unnecessary, though). However, once we use some file-backed memory (future use case), even reading will populate memory. Let's cut out all parts marked as not-populated (discarded) via the RamDiscardManager. As virtio-mem is the single user, this now means that logically unplugged memory ranges will no longer be included in the dump, which results in smaller dump files and faster dumping. virtio-mem has a minimum granularity of 1 MiB (and the default is usually 2 MiB). Theoretically, we can see quite some fragmentation, in practice we won't have it completely fragmented in 1 MiB pieces. Still, we might end up with many physical ranges. Both, the ELF format and kdump seem to be ready to support many individual ranges (e.g., for ELF it seems to be UINT32_MAX, kdump has a linear bitmap). Reviewed-by: Peter Xu <[email protected]> Cc: Marc-André Lureau <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: "Michael S. Tsirkin" <[email protected]> Cc: Eduardo Habkost <[email protected]> Cc: Alex Williamson <[email protected]> Cc: Dr. David Alan Gilbert <[email protected]> Cc: Igor Mammedov <[email protected]> Cc: Claudio Fontana <[email protected]> Cc: Thomas Huth <[email protected]> Cc: "Alex Bennée" <[email protected]> Cc: Peter Xu <[email protected]> Cc: Laurent Vivier <[email protected]> Cc: Stefan Berger <[email protected]> Signed-off-by: David Hildenbrand <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 3513bb1 commit cb83ba8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

softmmu/memory_mapping.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ static void guest_phys_block_add_section(GuestPhysListener *g,
246246
#endif
247247
}
248248

249+
static int guest_phys_ram_populate_cb(MemoryRegionSection *section,
250+
void *opaque)
251+
{
252+
GuestPhysListener *g = opaque;
253+
254+
guest_phys_block_add_section(g, section);
255+
return 0;
256+
}
257+
249258
static void guest_phys_blocks_region_add(MemoryListener *listener,
250259
MemoryRegionSection *section)
251260
{
@@ -257,6 +266,17 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,
257266
memory_region_is_nonvolatile(section->mr)) {
258267
return;
259268
}
269+
270+
/* for special sparse regions, only add populated parts */
271+
if (memory_region_has_ram_discard_manager(section->mr)) {
272+
RamDiscardManager *rdm;
273+
274+
rdm = memory_region_get_ram_discard_manager(section->mr);
275+
ram_discard_manager_replay_populated(rdm, section,
276+
guest_phys_ram_populate_cb, g);
277+
return;
278+
}
279+
260280
guest_phys_block_add_section(g, section);
261281
}
262282

0 commit comments

Comments
 (0)