From nobody Sun Feb 8 15:59:29 2026 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487292799521349.27798850695126; Thu, 16 Feb 2017 16:53:19 -0800 (PST) Received: from localhost ([::1]:51022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceWnW-0002rI-98 for importer@patchew.org; Thu, 16 Feb 2017 19:53:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60055) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceWm7-0001C6-Gq for qemu-devel@nongnu.org; Thu, 16 Feb 2017 19:51:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceWm6-0007qa-O2 for qemu-devel@nongnu.org; Thu, 16 Feb 2017 19:51:51 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:35436) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceWm6-0007po-I0; Thu, 16 Feb 2017 19:51:50 -0500 Received: by mail-wr0-x241.google.com with SMTP id q39so3775042wrb.2; Thu, 16 Feb 2017 16:51:50 -0800 (PST) Received: from lean.local (bzq-79-181-80-34.red.bezeqint.net. [79.181.80.34]) by smtp.gmail.com with ESMTPSA id u184sm123712wmb.29.2017.02.16.16.51.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 16:51:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6A2JjvFrrdbYPT2T/is8MFxiKSez/7dvpR7ZphEgdSk=; b=c6UOoiitiq4a01KOSpCyGRhDd0mzN9OF3ymevkdTtVH3rmurkl4uGVxlVQnoiYPpiP fC37Pl1uyxSA6UsDd/v/gh0ah/Qsy2OAEcA2uJbTxeDEow3NxSNgDXWzq2Bw+0Nddv6X r0dBE1qRMQY/eNj16dYjhB0RAmaiVD2R4Io6pWp8786MdIVifTv+08bdyhOxCxnewCH1 VEVkfJLSNTlc27c8mJDD9i7qCBWoCTGsLfzNR+Vkq7VSgcMqBnG79V1zNIoV7eLdOMWZ Zgh+vjZ+OxqtbJJeZXhZT371jbH41bemfRZWvV3BhVRsuABSt6V0y5b5qISpJLOkI2JR 7TTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6A2JjvFrrdbYPT2T/is8MFxiKSez/7dvpR7ZphEgdSk=; b=blWR+dmU4s3lxBsvmfXuv5QAyM9ZJzEG7XUY+3NKyWRC4YwA0Njhj7bEaujDk3Xceh AOPQg/75x7OS+sG8YtUmxSrDpJceqC55XsATVMSJqdzLIQhLv+zPy2LSw1uwjlYdL1Kc lA+3caqy4ucaHaxhjM+FhINAZ/esflPdjATJmwUhOqI56niNLeK+sWq21QdbVytGqfIy xb0VSR/p5Ta1JzvUg1LQNTtTHlAzWuwztGloBxx9W+MVpjy1V03xsS10mgA897RKG5b9 PFlat13Jf9VcqDv6mSQXw8oySOLoQxw3BewEK4T1pRdauEpdKj9TR89+1591v+w/KxGa uKOQ== X-Gm-Message-State: AMke39mbPy5sX4KRbn56D8e7csOV5q46KtHSfoKfddmURT3OOQpuOD+S25F8IhTxre5bHw== X-Received: by 10.223.177.18 with SMTP id l18mr4466792wra.96.1487292709477; Thu, 16 Feb 2017 16:51:49 -0800 (PST) From: Nir Soffer To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 02:51:26 +0200 Message-Id: <20170217005127.21010-3-nirsof@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170217005127.21010-1-nirsof@gmail.com> References: <20170217005127.21010-1-nirsof@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PATCH 2/3] qemu-img: Truncate before full preallocation 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, Nir Soffer , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In commit 10ddfe7b6044 (qemu-img: Do not truncate before preallocation) we moved truncate to the PREALLOC_MODE_OFF branch to avoid slowdown in posix_fallocate(). However this change is not optimal when using PREALLOC_MODE_FULL, since knowing the final size from the beginning could allow the file system driver to do less allocations and possibly avoid fragmentation of the file. Now we truncate also before doing full preallocation. Signed-off-by: Nir Soffer --- block/file-posix.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 442f080..d24e34b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1604,6 +1604,17 @@ static int raw_create(const char *filename, QemuOpts= *opts, Error **errp) #endif case PREALLOC_MODE_FULL: { + /* + * Knowing the final size from the beginning could allow the file + * system driver to do less allocations and possibly avoid + * fragmentation of the file. + */ + if (ftruncate(fd, total_size) !=3D 0) { + result =3D -errno; + error_setg_errno(errp, -result, "Could not resize file"); + goto out_close; + } + int64_t num =3D 0, left =3D total_size; buf =3D g_malloc0(65536); =20 @@ -1642,6 +1653,7 @@ static int raw_create(const char *filename, QemuOpts = *opts, Error **errp) break; } =20 +out_close: if (qemu_close(fd) !=3D 0 && result =3D=3D 0) { result =3D -errno; error_setg_errno(errp, -result, "Could not close the new file"); --=20 2.9.3