From patchwork Fri May 19 09:34:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9736771 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 9B55A6034C for ; Fri, 19 May 2017 09:39:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BF51288EC for ; Fri, 19 May 2017 09:39:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FEC4288F4; Fri, 19 May 2017 09:39:08 +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 E53AF288EC for ; Fri, 19 May 2017 09:39:07 +0000 (UTC) Received: from localhost ([::1]:57481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBeNG-0000Qp-Uh for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 May 2017 05:39:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48202) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBeJT-0006hc-Lv for qemu-devel@nongnu.org; Fri, 19 May 2017 05:35:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBeJP-0006ho-Ou for qemu-devel@nongnu.org; Fri, 19 May 2017 05:35:11 -0400 Received: from mail-db5eur01on0095.outbound.protection.outlook.com ([104.47.2.95]:23375 helo=EUR01-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 1dBeJP-0006g9-F5 for qemu-devel@nongnu.org; Fri, 19 May 2017 05:35:07 -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=5xv/duKT7i4a6N9W7pyZBjwq7UM1uqR4dcqqGnDICCM=; b=b72c5P3aQ0VjjHSp6wGDYNuGEPY3jRMdxsmXfoaAyYJoLBp6a12mY1ZYlEcQEyVjOB4jBHdXB91hW9OgrLUTD6zhP4eDEniNTCL/3/esn7jAiproY9ICZIVR1RW9PHKKQpDT2ZS9b9ubRxi6/PTBwRRCjvgiaBd9ywLxapSqvV0= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by AM5PR0801MB1988.eurprd08.prod.outlook.com (2603:10a6:203:4b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1101.14; Fri, 19 May 2017 09:35:04 +0000 From: Anton Nefedov To: Date: Fri, 19 May 2017 12:34:28 +0300 Message-ID: <1495186480-114192-2-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495186480-114192-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1495186480-114192-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR09CA0073.eurprd09.prod.outlook.com (2603:10a6:7:3d::17) To AM5PR0801MB1988.eurprd08.prod.outlook.com (2603:10a6:203:4b::15) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM5PR0801MB1988: X-MS-Office365-Filtering-Correlation-Id: 63e9d5f5-156e-4782-f863-08d49e9a550a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:AM5PR0801MB1988; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1988; 3:GfwZTAaEDF1eVAI53q7Kd6/DAMQdiY6OligqaZFmYIOmVTKFznFjKo9cvBbfo2jfb5sCQvM8w+qowWCP2lQDFBNunifiBNFTLXILKDwZ3V3O2vkJ7BK7XCyzQQGIHU2lyIFYKUn6Tq5Us1s7bnBS9fkiNVbrl4TOsqqxVgPmjRUKRQQeSDOKlu7be1tOm8SRnfuYdvPqzqbK6wMZLcOadaOct5S5Cp4MUmsiOlVtGdQU/EA355Lic/HTuSyf7o0C6lHv7fGQ4mwVo9PX9rl3+ygHkMbO5VccNa1m8xlGFqYMEIW+hPqoOq51Vy5i1FX0Y/GKjrTwcYJP64FbG1iVVA==; 25:q5rMvNwRF6SEIfqG4xr07hqYtmr6jlrnfTmspYSgDX3KV4H+OOPejR36RmY1uj7AaDB7BLK4n0RDYOyMqaoOxUX84qcf1e0O2ljpghSEISaMmlE1pt7R2P7MXoCOjEsxDvBsYTN3WcoGctSsWjOIa6GtUWrD+4Oji3rWQ9hMJzgdewhP6byZUFikbxgzb7EwyQhONFbpMkVbbwfV67IUfUBufzyt48nhcndX75MA2dHtyZ2R576b00G6qUTOh2yUAanS8ipft26tdMIe7tQLLkzr1LyGCkdWNHVQi+mrkmU5+XeWhp4+QTuEBxvDGWXioQey4l2HPlDVvMhUSHzXh/MaP6hRc1WzSjDCvc/f3yTYAkHT6pkP/932UK/tTziMkSxh2aG3dZbUbcLtSF7T3HVNdd2WNhxO4u51ebN9hZv/m57CrG+B55X9ZRkk9e1aAuUvC9vv5DsNnyDVg27ESD4qrEmYuRacxTlThUiZcSw= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1988; 31:ibO5baDom9KOLZnkunuZdwNKwwe28FopV5Du3JJdVhFvMjBkguNofdbh0gh9F24EbpIeYICk2Se6mXge1w+576Jkbft2zolC/CrdJ6Z4dg6C1ySL6RdXGIoZak7QPjZG30jtK6Hmhz6iegSLC0RNKjzKoA9ffkVdoB35ACI+iNWr8kUtP17gyOnBuTCL+xN+c8gdcTfi5F0fbsMLwQq3as38RmOSzJFMaZAjqLRwMXo=; 20:TIRbYFfJmYVtTgavnk7oLiw5rWkaHiVP0Etke5ufz9y7ejmR6YwCm62uDZ58dGVetcstnj0ZMWNu13u8vJw25opo0C88rKaEoCVsetmEYh+jiYK/E73EpBAAAyp7CzqfSxXsUDp4dtN6bj+VWxgF6N8CAD0e5YV6pwx1ICvFNUx+oMJis0RtKxy2yFA7ZrWvz7uYqLeW0Erhc54rbd22HBkfAj/jd4Mk9huOi3sPJ8AJtZaXaAwrVTgH1Ii7U7NtjYV1oBdOL/rqo2H2KJHuzc5HrMA/KDChrlHMmSQUxcRDl4WiPgfZmigNd+JGugKnMGJs8jP7/lmOfBWD87vHchBxf95fGl4XTT9ZZGWg36pVw+u15fLdDAYEGu0qvuUMxWoF/BdCd3nn+OBvbdCYKSPh/WonCOZaWwpqjthCoIQ= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(10201501046)(6041248)(20161123555025)(20161123558100)(20161123562025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148); SRVR:AM5PR0801MB1988; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0801MB1988; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1988; 4:uzW9epzTA8YvC/B2pvuS4rwLXWHpGkdBFIHwCGkwyUSaCqzRPJ8G4x5f14olS3zI7wJ9rFYMdez5WgDDY2ffjp3HQNfj09fKuOXFmihEBmaVbQoTMu9Dh1574VFEe72jGKwwqSxn0ZWGxfUPTpNbMtO31ZekNUmVaNOy0aMh1hwc6zhCDqnoy8d8klipVxnfwwycMBRriAMasdk0VM7gKrFAKq0/GF3lMZeE0cxJvWFhiLzTKN+V+h0QBFotOwQyqEQc4f9sC4jCFfi8lwmsz4s71DJH9YnhbwICBn0W2wpvlMsFW+JJuSECwu5PcNoO4xRSFzGhToDN8eGLUn8V/ky7McNywITt5dcOdFuIIKtx8OaDw/RjsBLHWArXkNI2fKkc584c28YUvWe4tTHOZ7hjXbDE0bOVHe3KinvZ4/zYOnW3iuk9McSkGG93iMcVhIHMum4VfAUfMd0szcxxypgLFu8LSd2wAzdh5rbJqbxl1tChdrt8g+LItJoqF14D7bGJhDIbNnBIiy2XB+d+ZZuxEvPLlt/OLEL3od/qPjD1sqHUuTkv7+PDpFpXOWkfr/Tj2HiNnsKGk5oYdBbN+5giNueAaU/WiIq5dRnVABpO6upib8YcP17lBicsiuicOGlvBrm4YKSGkOB7mpP7r+kXbf3hgk7CjIodDrP38k6IVmW6G4LLXAjFBdbxoaC0t7OnhrsUpxeP8cn6hVI8RPV3lPycgDnGl6V+YpVnuKGSeD1FkfYnSx4brq0lHn49lnkGS1JmeU7zanR1/4Ftnx7zKb67uUR8nGtJTus40eM= X-Forefront-PRVS: 031257FE13 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39450400003)(39840400002)(39410400002)(39400400002)(48376002)(8676002)(7736002)(81166006)(53416004)(305945005)(50226002)(33646002)(5003940100001)(42186005)(3846002)(4326008)(25786009)(66066001)(189998001)(50466002)(2351001)(2906002)(478600001)(6486002)(6506006)(50986999)(575784001)(6512007)(54906002)(36756003)(5660300001)(86362001)(53936002)(2950100002)(110136004)(6666003)(6916009)(107886003)(38730400002)(76176999); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0801MB1988; H:xantnef-ws.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM5PR0801MB1988; 23:njuXi9zIU2BBASEMClU4MZjVNr0L2TX+dESG8K9?= =?us-ascii?Q?jGRqY/nAB9x+VtettZ1d78o35LTfKlbbnVZ6+RzWnBOEC/BqT4iicFRXZumU?= =?us-ascii?Q?tozY7bg6uEhQ/3mWIJFNtNVaFxAPyMhAKE+spqnHbpsgFOPvn08+4MFkxIiY?= =?us-ascii?Q?1Iwj6klsxJMo/pi/1seHaMGWQthR2jfwLxrW5UnMbnxUD73i/TP7JBmuZClQ?= =?us-ascii?Q?moAhQ5BXVgg+O95p6DjPUetMn0sLP8P6VNt7MowXrC5MD8XheafuDGCC9XIR?= =?us-ascii?Q?yXHT/y9bcy7ywoZDB5w6MNwJhk4Lml5PStO24Qr+1F56Oh98KG8jcP4R8wZE?= =?us-ascii?Q?mu0V671j4xIaRCGKtJbE5mzcZKFiyQYs7sNbtJ3WXI6wwLQhYCg+nT+bUIHz?= =?us-ascii?Q?hVLNLJ77xD+A/a2oPjtFhNrByFDodGgZoHL0hCpaoETiNZQiEpqhBLrTyEUO?= =?us-ascii?Q?r6UPZYhyc3BsbpZW4fMk5kvzZqoiwhotFSt4f4TTNdL5uUD2ZIWbZSbwFw0O?= =?us-ascii?Q?UPbMDC+P6bthZqcG9LhsM384P2TU6wGc1sz+pYFGGVFiSKgEOTMutq25ds6w?= =?us-ascii?Q?mRofIRq1L6uxln4feHvnP9cBdFk0yWtPB08/gZlGN98kHlGkYCkKqOELUn6H?= =?us-ascii?Q?Xq8RBdgviQxcGqsqWDrga90TQ1176g207/moj1vI2lw5iu1ZcYQtYj6uhTAT?= =?us-ascii?Q?/sOqwoscamfkxluF2JDtT2KQ+A2tWpURKS4Odr7cwJEiodugFuD7LSr5Tk77?= =?us-ascii?Q?nluAJ1ed1yaiJWP5/VvG6UOAF5X0tV/RceNmMKq1dak/5/6/Th/SLnWQ42IE?= =?us-ascii?Q?vcRrfxnHS8ypA64Yp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LJZpqUByhAK08nj5UngSyU+XyAZeAiWpPDIgbM65PIQt/Tjg0K0us43iGTQ76RWmF2cxAREJMARLM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1988; 7:g4KWv6A2m0dzEaHGqzuJQ4BPstlYiH74xd8MtQtoEhsXtRmXKsTE7K1POymXABNtjWFTRCTrcG0tpeDUoXG3oPWd1PHFY66k9Xql4AgFEafootqB/VgcTU0U4dO1QYKqHz/9XXKd7oPfntG1W4Qvv3LFsC4Yq+OMF1/XmzqO3ztPhAzvkdJZvJWZccGBGFdH+KGZlspIyxZIAIxfz1lXhi+nFnYUHV4a48VT82Ad1GuwGvl+dypVX8xSX/OUndAObLknogQ04t1PRZFxCr8a+b5wK0xxe6t1vogWF7KzPheiIh+aZRyT1P2ITALSTpHfqBY5wvUI9oasMk/Bkgss9A==; 20:Mtl2/77gO+NRCtQTtOmQgFg5cfOJAk3nvI0aQXdWWndGbDCx7Qetnw//Ul60DN5b20Pf0r0xCxgXmILiTG9W1SGBUeKvB4+/En/SIBPCtVE4+dvZV0DUQkaUYJN1DHyvFL2PzRBEtq1OuM33Z+/Z2X9jLfQGUemW6AQfbApZgnw= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2017 09:35:04.8231 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1988 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.95 Subject: [Qemu-devel] [PATCH v1 01/13] qcow2: alloc space for COW in one chunk 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, "Denis V. Lunev" , Anton Nefedov , den@virtuozzo.com, 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 From: "Denis V. Lunev" Currently each single write operation can result in 3 write operations if guest offsets are not cluster aligned. One write is performed for the real payload and two for COW-ed areas. Thus the data possibly lays non-contiguously on the host filesystem. This will reduce further sequential read performance significantly. The patch allocates the space in the file with cluster granularity, ensuring 1. better host offset locality 2. less space allocation operations (which can be expensive on distributed storages) Signed-off-by: Denis V. Lunev Signed-off-by: Anton Nefedov --- block/qcow2.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index a8d61f0..2e6a0ec 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1575,6 +1575,32 @@ fail: return ret; } +static void handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta) +{ + BDRVQcow2State *s = bs->opaque; + BlockDriverState *file = bs->file->bs; + QCowL2Meta *m; + int ret; + + for (m = l2meta; m != NULL; m = m->next) { + uint64_t bytes = m->nb_clusters << s->cluster_bits; + + if (m->cow_start.nb_bytes == 0 && m->cow_end.nb_bytes == 0) { + continue; + } + + /* try to alloc host space in one chunk for better locality */ + ret = file->drv->bdrv_co_pwrite_zeroes(file, m->alloc_offset, bytes, 0); + + if (ret != 0) { + continue; + } + + file->total_sectors = MAX(file->total_sectors, + (m->alloc_offset + bytes) / BDRV_SECTOR_SIZE); + } +} + static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) @@ -1656,8 +1682,12 @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset, if (ret < 0) { goto fail; } - qemu_co_mutex_unlock(&s->lock); + + if (bs->file->bs->drv->bdrv_co_pwrite_zeroes != NULL) { + handle_alloc_space(bs, l2meta); + } + BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); trace_qcow2_writev_data(qemu_coroutine_self(), cluster_offset + offset_in_cluster);