From patchwork Thu Aug 25 13:44:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9299413 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 5A6DB60757 for ; Thu, 25 Aug 2016 13:59:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 478281FF0B for ; Thu, 25 Aug 2016 13:59:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3ABB92935D; Thu, 25 Aug 2016 13:59:54 +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 9E75E29359 for ; Thu, 25 Aug 2016 13:59:53 +0000 (UTC) Received: from localhost ([::1]:56442 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcvCC-0000UB-O7 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Aug 2016 09:59:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuye-0004OH-1N for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:45:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcuyZ-0002GY-Df for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:45:51 -0400 Received: from mail-db5eur01on0139.outbound.protection.outlook.com ([104.47.2.139]:49482 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuyO-0002AT-J1; Thu, 25 Aug 2016 09:45:36 -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=25mjho46Kcd5IlXHRhmPVmkVDEvS7B8lrTeSrGuwOOU=; b=aoiZqk2SxGtJ56P7oDJ+WjkUjMhwQ/KK9mYlbaDw3wC+uIRajiOU7AVyL6ZSDvXHqmBF5AjxKgB7V7ABOhoVZv0rCxokClM2CcWpJlO3Iv2YUvvLf+xkuweZWWbyWEptpkJ8PGipyx1J24AWZjBuqVSlSwuryIa9soLGRLOS/QI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.10) by DB6PR0802MB2549.eurprd08.prod.outlook.com (10.172.251.147) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.9; Thu, 25 Aug 2016 13:45:34 +0000 From: Pavel Butsykin To: , Date: Thu, 25 Aug 2016 16:44:07 +0300 Message-ID: <20160825134421.20231-9-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160825134421.20231-1-pbutsykin@virtuozzo.com> References: <20160825134421.20231-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AMSPR02CA0013.eurprd02.prod.outlook.com (10.242.225.141) To DB6PR0802MB2549.eurprd08.prod.outlook.com (10.172.251.147) X-MS-Office365-Filtering-Correlation-Id: 3be70328-51c8-4c85-b8f5-08d3ccee16fa X-Microsoft-Exchange-Diagnostics: 1;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ptBjnjW/ubecMhuykVEp94elD/4PU=; 4:FYvi0hGBuqltgpSQPha0MZcXOIj/qDtM4fPPglIBRVtDwbRhzfkEXguAZDdfodPXakHXkKR0ApNfV2rO0oe2nnyOseD8ieyKzIXg2VJlD8Yfe8635tKi6Ega985YilcsiJrb2eFsjAyi4bapb9MuEJ6jvrTrPcYcghF4lDItk53x71FnoHAU7toZeB20+CcHQ6u7UtlhIS7pOGhP1WLI02BE5zPSMGLqaUky2HucUPRw5DaSLAHHoIDlAum4nejPMNMCZtuZx+jKsk7KWDWmrATVlsxGVAoIUpKC90lDCfrjKhVEvlQEITOX1jrRDB8+xrM06issmzgwNRj9FlfOQcqUBMDATxKa7EiP2DSEsamhfY6/SOVgCseKh2NUDmcsgHY8lJeoWGeh0txcpHFR17mPICBTapSFML/Dwcp5+Jo= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6043046)(6042046); SRVR:DB6PR0802MB2549; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0802MB2549; X-Forefront-PRVS: 0045236D47 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(189002)(199003)(86362001)(33646002)(1076002)(69596002)(5003940100001)(42186005)(68736007)(189998001)(92566002)(66066001)(106356001)(47776003)(6116002)(3846002)(586003)(36756003)(5001770100001)(97736004)(2906002)(4326007)(2950100001)(5660300001)(76176999)(48376002)(53416004)(105586002)(50466002)(81156014)(8676002)(50226002)(77096005)(81166006)(19580405001)(50986999)(229853001)(101416001)(7846002)(7736002)(305945005)(19580395003)(21314002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0802MB2549; H:pavelb-Z68P-DS3.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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:z6ut8/vyqn9icitd9GrgYt7c+PTMyCoDvvJX9Fu?= =?us-ascii?Q?JDI4hu6SfMGQBah2GHcwsaGxR+BlPerVMHfizqOBkeno339iEnseVQgGeNOy?= =?us-ascii?Q?zUduls2LnzB6/jJ8I0k+vB6A57tMihjHn+t66T49TFrHKGdC/ELquf15HYsR?= =?us-ascii?Q?4JvSSxp6CA7a1byU6VkEoXOOtQrwdyZGVfPEkRjL07ynlxR+q6JKXd07zHy8?= =?us-ascii?Q?5iafIzmODWJ2R+mpEYm0ljdyVlFghoP0B1Y3eXUBioOW45ukalRPneDfuTfd?= =?us-ascii?Q?aXllCoRz+tzUo1VCrAhYN6q0Q4KAw4F/4vXMcH+muTLP+rslpLnwjezbDlzS?= =?us-ascii?Q?/w7IE78MRojEyGERvKBi1yFIe9MMv+w4dMp/J7VIoOfG4MhziTjEVcJ7iX3Z?= =?us-ascii?Q?wg0gjYs/HDVtkEQmgU8/bdLzz2Q8ZDf2MnD+ZQempoSvm1YyHuIXohumRP2X?= =?us-ascii?Q?cj5N/ALyLLf0uTyb1920UGNB9qmFxhYH092USa9a8ZMutto/LqvCUk2alzJq?= =?us-ascii?Q?zyqYjn3ufE29aRyqYJms93EtUNQTAHWm1Y8ku9yHrYPID+cwTWlTkm+obbpd?= =?us-ascii?Q?SM43tLkfxUUmXHcPr8Szz9LBwb8eXsYBMzeYlZ0R77ENSAY5FJl0B03JWSq/?= =?us-ascii?Q?/sXYIdGna6BRLq2aU0RCprWv3C4GZoHA0GQkuXOXmrOdvAUK6O2mmtVNZkR6?= =?us-ascii?Q?tfT6PDrNWwlvi921v81HHI7BQ/lPGylhT7Fq+SjnsE1BvSnJS6DvG00sWwp2?= =?us-ascii?Q?XR80tJLW5kT5F525ukpSbeMJ+gT75ukbSDJrpHYdz9S0DwMg/HiJHCOlyewU?= =?us-ascii?Q?aQRI6Qv3PV866B94qe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 7:hDPB4Rvl/m8nDAnYChBkaXRN9Tk+jVYvE6zGINQfhkIw463DhEIqTqTOg6P55YnW6cdx4+OqFsZHxyUSI2udvDx1hdQFuQafIm9xuDMQfQEMYbvp88p1S6fPNjujBcX7cz/FIPZLuqrO7uUOlmWvPtzQrvTs0c/ueNqp7LmjAL0+Xk1Bmw/j3MxMFceI7sEau5EWGqrhIVpEhHNRgtHWOcNZRo8T8eTzmTUXD+mk/jdkQagtvduL6WHKWhjLT4Sa SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 20:q27vnaGLIFQfAAi/E2yvJbUBL3yjIWlhd+fHEJRbYacKl2yi2SMpFp8/LmGRLDCqahki88sGS18fxYI4hwrYvM/yiOCt9jqM/V6/BvkDlCZ1gJfacG90MOikMgIQld+++s2mjd4mQEcEvtQuCV0gw8TGyMC5pAE9n+XqvlKacLo= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2016 13:45:34.2228 (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: 104.47.2.139 Subject: [Qemu-devel] [PATCH RFC 08/22] block/pcache: implement pickup parts of 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, jsnow@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Implementation of obtaining fragments of the cache belonging to one area of request. This will allow to handle the case when a request is partially hits the cache. Signed-off-by: Pavel Butsykin --- block/pcache.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/block/pcache.c b/block/pcache.c index 7504db8..28bd056 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -143,6 +143,24 @@ static int pcache_key_cmp(const RbNodeKey *key1, const RbNodeKey *key2) return 0; } +static BlockNode *pcache_node_prev(BlockNode* node, RbNodeKey *key) +{ + while (node) { + struct RbNode *prev_rb_node = rb_prev(&node->rb_node); + BlockNode *prev_node; + if (prev_rb_node == NULL) { + break; + } + prev_node = container_of(prev_rb_node, BlockNode, rb_node); + if (prev_node->sector_num + prev_node->nb_sectors <= key->num) { + break; + } + node = prev_node; + } + + return node; +} + static void *node_insert(struct RbRoot *root, BlockNode *node) { struct RbNode **new = &(root->rb_node), *parent = NULL; @@ -152,7 +170,7 @@ static void *node_insert(struct RbRoot *root, BlockNode *node) BlockNode *this = container_of(*new, BlockNode, rb_node); int result = pcache_key_cmp(&node->key, &this->key); if (result == 0) { - return this; + return pcache_node_prev(this, &node->key); } parent = *new; new = result < 0 ? &((*new)->rb_left) : &((*new)->rb_right); @@ -258,6 +276,45 @@ static inline void prefetch_init_key(PrefCacheAIOCB *acb, RbNodeKey* key) key->size = acb->nb_sectors; } +static void pcache_pickup_parts_of_cache(PrefCacheAIOCB *acb, PCNode *node, + uint64_t num, uint32_t size) +{ + uint32_t up_size; + + do { + if (num < node->cm.sector_num) { + PCNode *new_node; + RbNodeKey lc_key = { + .num = num, + .size = node->cm.sector_num - num, + }; + up_size = lc_key.size; + + if (!pcache_node_find_and_create(acb, &lc_key, &new_node)) { + node = new_node; + continue; + } + size -= up_size; + num += up_size; + } + /* XXX: node read */ + up_size = MIN(node->cm.sector_num + node->cm.nb_sectors - num, size); + + size -= up_size; + num += up_size; + if (size != 0) { + RbNodeKey lc_key = { + .num = num, + .size = size, + }; + if (pcache_node_find_and_create(acb, &lc_key, &node)) { + size -= lc_key.size; + assert(size == 0); + } + } + } while (size); +} + enum { PREFETCH_NEW_NODE = 0, PREFETCH_FULL_UP = 1, @@ -281,6 +338,7 @@ static int32_t pcache_prefetch(PrefCacheAIOCB *acb) { return PREFETCH_FULL_UP; } + pcache_pickup_parts_of_cache(acb, node, key.num, key.size); return PREFETCH_PART_UP; }