From patchwork Mon Aug 29 17:10:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9304403 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 28770601C0 for ; Mon, 29 Aug 2016 19:47:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18471288FA for ; Mon, 29 Aug 2016 19:47:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C5722895E; Mon, 29 Aug 2016 19:47:05 +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 5E4AC288FA for ; Mon, 29 Aug 2016 19:47:04 +0000 (UTC) Received: from localhost ([::1]:45506 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beSWN-0002I6-FK for patchwork-qemu-devel@patchwork.kernel.org; Mon, 29 Aug 2016 15:47:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beSSP-00079E-Tk for qemu-devel@nongnu.org; Mon, 29 Aug 2016 15:43:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beSSN-00049t-TN for qemu-devel@nongnu.org; Mon, 29 Aug 2016 15:42:56 -0400 Received: from mail-ve1eur01on0114.outbound.protection.outlook.com ([104.47.1.114]:53724 helo=EUR01-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beSSF-00047G-9H; Mon, 29 Aug 2016 15:42:47 -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=jx0BLhFACunnvz6+qoA68QUuN5HWFbPAcxZ+MvunOJY=; b=M5YNpMZ2qNYc/4MnCfGF2t8tDPxScmA7feGCeId7+ilU17e97ew4t2bu76OLij7CeICR6VcF7aYUlGoqXQjaxGSBwxiKWFD38QnatNz6wxKcPBfZKY/ZRUH0/aC1+rbEXlDD0z2dqjq3RocxS/A3/yre+QPItzRlloWetb+4wpI= 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:27 +0000 From: Pavel Butsykin To: , Date: Mon, 29 Aug 2016 20:10:15 +0300 Message-ID: <20160829171021.4902-17-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: 0653e217-f2ce-49dc-78e0-08d3d02f83ee X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 2:KCER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; 4:2Gaj+gg+Xvt1VNZsnTzJjkwDBagh3M+IyZyHoufg1+oYWfHsd1o3mYqGN9/nBXLE/kmaKzfM1SEZvTAjQrUlWj+f/L/D+7ZU33rsqeWViQ2RuMzlZPZSB62c6OB0muLadqWdUiN446Yh4Sj4Gb6UWxSyvVvUx1nA9lO5LVAU357OHTHOpx8nIc/cplsFKouJF2uLfpvx4NxGKUkuWGLAmbhNubdGL4u5jsANz8bOZVkrvpaKjvv8YKcCHADEOXBHgzqO9K/+2vDygGPpbTDeosFQuuKlVFqEeThnWTECv6zwnwcT0Lyy5lpVrx3a3yzL+yTP3DjVFh4Gj37OEVuTZbqWrNjsiK+coleF/D2LaVIL4sJKTXNWObI/B6cCE3vHEoXh+ddccnJOrPA18Vgqos7xZJylbz1cr9JWKOe0IOk= 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-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)(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:W0GfTqsAkws3q9xmdrVhBVkRzsuhDC/5S6WzaHz?= =?us-ascii?Q?RqCfsTfxRDYVAfpEi3Z+ky7Mt/bPCfdY57RsrSNj/QlB2pL1eH4jO+eIWFiE?= =?us-ascii?Q?j77g3PiUCsfHFFsVULV0CHVJD3NT3cZiv05MmzsGihdv4VQxgvxZC6xPzlHd?= =?us-ascii?Q?WNkxDSca0HeRP4kdmBB9HjqZWLe+NPRxtx9up6J+yXCgQ3TU2jOBKqA2ZHsj?= =?us-ascii?Q?WHL8YyhVAGR3uL+2JUUdhVOXQwoxaaIUinWrteFLbuajZGzLzqMiprJGkFnX?= =?us-ascii?Q?7Ee12C8yhwUewRRuClddFMRGgMXL/+04j9hzXOfTEiP0WXKe60F9erVAtI24?= =?us-ascii?Q?Wk778W4saIDkisegCa74J1DNKYvjoxBe8tgAD44Sxtj4XLA2TFj9fPS5KHUQ?= =?us-ascii?Q?sj7wvsxZgFV0qydTK01KbfCRdWK1KkFGh6VviOxtroTIkAqkAnJbmt7f+d0k?= =?us-ascii?Q?tCZ0w0q4aLZuySN1SCP6KXz/x0CKMLODVUUSCVaa7ggFC8LBtaTmw2zOcIGS?= =?us-ascii?Q?EKs3LDJd9kGvtRiJGCdx+Qzk/bIjDE9gGpLYR/lS6ncafLXe6gOrx4NeajjS?= =?us-ascii?Q?Qhqsl7jewMHT6d3fMSyQlD8fqTlo570RVMwm1S6kM+mV7rmf2ay81sB095JX?= =?us-ascii?Q?0dYdCFsP1y9uc2nh43c+qIVjuJJD1wbgaV5OhNJe62VmadAEM5cGEXao5tuN?= =?us-ascii?Q?u8JT4CckvrC+HpnKnwLKZ+YOKTJbvjMZbpJ/Rv40m2gBNKIVa642/rU3UG9U?= =?us-ascii?Q?e2Mu7qizij06peRO1LZCPKF5a5zW5HkjoyCajObgJRW/prRKIgpfrioGNnqw?= =?us-ascii?Q?9vtSmPsbBUdsd8hNS+aKna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mLDZdaW+jM4DhgcHvSCu/eUbv4Z1VBjXlCzS+OYR1ATZLRvKynPndViltkSQYjUrwqkPbQTm9AnRL7FCgcfBeHl0JoPy1eqx8sh51LZUqjmfqHRuK8oCh0fOiky3yOvDeWZkEIAPuz4LSUhE6spZP682MsyndwXH69csM6jOHNLJ/ICbWQgYHiMUO2ECcrQDdfya1E0haihcyC5p6mozZ6yms7gtHJ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 20:uhcnOgTO34q4JqJIZo1XLSOxoKdyGD/N72SYvrvjmu732jnBqBX654YMFpnzeKfSUSRrf2GNVl9gxobrirwt31TyxeNaLR9tKGPCfnnTdWl7gKYKgxnPlSA3u8MSc8Shui0Hvu9/f61+WLV3RQkxA7wE0Td4YF+kMS93WKBAwCU= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2016 17:11:27.9431 (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.114 Subject: [Qemu-devel] [PATCH RFC v2 16/22] block/pcache: pcache readahead node around 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 if the next block is cached, then we need to check the size of node to ensure full readahead. Signed-off-by: Pavel Butsykin --- block/pcache.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/block/pcache.c b/block/pcache.c index 90b3f85..ae7ac8d 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -427,6 +427,16 @@ static bool pcache_node_find_and_create(PrefCacheAIOCB *acb, RbNodeKey *key, return true; } +static inline PCNode *pcache_node_add(PrefCacheAIOCB *acb, RbNodeKey *key) +{ + PCNode *node = NULL; + if (!pcache_node_find_and_create(acb, key, &node)) { + pcache_node_unref(acb->s, node); + return NULL; + } + return node; +} + static uint64_t ranges_overlap_size(uint64_t node1, uint32_t size1, uint64_t node2, uint32_t size2) { @@ -735,6 +745,38 @@ static void pcache_send_acb_request_list(BlockDriverState *bs, qemu_co_mutex_unlock(&acb->requests.lock); } +static void readahead_node_prev(PrefCacheAIOCB *acb, PCNode *node, + RbNodeKey *key) +{ + RbNodeKey lc_key; + if (node->cm.key.num <= key->num) { + return; + } + + lc_key.num = key->num; + lc_key.size = node->cm.key.num - key->num; + + pcache_node_add(acb, &lc_key); +} + +static void readahead_node_next(PrefCacheAIOCB *acb, PCNode *node, + RbNodeKey *key, uint64_t total_sectors) +{ + BDRVPCacheState *s; + RbNodeKey lc_key; + if (node->cm.key.num + node->cm.key.size >= key->num + key->size) { + return; + } + s = acb->s; + + lc_key.num = node->cm.key.num + node->cm.key.size; + lc_key.size = s->cfg.readahead_size; + if (total_sectors <= lc_key.num + lc_key.size) { + return; + } + pcache_node_add(acb, &lc_key); +} + static bool check_allocated_blocks(BlockDriverState *bs, int64_t sector_num, int32_t nb_sectors) { @@ -777,9 +819,14 @@ static void pcache_readahead_request(BlockDriverState *bs, PrefCacheAIOCB *acb) acb->common.opaque, PCACHE_AIO_READ | PCACHE_AIO_READAHEAD); if (!pcache_node_find_and_create(acb_readahead, &key, &node)) { + readahead_node_prev(acb_readahead, node, &key); + readahead_node_next(acb_readahead, node, &key, total_sectors); + pcache_node_unref(s, node); - qemu_aio_unref(acb_readahead); - return; + if (acb_readahead->requests.cnt == 0) { + qemu_aio_unref(acb_readahead); + return; + } } pcache_send_acb_request_list(bs, acb_readahead); }