From patchwork Thu Feb 28 09:26:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Shinkevich X-Patchwork-Id: 10832711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 13AD513B5 for ; Thu, 28 Feb 2019 09:27:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 028AC2DDA5 for ; Thu, 28 Feb 2019 09:27:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9B632DDF0; Thu, 28 Feb 2019 09:27:49 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9BD702DDA5 for ; Thu, 28 Feb 2019 09:27:49 +0000 (UTC) Received: from localhost ([127.0.0.1]:34984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzHym-0001jA-KH for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Feb 2019 04:27:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzHy5-0001ND-S0 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 04:27:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzHy4-00022s-TB for qemu-devel@nongnu.org; Thu, 28 Feb 2019 04:27:05 -0500 Received: from relay.sw.ru ([185.231.240.75]:48128) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gzHy4-00021J-GN; Thu, 28 Feb 2019 04:27:04 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gzHxz-0001z7-NU; Thu, 28 Feb 2019 12:26:59 +0300 From: Andrey Shinkevich To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 28 Feb 2019 12:26:59 +0300 Message-Id: <1551346019-293202-1-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v2] qcow2: discard bitmap when removed 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, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@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 When a bitmap is removed, we can clean some space on the disk. The size of a cluster may be larger, so is the size of the bitmap that includes many clusters. Some bitmaps can be as large as tens of megabytes. The flag QCOW2_DISCARD_ALWAYS allows a call to the raw_co_pdiscard() that does the actual cleaning of the image on disk, while with the flag QCOW2_DISCARD_OTHER, a reference count of the cluster is updated only. Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- v1: Discard old bitmap directories in QCOW2 image In the first version of the patch, any call to qcow2_free_clusters() in block/qcow2-bitmap.c was with the flag QCOW2_DISCARD_ALWAYS, even in the cases when the cleaned space is insignificant, particularly, in case of bitmap directories. Discussed in the email thread with the message ID <1549974951-731285-1-git-send-email-andrey.shinkevich@virtuozzo.com> block/qcow2-bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 3ee524d..162744e 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -202,7 +202,7 @@ static void clear_bitmap_table(BlockDriverState *bs, uint64_t *bitmap_table, continue; } - qcow2_free_clusters(bs, addr, s->cluster_size, QCOW2_DISCARD_OTHER); + qcow2_free_clusters(bs, addr, s->cluster_size, QCOW2_DISCARD_ALWAYS); bitmap_table[i] = 0; } }