From patchwork Thu Aug 25 13:44:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9299427 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 C5FC560757 for ; Thu, 25 Aug 2016 14:09:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B638129278 for ; Thu, 25 Aug 2016 14:09:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A978E29345; Thu, 25 Aug 2016 14:09:38 +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 E176629278 for ; Thu, 25 Aug 2016 14:09:37 +0000 (UTC) Received: from localhost ([::1]:56510 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcvLd-000068-07 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Aug 2016 10:09:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcvE0-0002Hj-8d for qemu-devel@nongnu.org; Thu, 25 Aug 2016 10:01:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcvDv-0007GZ-BJ for qemu-devel@nongnu.org; Thu, 25 Aug 2016 10:01:44 -0400 Received: from mail-db5eur01on0093.outbound.protection.outlook.com ([104.47.2.93]:32288 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcvDh-0007Ca-35; Thu, 25 Aug 2016 10:01:25 -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=m82coM1baiS7Yu+kaHFwlNr0TezR22zkCHRmrZj9ASs=; b=QVJyTIZ3q9syfNIGav2x1vmxXpRGL+HJeK4BM/1mGFhORN0Soneuc+dI3ykZbOCjK4p+K0iEzQI3jRRrVYG6PIVVLwP7Urul4XFmxzJAGp0NgjkJ9KHsLWkk9RHLVjWnB7bNKbms2o/5m/yBCnY2Tc6nFQU8TuApfd3CuxnXxW8= 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:44 +0000 From: Pavel Butsykin To: , Date: Thu, 25 Aug 2016 16:44:17 +0300 Message-ID: <20160825134421.20231-19-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: 646c8d64-d444-4b03-157e-08d3ccee1d3e X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 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2yNf4EfZtAA=; 4:si/Yef5ln1spYTs4Q1aF1nDFVV0gdf+v0Rnq1b7UEXUFAo1MAzQJ7n6nCTUEDGxANICKA3UxHb9IHWAaYIbc9S+QTSGHV09rmrVNEMxKchyh0stUUw39qD8eSeQScDvbPkyu1cyk7TyjDqEcXgxCDWSgI/nOW+Ta+rThgJ1+xFlxEbwsmXnMBxZVYHQAuBdCgKYLqpBuf2YLrSJZcaoJHDlTUJ3YNyLK8Hm9MeOXDMCxERIgn8m8rqThadpytIk8f0mFvebUBmONxolNPRPU+AFi4B7dxDpG/yMfmPwP9daboMH1UfVh2J7IOVpKqlMAWJDKAsYUDy6LRmKNKCM256P6OYucdjY0Vk9TAq/hLqxO7diNqh5VCoQG7ftO6qfvuCdTCdWi8h7gGYud/5D1HlaMMBVUCfNGr2MZb3kQCYo= 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:9BgsrpbSYzsV57dhYiixzNpRVZJqofgimopDnYg?= =?us-ascii?Q?V2E9kX1p3OaVReU9rmCLgqA92p4sHbmM2YdefjKOCDaGROWJgDLE3DaRroyb?= =?us-ascii?Q?F8rJwVJDhqdLLjoGVGsog3j2CsIW2aoxCRK8dHMTwG0tewq7ct9dMFgxKdmL?= =?us-ascii?Q?xRTlxbj+atKzLRYtboJu5oQRTmSkgSO4id0TOolRoEE88UfPNm3CB7vApCF2?= =?us-ascii?Q?i6kT68KWg1FwaxuhPbWPeELaHG3Gp846u0P8zQfvl3HRDKmpvSTEEzGiiPs7?= =?us-ascii?Q?GYhksx+RB0Q/wU6ZWQfZuqQt3GyZ8rbmZJ9G0OxygcaRorIbUDcqYYuo+cR8?= =?us-ascii?Q?jvLR9rn0yj8TKT3yxRxNgm0muLiEedhLIItaIRVoFGXU4wJ3DIvs7OCuLSk5?= =?us-ascii?Q?tOQk6IcXTzruPb0NSRojOqK7EgxOp8VOB08hRatQjHEz8Inf9oXerLl5iWfx?= =?us-ascii?Q?s/rJiPoCABuhnH1Apf1mKR45guZg3sgyctq038/b7nV6bXRKCZImNBd0LbRr?= =?us-ascii?Q?aK/Zsd/rzdw7qyl5j4rVyTsAexG10jsJKdLJtjC8TKf9dYMAOw6R46Ppqnoj?= =?us-ascii?Q?aLjROctK53IrQH3VQI9CO6m35LTtymWWKAkTp+BU/UjEZAB1uwTTjG7wjSA8?= =?us-ascii?Q?2C6aWgSGwI3Ipwe1yen2ydR2aD3qVTPJencZ+q99hlPt+NR9sfRIwjRYE6VX?= =?us-ascii?Q?3C2SBr+D/fpPmdTKVg12kgyf80suzpkysoHgh0MRlFLhibxyooDOVcnSdQkj?= =?us-ascii?Q?UkfzXbvJfti3qT4mfHi0kEqL77vOSrFSnvkEx1AMB/uVacRrkxonSUtyUx1I?= =?us-ascii?Q?UgqJrnQMRc6mX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7:JdjBuhEb0qTJj9DgvBaclyIJ9vRV4DKAg1HANfcWl412u5WPls1jT3RiGKCQg9mmNm5kQVrvPhyiJlfcoSQXt81ev28k83iuHaWca22E4Mcjf2cb1vDVaftdsGXXEXc0NfJP7NnwQgFGzaIl1IRgVKvvlkaWzPXKqWmjmZhItu0SV09ipq1s7I2n0vTFW0XLNrEzxX4zV9/RHnMZUQGzbw/EM8qr5Dwhiv8EbaCKpuYvsXzZzA31UmyzL0N+BKYs SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 20:jB2ePxHkfDDhzcaYS5AQg1jmbPdacjpjcZWDuRsPaf48rsMeoq2CQLblv8jKuEqShnGy4h7izpitD7QnVGIC30vGP8rXR7/oHutdf2kb3Phy+BZvrNkoDsYNUfDBe1Kkt02TFdciUij+Gz+lf7LzLLuM8Yfj018aUnuQT5jg94M= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2016 13:45:44.7156 (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.93 Subject: [Qemu-devel] [PATCH RFC 18/22] block/pcache: add pcache skip large aio read 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 This change will allow more efficient use of cache memory and filter the case for which the pcache isn't efficient. We miss requests that are not required in the optimization and thereby reducing the number of unnecessary readaheads. Add pcache-max-aio-size open parameter. Signed-off-by: Pavel Butsykin --- block/pcache.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/block/pcache.c b/block/pcache.c index 7a317fc..287156a 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -100,6 +100,7 @@ typedef struct BDRVPCacheState { struct { uint32_t cache_size; uint32_t readahead_size; + uint32_t max_aio_size; uint32_t lreq_pool_size; } cfg; @@ -144,6 +145,7 @@ static const AIOCBInfo pcache_aiocb_info = { #define PCACHE_OPT_CACHE_SIZE "pcache-full-size" #define PCACHE_OPT_READAHEAD_SIZE "pcache-readahead-size" +#define PCACHE_OPT_MAX_AIO_SIZE "pcache-max-aio-size" static QemuOptsList runtime_opts = { .name = "pcache", @@ -164,6 +166,11 @@ static QemuOptsList runtime_opts = { .type = QEMU_OPT_SIZE, .help = "Prefetch cache readahead size", }, + { + .name = PCACHE_OPT_MAX_AIO_SIZE, + .type = QEMU_OPT_SIZE, + .help = "Maximum size of aio which is handled by pcache", + }, { /* end of list */ } }, }; @@ -173,6 +180,7 @@ static QemuOptsList runtime_opts = { #define PCACHE_DEFAULT_CACHE_SIZE (4 << MB_BITS) #define PCACHE_DEFAULT_READAHEAD_SIZE (128 << KB_BITS) #define PCACHE_DEFAULT_POOL_STAT_SIZE (1 << MB_BITS) +#define PCACHE_DEFAULT_MAX_AIO_SIZE (32 << KB_BITS) enum { NODE_SUCCESS_STATUS = 0, @@ -386,12 +394,7 @@ static void lreq_try_shrink(BDRVPCacheState *s) { while (s->lreq.curr_size > s->cfg.lreq_pool_size) { LRNode *rmv_node; - /* XXX: need to filter large requests */ - if (QTAILQ_EMPTY(&s->lreq.lru.list)) { - DPRINTF("lru lreq list is empty, but curr_size: %d\n", - s->lreq.curr_size); - break; - } + assert(!QTAILQ_EMPTY(&s->lreq.lru.list)); qemu_co_mutex_lock(&s->lreq.lru.lock); rmv_node = LRNODE(QTAILQ_LAST(&s->lreq.lru.list, lru_head)); @@ -943,6 +946,23 @@ static void pcache_readahead_request(BlockDriverState *bs, PrefCacheAIOCB *acb) pcache_send_acb_request_list(bs, acb_readahead); } +static inline bool pcache_skip_aio_read(BlockDriverState *bs, + uint64_t sector_num, + uint32_t nb_sectors) +{ + BDRVPCacheState *s = bs->opaque; + + if (nb_sectors > s->cfg.max_aio_size) { + return true; + } + + if (bdrv_nb_sectors(bs) < sector_num + nb_sectors) { + return true; + } + + return false; +} + static BlockAIOCB *pcache_aio_readv(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, @@ -950,9 +970,16 @@ static BlockAIOCB *pcache_aio_readv(BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque) { - PrefCacheAIOCB *acb = pcache_aio_get(bs, sector_num, qiov, nb_sectors, cb, - opaque, PCACHE_AIO_READ); - int32_t status = pcache_prefetch(acb); + PrefCacheAIOCB *acb; + int32_t status; + + if (pcache_skip_aio_read(bs, sector_num, nb_sectors)) { + return bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, + cb, opaque); + } + acb = pcache_aio_get(bs, sector_num, qiov, nb_sectors, cb, + opaque, PCACHE_AIO_READ); + status = pcache_prefetch(acb); if (status == PREFETCH_NEW_NODE) { BlockAIOCB *ret = bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, cb, opaque); @@ -993,9 +1020,12 @@ static void pcache_state_init(QemuOpts *opts, BDRVPCacheState *s) PCACHE_DEFAULT_CACHE_SIZE); uint64_t readahead_size = qemu_opt_get_size(opts, PCACHE_OPT_READAHEAD_SIZE, PCACHE_DEFAULT_READAHEAD_SIZE); + uint64_t max_aio_size = qemu_opt_get_size(opts, PCACHE_OPT_MAX_AIO_SIZE, + PCACHE_DEFAULT_MAX_AIO_SIZE); DPRINTF("pcache configure:\n"); DPRINTF("pcache-full-size = %jd\n", cache_size); DPRINTF("readahead_size = %jd\n", readahead_size); + DPRINTF("max_aio_size = %jd\n", max_aio_size); s->pcache.tree.root = RB_ROOT; qemu_co_mutex_init(&s->pcache.tree.lock); @@ -1012,6 +1042,7 @@ static void pcache_state_init(QemuOpts *opts, BDRVPCacheState *s) s->cfg.cache_size = cache_size >> BDRV_SECTOR_BITS; s->cfg.readahead_size = readahead_size >> BDRV_SECTOR_BITS; s->cfg.lreq_pool_size = PCACHE_DEFAULT_POOL_STAT_SIZE >> BDRV_SECTOR_BITS; + s->cfg.max_aio_size = max_aio_size >> BDRV_SECTOR_BITS; #ifdef PCACHE_DEBUG QTAILQ_INIT(&s->death_node_list);