From patchwork Wed Sep 7 23:06:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yehuda Sadeh X-Patchwork-Id: 1128542 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p87Mwen5028875 for ; Wed, 7 Sep 2011 22:58:52 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751969Ab1IGW6j (ORCPT ); Wed, 7 Sep 2011 18:58:39 -0400 Received: from mail.hq.newdream.net ([66.33.206.127]:51830 "EHLO mail.hq.newdream.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755535Ab1IGW6i (ORCPT ); Wed, 7 Sep 2011 18:58:38 -0400 Received: from mail.hq.newdream.net (localhost [127.0.0.1]) by mail.hq.newdream.net (Postfix) with ESMTP id 5B049C067; Wed, 7 Sep 2011 16:02:20 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=hq.newdream.net; h=from:to:cc :subject:date:message-id:in-reply-to:references:in-reply-to: references; q=dns; s=drama; b=QrCJ9NKwakvXHZc3+Ntx2mxXtflVotYo6G ZurvnpdAI/t1VSPdMX97FWdrPDOv9n5V4PX9vIB0UxBgo3O0Lr9oLOXva4Pk3Hhj fz7kZKtC1j2iBrvJwhn6Obb9zvuTxgbKoUeviL5vmZH8AMHbEupWx/YAunY+SVF7 L7ex6jjqM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=hq.newdream.net; h=from:to :cc:subject:date:message-id:in-reply-to:references:in-reply-to: references; s=drama; bh=Z9vioE/ED0OPnR1Fx2LDC6Hx6f4=; b=QPVlxiq6 Cjnxx50BNr4hByAjwUkmXmvzKDUJEeeLtS3fY7LkE4PN0+SgHf3mMFhGSe65+4HN u4SqPS/JHyxrgb/XudxDw4CjaMwKHGVe822/apz0jRF5EMcBts33sNBn+ahWBYa/ u5NCrYi5EQyIsdE5eEbfOQyqH2W/yYBmlEU= Received: from localhost.localdomain (aon.hq.newdream.net [64.111.111.107]) by mail.hq.newdream.net (Postfix) with ESMTPSA id 54793C065; Wed, 7 Sep 2011 16:02:20 -0700 (PDT) From: Yehuda Sadeh To: qemu-devel@nongnu.org, ceph-devel@vger.kernel.org Cc: sage@newdream.net, yehudasa@gmail.com, Yehuda Sadeh Subject: [PATCH 2/2] qemu-img: don't skip writing small holes Date: Wed, 7 Sep 2011 16:06:53 -0700 Message-Id: <92a5407ccc0617e43a4bf7d2a74fe1887382dd75.1315436097.git.yehuda@hq.newdream.net> X-Mailer: git-send-email 1.7.5.1 In-Reply-To: References: In-Reply-To: References: Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 07 Sep 2011 22:58:52 +0000 (UTC) When doing convert, we check that the sectors that are written are not empty. When holes are small, and interleaved with data it can lead to a significant performance issue. Signed-off-by: Yehuda Sadeh --- qemu-img.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 0552746..757fc3a 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -623,6 +623,7 @@ static int compare_sectors(const uint8_t *buf1, const uint8_t *buf2, int n, #define IO_BUF_SIZE (2 * 1024 * 1024) #define IO_WRITE_WINDOW_THRESHOLD (32 * 1024 * 1024) +#define IO_WRITE_MIN_SIZE (128 * 1024) static int write_window = 0; @@ -991,6 +992,7 @@ static int img_convert(int argc, char **argv) should add a specific call to have the info to go faster */ buf1 = buf; while (n > 0) { + int is_allocated = is_allocated_sectors(buf1, n, &n1); while (write_window > IO_WRITE_WINDOW_THRESHOLD / 512) { qemu_aio_wait(); } @@ -1001,8 +1003,8 @@ static int img_convert(int argc, char **argv) If the output is to a host device, we also write out sectors that are entirely 0, since whatever data was already there is garbage, not 0s. */ - if (!has_zero_init || out_baseimg || - is_allocated_sectors(buf1, n, &n1)) { + if (is_allocated || n != n1 || !has_zero_init || out_baseimg) { + n1 = MAX(n1, MIN(n, IO_WRITE_MIN_SIZE / 512)); QEMUIOVector *qiov = qemu_mallocz(sizeof(QEMUIOVector)); qemu_iovec_init(qiov, 1); qemu_iovec_add(qiov, (void *)buf1, n1 * 512);