[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/26] migration/ram: Optimize ram_write_tracking_start() for RamD
From: |
Juan Quintela |
Subject: |
[PULL 11/26] migration/ram: Optimize ram_write_tracking_start() for RamDiscardManager |
Date: |
Thu, 2 Feb 2023 17:06:25 +0100 |
From: David Hildenbrand <david@redhat.com>
ram_block_populate_read() already optimizes for RamDiscardManager.
However, ram_write_tracking_start() will still try protecting discarded
memory ranges.
Let's optimize, because discarded ranges don't map any pages and
(1) For anonymous memory, trying to protect using uffd-wp without a mapped
page is ignored by the kernel and consequently a NOP.
(2) For shared/file-backed memory, we will fill present page tables in the
range with PTE markers. However, we will even allocate page tables
just to fill them with unnecessary PTE markers and effectively
waste memory.
So let's exclude these ranges, just like ram_block_populate_read()
already does.
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
migration/ram.c | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index a6956c9e7d..7f6d5efe8d 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1865,6 +1865,39 @@ void ram_write_tracking_prepare(void)
}
}
+static inline int uffd_protect_section(MemoryRegionSection *section,
+ void *opaque)
+{
+ const hwaddr size = int128_get64(section->size);
+ const hwaddr offset = section->offset_within_region;
+ RAMBlock *rb = section->mr->ram_block;
+ int uffd_fd = (uintptr_t)opaque;
+
+ return uffd_change_protection(uffd_fd, rb->host + offset, size, true,
+ false);
+}
+
+static int ram_block_uffd_protect(RAMBlock *rb, int uffd_fd)
+{
+ assert(rb->flags & RAM_UF_WRITEPROTECT);
+
+ /* See ram_block_populate_read() */
+ if (rb->mr && memory_region_has_ram_discard_manager(rb->mr)) {
+ RamDiscardManager *rdm = memory_region_get_ram_discard_manager(rb->mr);
+ MemoryRegionSection section = {
+ .mr = rb->mr,
+ .offset_within_region = 0,
+ .size = rb->mr->size,
+ };
+
+ return ram_discard_manager_replay_populated(rdm, §ion,
+ uffd_protect_section,
+ (void
*)(uintptr_t)uffd_fd);
+ }
+ return uffd_change_protection(uffd_fd, rb->host,
+ rb->used_length, true, false);
+}
+
/*
* ram_write_tracking_start: start UFFD-WP memory tracking
*
@@ -1900,8 +1933,7 @@ int ram_write_tracking_start(void)
memory_region_ref(block->mr);
/* Apply UFFD write protection to the block memory range */
- if (uffd_change_protection(rs->uffdio_fd, block->host,
- block->used_length, true, false)) {
+ if (ram_block_uffd_protect(block, uffd_fd)) {
goto fail;
}
--
2.39.1
- [PULL 12/26] migration/savevm: Move more savevm handling into vmstate_save(), (continued)
- [PULL 12/26] migration/savevm: Move more savevm handling into vmstate_save(), Juan Quintela, 2023/02/02
- [PULL 13/26] migration/savevm: Prepare vmdesc json writer in qemu_savevm_state_setup(), Juan Quintela, 2023/02/02
- [PULL 14/26] migration/savevm: Allow immutable device state to be migrated early (i.e., before RAM), Juan Quintela, 2023/02/02
- [PULL 16/26] migration/ram: Factor out check for advised postcopy, Juan Quintela, 2023/02/02
- [PULL 17/26] virtio-mem: Fail if a memory backend with "prealloc=on" is specified, Juan Quintela, 2023/02/02
- [PULL 06/26] util/userfaultfd: Add uffd_open(), Juan Quintela, 2023/02/02
- [PULL 03/26] migration: Split save_live_pending() into state_pending_*, Juan Quintela, 2023/02/02
- [PULL 15/26] migration/vmstate: Introduce VMSTATE_WITH_TMP_TEST() and VMSTATE_BITMAP_TEST(), Juan Quintela, 2023/02/02
- [PULL 18/26] virtio-mem: Migrate immutable properties early, Juan Quintela, 2023/02/02
- [PULL 19/26] virtio-mem: Proper support for preallocation with migration, Juan Quintela, 2023/02/02
- [PULL 11/26] migration/ram: Optimize ram_write_tracking_start() for RamDiscardManager,
Juan Quintela <=
- [PULL 23/26] migration: Perform vmsd structure check during tests, Juan Quintela, 2023/02/02
- [PULL 20/26] migration: Show downtime during postcopy phase, Juan Quintela, 2023/02/02
- [PULL 22/26] migration: Add canary to VMSTATE_END_OF_LIST, Juan Quintela, 2023/02/02
- [PULL 24/26] migration/dirtyrate: Show sample pages only in page-sampling mode, Juan Quintela, 2023/02/02
- [PULL 26/26] migration: check magic value for deciding the mapping of channels, Juan Quintela, 2023/02/02
- [PULL 21/26] migration/rdma: fix return value for qio_channel_rdma_{readv, writev}, Juan Quintela, 2023/02/02
- [PULL 25/26] io: Add support for MSG_PEEK for socket channel, Juan Quintela, 2023/02/02
- Re: [PULL 00/26] Next patches, Peter Maydell, 2023/02/04