[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 16/22] migration: API to clear bits of guest free pag
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PULL 16/22] migration: API to clear bits of guest free pages from the dirty bitmap |
Date: |
Wed, 6 Mar 2019 11:42:21 +0000 |
From: Wei Wang <address@hidden>
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: Wei Wang <address@hidden>
CC: Dr. David Alan Gilbert <address@hidden>
CC: Juan Quintela <address@hidden>
CC: Michael S. Tsirkin <address@hidden>
CC: Peter Xu <address@hidden>
Reviewed-by: Peter Xu <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
include/migration/misc.h | 2 ++
migration/ram.c | 47 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git a/include/migration/misc.h b/include/migration/misc.h
index 6f9df74436..81ee347e35 100644
--- a/include/migration/misc.h
+++ b/include/migration/misc.h
@@ -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 */
diff --git a/migration/ram.c b/migration/ram.c
index 0747873ca9..32c0dbb98a 100644
--- a/migration/ram.c
+++ b/migration/ram.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
--
2.20.1
- [Qemu-devel] [PULL 07/22] migration: Add an ability to ignore shared RAM blocks, (continued)
- [Qemu-devel] [PULL 07/22] migration: Add an ability to ignore shared RAM blocks, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 08/22] tests/migration-test: Add a test for ignore-shared capability, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 09/22] migration: Add capabilities validation, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 10/22] tests: Add migration xbzrle test, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 11/22] migration: Create socket-address parameter, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 12/22] tests: Add basic migration precopy tcp test, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 13/22] bitmap: fix bitmap_count_one, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 15/22] migration: use bitmap_mutex in migration_bitmap_clear_dirty, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 16/22] migration: API to clear bits of guest free pages from the dirty bitmap,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PULL 14/22] bitmap: bitmap_count_one_with_offset, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 17/22] migration/ram.c: add a notifier chain for precopy, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 18/22] migration/ram.c: add the free page optimization enable flag, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 19/22] virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 20/22] Migration/colo.c: Fix double close bug when occur COLO failover, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 21/22] Migration/colo.c: Make COLO node running after failover, Dr. David Alan Gilbert (git), 2019/03/06
- [Qemu-devel] [PULL 22/22] qapi/migration.json: Remove a variable that doesn't exist in example, Dr. David Alan Gilbert (git), 2019/03/06