From patchwork Thu Aug 25 13:44: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: 9299403 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 5BE0860459 for ; Thu, 25 Aug 2016 13:52:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C93D2933E for ; Thu, 25 Aug 2016 13:52:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4166B29341; Thu, 25 Aug 2016 13:52:01 +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 9101B2933E for ; Thu, 25 Aug 2016 13:52:00 +0000 (UTC) Received: from localhost ([::1]:56379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcv4Z-00014h-6Q for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Aug 2016 09:51:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuym-0004Ve-Ix for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:46:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcuyg-0002JA-R1 for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:45:59 -0400 Received: from mail-db5eur01on0106.outbound.protection.outlook.com ([104.47.2.106]:49715 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuyW-0002F8-Vm; Thu, 25 Aug 2016 09:45:45 -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=Jy/NlYKNtFKOTwIaArq2cgVYUIHgmmWjoJHxTy5RFEHN6IawZBB7j1XtqyWGNiJC8k6olwTMV8ed2cO1r0lK3UTIuS7R7G7eoqMQPqGiEViSsCzats2/zcGdiut+LmwhjW7V+2n7ddWB8VoHt8DQRSE0XeRB5T1nWPWfvRNEmeg= 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:42 +0000 From: Pavel Butsykin To: , Date: Thu, 25 Aug 2016 16:44:15 +0300 Message-ID: <20160825134421.20231-17-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: 2e228507-00b9-4eca-7756-08d3ccee1c1b X-Microsoft-Exchange-Diagnostics: 1; DB6P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Z/+emvHq7S0Ev5Hpog=; 4:ByPmGonkXYsN7qCRJAiU/ddDRGpmiOjPbfvzwFXRtGEUTN5ioGp7ZmYEYpz/WKLNNHbCmfD4vGP0fIUrCHpmtaGVdobtJOfLNYG0fbUxKMb6AghXnf2BkFlkYg/BLyP3UyFiTbxK3NgQaIrXheFvW2Fnj1dVDoofCXxGNsubIornCvTne7Ma57oAYkyo5nwW3K3KDyoLr0j4kYZUUx3giXsk5ci7/OLW8qU+kpRH9Jd50B9ATUk52GahX72nv+a15zicHT9vHEQNCm4ZU8rfoeciffgVSvO++8y8WaOr2Q4XjGLto9k3AABkuS0/s1GBqZt1AYPCa1xFXPR/K5w1YbT5/p7Grmv7sKaP7sdlCpj6pQXqU7WV3TAu57G+S7ZD12cjz5uCmnaDvxq0S1x3zQ1tzS43lcrHyr9etydYwfI= 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)(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:JSvtpu78NKuKukq2urXH8yodOGITLGwliugj4Tc?= =?us-ascii?Q?bPATzGePrV7oQkPZ9sHnfa639DYcNIsldI3ub0jtByUMi8HNp7tlF7KALE7T?= =?us-ascii?Q?xEBTrnYEoax7WK9IzyAIY5e154Gsn3meIyAjVSa0qZvkg+TacC3kh1noNLOq?= =?us-ascii?Q?OAkkUHlXxf7b2GTZs7Zpd9jL5gsV/iEozcVn5kwMmAvNPKglt6Q9lO3dD1Hl?= =?us-ascii?Q?C6fZEPmdm4xPDgofxt/hwsengVm0HelizssSt9UUg4XlCagt9XrpjdGqjZXb?= =?us-ascii?Q?PkcWdKP4Avq2aTfLGsbPwZLP/S8gzXVmzILtiedyYxjJhB7xbMp1djXFFusw?= =?us-ascii?Q?unu3/nXUqJwgFnBxczx8Yr6ltJqGWx3lneARY4fqjX1rqrJx2lb4NiD7Mb57?= =?us-ascii?Q?HwURNsaB694PLMd+qGC+LWiM2qOyeygGDvVL86D/bkHuEtscI+LAftBXLpNO?= =?us-ascii?Q?8r4je7vWNuZ02otUO1RY9jStWyGMa9qp8EqU1OMLAxA8BzdW7bwjz0TNX38K?= =?us-ascii?Q?5T49nzbelyotZvrOCGZ0I3rRENwpYWU2i8BBgfBDvzJBDpYrmsUA0EE9x0Er?= =?us-ascii?Q?9t7CGbv+tqg+bX9VDO4MRa156moRlLBt+3J+A+jITdgwe6ITSMypwIoeL1zq?= =?us-ascii?Q?j18HOyB5fagexDI4JGJhx77pJy4smJ9oKdhtT8l1y/enFWe/Qi4OQEUzbC6I?= =?us-ascii?Q?xxhhHbi7vY+HhS8jLQxudO3BC6ks4TLdITbr/zGAFMRnaVGeOSJgnB8+shMk?= =?us-ascii?Q?JBypjU/A5ApJT7wxOiow8dfRjPZ70c7TMH685VHyj59pwx11hqw6XuG9efaR?= =?us-ascii?Q?1oGW9TRSTO5ays6JkxNNZCk2z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q3Mn8GDAyei+DFT2/jSJ3urjZdSVv/btY7L+pNFn9xvBtaP9oorIFl1nOh7+NfWoK30VRN4ckSs0MiCP0KHOg1tzbohPfcUwWnv0wOtzxoVBZWP/J9l/OAMnUY17qsrJ2+xi6Th7bCPevbs4l7+mNww/mgMIlneyHMnuR12ppnG2qEZGee1Fj3HHND7p19vQnKS1matngt4viveJzdYOZR3jiHo5PGXLC3GEJ1VlzC6nWd SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 20:Lk2/l1TqF5/l9tgVHMVuM0ctUaL0WhrRzs4kTTwDd6UO6FiCJJZBQ/ENNR1Y/59ZqacodadrhRpC2Lg2hFoAiuJd3VE/kOMGI3rR62czJ36dpJiijf73s/ehQBpN5eFOEZqHhcOL29+GDZNuL8piJJ31ZR0QzznKhb2YI66INss= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2016 13:45:42.8360 (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.106 Subject: [Qemu-devel] [PATCH RFC 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, 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 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); }