diff options
author | Lukas Straub <lukasstraub2@web.de> | 2023-05-08 21:10:52 +0200 |
---|---|---|
committer | Juan Quintela <quintela@redhat.com> | 2023-05-10 18:48:11 +0200 |
commit | 871cfc540014bb2292d79ce4348484a3dbb33034 (patch) | |
tree | aa057cba92e6fbcb40b2f026a48ec375154a09fa /migration/ram.c | |
parent | caa9cbd566877b34e9abcc04d936116fc5e0ab28 (diff) | |
download | qemu-871cfc540014bb2292d79ce4348484a3dbb33034.zip qemu-871cfc540014bb2292d79ce4348484a3dbb33034.tar.gz qemu-871cfc540014bb2292d79ce4348484a3dbb33034.tar.bz2 |
ram: Add public helper to set colo bitmap
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>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Message-Id: <22d83cb428f37929563155531bfb69fd8953cc61.1683572883.git.lukasstraub2@web.de>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Diffstat (limited to 'migration/ram.c')
-rw-r--r-- | migration/ram.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/migration/ram.c b/migration/ram.c index f78e991..b5d03f8 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3408,6 +3408,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, uint32_t pages) +{ + qemu_mutex_lock(&ram_state->bitmap_mutex); + for (int i = 0; i < pages; 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) { @@ -3425,9 +3437,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; } |