[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 08/36] hbitmap: enable merging across granularities
From: |
John Snow |
Subject: |
[Qemu-devel] [PULL 08/36] hbitmap: enable merging across granularities |
Date: |
Fri, 16 Aug 2019 19:12:50 -0400 |
Signed-off-by: John Snow <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Message-id: address@hidden
Signed-off-by: John Snow <address@hidden>
---
util/hbitmap.c | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/util/hbitmap.c b/util/hbitmap.c
index 83927f3c08a..fd44c897ab0 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -781,7 +781,27 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size)
bool hbitmap_can_merge(const HBitmap *a, const HBitmap *b)
{
- return (a->size == b->size) && (a->granularity == b->granularity);
+ return (a->orig_size == b->orig_size);
+}
+
+/**
+ * hbitmap_sparse_merge: performs dst = dst | src
+ * works with differing granularities.
+ * best used when src is sparsely populated.
+ */
+static void hbitmap_sparse_merge(HBitmap *dst, const HBitmap *src)
+{
+ uint64_t offset = 0;
+ uint64_t count = src->orig_size;
+
+ while (hbitmap_next_dirty_area(src, &offset, &count)) {
+ hbitmap_set(dst, offset, count);
+ offset += count;
+ if (offset >= src->orig_size) {
+ break;
+ }
+ count = src->orig_size - offset;
+ }
}
/**
@@ -812,10 +832,24 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b,
HBitmap *result)
return true;
}
+ if (a->granularity != b->granularity) {
+ if ((a != result) && (b != result)) {
+ hbitmap_reset_all(result);
+ }
+ if (a != result) {
+ hbitmap_sparse_merge(result, a);
+ }
+ if (b != result) {
+ hbitmap_sparse_merge(result, b);
+ }
+ return true;
+ }
+
/* This merge is O(size), as BITS_PER_LONG and HBITMAP_LEVELS are constant.
* It may be possible to improve running times for sparsely populated maps
* by using hbitmap_iter_next, but this is suboptimal for dense maps.
*/
+ assert(a->size == b->size);
for (i = HBITMAP_LEVELS - 1; i >= 0; i--) {
for (j = 0; j < a->sizes[i]; j++) {
result->levels[i][j] = a->levels[i][j] | b->levels[i][j];
--
2.21.0
- [Qemu-devel] [PULL 00/36] Bitmaps patches, John Snow, 2019/08/16
- [Qemu-devel] [PULL 03/36] blockdev-backup: utilize do_backup_common, John Snow, 2019/08/16
- [Qemu-devel] [PULL 01/36] qapi/block-core: Introduce BackupCommon, John Snow, 2019/08/16
- [Qemu-devel] [PULL 02/36] drive-backup: create do_backup_common, John Snow, 2019/08/16
- [Qemu-devel] [PULL 06/36] block/backup: add 'never' policy to bitmap sync mode, John Snow, 2019/08/16
- [Qemu-devel] [PULL 04/36] qapi: add BitmapSyncMode enum, John Snow, 2019/08/16
- [Qemu-devel] [PULL 08/36] hbitmap: enable merging across granularities,
John Snow <=
- [Qemu-devel] [PULL 07/36] hbitmap: Fix merge when b is empty, and result is not an alias of a, John Snow, 2019/08/16
- [Qemu-devel] [PULL 09/36] block/dirty-bitmap: add bdrv_dirty_bitmap_merge_internal, John Snow, 2019/08/16
- [Qemu-devel] [PULL 10/36] block/dirty-bitmap: add bdrv_dirty_bitmap_get, John Snow, 2019/08/16
- [Qemu-devel] [PULL 05/36] block/backup: Add mirror sync mode 'bitmap', John Snow, 2019/08/16
- [Qemu-devel] [PULL 14/36] iotests: teach run_job to cancel pending jobs, John Snow, 2019/08/16
- [Qemu-devel] [PULL 15/36] iotests: teach FilePath to produce multiple paths, John Snow, 2019/08/16
- [Qemu-devel] [PULL 13/36] iotests: add testing shim for script-style python tests, John Snow, 2019/08/16
- [Qemu-devel] [PULL 18/36] block/backup: loosen restriction on readonly bitmaps, John Snow, 2019/08/16
- [Qemu-devel] [PULL 16/36] iotests: Add virtio-scsi device helper, John Snow, 2019/08/16
- [Qemu-devel] [PULL 12/36] block/backup: add 'always' bitmap sync policy, John Snow, 2019/08/16