From: Charlie Shepherd <charlie@ctshepherd.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, gabriel@kerneis.info,
Charlie Shepherd <charlie@ctshepherd.com>,
stefanha@gmail.com
Subject: [Qemu-devel] [PATCH v2 2/3] COW: Extend checking allocated bits to beyond one sector
Date: Wed, 6 Nov 2013 13:56:56 +0100 [thread overview]
Message-ID: <1383742617-14742-3-git-send-email-charlie@ctshepherd.com> (raw)
In-Reply-To: <1383742617-14742-1-git-send-email-charlie@ctshepherd.com>
cow_co_is_allocated() only checks one sector's worth of allocated bits before returning. This is
allowed but (slightly) inefficient, so extend it to check all of the file's metadata sectors.
Signed-off-by: Charlie Shepherd <charlie@ctshepherd.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
---
block/cow.c | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/block/cow.c b/block/cow.c
index 5dfffb0..41097d8 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -152,18 +152,34 @@ static int coroutine_fn cow_co_is_allocated(BlockDriverState *bs,
{
int64_t bitnum = sector_num + sizeof(struct cow_header_v2) * 8;
uint64_t offset = (bitnum / 8) & -BDRV_SECTOR_SIZE;
- uint8_t bitmap[BDRV_SECTOR_SIZE];
- int ret;
- int changed;
+ bool first = true;
+ int changed, same = 0;
- ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
- if (ret < 0) {
- return ret;
- }
+ do {
+ int ret;
+ uint8_t bitmap[BDRV_SECTOR_SIZE];
+
+ bitnum &= BITS_PER_BITMAP_SECTOR - 1;
+ int sector_bits = MIN(nb_sectors, BITS_PER_BITMAP_SECTOR - bitnum);
+
+ ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (first) {
+ changed = cow_test_bit(bitnum, bitmap);
+ first = false;
+ }
+
+ same += cow_find_streak(bitmap, changed, bitnum, nb_sectors);
+
+ bitnum += sector_bits;
+ nb_sectors -= sector_bits;
+ offset += BDRV_SECTOR_SIZE;
+ } while (nb_sectors);
- bitnum &= BITS_PER_BITMAP_SECTOR - 1;
- changed = cow_test_bit(bitnum, bitmap);
- *num_same = cow_find_streak(bitmap, changed, bitnum, nb_sectors);
+ *num_same = same;
return changed;
}
--
1.8.4.rc3
next prev parent reply other threads:[~2013-11-06 12:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-06 12:56 [Qemu-devel] [PATCH v2 0/3] COW: Speed up writes Charlie Shepherd
2013-11-06 12:56 ` [Qemu-devel] [PATCH v2 1/3] " Charlie Shepherd
2013-11-06 12:56 ` Charlie Shepherd [this message]
2013-11-06 12:56 ` [Qemu-devel] [PATCH v2 3/3] COW: Skip setting already set bits Charlie Shepherd
2013-11-06 13:03 ` Paolo Bonzini
2013-11-06 13:07 ` Charlie Shepherd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1383742617-14742-3-git-send-email-charlie@ctshepherd.com \
--to=charlie@ctshepherd.com \
--cc=gabriel@kerneis.info \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).