From patchwork Mon Aug 29 17:10:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9304401 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 253AC601C0 for ; Mon, 29 Aug 2016 19:43:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1564B28966 for ; Mon, 29 Aug 2016 19:43:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07EB028954; Mon, 29 Aug 2016 19:43:28 +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 24FB528954 for ; Mon, 29 Aug 2016 19:43:26 +0000 (UTC) Received: from localhost ([::1]:45486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beSSr-0007F3-NW for patchwork-qemu-devel@patchwork.kernel.org; Mon, 29 Aug 2016 15:43:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47987) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beSSN-000752-7V for qemu-devel@nongnu.org; Mon, 29 Aug 2016 15:42:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beSSL-00048n-A5 for qemu-devel@nongnu.org; Mon, 29 Aug 2016 15:42:54 -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 1beSSE-00047G-Eq; Mon, 29 Aug 2016 15:42:46 -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=AFCpdCPIL384WB+rFGH9wEkib0BjocxG6e8dURPVd0A=; b=PkelrrK+LjYpA98wlKlKhgQZllDhVEGcxL7fCb/BHwakObjfASdMg7eci8o26bhA5//5rFVuUxoIRdQVC0iFcVcHLJo+RQaaFoNGBZjB6eQGQ+R1V4kHhcq8FP2YS3ZzJ+w+TSV1XA/ZtNFjXsN5Zp0js8JfJaQn5nCahVr9TdE= 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:19 +0000 From: Pavel Butsykin To: , Date: Mon, 29 Aug 2016 20:10:05 +0300 Message-ID: <20160829171021.4902-7-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: 4107571c-65ce-417d-d8ef-08d3d02f7f0f X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 2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kF9QdXgm8=; 4:djrOO/yTN8Itwhvg1sDyQZg6RVxGT91xBaYOVl7kcopjKYq0VvWF5la1g+4VsP2c+yz2OE6bgi9jRfHMPZNwBgM9l0mIMS8dFNA/kfPDYYuamY1FstEgaHHYrLL/nefE/TSx8UCzDtUf/4NbfWbgCMzbspx6Fi+z8HIDylk2PPc4jfZcoxoyxBSB1MdLNEEPEvcJHvzcpT3D9Rp8CGFQt2c41c7VIz5/ysMeGdEyul2EqP5RYXoE8dJOaWEyXuc9HQn8N09L6DRpzm/FOPts7tL4VF5U69zbXuGKtUTESNQSgAoHa16e8FPfeMKztUSxHnv6wL+LnK5RbPGkCVyWzg7hXfu+ExEQZZJ96GQqyjgim/EqBz0Voq9Za6QdIeN89z6+HV2pSu+ahF/amNwC4PUHGPd+NGNE6fWEmJ/FTW4= 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 permit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WtYdoB9Nl4=; 7:ih1piEbOA2sCu4T0bp7cqutGwAYpHAHrALgy2VbjW1TaBlnr+T7lso3naGG/6UILaIbGfX7rdfbxCojELCqp1tPuamWOWmwao2KLv143lts/d5Fr8mtwSEOOMBj/CFBJ9Vi7Mb52Kolas8yBbQAeatHVQVm2RsCUaL18Ou/5/hX9pcyOp+LzL6cp+Hh00/wu18D26vl4WEHwN8KoiBN7nhAEgE414mt+EDcLYKq/zx2A1yEh4ol7tycKilo28Wyg SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 20:kDFLLzBIh+XEGbhGCwdABQFHR9tHsSHb8FQqu0u0ReRX6s6Y7BG/oS05WkbvP9UOyondh/n9dDE5qZxdwOjHU1hjGVXRwKuJxl+pTKGn2l33Txq7vCoTIKdscv31cuVVUIyY6lgf/djpijiEKG6AN9ccR1RTlu06TLmDXG7IdKU= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2016 17:11:19.7712 (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 06/22] block/pcache: restrict cache size 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 Add pcache-full-size open parameter. Signed-off-by: Pavel Butsykin --- block/pcache.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/block/pcache.c b/block/pcache.c index f5022f9..54d4526 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -79,6 +79,8 @@ typedef struct BDRVPCacheState { QTAILQ_HEAD(pcache_head, BlockNode) head; CoMutex lock; } list; + + uint32_t cfg_cache_size; } BDRVPCacheState; typedef struct PrefCacheAIOCB { @@ -96,6 +98,8 @@ static const AIOCBInfo pcache_aiocb_info = { .aiocb_size = sizeof(PrefCacheAIOCB), }; +#define PCACHE_OPT_CACHE_SIZE "pcache-full-size" + static QemuOptsList runtime_opts = { .name = "pcache", .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), @@ -105,10 +109,19 @@ static QemuOptsList runtime_opts = { .type = QEMU_OPT_STRING, .help = "[internal use only, will be removed]", }, + { + .name = PCACHE_OPT_CACHE_SIZE, + .type = QEMU_OPT_SIZE, + .help = "Total cache size", + }, { /* end of list */ } }, }; +#define KB_BITS 10 +#define MB_BITS 20 +#define PCACHE_DEFAULT_CACHE_SIZE (4 << MB_BITS) + #define PCNODE(_n) ((PCNode *)(_n)) static int pcache_key_cmp(const RbNodeKey *key1, const RbNodeKey *key2) @@ -263,7 +276,9 @@ static BlockAIOCB *pcache_aio_readv(BlockDriverState *bs, PrefCacheAIOCB *acb = pcache_aio_get(bs, sector_num, qiov, nb_sectors, cb, opaque, QEMU_AIO_READ); - pcache_prefetch(acb); + if (acb->s->pcache.curr_size < acb->s->cfg_cache_size) { + pcache_prefetch(acb); + } bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, pcache_aio_cb, acb); @@ -287,13 +302,18 @@ static BlockAIOCB *pcache_aio_writev(BlockDriverState *bs, static void pcache_state_init(QemuOpts *opts, BDRVPCacheState *s) { + uint64_t cache_size = qemu_opt_get_size(opts, PCACHE_OPT_CACHE_SIZE, + PCACHE_DEFAULT_CACHE_SIZE); DPRINTF("pcache configure:\n"); + DPRINTF("pcache-full-size = %jd\n", cache_size); s->pcache.tree.root = RB_ROOT; qemu_co_mutex_init(&s->pcache.tree.lock); QTAILQ_INIT(&s->list.head); qemu_co_mutex_init(&s->list.lock); s->pcache.curr_size = 0; + + s->cfg_cache_size = cache_size >> BDRV_SECTOR_BITS; } static int pcache_file_open(BlockDriverState *bs, QDict *options, int flags,