[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 1/6] ram: Add public helper to set colo bitmap
|
From: |
Lukas Straub |
|
Subject: |
[PATCH v2 1/6] ram: Add public helper to set colo bitmap |
|
Date: |
Mon, 8 May 2023 21:10:52 +0200 |
The overhead of the mutex in non-multifd mode is negligible,
because in that case its just the single thread taking the mutex.
This will be used in the next commits to add colo support to multifd.
Signed-off-by: Lukas Straub <lukasstraub2@web.de>
---
migration/ram.c | 17 ++++++++++++++---
migration/ram.h | 1 +
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index 5e7bf20ca5..2d3fd2112a 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3633,6 +3633,18 @@ static ram_addr_t
host_page_offset_from_ram_block_offset(RAMBlock *block,
return ((uintptr_t)block->host + offset) & (block->page_size - 1);
}
+void colo_record_bitmap(RAMBlock *block, ram_addr_t *normal, uint normal_num)
+{
+ qemu_mutex_lock(&ram_state->bitmap_mutex);
+ for (int i = 0; i < normal_num; i++) {
+ ram_addr_t offset = normal[i];
+ ram_state->migration_dirty_pages += !test_and_set_bit(
+ offset >> TARGET_PAGE_BITS,
+ block->bmap);
+ }
+ qemu_mutex_unlock(&ram_state->bitmap_mutex);
+}
+
static inline void *colo_cache_from_block_offset(RAMBlock *block,
ram_addr_t offset, bool record_bitmap)
{
@@ -3650,9 +3662,8 @@ static inline void *colo_cache_from_block_offset(RAMBlock
*block,
* It help us to decide which pages in ram cache should be flushed
* into VM's RAM later.
*/
- if (record_bitmap &&
- !test_and_set_bit(offset >> TARGET_PAGE_BITS, block->bmap)) {
- ram_state->migration_dirty_pages++;
+ if (record_bitmap) {
+ colo_record_bitmap(block, &offset, 1);
}
return block->colo_cache + offset;
}
diff --git a/migration/ram.h b/migration/ram.h
index 6fffbeb5f1..887d1fbae6 100644
--- a/migration/ram.h
+++ b/migration/ram.h
@@ -82,6 +82,7 @@ int colo_init_ram_cache(void);
void colo_flush_ram_cache(void);
void colo_release_ram_cache(void);
void colo_incoming_start_dirty_log(void);
+void colo_record_bitmap(RAMBlock *block, ram_addr_t *normal, uint normal_num);
/* Background snapshot */
bool ram_write_tracking_available(void);
--
2.39.2
pgpF38iLzZ0xb.pgp
Description: OpenPGP digital signature
- [PATCH v2 0/6] multifd: Add colo support, Lukas Straub, 2023/05/08
- [PATCH v2 1/6] ram: Add public helper to set colo bitmap,
Lukas Straub <=
- [PATCH v2 2/6] ram: Let colo_flush_ram_cache take the bitmap_mutex, Lukas Straub, 2023/05/08
- [PATCH v2 3/6] multifd: Introduce multifd-internal.h, Lukas Straub, 2023/05/08
- [PATCH v2 4/6] multifd: Introduce a overridable revc_pages method, Lukas Straub, 2023/05/08
- [PATCH v2 5/6] multifd: Add the ramblock to MultiFDRecvParams, Lukas Straub, 2023/05/08
- [PATCH v2 6/6] multifd: Add colo support, Lukas Straub, 2023/05/08