提交 6bcb05fc 编写于 作者: W Wei Wang 提交者: Dr. David Alan Gilbert

migration: API to clear bits of guest free pages from the dirty bitmap

This patch adds an API to clear bits corresponding to guest free pages
from the dirty bitmap. Spilt the free page block if it crosses the QEMU
RAMBlock boundary.
Signed-off-by: NWei Wang <wei.w.wang@intel.com>
CC: Dr. David Alan Gilbert <dgilbert@redhat.com>
CC: Juan Quintela <quintela@redhat.com>
CC: Michael S. Tsirkin <mst@redhat.com>
CC: Peter Xu <peterx@redhat.com>
Reviewed-by: NPeter Xu <peterx@redhat.com>
Message-Id: <1544516693-5395-5-git-send-email-wei.w.wang@intel.com>
Signed-off-by: NDr. David Alan Gilbert <dgilbert@redhat.com>
上级 386a907b
......@@ -14,12 +14,14 @@
#ifndef MIGRATION_MISC_H
#define MIGRATION_MISC_H
#include "exec/cpu-common.h"
#include "qemu/notify.h"
#include "qapi/qapi-types-net.h"
/* migration/ram.c */
void ram_mig_init(void);
void qemu_guest_free_page_hint(void *addr, size_t len);
/* migration/block.c */
......
......@@ -3181,6 +3181,53 @@ static void ram_state_resume_prepare(RAMState *rs, QEMUFile *out)
trace_ram_state_resume_prepare(pages);
}
/*
* This function clears bits of the free pages reported by the caller from the
* migration dirty bitmap. @addr is the host address corresponding to the
* start of the continuous guest free pages, and @len is the total bytes of
* those pages.
*/
void qemu_guest_free_page_hint(void *addr, size_t len)
{
RAMBlock *block;
ram_addr_t offset;
size_t used_len, start, npages;
MigrationState *s = migrate_get_current();
/* This function is currently expected to be used during live migration */
if (!migration_is_setup_or_active(s->state)) {
return;
}
for (; len > 0; len -= used_len, addr += used_len) {
block = qemu_ram_block_from_host(addr, false, &offset);
if (unlikely(!block || offset >= block->used_length)) {
/*
* The implementation might not support RAMBlock resize during
* live migration, but it could happen in theory with future
* updates. So we add a check here to capture that case.
*/
error_report_once("%s unexpected error", __func__);
return;
}
if (len <= block->used_length - offset) {
used_len = len;
} else {
used_len = block->used_length - offset;
}
start = offset >> TARGET_PAGE_BITS;
npages = used_len >> TARGET_PAGE_BITS;
qemu_mutex_lock(&ram_state->bitmap_mutex);
ram_state->migration_dirty_pages -=
bitmap_count_one_with_offset(block->bmap, start, npages);
bitmap_clear(block->bmap, start, npages);
qemu_mutex_unlock(&ram_state->bitmap_mutex);
}
}
/*
* Each of ram_save_setup, ram_save_iterate and ram_save_complete has
* long-running RCU critical section. When rcu-reclaims in the code
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册