From patchwork Thu Aug 17 09:15:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9905419 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 544A160244 for ; Thu, 17 Aug 2017 09:20:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53D70285FF for ; Thu, 17 Aug 2017 09:20:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48BAD28AD7; Thu, 17 Aug 2017 09:20:11 +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 97BEB285FF for ; Thu, 17 Aug 2017 09:20:10 +0000 (UTC) Received: from localhost ([::1]:40523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diGyH-0002hR-Oa for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Aug 2017 05:20:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diGuY-0000D1-Km for qemu-devel@nongnu.org; Thu, 17 Aug 2017 05:16:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diGuX-0004V4-CL for qemu-devel@nongnu.org; Thu, 17 Aug 2017 05:16:18 -0400 Received: from mail-db5eur01on0099.outbound.protection.outlook.com ([104.47.2.99]:34144 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 1diGuT-0004EF-PH; Thu, 17 Aug 2017 05:16:13 -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=gCNAIZpJOkirez4BhYXygnjVdbbHuKND35wPmfOlxZM=; b=OIDwCVYxgEG4kt1paPJ1Jhj0cloweerUYVFA/pbGoiLFnDzL+lZ/ZNMuo6B/nXvkVMi10C8yj0T4o9krjvqHFWkdIgfb78exMwhbfwaKfegIgRziNFCzgMl271o00QayHGiksiB/to0J+6JJwGa8ZMFyVzOxK3cmzVgC9tBF020= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.6) by HE1PR0802MB2556.eurprd08.prod.outlook.com (2603:10a6:3:e1::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1341.21; Thu, 17 Aug 2017 09:16:10 +0000 From: Pavel Butsykin To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 17 Aug 2017 12:15:40 +0300 Message-Id: <20170817091542.9403-3-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170817091542.9403-1-pbutsykin@virtuozzo.com> References: <20170817091542.9403-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: AM5PR0602CA0016.eurprd06.prod.outlook.com (2603:10a6:203:a3::26) To HE1PR0802MB2556.eurprd08.prod.outlook.com (2603:10a6:3:e1::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 376b16b0-1d96-42b6-0b8f-08d4e5509a66 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:HE1PR0802MB2556; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2556; 3:EXHxM9KZcL8eea4L9/6GWiQiC9lVgPpZnzM/nQMHq6Hqrip3q2bVnK7fD0K9uoBkr5WaA1zlgwnHBF3MpIUA5NP+CsW2Abs3X1+JhulBghPydftYLerie6ezXgvStqsH65VfLKUDgboUCSjLUUjoO99qoe5a0rD0Qcg5PI0DyaBgm5Q+p2YtnKOdB5nOaDmL6gqRl+rWV3jfApWP66ZxSSA4H9x2MBGIvbEdyEhvcfg2F5E4+vuacJ90Lj/1Er58; 25:sbwopwyQKJSR22qwNJc0jWKG/zPj/+oGV6dyeNWmIEkDe5XMVPS/zZ7uqp2wwJ1qyxlDaKO7Xph04/nEt0Zlg9ehDjBTDH5CBMKhzrwE2NmdKDmu8ABYDuqjmwIg34fvZowcfdLcDHSNgwPrcXsL2dcmrcipc312Hh7RBsSznkc7C3/r4RakJRmrNl0VPznhKdMt4ozO0mOf8Gt5s+mnvssVDuiEO4DKcYOBg094y1F8nKGCdr/Jl/lQrydoYYIBSmnCG7l44ohta5yLoKEbpaijMUssLzc3XCtGX7i/MpNXAu0zANJv1KyxHeKPrsh5pUw+I5qHRpwIPCA3vg3yRw==; 31:7MTVYYKnB5Iuk5AmLFjNbOTumK/BwHJsY+M2irhCP7l9lMU/b0OBfyjGaTvzk2NMcdMLawlOVzGMxj5O3Tl+7tQqFOJlj50OlUdv7oKFNreBlYs1iJg6cMaCeraFtqvAk8Jd/t+6mRMnLS7BDQShnugpy9nZNTzAHQ1qL31QJtXpSBXh2CgJMgU5YuibMYjdAg6nBZyiTC+uefGMlBMgS10Jd4kA+yzdyVX2BTjQN34= X-MS-TrafficTypeDiagnostic: HE1PR0802MB2556: X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2556; 20:t5rWpIXhuTUdfDOgjX4XkRr4w1ZLTfnABzooRsUoEHmmkL8HUnw5MBWyY/b9ejLIoHU2kdtue6xyYB+xMKtBcepMhweom1W3F75mlTXgwFTi7S5NZr1nYvUs5hCjuehFGxA3iaIwuH93srmKgaqoTzhxmPai0JWTPrM31BrGVvNT4UFaCQT4RKE5ZtwpKeFMObmCN4fqMhMJuowNWc3EpD3zFl4T4KQn9YHZL1NOIaHxxr60vh8J1YMYg5uTy0cUJTD+ezpuJphpXG4yQgN7zSnQv6wol1+bzH60sTWiSpNTf3qyY9rl9QaH+MX6GZ19wzK7SnmgxnJ6jdg6/tucW3EWJR1jdZ34la4qhQ0DqmpGmdS3d7gHI3qxFchv1Ez5s1Yx/y4cpT6Qa+hwkYpFbxyc1+EKgyYYSy/JOIfITZ8=; 4:Pag/XLnKPNurUDRnFc253/Tw9K0ajClJk3T3z5+7iAagcNt558/iCXkWAEl/Jw8wQFjZdv7Zjx79cAKXfR7svz7YQKyND6dHxNX8No18EXS4VliIXKFYAS40yDdVxbyfA+qFwA3EtNr9hC0blgG/Bdj4NUwtP9lXh9GlMNUYgu2F0j/0NR0OwdTKvLwV7Jx5U/Z7/KYbl27d6BasSvg+APWbzZbNMKCGRsjpKSTENWoIYTeuyP0Lp0B3fKex0qp/ 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)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6041248)(20161123562025)(20161123558100)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:HE1PR0802MB2556; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:HE1PR0802MB2556; X-Forefront-PRVS: 0402872DA1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(7370300001)(4630300001)(6009001)(39830400002)(199003)(189002)(86362001)(105586002)(36756003)(81166006)(50226002)(7736002)(66066001)(189998001)(6116002)(1076002)(97736004)(3846002)(81156014)(8676002)(33646002)(53936002)(107886003)(110136004)(478600001)(6506006)(575784001)(5003940100001)(6486002)(69596002)(48376002)(4326008)(2906002)(50466002)(47776003)(25786009)(6512007)(7350300001)(42186005)(53416004)(6666003)(2950100002)(5660300001)(305945005)(68736007)(50986999)(76176999)(106356001)(101416001)(15760500002); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0802MB2556; 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; HE1PR0802MB2556; 23:mh6rHW0heQcFakmMz91msMHMRnyVWSWOmwQYOtS?= =?us-ascii?Q?rGR4wr1PM5/LE9L66gAuimH6l/mj8aSq3Jmn+1TFW6KY0uoq4ZyLiAs+W7Dh?= =?us-ascii?Q?1//XTAhrQbVRWsym8dN35oqyFCrAkPzo+fJ3wsjmnncO00nshvAFEAZSeSwM?= =?us-ascii?Q?z6wbFy50JZc7j6Z1UL4zUOknCN8kuhntbSCCTVfM4smiUEOVt0VB49kCnK2u?= =?us-ascii?Q?7EILQEBZZIgezWiYMhy8h024pWp1/b1lR4q+T+++3d2lcqx+lnB81wu4J1Hz?= =?us-ascii?Q?G6pZHn0GxeA2LcD8yi6CR2hkwhnimqVGqIHCN9AO1P3ylUMShgi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aw4xiHf1yMdcau/LHROTQzVJH+IC1hkinZfOAh3KwFohNG7oENA?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2556; 6:gt8VWEk3Bli9zMn0PUOSPy8NbR7whKF58sPLX5njXleXt47qfEaSxpuCBgmUMcWFu2LkK8B4AylJhBfX7Tq/niPhSYv5my4bhxpIkXy6CrdMhDsi4vusYhamPZf5x4qee9SFD+3GBeLfTMGT7pnE+xwuMnv7LKV/q2pc/M6iToNbM5bEDIJIaveC7So/nEdTjUf+c+ljTQWncz4rh9A2wFJoR5kfZF59/7BA0VB8ffPJEgCG3joiK0UPl9VbR/qCVG8uTQyIMur2nd51eMNoon0kbt0NYvyhWuvgyCbVmbgdVwYtmv1WJ4i+AT2km9BCD9Gl8yxwFAaX+d8uvzcuaw==; 5:u193ZdeiHvs4N65DwRtIZrSfrWbP0TVXQxpcREKl2iSkFeegWVctOEo+rMcvpYLg2A7vVsnkK6oVU102807jDNN3QrHQibJDtks01dPT+u9fCKHp9931K7p/PeJ6BPpHlcI1KE0Mi4hXXPUOEDCq+Q==; 24:oxONCaHxo6a22XWiGFCxLHAK0eHXVuNdhAuq1gpOA+Zte9m/2nBUrK0Oasc+wZXTFt5K2mIeoU2wgsA8toKYxYdQvfWbqErB5zewl6cEgHU=; 7:6W40YsPCBBMbuqgqiEvM/9ftZAXRR/JLczXvhMj76NfOYuThdh3wpl8Y2Ua8fWsbk5Q/1b3u521E95Sq0KZbCsGlWrczazqDxyHugacZRkPjqwlFVm5KV/p2DS1NhcPhpYxeCN056ZvwZ4gap6Me12t4rougXpjcad6AQJxlzZM4bbuCEifn17ECgDrJGy9nLFOExkEZ9Hdtjh4Fh3ChOng6p6kuTk5/kYXalsWKlCc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2556; 20:yzFXYu2oaBdIuCoxbEQMk7j6xiMVm/NDv7saX36PfIYtpkpXdyLeFFc4s9wKts7c8y03aixxVPr3e4TQlvNUIHJGWP39+XA82MOU/N+DuzlSdhunIRb/c6zJgKK0zF/u8cvcFCdJJm1IPBm+2UuqfL4NuwkLXxxB+w4zUizAWy4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2017 09:16:10.8012 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2556 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.99 Subject: [Qemu-devel] [PATCH v7 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: Max Reitz --- 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,