From patchwork Fri Dec 30 14:31:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9492489 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 1784C60417 for ; Fri, 30 Dec 2016 21:03:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F11B8223B2 for ; Fri, 30 Dec 2016 21:03:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E567E22701; Fri, 30 Dec 2016 21:03:26 +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 4CE3D223B2 for ; Fri, 30 Dec 2016 21:03:25 +0000 (UTC) Received: from localhost ([::1]:41474 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN4Ki-0000aK-Db for patchwork-qemu-devel@patchwork.kernel.org; Fri, 30 Dec 2016 16:03:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN4KP-0000a4-IU for qemu-devel@nongnu.org; Fri, 30 Dec 2016 16:03:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cN4KK-0002Hv-MN for qemu-devel@nongnu.org; Fri, 30 Dec 2016 16:03:05 -0500 Received: from mail-ve1eur01on0114.outbound.protection.outlook.com ([104.47.1.114]:59250 helo=EUR01-VE1-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 1cN4KK-0002Hh-18; Fri, 30 Dec 2016 16:03:00 -0500 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=Af02/qmBpQgARTCBcJrH1I8Yjumv2Gg4FxmTGE4GxQU=; b=JRWu+Wfo7OFPDRUwDOheq2h8DKc9k5rXkCTD+pY29wT5SSj/IL9/1SPTdzR8PnXucLtOKfdmKQCAzJZKca/TzlK1+2xKx/3ms3epbyql2b3/K4nNZn4iTIDOEo2EMaPyxo3L5fAyHle485d7S/LXqK+KlQiAG5Y+N3SnOcqVh00= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.6) by HE1PR0802MB2555.eurprd08.prod.outlook.com (10.175.35.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.803.11; Fri, 30 Dec 2016 14:32:10 +0000 From: Pavel Butsykin To: , Date: Fri, 30 Dec 2016 17:31:37 +0300 Message-ID: <20161230143142.18214-14-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161230143142.18214-1-pbutsykin@virtuozzo.com> References: <20161230143142.18214-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0802CA0010.eurprd08.prod.outlook.com (10.172.123.148) To HE1PR0802MB2555.eurprd08.prod.outlook.com (10.175.35.148) X-MS-Office365-Filtering-Correlation-Id: 3ef13f2e-0478-46ec-d54b-08d430c0a406 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:HE1PR0802MB2555; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 3:QWYlMNn+aCU8jvvGd4SPN6S0V2DST7N5IcH6syNiQvogp8jwMr1OhD0XJE+GFhdzXwr2ejSZa1/CwcNFINo/ArtSW2TlLfITaFVaZo5eRgotLdkg0RzBSq47h7h9qeSzV9xQvCPga1X3ehj0LO+RcK+ByqflX/5fbSP6hIglLJATPIBQYeOqUJQAcNB8XC2F71aZxVVl2oHUyCmlMc0XwG9oFfMablouSkxLGG1Sbo+Yxe/QNTlpmk/oTmvFNGByN0ZOgX0FVVVTxX2rD5on4A== X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 25:JMC46lqypJ/bF66NLS9F2YDEmWpEPTqCHcRtH/qRIWd/cJVmuMuPTcxd/Hk2Q9uztK7dhggkD6DLgbtoC68gjrxWSHcxZ2O1qzT0anVwE70opDP8bvm3nVeJeucZnnFftdnKB7+zmjrEU9PgKHsBbwsvyya+6VwnrrxlT//UliVV8G495vddmxnGkFlwjXnFbrk2NGQEbU4J0nlJRLoT1JdsUy803WHWy2Pggu/sbjdt31J8nTY8ehKfos/n69654YajjGoNS/gRJhxEllquMTDDVJOCHns5gJ79bJAwDaR8VtqYdqCvZtyku61ZjuzsP/ur74Aml6jNVck11VubLpBmoEqOsJIkqNPDxTIcdk5fnohOgfOSzSqMbYORBpj6qF8uiBL7bgjU0MOkdsGzohUkEKr6pkRLy1kBfOFykmoXwy7lGCRhdk/fhR5eei14ExRc9su+7DgLp22Qk4Rxp/+G8gKTcfnnYLwcxN2tsyXC+eglh6mxIzLrvkSE5DisLXnyI00ezVYQUTQ9Fg2N2DZ+UzeTWA1ARluuCZOZj+gqS1SsE4K7sRsoEjltMTbtPpYXt6uEnpRsnSD9UMxfFApfvzR7onzoH+1kpGIRIebw6CdDyyWdHD7SZt/uARRmuQ2nkK4ouZjhE7rDoqaMfrbMH3pC6XLd32lxaews3dKK3aqkTLsx19osf7Ws1BH/Bbn0WVjxRr14YQRk9G0hMuac6bH4NtqjvVOQx57K6cPZAVr91/ISJ4ZswnO30G0QLzNUETdOo+6H/t9VO+3L8g== X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 31:zt8hkCZkovmh5tdAjwHZgVRTEW2vV/Rcq3d3slVLnzMIDcO3sQSbBsN+sM9OBVv1w4mYNm95voAr0MrRhvSznPPTYfRLsRdLX32QagJLxPL5RLp4galCZQ1XdthRzs+27k8qcfWhTrVqiIzN71ZH18KOM/ynXPg2+5Vm+6KSJhXEj/dkCTzuSQOiqscLQKneZH2GbEIa/cONNIrA3z2Ko3XtP4Z09wegIsgOJLAP6m7i6+P75wRHyfrh6gYlpazE4ZYZvVebWpjsXFf5wuzxSg==; 20:gnz1InMRKCDdlkpGAZifmB6bWLFSNztqZ+TWICZjyxDEePw4LSqUPZxK/XuNqlEPO+UMVuQtSuErq/oR5yiS6iYfLRKpa1gy0oo9MXlWAQsckc6koaz+0AOIXhTMgi3f5DiT9hfZRtwa3LB76mbrc5+ql02oo9yOVYlDVg01Ri0HKYi2+wL83leg8OpY74qt9+DaiMVMo/TTaGhF/t3LQhmqADptNE4BV9c+yibPeC0kg8CN3QTQsKYaipb58C1n X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123564025)(20161123562025)(20161123555025)(20161123558021)(20161123560025)(6072148); SRVR:HE1PR0802MB2555; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0802MB2555; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 4:CuVuswfPAZX1inLi/VIai+/H0y1SrX5ZR0AFiUJG3KnnR2XeH3fYOTJGNMR5O8k+evU0XCldVK3cF0GPhU0jKMHS2BbPjOkcXzOD8fSA/e6yI7hXzOCSruG/hrOpwsS5BhMdfl8tgSdlu5exJw3gha+7sb9vDi/0NCkhAOH36az1FpvA+6/XyltqT0kXyxo3ZlZK7QFipShRai7zx2mD3+bdOh361O/EtDjzmMQfmfbAAUzTXeyB+EFuBGdMF2EWvuryyOuMAVpAGaw9hEmbyav/lTGjWJN9l4z0EoCuy4vpYj59Vjok+ZDIE8ZYNbmgWwit5NjzX3MgmvTxkDy1AGJqEL487149w9DZXqLvH3Z27WPug+BjciSsM07DDA8Dh+papDqyeGTOQ9jPZC7gReBAdDGQUDEw4J28Yg0VsrIDJgWu/xaa+ZyMwPOPT8BXXJbLZBwssm1chcFEbazEuJIDlPwT7PLFMtJSPhNUUHLdZgRprbQyNs7IEQbbcpnpwBD1TmTEvvZJXLnmBkmWt+3WLr95N39GwBOsrGTk0GnFMPQowYvGqQvq3N6aLNLzI7ZcY/MM+GnCo7vkHOM9F9hQSQFomLjfd+Flowe0gLQ= X-Forefront-PRVS: 0172F0EF77 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(39450400003)(199003)(189002)(6666003)(5660300001)(189998001)(5001770100001)(50226002)(81156014)(81166006)(5003940100001)(8676002)(97736004)(47776003)(66066001)(6486002)(36756003)(6116002)(3846002)(76176999)(105586002)(33646002)(92566002)(305945005)(38730400001)(50466002)(106356001)(50986999)(1076002)(6506006)(6512006)(69596002)(4326007)(2950100002)(25786008)(2906002)(7736002)(68736007)(53416004)(42186005)(48376002)(101416001)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0802MB2555; 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; HE1PR0802MB2555; 23:zUKC6R42RNsn3PM5yap/W3Ym5ZGWm8zwpnIXfpe?= =?us-ascii?Q?ULtcbirwTgBoo+1JKQWvCwxbOm/PTTtfq3nAplGBbwRX+8jhrTq6dwnghqEP?= =?us-ascii?Q?N8IgK6jS2kglOyy+iBPSEpZupEBG4bttz08Al0/5IfVBER96Hdj3R07Av+fr?= =?us-ascii?Q?/N1LfHlxcxqL8K8Hz33cfnrvLJfyyLqK+kXaYGownRB0xRPonkYhkqVQhGKH?= =?us-ascii?Q?NxQrU16HEWJ53nRZERC3qEou/UxYiYy7Aedy56nQOZeof7IVkYO3b1Z9gBl0?= =?us-ascii?Q?qo1D4SW1v978zC1LudgXjy2YjRqwScftQ36ct8boL9N3KZxB7ylad5pOAc3m?= =?us-ascii?Q?UmoDBpC/WxaQmilBbpJtmIMcuFJ+AaW7xmFgKpq4q3K22IrpphKJYBMdR38/?= =?us-ascii?Q?VXhx4OFdimunIQ/tBbERixhTm5jjYEVBPK/xJErVRbPlQ79JcOtbNg/L9hqL?= =?us-ascii?Q?X6vjX0JyagNamxLj++ucbzNV3T01zyYyxrLelS5OY1u/vfSXKay+EiYgKBog?= =?us-ascii?Q?xBbcXM9s5AAHnnfcl1Jq/KQXANjHYegwulTnVcvS7YS3Df9T4zrhrxr9uEr4?= =?us-ascii?Q?HVewVPtAGKdBcu7ezT2O+sLWwgIn/0S8ur2db924a/8NoXjL3+IH/JxWQ5sF?= =?us-ascii?Q?MMcprX7dEL+QXrBOesPE2OirXTt/8B9AAmNT7aI3kP3hbSkgYyQIlyKHV4YY?= =?us-ascii?Q?uZPbHhX1W1h7z8wT8wR+qJ3NMPiQ/l6PIj1Psrr+u1KkjqwaahbBrj61dGYK?= =?us-ascii?Q?xDc/OJQ3yXTM03idh23uxBSlU6a381UVZq9vKYzJboAzwns3KjFOkllX7QBZ?= =?us-ascii?Q?n2wPMxoPO7iWqxgXI67HVKGnfs6okDiqysQkcfv7sKnzAoMPxcpUUrp1J7Xm?= =?us-ascii?Q?oRm74orCZolM6SrkXLBKyRr+C6B8lDTBXQnFwVETY99tWlCv5xoC2SYvc9ju?= =?us-ascii?Q?7VIMH63ZV9QA11g5zqogIXJPL/iVbMbBvJjP5Sxqmn2NF4oDBf3cIZch4MPq?= =?us-ascii?Q?jroiwgC/0WV9L84tPNhRysXDRKg5odLbu0TSU/3nU3ydsqQ9tVtuGV/D4GjQ?= =?us-ascii?Q?YHwJ/fC66dKwRzWRqKJW5QJoAo4QnmgjVO/UGv+DcMbVa1EOaCyIYZN5LKBr?= =?us-ascii?Q?Yhk/fth7AH44=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 6:FeGn8UJQVmq/1yqJc32xvNTWMxv+P2+lUEgJTXcs42BLLNUf1ljHgQiW5bgM4mullQjDCw9iiC4b5LLGsd92sMIehGZiLbwh6pBQY5UZ6yQpX+3VchebBauEgPKsTZnDXmqN0a4sZUqfvOYpBUmz75zqqZHHFJEb2jzKTM5FXStC0xlFU0qemCfOII1LXiOs6Lf/UsHi7z7wW4P9QBumnGG7wO/HLp15qwGwrSkfnUlbciIO+9fH06RWUVz/2GPvdVSkuji3GrE3ysA0Aq4m+YllPDDr9erfHSXZQjy9YwtJQ/7fn82jIzIwUfH4FRSygWXSqABqJxU7qy3NXNDJ/dBoHErvdJ9+rDKxJFvrkZUqJeYvHCC16YjpK8Gc5RS3kAe1ARo8vvfki4G89l6tQO/orf8KF0A63MExU0tTxAE=; 5:xPreN5rhhq04n4oPMk8ma/E3jYdJB1TqoDt+FVd/vn2/WQOKkNsjAQG87FPjsT3GqHeUDYkCcS7OHBOLPRHVqsgA2o3wFdXe1zGrO+p/rYvr27Q3RTWEoe2+TUQBsu7Ela7FJZIAXyNMXt8XFZUWNw==; 24:Pr9zFGy1tAZy5ux0hJotyEadxyMTApE5hXPR3kRvOJwU2EOChAv4fUYSkjZqLR3dA3THL+K2gL24sMhYRXi6Mb/bLhGKLEOXeQnA/u/VSB8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 7:4cdhdswYWENlNOz7QllvBdLoRmVyMYQ+/Ev6M/cMZCRN+SHxaQz6qIGA/9g1ZbR+FgwVnh23fAjPfCRKT0AxWMf5AHFN//pGv/krjQdX+JGlDOFWEtWJP0TzjEjVwCuVdvC2pvuQEWoWnMJ2GlDW7nRyEjTPaVWNj4bkhDAvISQw9iM31qH/4Sa42KHAgJ64XcVZry/cPVP8TuETOaRTzUVMDAd4ElbIKtCPpeFWnUTeZCRxo1+TBbmFrxId01EO55Az4noWxd+O8APnO9QLXJGbg25G0TrRO3AuQXLio0NbGNRStVluYBBi5PeleksclQm4MpQFgSnzl2p84LSL9e8VZKmWEuumN/ARIyrnmsLbwtFozIu7WABrMi5dkHtQD/sFk7XK7awwHshvLrK9T/9tEhMtC6QItHAMaRAjoW80QaTbI78oYEyMtflBhP4y1JUkA8XTUZkFm+BRQzMySA==; 20:KegnZhxglqGRaxcpz3y3WOT+q7cYckTXZmL/AwfkNhOaVXRZyRxPWEZolGbjAcscJb/y8WkkbEQ5o69M32SrG6Ft85ieA+B65ufhye9mjAk9HP+SDFzymkiAuns7XLqQ8urVsBwIhjKQ7TmPQQO6X/AW05cpAXqhEIg8Eq2877A= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Dec 2016 14:32:10.7285 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2555 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.1.114 Subject: [Qemu-devel] [PATCH v2 13/18] block/pcache: write through 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, armbru@redhat.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 Write-through is another way to keep the cache up-to-date. Even if this case will be rare, write to the cache is more optimal than drop-cache. Signed-off-by: Pavel Butsykin --- block/pcache.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/block/pcache.c b/block/pcache.c index c1cbfa7040..140f90d6d7 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -410,8 +410,26 @@ skip_large_request: return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); } -static void pcache_invalidation(BlockDriverState *bs, uint64_t offset, - uint64_t bytes) +static void write_cache_data(PCacheNode *node, uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov) +{ + uint64_t qiov_offs = 0, node_offs = 0; + uint64_t size; + uint64_t copy; + + if (offset < node->common.offset) { + qiov_offs = node->common.offset - offset; + } else { + node_offs = offset - node->common.offset; + } + size = ranges_overlap_size(offset, bytes, node->common.offset, + node->common.bytes); + copy = qemu_iovec_to_buf(qiov, qiov_offs, node->data + node_offs, size); + assert(copy == size); +} + +static void pcache_write_through(BlockDriverState *bs, uint64_t offset, + uint64_t bytes, QEMUIOVector *qiov) { BDRVPCacheState *s = bs->opaque; uint64_t chunk_offset = offset, chunk_bytes = bytes; @@ -429,7 +447,7 @@ static void pcache_invalidation(BlockDriverState *bs, uint64_t offset, chunk_bytes = end_offs - chunk_offset; if (node->status & NODE_STATUS_COMPLETED) { - rbcache_remove(s->cache, &node->common); + write_cache_data(node, offset, bytes, qiov); } } while (end_offs > chunk_offset); } @@ -442,7 +460,7 @@ static coroutine_fn int pcache_co_pwritev(BlockDriverState *bs, uint64_t offset, if (ret < 0) { return ret; } - pcache_invalidation(bs, offset, bytes); + pcache_write_through(bs, offset, bytes, qiov); return ret; }