From nobody Wed Nov 5 08:27:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533318881190729.1177962601504; Fri, 3 Aug 2018 10:54:41 -0700 (PDT) Received: from localhost ([::1]:52552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fleHa-0004NV-Qy for importer@patchew.org; Fri, 03 Aug 2018 13:54:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fleAJ-00007N-DE for qemu-devel@nongnu.org; Fri, 03 Aug 2018 13:47:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fleAE-0008QL-HE for qemu-devel@nongnu.org; Fri, 03 Aug 2018 13:47:03 -0400 Received: from relay.sw.ru ([185.231.240.75]:42028) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fleAE-0008PU-7v; Fri, 03 Aug 2018 13:46:58 -0400 Received: from vz-out.virtuozzo.com ([185.231.240.5] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fleAA-0003t9-Ti; Fri, 03 Aug 2018 20:46:54 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 3 Aug 2018 20:46:49 +0300 Message-Id: <20180803174654.278336-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180803174654.278336-1-vsementsov@virtuozzo.com> References: <20180803174654.278336-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/6] dirty-bitmap: improve bdrv_dirty_bitmap_next_zero X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com, jcody@redhat.com, mreitz@redhat.com, den@openvz.org, pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add bytes parameter to the function, to limit searched range. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/dirty-bitmap.h | 3 ++- include/qemu/hbitmap.h | 7 +++++-- block/backup.c | 2 +- block/dirty-bitmap.c | 5 +++-- nbd/server.c | 2 +- util/hbitmap.c | 13 ++++++++++--- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 259bd27c40..5dc146abf3 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -98,7 +98,8 @@ bool bdrv_has_changed_persistent_bitmaps(BlockDriverState= *bs); BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, BdrvDirtyBitmap *bitmap); char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp= ); -int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t star= t); +int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t star= t, + uint64_t bytes); BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, Error **errp); diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index ddca52c48e..259bfc2936 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -295,10 +295,13 @@ unsigned long hbitmap_iter_skip_words(HBitmapIter *hb= i); /* hbitmap_next_zero: * @hb: The HBitmap to operate on * @start: The bit to start from. + * @bytes: Range length to search in. If @bytes is zero, search up to the = bitmap + * end. * - * Find next not dirty bit. + * Find next not dirty bit within range [@start, @start + @bytes), or from + * @start to the bitmap end if @bytes is zero. */ -int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start); +int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start, uint64_t byte= s); =20 /* hbitmap_create_meta: * Create a "meta" hbitmap to track dirtiness of the bits in this HBitmap. diff --git a/block/backup.c b/block/backup.c index 8630d32926..3c8b054587 100644 --- a/block/backup.c +++ b/block/backup.c @@ -458,7 +458,7 @@ static void backup_incremental_init_copy_bitmap(BackupB= lockJob *job) break; } =20 - offset =3D bdrv_dirty_bitmap_next_zero(job->sync_bitmap, offset); + offset =3D bdrv_dirty_bitmap_next_zero(job->sync_bitmap, offset, 0= ); if (offset =3D=3D -1) { hbitmap_set(job->copy_bitmap, cluster, end - cluster); break; diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index c9b8a6fd52..a9ee814da7 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -785,9 +785,10 @@ char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *= bitmap, Error **errp) return hbitmap_sha256(bitmap->bitmap, errp); } =20 -int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offs= et) +int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offs= et, + uint64_t bytes) { - return hbitmap_next_zero(bitmap->bitmap, offset); + return hbitmap_next_zero(bitmap->bitmap, offset, bytes); } =20 void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap = *src, diff --git a/nbd/server.c b/nbd/server.c index ea5fe0eb33..92a5651ba9 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1952,7 +1952,7 @@ static unsigned int bitmap_to_extents(BdrvDirtyBitmap= *bitmap, uint64_t offset, assert(begin < overall_end && nb_extents); while (begin < overall_end && i < nb_extents) { if (dirty) { - end =3D bdrv_dirty_bitmap_next_zero(bitmap, begin); + end =3D bdrv_dirty_bitmap_next_zero(bitmap, begin, 0); } else { bdrv_set_dirty_iter(it, begin); end =3D bdrv_dirty_iter_next(it); diff --git a/util/hbitmap.c b/util/hbitmap.c index bcd304041a..73137c10a0 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -192,16 +192,23 @@ void hbitmap_iter_init(HBitmapIter *hbi, const HBitma= p *hb, uint64_t first) } } =20 -int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start) +int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start, uint64_t byte= s) { size_t pos =3D (start >> hb->granularity) >> BITS_PER_LEVEL; unsigned long *last_lev =3D hb->levels[HBITMAP_LEVELS - 1]; - uint64_t sz =3D hb->sizes[HBITMAP_LEVELS - 1]; + uint64_t end_bit =3D + bytes ? ((start + bytes - 1) >> hb->granularity) + 1 : hb->siz= e; + uint64_t sz =3D (end_bit + BITS_PER_LONG - 1) >> BITS_PER_LEVEL; unsigned long cur =3D last_lev[pos]; unsigned start_bit_offset =3D (start >> hb->granularity) & (BITS_PER_LONG - 1); int64_t res; =20 + assert(!bytes || start + bytes <=3D (hb->size << hb->granularity)); + + /* There may be some zero bits in @cur before @start. We are not inter= ested + * in them, let's set them. + */ cur |=3D (1UL << start_bit_offset) - 1; assert((start >> hb->granularity) < hb->size); =20 @@ -218,7 +225,7 @@ int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t s= tart) } =20 res =3D (pos << BITS_PER_LEVEL) + ctol(cur); - if (res >=3D hb->size) { + if (res >=3D end_bit) { return -1; } =20 --=20 2.11.1