[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 8/9] migration/ram: Factor out populating pages readable in ra
From: |
David Hildenbrand |
Subject: |
[PATCH v1 8/9] migration/ram: Factor out populating pages readable in ram_block_populate_pages() |
Date: |
Mon, 11 Oct 2021 19:53:45 +0200 |
Let's factor out prefaulting/populating to make further changes easier to
review and add a comment what we are actually expecting to happen. While at
it, use the actual page size of the ramblock, which defaults to
qemu_real_host_page_size for anonymous memory. Further, rename
ram_block_populate_pages() to ram_block_populate_read() as well, to make
it clearer what we are doing.
In the future, we might want to use MADV_POPULATE_READ to speed up
population.
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
migration/ram.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index b225ec7507..c212081f85 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1639,26 +1639,35 @@ out:
return ret;
}
+static inline void populate_read_range(RAMBlock *block, ram_addr_t offset,
+ ram_addr_t size)
+{
+ /*
+ * We read one byte of each page; this will preallocate page tables if
+ * required and populate the shared zeropage on MAP_PRIVATE anonymous
memory
+ * where no page was populated yet. This might require adaption when
+ * supporting other mappings, like shmem.
+ */
+ for (; offset < size; offset += block->page_size) {
+ char tmp = *((char *)block->host + offset);
+
+ /* Don't optimize the read out */
+ asm volatile("" : "+r" (tmp));
+ }
+}
+
/*
- * ram_block_populate_pages: populate memory in the RAM block by reading
- * an integer from the beginning of each page.
+ * ram_block_populate_read: preallocate page tables and populate pages in the
+ * RAM block by reading a byte of each page.
*
* Since it's solely used for userfault_fd WP feature, here we just
* hardcode page size to qemu_real_host_page_size.
*
* @block: RAM block to populate
*/
-static void ram_block_populate_pages(RAMBlock *block)
+static void ram_block_populate_read(RAMBlock *block)
{
- char *ptr = (char *) block->host;
-
- for (ram_addr_t offset = 0; offset < block->used_length;
- offset += qemu_real_host_page_size) {
- char tmp = *(ptr + offset);
-
- /* Don't optimize the read out */
- asm volatile("" : "+r" (tmp));
- }
+ populate_read_range(block, 0, block->used_length);
}
/*
@@ -1684,7 +1693,7 @@ void ram_write_tracking_prepare(void)
* UFFDIO_WRITEPROTECT_MODE_WP mode setting would silently skip
* pages with pte_none() entries in page table.
*/
- ram_block_populate_pages(block);
+ ram_block_populate_read(block);
}
}
--
2.31.1
- [PATCH v1 0/9] migration/ram: Optimize for virtio-mem via RamDiscardManager, David Hildenbrand, 2021/10/11
- [PATCH v1 1/9] memory: Introduce replay_discarded callback for RamDiscardManager, David Hildenbrand, 2021/10/11
- [PATCH v1 2/9] virtio-mem: Implement replay_discarded RamDiscardManager callback, David Hildenbrand, 2021/10/11
- [PATCH v1 3/9] migration/ram: Don't passs RAMState to migration_clear_memory_region_dirty_bitmap_*(), David Hildenbrand, 2021/10/11
- [PATCH v1 4/9] migration/ram: Handle RAMBlocks with a RamDiscardManager on the migration source, David Hildenbrand, 2021/10/11
- [PATCH v1 6/9] migration/postcopy: Handle RAMBlocks with a RamDiscardManager on the destination, David Hildenbrand, 2021/10/11
- [PATCH v1 7/9] migration: Simplify alignment and alignment checks, David Hildenbrand, 2021/10/11
- [PATCH v1 5/9] virtio-mem: Drop precopy notifier, David Hildenbrand, 2021/10/11
- [PATCH v1 8/9] migration/ram: Factor out populating pages readable in ram_block_populate_pages(),
David Hildenbrand <=
- [PATCH v1 9/9] migration/ram: Handle RAMBlocks with a RamDiscardManager on background snapshots, David Hildenbrand, 2021/10/11
- Re: [PATCH v1 0/9] migration/ram: Optimize for virtio-mem via RamDiscardManager, Dr. David Alan Gilbert, 2021/10/13