From patchwork Fri Dec 30 14:31:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9492235 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 3914B60417 for ; Fri, 30 Dec 2016 15:04:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29F401FF8F for ; Fri, 30 Dec 2016 15:04:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E6C0223B2; Fri, 30 Dec 2016 15:04:17 +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 4C6251FF8F for ; Fri, 30 Dec 2016 15:04:15 +0000 (UTC) Received: from localhost ([::1]:40192 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMyj7-0008KI-Q2 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 30 Dec 2016 10:04:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMyio-0008KC-K0 for qemu-devel@nongnu.org; Fri, 30 Dec 2016 10:03:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cMyik-0000AI-Kw for qemu-devel@nongnu.org; Fri, 30 Dec 2016 10:03:54 -0500 Received: from mail-db5eur01on0108.outbound.protection.outlook.com ([104.47.2.108]:36152 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 1cMyij-00008Y-Vp; Fri, 30 Dec 2016 10:03:50 -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=o+bdmXKOib7p0cbFzMb3VvyCzFDERQ68MOwcJXCZudY=; b=exBn4bpaEONaVeMkB+CDOh1fZEeBaMYo+M4yrbBtezG1ceqcYj4g3+qtg7U4NdJcJdA12dQWEF23yeUkHT3+JF37RUY9UVDNgSZNlfGt5dX2J008z7O3NIoee9AWrIgtC203Na20fZVBGV3FWfFx6rwlc3y6Cul1aispEEKNIXY= 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:08 +0000 From: Pavel Butsykin To: , Date: Fri, 30 Dec 2016 17:31:35 +0300 Message-ID: <20161230143142.18214-12-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: 36e0a141-c8bd-4507-d6ba-08d430c0a2a4 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:HE1PR0802MB2555; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 3:xOLFlsswmUBUG4MPGeN1L/xgRNTV8w3IyvuL/B6oYHtzDaPkKL13rnenNK5FDaoVOm53CMlKpFyCk7TdLtm35vTSYr7PuJF6kpTMNLt9lk2a8i0zeCjyCWKXSx/A+PZSf6NE3kLUnB/5NTxsLnRv/eLd1ThvkNRgXSjWnii3iiYDa8domGb42wdDUNhbbCxNc9W/+PvWZgvR9JiDIQB6h5IRaS9PGz16sxMThdIV8aebG6D1xw+II7jCUk8+GhR9/kKdDcj/H8kS/7nQbQUNSg== X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 25:utjb757P/Dnoc5fR7qJ40lcdkuuLyk9ByQgVsXgLlWfcCNyB4HVgbGxXGY0pR6zPEXaHmT0KROJeTFAnXQTbel0xsiysJ/+CcohopredxbXWvKU6MeWrj7tL5PrZBEaSembzCnYiFguhpzES/lp4smLHpp6+BiIyKo627w/ow7kl0js1wReCpCyFqzd81YCW8s0rnKNvYITWskhOXoOvjP3iGdx/xdY8GnMIjVnzDDSVccr6GZxCV6bOojM8SeELW1DI63F6iEUCp8wKcfgye0j+W7tTuL+MaHm2Z/w/rndeCjIFKBUdPqZZZYiGebeXTVtYC5GObh+WPheK1Rd6fgtRlQrzSECEm2IsZ1bw7qIjfcLjx3HvY4FyE3eMNFyODYJhsI+o59fAOd7umvI9GrihZu5bqmm8uAePkAXvmbZOJMaWgo+NGMW7O7Hu+3PIrTyVUp6ak1JvN8IO6hBu+uQfAgqQO24xK1Gm3Ndr4zSamhizh3mlCm0dkQFvaxZydEX7purVevy2TClHzGeBldWVScz7FMj+ZEAfIRtpjgUqhKg4hVFsth0medNJJf9ocMRievPPxzdRXajb8vhJCpRyKDQgIMkaek2A3Q7gxvp39ZmEJEsxKFt6Gnvhp1AlCTRvWgGbzAXmi3uLda3+su20vekCnZ9/pTZthMs0E2xZj+eqVCZX2CnvnuiZ+7TVLfFgT3uml58CNHmibqASHUoVTUbwYadS85cKVVguyS2PHElEwJntyX8mu5YtrkbJau4jrNd2P8xkXICPXNQK9g== X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 31:wZEEQQtdIaNxQepQhmqDLcGEV9w4TYTjYDOaz0gI0bjRvnD44Prqezuxd3mSUIyBdVcX+CuNEz6ItOWqZu+iwIOgILm1vlN6UZM5EC6qww1nDNKhDgwlwAQRRL6gnXHh04KMTewlgiwgGC5oMikKLWtf81ThvkPl/lUAHTxGb8FA2eQaOQTu4Xm7FWL17H+N7X5D43vCkAZMWELKSjBtdkHTR4g3bjpDg0w2BLnYkwPqs6KP7RKwHU3FLBO24X6+; 20:/3eQCwxU90zFvtihR0ixvvmw4pMW7aC8+XBU1Jr5NIDYuEpZmnjsY/mW5AwhSCarZ5i+M8w4kj5AirMSfk5LW3RRSGtS8l7YaAgPm0LaOqfO6a4aM7NbvWqdlndd/6lIrzQlXV8BdXKNnMPj9kVynWmqdIcGLTGBy2+ekWOqZ1oqc5yIPFjWIvOHxhppz61c16aCFwCZGMPJ5rWd+jomSnAQXqYZq8a1CIznS/6btg0WQNW0DywJgWSJ/IxPEszS 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:a2nzGl8MM4HsJ5xv0tDIrHKTGO0bSVqkxyzHJnKW9ILDOAL9hmcn1wUPpedrL78QeI+5MauzB7UGIMNq4REZWXNoZPGOtpmPD0w4bAFe1C7sA6CjnINsdX/Oju6/ZbiVYgn0V++QOCSKlrhzAIEeOk8eS5FThNmNskiBlLRnaiAppczW3i1UZ51mcPhrw6Wb/UyTh6ENHyZMp9rAwFV9O1Nge8L3X7HWMgCcH7Ph+7vwVBIvoBpdqVI8tAXUqiQy6MrmzwT+h1kHpQzC0k0mWvm/ZYqdr0q9J73C6Yl7W+gRmH9eNTae7pYqd/66vP5AcOvDZxfy6uIGNtnVppC2wwAcuWi1/xZ7luMWVCsPDXJMQcy6M3BtVtFOzlzN5Z64jYQ8dEubz5LBm8vKLkP7XY8NceHTbF/cvdDbYnJrLsx7rGc5hh+cFsKdCP/Z5LVZt7IbRgeuyE1dwf19Pv27KQS6J71kUngifVpvN/IUjeO9DF3o0fKTFXrR3FSKpkrpmE9Q4H3Lqk9S5LxnWvyNb3tIX7oxd/jxOIbHXCiu51CCC5UG3nTxIB54JFESK+wyjlsZNHSmP9iNzzYk9EhseVgA7sFe0pcTURcSrahZqCQ= 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:AglMutqvJFFKzfU1EZUlrb4EBs4rpB817q6wPtf?= =?us-ascii?Q?38FWYYrtPlE4WAGjZ6VFn0TD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?59i/Bi6MdXjGXe+TcD7mQhJwqohKfwkP7lZeaaSd/Iix3uZ4mL4pTvzKRn9/?= =?us-ascii?Q?E9Pzrdvbz7It0bWZLEpp0Ew4K+W+oEDp185vb/VHaUq4P/fFFZ8cfLuuq0zq?= =?us-ascii?Q?vgljCEi3/mMNmDV2lkl4xBN9SFaGjIul259T8n8C5IHQbkaaklOp++iQpw+q?= =?us-ascii?Q?BjIOP4LNfEJM=3D?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 6:Ou7jL0BrgIe7fbuK6RPRPQ4pxc4aVIo7FZff+eOQABxSb3EmJwPou4SDARAZOjED9ENSGwpNy4d1EBStNGDjnEm9LCP90CosHf3ZLI8ybsJVvWjoXZHa11tlMtOXjkpvm0FzE7uS4B7RC2VmSHtgwuq+tKqOfD+j98OFL6GaqcPSLGRxylI3CFXcpu9hORlA56sSPo1NrlLiCQlPSWx7gV/ni+h3wvi7v7k8WcnODAZCwabKXAXTow0eT5KXZ3RI0aef0ITrjeG2VQEu3ApYZgPwwLYhk0kcIINQq8YRTLWqgah0dKuStR+DZqHAaKQOvwedV6C9GPb8i1NL+H2TZqosBNwNJSrx1OMl1ewn1XzTeX2GGDO6zQCaTifwJ8DuAZ6fueMGgimHXrkoKfjTSHIpx+vBBFXMSxckyH47hQU=; 5:fo/pa8wiZ9f2azRnEVXIFJGoFlVGSnfo9WGAaYhFtJVAA4W5ITMgI+y4f3+ykGaiamzxdXdS62z/7cGG7UQ3/hm3KSd4KObLIBxphgfpH6S2sq06xb5WCvR5nRpLAix60UJzjDkNaIB+iCqbpJT1ag==; 24:2eik5MM9gYs4Kg3hQvLpHc0R/5RLlFQ495PA31UzFleP2E9TLqMlq2P9No8at5uY7Pukc9pac7/qUpR/hU9Vb48BiTCwW9uR034gUrc19kc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0802MB2555; 7:9R8vf4RFub0QESQcuA1N/KQMhuo6FC3fHxDMuOgZiNOTyf+YqQ6h0IrAnj/XBEPDDU0C3UxWGO74ejusFYVdnlJJV/Q02p23HUjo9lqP3Bc6CuRbnSQ4Fc8EFY7HXMybAFGzV9ojz/pQgbHzV3LmJnGqY44mtVzN+3cLXnw5/pvJjYqhemUah4QTOVfwuImf39jm2Cq+VjzQbFEBgLCFbcvZf3QZnEEVTNdHMyOKzeFidoy6GycXp8SbZPDRW4GQVUKTEqf/BystqXH5dJIlXwnUSBYJ26WGThNCShgFyf+7IQopJ7er2XzzVBEs28wShRzbzG1PfCjUvzADU8B/W1JarWAeaQ5zT9JY0NJ16z9lQz9LQhSpar0Cp8C8H6qhki5LAs3MnvZitbfjPIoxdkovwvJ58X0Nnf7jpEoSkdHCcyotKD6LuYujuMuoMctm9PqGax6G6XxOJnYpjuxJIw==; 20:topnpYkLi1MsikeZrQuPFJPIr3HFXV9LT9WjPL3aducpu/+oXCizTzp8abhwKgsCQLr6q7ih356mVl1m4oATbZvKxShmRIUagLhJtHDiq9LYBLdxWJ5MR1PzHav2q6tAv5cQX75syVbFKlaHcXvaOoWpmHomqvHz7zCBGgsqZAc= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Dec 2016 14:32:08.4106 (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.108 Subject: [Qemu-devel] [PATCH v2 11/18] block/pcache: add reading data from the cache 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 Added read_cache_data_direct() allowing to read data from node to qiov. And the simplest use case - read data from node provided that the node is not in flight and fully covers read request. Signed-off-by: Pavel Butsykin --- block/pcache.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/block/pcache.c b/block/pcache.c index 4007241d37..e3749679ca 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -92,6 +92,30 @@ static void pcache_node_unref(PCacheNode *node) } } +static uint64_t ranges_overlap_size(uint64_t offset1, uint64_t size1, + uint64_t offset2, uint32_t size2) +{ + return MIN(offset1 + size1, offset2 + size2) - MAX(offset1, offset2); +} + +static void read_cache_data_direct(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_from_buf(qiov, qiov_offs, node->data + node_offs, size); + assert(copy == size); +} + static void update_req_stats(RBCache *rbcache, uint64_t offset, uint64_t bytes) { do { @@ -288,6 +312,32 @@ static void pcache_readahead_entry(void *opaque) readahead_co->bytes); } +enum { + CACHE_MISS, + CACHE_HIT, +}; + +static int pcache_lookup_data(BlockDriverState *bs, uint64_t offset, + uint64_t bytes, QEMUIOVector *qiov) +{ + BDRVPCacheState *s = bs->opaque; + + PCacheNode *node = rbcache_search(s->cache, offset, bytes); + if (node == NULL || node->status & NODE_STATUS_INFLIGHT) { + return CACHE_MISS; + } + + /* Node covers the whole request */ + if (node->common.offset <= offset && + node->common.offset + node->common.bytes >= offset + bytes) + { + read_cache_data_direct(node, offset, bytes, qiov); + return CACHE_HIT; + } + + return CACHE_MISS; +} + static coroutine_fn int pcache_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) @@ -295,6 +345,7 @@ static coroutine_fn int pcache_co_preadv(BlockDriverState *bs, uint64_t offset, BDRVPCacheState *s = bs->opaque; PCacheReadaheadCo readahead_co; Coroutine *co; + int status; if (bytes > s->max_aio_size) { goto skip_large_request; @@ -310,6 +361,11 @@ static coroutine_fn int pcache_co_preadv(BlockDriverState *bs, uint64_t offset, co = qemu_coroutine_create(pcache_readahead_entry, &readahead_co); qemu_coroutine_enter(co); + status = pcache_lookup_data(bs, offset, bytes, qiov); + if (status == CACHE_HIT) { + return 0; + } + skip_large_request: return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); }