From patchwork Wed Nov 1 15:44:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10036677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E166260291 for ; Wed, 1 Nov 2017 15:52:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E29C928CA1 for ; Wed, 1 Nov 2017 15:52:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D79CB28CA9; Wed, 1 Nov 2017 15:52:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 245F328CA1 for ; Wed, 1 Nov 2017 15:52:20 +0000 (UTC) Received: from localhost ([::1]:56407 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vJT-00053r-5a for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Nov 2017 11:52:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vCI-0008FP-SM for qemu-devel@nongnu.org; Wed, 01 Nov 2017 11:44:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9vCG-0006mj-Rx for qemu-devel@nongnu.org; Wed, 01 Nov 2017 11:44:54 -0400 Received: from mail-eopbgr40111.outbound.protection.outlook.com ([40.107.4.111]:51842 helo=EUR03-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e9vCG-0006lD-DN; Wed, 01 Nov 2017 11:44:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=VzWbtiKY3m8iWEwYlGVyxC4jbRro+meA2ZrDLVqCmZY=; b=aavxDPS5I25Mclg8+ohZJr88j0wz9JfpgIwLXk9YHwjLSEP8l6mjfHNYxSb+Nh+Z71haULsRJerTxR8DKrhua3b6Ho3Rn8O3xSMYpP3FnyBtdtXitTA1N1g4+GYaZsrqrM0D4cv3fw75joPP/sIBvKVA74cPxfvwVRPXiXbaEOI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by AM5PR0801MB1987.eurprd08.prod.outlook.com (2603:10a6:203:4b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.178.6; Wed, 1 Nov 2017 15:44:49 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Wed, 1 Nov 2017 18:44:06 +0300 Message-Id: <1509551048-129830-14-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509551048-129830-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1509551048-129830-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: VI1PR0501CA0017.eurprd05.prod.outlook.com (2603:10a6:800:92::27) To AM5PR0801MB1987.eurprd08.prod.outlook.com (2603:10a6:203:4b::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8f3c39e6-8840-4274-ff57-08d5213f7cdc X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(2017052603199); SRVR:AM5PR0801MB1987; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 3:qlwvynlFJjh8dA00/6OAUjZYEX7F4sE1h0bEn1ccDXOCGM3AppcfuJUz4GX+MlAXiVIbC0eX+Rth5y1oD5sLAWNktWzR5616ogS4rCFkU2MBoRaDc5z84ODXVK1ZWZ1cUbS2EAMbNpu96bF80/D6ol7ab4gbpLkDtJSNKic4SlviWKIbyag2rUA+ke3LvBRvKegXiTmO+Tg5UlFojzicH0DbU9+iYRDMpAlY33NJ2x3D0uMTRoqLqNjCrxag4koY; 25:kVTMn1UuWzuUPvFb6QxsTQ4zkQ2vMK9RCAy5OSz9k4q9Waln7XW+/LjRFOtNK0B3C35g0h3qxGHF4/90vPq0qqqE1kMZ9c7CbTClf0mB/Bkv5XHiamGdwjmiCXdxOHYkXDF2u0VN7pkLx85aAurtjwPyX7LO07pC5bLWMZFiPXvOFK5txsvb1yHfXH1FoD0RIsJJCqGvFfjiqP2RoxAqFTJmlTY6aK7tp0ziUvKuJl/85s9Icv/Oot5Md2XXvbW1uw6ZlU060GW2F23NFo3VdQiZD5xOusPTdzY/KxQ1SppdOmObw/oQh2xFv4tzCbhE4cvEfEOm1efr13SySr+zRA==; 31:J6pY3TUNnVDbD8//KeLNXP8FpzWbIEIydDnAdJBuaWn0X0KRyJav8+fjDikAaSrwCgKD8DjVuQHBgHyq6HVHOWg48WB+gcRRSEvscPtzZdoqZb2+qa+/3GnO9MBMIUlLj/+MWw6FC/dXE4oHhkg34SvL1+qcoibwgKM4k7nB8PhCYBpLLmAu+FRJyYKReasPmVc4hh/Mp0d6gLdvdJ92Gsnp2+xje6n1tQ0cHITJhEg= X-MS-TrafficTypeDiagnostic: AM5PR0801MB1987: X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 20:vywFPKLXbh8dNN0hdo9T+9qzqzEckCHqB7T19aXQbvaYwJ8qHwwfhW+Ydi3WJMN132pANZynX4bRWYdMPpyTEoXYHeEaAPoGtwCD629tQSUhGDGe2tDhQZZqTipgzZcisr5nfCBlYSqw4LMMzBljRmNxPARYAl6f3JxwXH+9OuzpnVY/2cUsT5njSEzT8geD8P5tqYNKN/oUg0KrXVsfej5TsC/nJYVqHC5leKTP3s1y3UrMbGrIa9XPjTozf+22Mtv7PdMtsEAavXFwqGm6za245Yo3IAfVzOIBEDbHVNZSrovZgX7OQPv+AqWIs/mySej3YdqlHDLCV1Dprh+ISp1mpfl3BAEELuFEmMaX2VAEw+IsyS1RHlhmFSj8CZocsVJHlE8eVJJDlSoJBampl9xqPeYS8tCh1Xs75lSAC30=; 4:1fgiZ7qGH5QH8Fa+Ci0UzbJrS3FLYbemKNIMQT+C5bdl4UW7RmJPmYZPeVgvz8xV4guKIxGhl/eWS1aMcwc+VnqvEB/i4ZJr37tXgjQJ4KAJ6hAnRTdXJXlwii8cW9t08jNInKTK67AodhY6grxLrjO2fwOt1R52wCqKvl3dsCb9zggs1YQeihRsy/fZ63KmOlQaFxRe3Gjjl0fdRjjWgw4Mmr3PnWP0EbixBIZEUkZU35zDKsmMrYxwOHyNfRG2Cf6v3vLnBhREHPOXcrMLgA== X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3231020)(100000703101)(100105400095)(3002001)(6041248)(20161123555025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123564025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM5PR0801MB1987; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM5PR0801MB1987; X-Forefront-PRVS: 0478C23FE0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(376002)(346002)(189002)(199003)(6666003)(16526018)(53936002)(107886003)(48376002)(86362001)(6916009)(2950100002)(3846002)(6116002)(101416001)(50986999)(76176999)(106356001)(69596002)(5660300001)(25786009)(105586002)(316002)(53416004)(2351001)(16586007)(2361001)(33646002)(4326008)(5003940100001)(478600001)(66066001)(36756003)(50226002)(6512007)(47776003)(2906002)(8936002)(6506006)(97736004)(6486002)(68736007)(305945005)(50466002)(81166006)(81156014)(8676002)(189998001)(7736002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0801MB1987; H:xantnef-ws.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM5PR0801MB1987; 23:QUoFu8flrdKzriJWk7TneVveS0tkiKXbhVijz/R?= =?us-ascii?Q?YPf385q+pGo3+IoDpwPM5nCDr+taH/9dFlKq58haTMEBoLFdmQmkgFaqJk4e?= =?us-ascii?Q?kFDk8irlTkvVKoHKNvBujaoQsQ5Q21medH9jAEJIoGKMmdnD8FJCzQM1XbCI?= =?us-ascii?Q?JBsqroF4gId9K5/WGSIdiB+wy9s1ua0Pc/eDToJ/CcEjqcidtUh1szbGKkmP?= =?us-ascii?Q?sNkB0WSjnVXUNb/ckf90anThghSUxN4wELva8jS1R+NqsHoDOEDtI8UFFw+n?= =?us-ascii?Q?ZtZ//m0Fv8cDzd7t26d1vEPs4Ud5ohbHhUkuOvPm6tGrV45ASxnag+QHm/T/?= =?us-ascii?Q?QW5ct1UbE+K4gE+aumM1ItKl1M2faUf5WXbhpKiw+JgiEjh69JzDlbo0WT9X?= =?us-ascii?Q?PTIkhL7ytEum7A9mPHpOkSB3Ph/kyaxfd2PIl1apQ7Wf2+Z/PktGte0p33wp?= =?us-ascii?Q?6ij5cF9BJCk2irSLR6IQZezY1QFf67WXgQDI/9DqiYJNcW8ihvAmMu59eBhs?= =?us-ascii?Q?IXFXNECZPAPzcuh0BmzGVgyOxTIMpD0xwyko/7/nbdUlDUyxnnRfU1MhwhmX?= =?us-ascii?Q?TChVwL0SaX6T4TMoCUS+sTRetstSSy/ei3wOYF3ByrRJSknJqvoRDRm8ua/j?= =?us-ascii?Q?n1+Q1IKPqnBBSOYariqS5LHRWtFw+YgcpM4hMfbImhA7UjQt+zXQzQeeruCw?= =?us-ascii?Q?NGWkEgdYdWpMS+3aEOU3oT1c52S6b1j/9O3bFvIVOYVrJrlYiFS4rDKYUIv/?= =?us-ascii?Q?6SPDCsRsvWixzkFfw7iqPQxwxuKj3eCSXz0shosENhAXPLxBfBuNs+s9aSdV?= =?us-ascii?Q?3gA7TkhaYnYAlNs9b9kQNVotu9GDCTtDdo35P3X0uu2iob+XNHByPPoLGL1g?= =?us-ascii?Q?Gu3bn15mPBouyE6wXTLLezhpjZIZGdJpXlhSkXgzApSJuFNmGcl1EDsYSHvL?= =?us-ascii?Q?fmY81ucWsqnham4+/bU42SJRGEf6zI2aAsG2anA4LUydsjjTvgDHhFnoBRG1?= =?us-ascii?Q?ATksjD3WHmzg3wBvjblrq39cEXYnqk1StylEAXqiFjomb7CJpFqV1IlIBKdg?= =?us-ascii?Q?Fd5qHorabo3so5zx0YYn8fDzonncn+eevFFAczi9cLIySz/qABMLs3a7P3Ik?= =?us-ascii?Q?EZLUIbqsghjRPniMwgeJMMFcTesDqV3w+r+Cb4fHdPX/VRLvR6PHP1g=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 6:gIPJ5u1C/F531QUdQzLpCynkJKrPauVRpibTTUOAj1EuBRCEMuIJXJz33IkNdDPkDDI9xGMq9tZ4kF2psd1Ph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-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2017 15:44:49.6026 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8f3c39e6-8840-4274-ff57-08d5213f7cdc X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1987 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.4.111 Subject: [Qemu-devel] [PATCH v5 13/15] qcow2: do not zero out clusters if already preallocated 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, Anton Nefedov , berto@igalia.com, den@virtuozzo.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP if space preallocation feature is used, it can be detected that the space is already zeroes, so COW can be skipped without additional zeroing of the clusters. Signed-off-by: Anton Nefedov --- block/qcow2.h | 6 ++++++ block/qcow2-cluster.c | 2 ++ block/qcow2.c | 45 +++++++++++++++++++++++++++++++-------------- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 579838d..5d96748 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -363,6 +363,12 @@ typedef struct QCowL2Meta bool keep_old_clusters; /** + * True if the area is allocated at the end of data area + * (i.e. >= BDRVQcow2State::data_end) + */ + bool clusters_are_trailing; + + /** * Requests that overlap with this allocation and wait to be restarted * when the allocating request has completed. */ diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 9b24cab..5698919 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1251,6 +1251,7 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset, uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m) { BDRVQcow2State *s = bs->opaque; + const uint64_t old_data_end = s->data_end; int l2_index; uint64_t *l2_table; uint64_t entry; @@ -1372,6 +1373,7 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset, .alloc_offset = alloc_cluster_offset, .offset = start_of_cluster(s, guest_offset), .nb_clusters = nb_clusters, + .clusters_are_trailing = alloc_cluster_offset >= old_data_end, .keep_old_clusters = keep_old_clusters, diff --git a/block/qcow2.c b/block/qcow2.c index ef65b5f..6019cf4 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1975,26 +1975,40 @@ static bool is_zero_cow(BlockDriverState *bs, QCowL2Meta *m) /* * If the specified area is beyond EOF, allocates it + prealloc_size * bytes ahead. + * + * Returns + * true if the space is allocated and contains zeroes */ -static void coroutine_fn handle_prealloc(BlockDriverState *bs, +static bool coroutine_fn handle_prealloc(BlockDriverState *bs, const QCowL2Meta *m) { BDRVQcow2State *s = bs->opaque; uint64_t start = m->alloc_offset; uint64_t end = start + m->nb_clusters * s->cluster_size; + int ret; int64_t flen = bdrv_getlength(bs->file->bs); if (flen < 0) { - return; + return false; } if (end > flen) { /* try to alloc host space in one chunk for better locality */ - bdrv_co_pwrite_zeroes(bs->file, flen, - QEMU_ALIGN_UP(end + s->prealloc_size - flen, - s->cluster_size), - BDRV_REQ_ALLOCATE); + ret = bdrv_co_pwrite_zeroes(bs->file, flen, + QEMU_ALIGN_UP(end + s->prealloc_size - flen, + s->cluster_size), + BDRV_REQ_ALLOCATE); + if (ret < 0) { + return false; + } } + + /* We're safe to assume that the area is zeroes if the area + * was allocated at the end of data (s->data_end). + * In this case, the only way for file length to be bigger is that + * the area was preallocated by this or another request. + */ + return m->clusters_are_trailing; } static void handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta) @@ -2004,9 +2018,10 @@ static void handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta) for (m = l2meta; m != NULL; m = m->next) { int ret; + bool preallocated_zeroes = false; if (s->prealloc_size) { - handle_prealloc(bs, m); + preallocated_zeroes = handle_prealloc(bs, m); } if (!m->cow_start.nb_bytes && !m->cow_end.nb_bytes) { @@ -2017,13 +2032,15 @@ static void handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta) continue; } - /* instead of writing zero COW buffers, - efficiently zero out the whole clusters */ - ret = bdrv_co_pwrite_zeroes(bs->file, m->alloc_offset, - m->nb_clusters * s->cluster_size, - BDRV_REQ_ALLOCATE); - if (ret < 0) { - continue; + if (!preallocated_zeroes) { + /* instead of writing zero COW buffers, + efficiently zero out the whole clusters */ + ret = bdrv_co_pwrite_zeroes(bs->file, m->alloc_offset, + m->nb_clusters * s->cluster_size, + BDRV_REQ_ALLOCATE); + if (ret < 0) { + continue; + } } trace_qcow2_skip_cow(qemu_coroutine_self(), m->offset, m->nb_clusters);