From patchwork Mon Aug 29 17:10: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: 9304405 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 2A6DF601C0 for ; Mon, 29 Aug 2016 19:48:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A7DD288FA for ; Mon, 29 Aug 2016 19:48:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F57D2895E; Mon, 29 Aug 2016 19:48:34 +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 D8571288FA for ; Mon, 29 Aug 2016 19:48:32 +0000 (UTC) Received: from localhost ([::1]:45517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beSXn-0003Qp-HC for patchwork-qemu-devel@patchwork.kernel.org; Mon, 29 Aug 2016 15:48:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48288) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beST5-0008PT-V5 for qemu-devel@nongnu.org; Mon, 29 Aug 2016 15:43:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beST3-0004ND-SB for qemu-devel@nongnu.org; Mon, 29 Aug 2016 15:43:38 -0400 Received: from mail-ve1eur01on0100.outbound.protection.outlook.com ([104.47.1.100]:49387 helo=EUR01-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beSSx-0004JQ-BT; Mon, 29 Aug 2016 15:43:31 -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=gHdkM0XyrURM//SMndDt/Z7Ya9H4MeocPNB4Kj3d/LJCjGR5JstsUlJCq3ph2u+uWgYFb+SupDnINtwThTz+8b/Bg4H/bLLmWyU1X9xUzIvmupnp4xW0by8kfgDxk0/uQDVZaR38KHf2mYImSjNCVO7XJm36VwrIDOe7gv0ZABo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.10) by AM5PR0802MB2547.eurprd08.prod.outlook.com (10.175.45.23) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.13; Mon, 29 Aug 2016 17:11:21 +0000 From: Pavel Butsykin To: , Date: Mon, 29 Aug 2016 20:10:07 +0300 Message-ID: <20160829171021.4902-9-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160829171021.4902-1-pbutsykin@virtuozzo.com> References: <20160829171021.4902-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AM5PR0901CA0011.eurprd09.prod.outlook.com (10.164.186.149) To AM5PR0802MB2547.eurprd08.prod.outlook.com (10.175.45.23) X-MS-Office365-Filtering-Correlation-Id: 8324a224-8be4-448b-b107-08d3d02f8009 X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB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pC9qSLfdsCEA7S2OKet9WaNkz/7pMc0ibP2y1Cb5aU2sr/TuUgnxhWYacnKo3DeJ4dF7Fq5kAGUL7Xg==; 31:pdSdgwX40mgEIWNmuHqnPYURidbSrEn6lTNwAA0m0I6rbKZw+omH5tsqRO0EsWvnZqTUwpai98gAMvwQah1vddmeFtgiF5i/UNckFkNsWrq/fu7KFkHOShfz9041dMcFS4m1RYBYIS8HW4JGeir2pk2JyXPRwezTJbvZZrc53qnZSlB7rgJ+aanMeJic7y+r7U18IPUtPgibJh8hui40SdXWKkd1qcjtd+c37TAlR7A= 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)(6042046)(6043046); SRVR:AM5PR0802MB2547; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0802MB2547; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 4:ibFGKUM+G0bPGs8q4IHMPOV6ZaaYj2T8lnvYroXUEiUZHPS/Z6Bz7sPv0kaxpDLN7kuanK4H5qpW/OLu9BL2VAy0AiMM8Psoqg1x5NwiFc8KIYSQWjQnGdqPrbzStzrs7ZA5G7mg6CUWC5Vr+22bN1Or6d9JvXKjnmWshgf7rpUnfwHznr4rBOW0QQLi4LB7ExD/6tbUWrahN2XRhbY8gRWmnOFGBJCewJR22jcySMQQfXIjt5ALtkDGVW+2QXv9RT7bp/BoHiPaTYMZnF7HApt8pboJQxnsp7d2zW5meBY28VVlEgrEQvWLB5r1ozQfCGDLAnJ03g1rruxOWsuYTMeQRlzMjB754/iHfLIzeyxczz55itjRLvoPb2U2tGDOWB/GtxuaMiWi+Sen66+B2/iXDfh2DIw51ugH92IDMHE= X-Forefront-PRVS: 0049B3F387 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(3846002)(305945005)(77096005)(86362001)(1076002)(53416004)(92566002)(68736007)(42186005)(97736004)(5001770100001)(47776003)(105586002)(2906002)(6116002)(189998001)(50986999)(4326007)(48376002)(586003)(2950100001)(5003940100001)(50466002)(66066001)(19580405001)(19580395003)(76176999)(69596002)(5660300001)(229853001)(101416001)(36756003)(7736002)(8676002)(106356001)(50226002)(7846002)(81156014)(33646002)(81166006)(21314002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0802MB2547; 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; AM5PR0802MB2547; 23:YS8eUtCJX+fbXNBTjunZ8bHI++9NoGjVPGKAdwf?= =?us-ascii?Q?xpKzKwyRaVBhugZ90r0LAX9rjOkCAMUhWzUWlekH5vWPcum76E7sHcViI1R4?= =?us-ascii?Q?XPPx84GEtHiXbPRpQa/1feTCY6jNtpN3hSun+IcgE8RHzTldMSSr+tKeR22E?= =?us-ascii?Q?tVjtM3V/vAFNJRir8c6LJR/CDMFt+Ejyo6PDgShikgzEL12hI5AeTvA9tan4?= =?us-ascii?Q?MkH5yZffzu3XZdh0iwkg8tPpHgfsMX9w2BreCd698eAeO5pbiQF7aGGL/rWF?= =?us-ascii?Q?xOJN2VzFfE8jDFfxLJz/9h69E96YfeR18hZ6ut/jA5uPVHD057Xn/CgpyaIf?= =?us-ascii?Q?jens+7EK7XpIai8VQFuTt7S34vGMcD5ZZiVIYb61n9R3xapAXnJmcaH6KNBn?= =?us-ascii?Q?0nB1KDQ+iy1oOwkgXE7BQ45mMqWyDJ2gB7qFf39Z4VKET7t786WOENkH3h4h?= =?us-ascii?Q?n34hnNCZZ+R54QGdxD0VEcWkvOH6NQaJSVnVpZMayD4iJwU+VDXceNCM+3Tm?= =?us-ascii?Q?oX102TDbynyFQ6qMyGvuu03ijkv/ujsjKXUR/vMV2U3kRWSijSyzK9d6jJKW?= =?us-ascii?Q?6Aa22MzKRoZHl6ORi3QCbe7CpBS+DAZztW0UPGe4E0FUf1+L+8egcp2wuUBi?= =?us-ascii?Q?Nt5VdZMYst50IEnDXWq/Jv7HKyRAq6dM+Z2xckifRrM8nFS2vtGNVoautLFj?= =?us-ascii?Q?yjmxovqVvQblshBzZQJbA9AEUJ6db68dPXdsZMq9ube5OPNKBxKykxccOnrP?= =?us-ascii?Q?mb/lr6V/iwuOGRX2c8X+G0Cghzng8B1rBq66RS2VYHFIBRHn4izhOrg9xfV2?= =?us-ascii?Q?uuU3mpUwVBPh5POpjemEsI7Fn/ZmjH/I6tRVNFAi24sh41gDF7EzCxA7RDBm?= =?us-ascii?Q?APTD3q6ZYitH0Fxi3TNwa5vFyNdJaiLqduMYYsohexwX4IK2SFs1DKm9bONl?= =?us-ascii?Q?J5mdJjdcwH/3jTljY1uZzptDTfDTNiStd+zCsMkG7XYE6LFrihglHVLL6OGA?= =?us-ascii?Q?8HM+UnhJIOj8rWpinuZ3PrjOQgPMnerBfrvNAjdwDvEROTsZZUGYT+M8VpNe?= =?us-ascii?Q?baNJvvdkvU49igjyKnPZWCvUeq7v0eDxEfmPqkF80vzSw3mPXWCSo3zCLXMH?= =?us-ascii?Q?is1zUh1Uv9UizOqpY1NEQaw+aWiO9+g6lYW80UD61ZDGzu7+QiZ91+wC0AfR?= =?us-ascii?Q?pmZsPryxgx57XHMo=3D?= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 6:HZFp4j1LleMC8cQMqH1E67Pszg0hBhzK/iT7yt26AbGOGTUqTbh80o1xu0iYsuziwHxAMXa8W3gPUXRSzpC3kV9HNhHaBUkuYTfvIgX2LELrMfJeOm8C66nrRocFQ0tG7/F4zA9cRwaMi3G/22RV7+nOQngjoDrkZP52akn/wxbL7AOfzzlWfQUDS7A8yRtdxSunmuoXwNBiyGDyr/0CpBetrhyILs1+EY5borHBt0RPzifco1TV0pcG303vmSoY/e/cTKFrIqhCyXxbk/TTSa7hCalA4HyXEA89d3epRn2wQvRIPUk3VS5+8L/MVAbQ; 5:SE063nje1/1BonzVPDmZX+RUyjD8DG8WaHKG0xAM0peil8yiIQIHS5TNcVWNgrTVWcjpL3zV3HZddAm/iuujAsRcVSk2rkqIZJ1x+X8JDCn1MyvayB3lVdmYPzDCjCVKIdTiyLIV6DXA6p0EZ3wBKA==; 24:ZfQdY+PoKYWLf0FsZyhJKO+jWMYQFIztlXanyaMhItfjYGuXZdl2HhxRb5BRip3tuNIG+gcpvVhph41sfi5OHLVggj9/OzQVV+8yHiv0XxY=; 7:VCpbXw9YlUNrT4dzK9/naHgw+DP1SYyvLMLgyQnhmovyxZj7X9Ab6CK/MJnGW5K5FCMUZ9kZjFYX2lUlCMjJMfZMYG+b/z3ghnwEq6w1ooIKv0TOU6Lf+Vb5fEtkREQCLZLA5zOiM/hFGFvnXx131+H2pli3sw3ZH8ty8Nrc8UiNGCRbL2kLb4zpEhvco4dBRVApW+8aN2kHhlCPpiG7/H17SU8A5Z2BhPvXYIrbCHGdaevSfK/vUksIropSvLob SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 20:k4EzLj9FxZuQRPE1keihJ22QjyoFaN8nit1lo75ORluwitytUu+37qPvLkKqePjUKQrntVaFIbKCSRKHw/V9q3txWF4i4CCJLIke4RHku8dJl02yuwFmFYPkzfem00781vqOULDMdvLERSyt3aZOMW4cx/S+6iMjgVL/RfM1lMc= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2016 17:11:21.3986 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2547 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.1.100 Subject: [Qemu-devel] [PATCH RFC v2 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, famz@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@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; }