From patchwork Fri Dec 30 14:31:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9492249 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 5B8D660488 for ; Fri, 30 Dec 2016 15:13:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BFE51FF29 for ; Fri, 30 Dec 2016 15:13:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EF4B223B2; Fri, 30 Dec 2016 15:13:12 +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 8CA101FF29 for ; Fri, 30 Dec 2016 15:13:11 +0000 (UTC) Received: from localhost ([::1]:40254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMyrm-0006We-Ge for patchwork-qemu-devel@patchwork.kernel.org; Fri, 30 Dec 2016 10:13:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMylA-0001NH-8N for qemu-devel@nongnu.org; Fri, 30 Dec 2016 10:06:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cMyl5-0001sh-Sy for qemu-devel@nongnu.org; Fri, 30 Dec 2016 10:06:19 -0500 Received: from mail-db5eur01on0133.outbound.protection.outlook.com ([104.47.2.133]:6896 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 1cMyl5-0001sI-Hz; Fri, 30 Dec 2016 10:06:15 -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=r/sq6A74aRnL9FygjeuR7R3rwa1Qj1ocwANOjDvq5CM=; b=HT53i2RxOZxOk8PckVhdmM5MSCjoUTPiOWC6BT/QTl+/sdhaTUZbAuoeqPM4FeWSDiXPRBaPRUD4P4F4VPxOCmpDBgtGHIOPkmGkK4MMnmNq6EBuiw9mgUn5tQjY1qdOuRJYRuBdoEf4VwlFrDO7ULkCXV3BmW4PSMko+Cgc7kQ= 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:03 +0000 From: Pavel Butsykin To: , Date: Fri, 30 Dec 2016 17:31:31 +0300 Message-ID: <20161230143142.18214-8-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: a5420d9e-c2e2-4c87-bd27-08d430c09f9c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:HE1PR0802MB2555; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 3:EyFLNT2UmSfqdhdeVa8cAIohWchr49m6VtbvVurYFYmZTNcOMjtT6gu7KW5GwfL0MwPGmaJFNKLjzvdjpEDOeeqGSzCp37aqEEDQHcE4pub/Adr8m8HLmbsz0yrQsoaadEKEpqrbRjx9KzSWS4vOtc1jnRkLvt8cF5NE6MH1NiXvCprg4Q5x44dIblgrl9lhpj4OwG4plmekheboJA2RYccyd2crBlGOUitdoe5J3yCwaAkgj1lUEHs/G3kSGDVk8d+FbmzBWwoYKq0pnvN7YA== X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 25:0OdWftI6Ta3AzADBXcSCfV9MKnmO6O+tPmv5dSb/SRugDwy7GFKLGn3S+Zx5V0L60BtjbJ8lFdQnxf8NdBARCKK5rKX77BE9jbdqlmQWOlc25atJk54UQt1bZ8SoMow7fF5QkT3Fv6rfxOIrhenQzUVs55lmEn2MhfjaMP3hrl9nInP3Z8O+6VFK6H2Sn6YIWoqR+cYHNOlj1kUEiHsvBZhlBpowYXBnB/wUwHCPzsXfoPTApadLdNslI7h1QQIdVCHCVc8wA9xFo+pkQJ3hDBzrtr0cABMMLHtx0HB83os/yt9pC3ZGGQLUoADSajfm/Fkzlk3keQO9nJgylllxDH7RBSWBjK9T2TMfCvQ9RdNYiWo2sTzbNWxJQ9SNNF0qSUdWTGojqHnDoXcXpF30mGZLbWpqIjZnzOCfA42m99bZbVMi/BMYGbwulnKTpXovO0ymzyKKf4LSbZDhifULzhsQMXcE+244hrMWuIwIh80uPLGvtTRX8INnO++S3Hps2AxGupYOYI5r9rYX/vLmmB0lwg88l4nCmmBsiiq2eR90tLgiQFAJebUB0JlR9ncvi9bZGjrUl8uaQnXDRUu4UrQauJjX4TGfrlvx6PlcvZvqRDIs9JF9Tcow4LRVpRHBLhk+fqstYmEgHqNK/HS65V2uFrCeYg2MB5yJFagoA+RNlqk06xOiUV4jm5YnnSCmVJBiY6VTtEyXIR2sHGEcPspD5x8N9246lV0nMkHDu8mMP1eEZp5D7zwtf/JN8kHNl5sqz05J0DPDJGBxaZlqBA== X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 31:m9lBLnDWz103ROrf09tycnhza/JOEv6Vty2/xlQOa3zEF5o4AxRgHW7PdqdFZwM6j9D1LjLX50fRIJfomXMLjjvhVpdOhOsnl2QL1WrksV44zucD2Z/ctzfc6XfB4cTKgHNOf/1uRbqo93X49Ca+0kXm3KbfAUXYUv3LP/lznUin0Fv6Ff7P+txFeTrD2VKddgCUoLJMdmjpyePZkemcYNKm4Ec2AXyfTu20BnH03sDouejExjgsLwda6e9XIzwS; 20:a+fPd0DteLz1uz17Ygtqb9J5nDJx9MoZzufJ7HBmswQ/zlJVf93dIlpeNKMZmhYltRB62nw/jso6xyKxjunHiyoNuU8PjQY1cMeGalnCCCoVeJ+rUpBeQIgDFrqgAIprcFE/TjBXPtbL7kVwWUDt3C5AhU1hd6nTPgpUumXgHAVx35MiICKSvk9TpoJm+jGm2ilTy31OFX56WHvDWVIb2lpQAZgfNpdfrOk/6b8suFby7ppFIV0aTaYTzxzuWM7f 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:1lszRDw7g7S0XjdBmtEqD8wFEt7UiXGVZtofKFhHOAzY3JK3kYzbEg7spPOuXExMmKauyyd48UepjANljEx5Gyg76iACT3WRq14QnENVJRrbdBQOeJb2dTSpIs5lUjh2/pS0iD47o4LdkJbLimEW/S0HZ9M9RlMcYxf/pUyBBXmr6FBmkxBTkNHAKFSg72odbhRrH/lxGwMIaKocLJIGakO7RnHCp8kMzZ/918DSCKxpVhMUkkGVmYa9+P2aEdim55aA+Yr98afNuxFOGrscnH08s8SSJ+gGJNKK9+yd3oIhFUWvHTp7BdJ2q6VE6iNHthqa4+wOjO9kRL7SGKLlICmi78RyVMyODWJwKtW1NyiMGay4UcJtSSgPcSX8dzQk/8unDJj9T949rkAARzM0ZKRt1QXq8QEA5Gq4/cCutnw4Jbv5fOmLjGjCvLYKAGe2MxnECoGHo1Vlcz0qF2i/LNpr0R7DSr1ZwBiKVe/8oYazzO3o6KjmGO5LhUoMMxfpulTcRBPsqs0UQW6nu48nSVzehQig6H5eAja7Jmu4ZZ1vG7DqyWFRxlOSFbt+4qkUNjbzqnaKiDuxXF+ZYHDKNojqaUzXIEEcY5x8LnHgmqw= X-Forefront-PRVS: 0172F0EF77 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(979002)(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)(969003)(989001)(999001)(1009001)(1019001); 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:uC1FESgHVGAkwDD1cO3aZAK+9cKf8YqmNCNsikJ?= =?us-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m7kiZz9y5eulISeo0sXXSIC1BlqunkSZlSAtr7ZbzG38L0L1tnvGbihnjXumSUSE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 7:bW9KVINLtSqaQUVGZyURRFb9L5yK8j1OI14mRR2ptIowDg4tz33FIa5RPL0MxgUbZ1/n4HNrR/BgD6iyeKktG2cL39fU34I9Rtm7T/HR2GH2sMKnLych1U3yCKMY5dICNeGT/cwWVQ5z54iLjlEgKYYiu/JhLd+D9ukKa+4GnW0O4I/gzHVYIei+fE3smr26b6GSlvFzuPjD+V64EJmhSVGZY5L9ezsIBiwmqnc2vEvYp7e5o+upQ8yBMvLbNNexJRruidQyXrfaqY32gheRsNUCQp+jKTsVdzTUAItS4pWX5oaN+UnZ4HwnEwuJcH31j1JfrAAHWXP9lIQHcNFy/LipgFU5VUvby6tlk0hW7VHhhMkSq12wi99lmtkr2xH8pfPpyzb3Cxo8V8SfPG8SdRGHS3hjjQvOTWZ9thpjEHZuKTv+jZjgegS1U9ECYrEOAH+UG9jMPRa7KEFfY+IDdA==; 20:wZ16OTw6xNi3ehSoshT3VPyimp/ZFMWAo0h5rFIa8b5GnDNn2HUFynmPFNT+lO/zXt2Ooe9BSyP1ELU2Xn3pEEFNe19PHER3UPoZWjAg7s5LB03rjDodeFVtyvPIh574N6EGnejvv4p40GhgRkj5WQ1hRgffEoziLWlWMqtcnBM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Dec 2016 14:32:03.3243 (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.2.133 Subject: [Qemu-devel] [PATCH v2 07/18] block/pcache: updating statistics for overlapping requests 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 When updating the statistics sometimes i/O requests can overlap each other, in this case the requests are not stored in the statistics. It's not very good, especially when the requests have a small range of intersection. We can cut the requests in the intersection and add the pieces of requests in the statistics. Maybe not significantly, but it can make the statistics more accurate. Here, update_req_stats() adds the ability to save overlapping requests. Signed-off-by: Pavel Butsykin --- block/pcache.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/block/pcache.c b/block/pcache.c index 1f3200af63..deac57c58d 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -46,6 +46,40 @@ typedef struct BDRVPCacheState { uint64_t max_aio_size; } BDRVPCacheState; +static void update_req_stats(RBCache *rbcache, uint64_t offset, uint64_t bytes) +{ + do { + RBCacheNode *node = rbcache_search_and_insert(rbcache, offset, bytes); + /* The node was successfully added or already exists */ + if (node->offset <= offset && + node->offset + node->bytes >= offset + bytes) + { + break; + } + + /* Request covers the whole node */ + if (offset <= node->offset && + offset + bytes >= node->offset + node->bytes) + { + rbcache_remove(rbcache, node); + continue; + } + + if (offset < node->offset) { + RBCacheNode *new_node = + rbcache_node_alloc(rbcache, offset, node->offset - offset); + if (new_node != rbcache_insert(rbcache, new_node)) { + /* The presence of the node in this range is impossible */ + abort(); + } + break; + } + + bytes = (offset + bytes) - (node->offset + node->bytes); + offset = node->offset + node->bytes; + } while (true); +} + static coroutine_fn int pcache_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) @@ -53,7 +87,7 @@ static coroutine_fn int pcache_co_preadv(BlockDriverState *bs, uint64_t offset, BDRVPCacheState *s = bs->opaque; if (s->max_aio_size >= bytes) { - rbcache_search_and_insert(s->req_stats, offset, bytes); + update_req_stats(s->req_stats, offset, bytes); } return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);