From acc8bc6ac2dfae7c956d688fd1060a48f36c5cb8 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Paolo Bonzini Date: Tue, 18 Sep 2012 15:25:09 +0200 Subject: [PATCH 06/27] block: allow customizing the granularity of the dirty bitmap RH-Author: Paolo Bonzini Message-id: <1347981910-9069-7-git-send-email-pbonzini@redhat.com> Patchwork-id: 41997 O-Subject: [RHEL 6.4/6.3.z qemu-kvm PATCH v3 6/7] block: allow customizing the granularity of the dirty bitmap Bugzilla: 844627 RH-Acked-by: Laszlo Ersek RH-Acked-by: Jeffrey Cody RH-Acked-by: Miroslav Rezanina Bugzilla: 844627 Upstream status: not yet applied Signed-off-by: Paolo Bonzini Conflicts: block.h block/mirror.c --- block-migration.c | 6 ++++-- block.c | 14 +++++++------- block.h | 5 +---- block/mirror.c | 14 ++++---------- 4 file modificati, 16 inserzioni(+), 23 rimozioni(-) Signed-off-by: Michal Novotny --- block-migration.c | 6 ++++-- block.c | 14 +++++++------- block.h | 5 +---- block/mirror.c | 14 ++++---------- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/block-migration.c b/block-migration.c index 15e8b53..37d039c 100644 --- a/block-migration.c +++ b/block-migration.c @@ -19,7 +19,8 @@ #include "block-migration.h" #include -#define BLOCK_SIZE (BDRV_SECTORS_PER_DIRTY_CHUNK << BDRV_SECTOR_BITS) +#define BLOCK_SIZE (1 << 20) +#define BDRV_SECTORS_PER_DIRTY_CHUNK (BLOCK_SIZE >> BDRV_SECTOR_BITS) #define BLK_MIG_FLAG_DEVICE_BLOCK 0x01 #define BLK_MIG_FLAG_EOS 0x02 @@ -214,7 +215,8 @@ static void set_dirty_tracking(int enable) BlkMigDevState *bmds; QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { - bdrv_set_dirty_tracking(bmds->bs, enable); + bdrv_set_dirty_tracking(bmds->bs, + enable ? BDRV_SECTORS_PER_DIRTY_CHUNK : 0); } } diff --git a/block.c b/block.c index 176dce2..9a8945b 100644 --- a/block.c +++ b/block.c @@ -3432,16 +3432,16 @@ void *qemu_blockalign(BlockDriverState *bs, size_t size) return qemu_memalign((bs && bs->buffer_alignment) ? bs->buffer_alignment : 512, size); } -void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable) +void bdrv_set_dirty_tracking(BlockDriverState *bs, int granularity) { int64_t bitmap_size; - if (enable) { - if (!bs->dirty_bitmap) { - bitmap_size = (bdrv_getlength(bs) >> BDRV_SECTOR_BITS); - bs->dirty_bitmap = hbitmap_alloc(bitmap_size, - BDRV_LOG_SECTORS_PER_DIRTY_CHUNK); - } + assert((granularity & (granularity - 1)) == 0); + + if (granularity) { + assert(!bs->dirty_bitmap); + bitmap_size = (bdrv_getlength(bs) >> BDRV_SECTOR_BITS); + bs->dirty_bitmap = hbitmap_alloc(bitmap_size, ffs(granularity) - 1); } else { if (bs->dirty_bitmap) { hbitmap_free(bs->dirty_bitmap); diff --git a/block.h b/block.h index a39c201..9eb1d96 100644 --- a/block.h +++ b/block.h @@ -307,11 +307,8 @@ int bdrv_img_create(const char *filename, const char *fmt, const char *base_filename, const char *base_fmt, char *options, uint64_t img_size, int flags); -#define BDRV_SECTORS_PER_DIRTY_CHUNK (1 << BDRV_LOG_SECTORS_PER_DIRTY_CHUNK) -#define BDRV_LOG_SECTORS_PER_DIRTY_CHUNK 11 - struct HBitmapIter; -void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable); +void bdrv_set_dirty_tracking(BlockDriverState *bs, int granularity); int bdrv_get_dirty(BlockDriverState *bs, int64_t sector); void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, int nr_sectors); void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector, int nr_sectors); diff --git a/block/mirror.c b/block/mirror.c index c41c2d2..6b23023 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -14,14 +14,8 @@ #include "trace.h" #include "block_int.h" -enum { - /* - * Size of data buffer for populating the image file. This should be large - * enough to process multiple clusters in a single call, so that populating - * contiguous regions of the image is efficient. - */ - BLOCK_SIZE = 512 * BDRV_SECTORS_PER_DIRTY_CHUNK, /* in bytes */ -}; +#define BLOCK_SIZE (1 << 20) +#define BDRV_SECTORS_PER_DIRTY_CHUNK (BLOCK_SIZE >> BDRV_SECTOR_BITS) #define SLICE_TIME 100ULL /* ms */ @@ -242,7 +236,7 @@ static void coroutine_fn mirror_run(void *opaque) } immediate_exit: - bdrv_set_dirty_tracking(bs, false); + bdrv_set_dirty_tracking(bs, 0); bdrv_close(s->target); bdrv_delete(s->target); block_job_complete(&s->common, ret); @@ -294,7 +288,7 @@ int mirror_start(BlockDriverState *bs, s->target = target_bs; s->full = full; - bdrv_set_dirty_tracking(bs, true); + bdrv_set_dirty_tracking(bs, BDRV_SECTORS_PER_DIRTY_CHUNK); s->common.co = qemu_coroutine_create(mirror_run); trace_mirror_start(bs, s, s->common.co, opaque); exit: -- 1.7.11.7