From patchwork Mon Sep 18 12:42:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9956619 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 0378460385 for ; Mon, 18 Sep 2017 12:44:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E80BB28D06 for ; Mon, 18 Sep 2017 12:44:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCF3528D0D; Mon, 18 Sep 2017 12:44:56 +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 9B78528D09 for ; Mon, 18 Sep 2017 12:44:55 +0000 (UTC) Received: from localhost ([::1]:36362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtvPO-0003OC-A1 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Sep 2017 08:44:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtvO8-0003LI-1f for qemu-devel@nongnu.org; Mon, 18 Sep 2017 08:43:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtvO6-0003Qq-Tt for qemu-devel@nongnu.org; Mon, 18 Sep 2017 08:43:00 -0400 Received: from mail-eopbgr00136.outbound.protection.outlook.com ([40.107.0.136]:6071 helo=EUR02-AM5-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 1dtvO0-0003Gr-Cd; Mon, 18 Sep 2017 08:42: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=Ie7ql0Ylerv1TzEr+zgaZKWcGsL3YlQ2nmLOFHqfB7I=; b=L0GGjtl+zs8hzsIdeYcQbVN5T9bkI+32X9iVEt3w6TS+dgsiofEFuz7rPVtuU1datGYfOCLnOMELHkiahHWbktjnSw0hLnqhyFnBMKI4QxbPEAMU1HMAbASTqj+JB8cczlLSqo6YoBB4K0hGNJhKtIemcW+7aeNTlzsE3Y6UEFA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.6) by DB6PR0802MB2549.eurprd08.prod.outlook.com (2603:10a6:4:a1::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Mon, 18 Sep 2017 12:42:48 +0000 From: Pavel Butsykin To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 15:42:28 +0300 Message-Id: <20170918124230.8152-3-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170918124230.8152-1-pbutsykin@virtuozzo.com> References: <20170918124230.8152-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB6PR0202CA0006.eurprd02.prod.outlook.com (2603:10a6:4:29::16) To DB6PR0802MB2549.eurprd08.prod.outlook.com (2603:10a6:4:a1::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 117771ff-b346-4931-c6db-08d4fe92c537 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DB6PR0802MB2549; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 3:0miuyEXvGDo5ypYLX53lW3igWu54I+wSw2dHUTbe+qaiXyDmFFeBWcv34fQaC48gXwCfDSn7WBfQJlDHRb+UqaINKX0G9v8Ie9xCRwR5lazaCWx6goQ4l8FeznB49wjSxj7x7Q5eTRJXXTUIPf+btpX7leGYjR+Kbyg5NqlOtf/E93gS5fZhzDdH2n+UfhnyuxiLJW7wqt5ne49ysMpgBdLl6r9uEjZWpH7MVt/ET7quQN2z2lg8aFQoK6jwPN+Q; 25:H4n+KUbU07p+Uo4UBfLveCKyynjVL6LmiF2afWVYK4i1wXMH4rTKWo+osqKNLdRVJX9rw+JV5HEsZ1syjIF6k4N3ejGdwIXb/vBSMMCr/u/8B9/sOi6IPB5naHTmwDm5QwAEd5hgmkAPm0whXUrmMNM86Ehh/AVh1m12HCreQzB2+or+FRYj6g/EMlsItucHrrQW+1twll0nOzidxIFYuzhMaWxNyRvJjunq/f/5I9gso5HbfMBBGYraS1mXSquzL7QbNnsiQzbfSDUGBEa0+Ni7bdDVDuAoNihZt30QzCjenuFLDvDTzPxJS6jWgT65Yyyy38WqSDUBnCtYDZJS4Q==; 31:hqXGIVRVsjv61uAWKCIKBca7rb14o0oKrH0HRWpvlPz9O1vEBG3WdDABxuPU8MswtP17c6zuLsOMlkaCHyFTGHd//zKYuX1ogSGBQmLe6CZ5Ckoya2SbncY/UMhfGhOlIw+D8imtWr7PdQldtebwIpVEi++H5pOLQHvgn8VYvBPcSd1RJtZYYZZ6x+Aj/7pWC4SwrH98eoekxdkgkFiY+0Mf1Bcgs+98upBpIDn1yj0= X-MS-TrafficTypeDiagnostic: DB6PR0802MB2549: X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 20:jteR/OeK4GuamU8ggzRfim82ek7Nz2+XqVK3Ak+HTKM5hAQRYWTSyBNdgP83K7kLd3Z3xpDl+ZbyOHKX4G9TcKV3olnoXHSAaEDzVUx7VIVXfCmY5Ndv9s3u5CkLb6ZFRFmRcIotC3F0KNXHB3ynIEf5rDH3i6C6Vgt/pcWpgcStY56IpNfsj5EYiJlmgxEGjmbTg08kOw4IAgXqiPi4IqJPHBVuVolxU1ZYIuj5dhRDEDF82W/hKZyDrqxWUU0UowiNmbtE5NLknwZ5FzFx4vFawBCuI9NXAstm/8l4CzYSNI1/JJOzZPaLizoHGavIcjvGvq5LO96Jj3Udcc7KZLrlOANAgl4TNtnhA43U0gOnzOknkJ0LlbtHZlkttyL20PueT/5ZYAC26im3hLql6U/jAyxhhy0bQ02jF0ksV4s=; 4:ewViljmMN/Dvte5g0gfMDtf1YyV+t4EX0EE8oMQOIVwvkMa0DkoBYI1xzSd9ZMPB1sQmHr70nsTiNJycs8KSiG8xxe5iJIW32WqvT61Z/7LyD3wGpkYFco33SK5sblvy4on0Qdvrw28MqZHiS7OyQFd9TA7O+5kLviKuK/0LdL7nUYj21uyGmVMQpOuPgZEOGSeR6dxx1bb/IUp89wIFvV3RLOMUujW8btNitsWvVDODbExo46Q6Kgbe4dG7lZc4 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)(3002001)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123558100)(20161123564025)(20161123555025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR0802MB2549; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR0802MB2549; X-Forefront-PRVS: 04347F8039 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(7370300001)(4630300001)(6009001)(346002)(376002)(39830400002)(199003)(189002)(36756003)(48376002)(105586002)(50466002)(107886003)(101416001)(110136004)(53416004)(50226002)(25786009)(305945005)(7736002)(53936002)(81156014)(4326008)(81166006)(6666003)(5003940100001)(68736007)(2906002)(8676002)(6506006)(3846002)(86362001)(478600001)(6486002)(6512007)(1076002)(6116002)(50986999)(76176999)(47776003)(2950100002)(33646002)(575784001)(16586007)(7350300001)(97736004)(16526017)(106356001)(316002)(5660300001)(66066001)(69596002)(189998001)(15760500002); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0802MB2549; H:pavelb-Z68P-DS3.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; DB6PR0802MB2549; 23:molDBwm8C/9AvKDkgzdwkrHbboxnXpdyaBXRNLS?= =?us-ascii?Q?Xly/VnTbeVaJRTrti7dfK5hrfTLvl9oWkQEDvTRRrBNMQAC5OuLmOhk2DqXx?= =?us-ascii?Q?OfDANC5LP+Sq1yqxM03j1JfN3YLqPWchUSZdXwoCFkxuGFHthFixWre+91Jx?= =?us-ascii?Q?RD/qbsoxlUynwX9pMOAQiwk8YUqUHOFqyN3ldZaVeiKDZrTrLTt2pOlGhKBo?= =?us-ascii?Q?LBz4Fg1CDVunyX5N/Sua/tO+Li7TzaDQvVUMF7CA9QkMxtUbqIuYrqQy52kG?= =?us-ascii?Q?/yAzpRuD6rGMw4iaOMjkz+PDaxUb2W0eu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ys0ogTM0WwudbersaSyaFXvnabSe2GPr8bD7XyYFLGio1ju+w6fqedAqbz57?= =?us-ascii?Q?FvXPoWE+NKvzx+hwJ6aKeC78EfkWbCy/4mVPudfsb7HLQ4rw7L6xWQQSOIVD?= =?us-ascii?Q?1fQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 6:/6B7XcrNpW+VMSqXdNk0/x7XYXWqbC210MyzQ3go20lhDKf3irzkAmjkfDWbTon7PmmOWTIGfIwJnuVU3RMXoKpOFGCgLg5oPXgxfO9xIGCKh/iyXwPMwwwtfZlVfqgvANuvhr5j1Ii1cwGUxBJ/vjb94HBMSgze3sMRrqpwmGUmsRdfDtC4p/wVTk6uh7EaA82WtQeJ8PkzbKTADJR2oXNlAfgIBETdwUHOyM2JmkwxNlaYkpukW73YaeRvQ0TSj3o1TRf4eaLmaJTj4QT/ApSUXXBpAExb8IaY+/pf28nMbSEdrwxRha8cTo3RgGM8Hkdpy+YKO4J65FsKgMcDOQ==; 5:WxqOII826x9svhHMKpT7hEysoJ8CKe2tHrao89aCVsCgmIKVd312l+aTMfCUu+VeymVSLnhP/jxxFBynr40LTEX8lScDaDA9sQzd95ays2kUtFLP8z0/3Ikxoj4hDjZXKkwBu/SeOpBWMgplrlshQQ==; 24:AdevsPc8yXbe6IKMGRTaOw0yG3rSIsqWBKPpJVvILProvCkdCYwHdanwh1C4iaQFHBFF7KpM4X38VFiymdgo/HrFs2U5j0OOUUFJMO+Nj48=; 7:osCuYQhKqj2tftruUHWrWRTNkW4DqLM+RFq9mFvouKIgdHI9s9obBotLaJ0tgHXN9SM1CPafBZaJHB09xPX8qcMvYDzMgwUxOK5hpSbynIgd4YnwLGr0OMjKSTgbgJmFP904Mcs0gsP0leza6Xd/IVsxKMhuX+nNLKB2sraVS6NxtMJiQ51wpILMOwYgybQ0XeBXv8kltqhoAlv+TTdsPndMF8F88jTF62iWPzZhYjs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 20:r1xJ3RrfvqrY+cZRBFxK0GVjPbvtR4v+mRwcqAhN/r72lCySGxu5MzsZ8l7MuNdobXtCtPGZUJoMmQAU7fIFFNCbsZembTtgOm4ZUnRtowhvMY1lXFVw71HqksEbBSN8bfYuY4XgqMVkSBxT7xmjk0b4y8XYrffKwpW3TglLRFY= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2017 12:42:48.5873 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2549 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.0.136 Subject: [Qemu-devel] [PATCH v8 2/4] qcow2: add qcow2_cache_discard 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, pbutsykin@virtuozzo.com, jsnow@redhat.com, armbru@redhat.com, mreitz@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Whenever l2/refcount table clusters are discarded from the file we can automatically drop unnecessary content of the cache tables. This reduces the chance of eviction useful cache data and eliminates inconsistent data in the cache with the data in the file. Signed-off-by: Pavel Butsykin Reviewed-by: Max Reitz Reviewed-by: John Snow --- block/qcow2-cache.c | 26 ++++++++++++++++++++++++++ block/qcow2-refcount.c | 20 ++++++++++++++++++-- block/qcow2.h | 3 +++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c index 1d25147392..75746a7f43 100644 --- a/block/qcow2-cache.c +++ b/block/qcow2-cache.c @@ -411,3 +411,29 @@ void qcow2_cache_entry_mark_dirty(BlockDriverState *bs, Qcow2Cache *c, assert(c->entries[i].offset != 0); c->entries[i].dirty = true; } + +void *qcow2_cache_is_table_offset(BlockDriverState *bs, Qcow2Cache *c, + uint64_t offset) +{ + int i; + + for (i = 0; i < c->size; i++) { + if (c->entries[i].offset == offset) { + return qcow2_cache_get_table_addr(bs, c, i); + } + } + return NULL; +} + +void qcow2_cache_discard(BlockDriverState *bs, Qcow2Cache *c, void *table) +{ + int i = qcow2_cache_get_table_idx(bs, c, table); + + assert(c->entries[i].ref == 0); + + c->entries[i].offset = 0; + c->entries[i].lru_counter = 0; + c->entries[i].dirty = false; + + qcow2_cache_table_release(bs, c, i, 1); +} diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 168fc32e7b..8c17c0e3aa 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -861,8 +861,24 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, } s->set_refcount(refcount_block, block_index, refcount); - if (refcount == 0 && s->discard_passthrough[type]) { - update_refcount_discard(bs, cluster_offset, s->cluster_size); + if (refcount == 0) { + void *table; + + table = qcow2_cache_is_table_offset(bs, s->refcount_block_cache, + offset); + if (table != NULL) { + qcow2_cache_put(bs, s->refcount_block_cache, &refcount_block); + qcow2_cache_discard(bs, s->refcount_block_cache, table); + } + + table = qcow2_cache_is_table_offset(bs, s->l2_table_cache, offset); + if (table != NULL) { + qcow2_cache_discard(bs, s->l2_table_cache, table); + } + + if (s->discard_passthrough[type]) { + update_refcount_discard(bs, cluster_offset, s->cluster_size); + } } } diff --git a/block/qcow2.h b/block/qcow2.h index 96a8d43c17..52c374e9ed 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -649,6 +649,9 @@ int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset, int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset, void **table); void qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table); +void *qcow2_cache_is_table_offset(BlockDriverState *bs, Qcow2Cache *c, + uint64_t offset); +void qcow2_cache_discard(BlockDriverState *bs, Qcow2Cache *c, void *table); /* qcow2-bitmap.c functions */ int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,