From patchwork Thu Aug 25 13:44: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: 9299545 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 E926460757 for ; Thu, 25 Aug 2016 16:18:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA59F29395 for ; Thu, 25 Aug 2016 16:18:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF46229397; Thu, 25 Aug 2016 16:18:18 +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 7AF8C29395 for ; Thu, 25 Aug 2016 16:18:17 +0000 (UTC) Received: from localhost ([::1]:57096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcxM8-0006LP-Ip for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Aug 2016 12:18:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcxLe-0006Hy-Vc for qemu-devel@nongnu.org; Thu, 25 Aug 2016 12:17:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcxLc-0007Nt-Qa for qemu-devel@nongnu.org; Thu, 25 Aug 2016 12:17:45 -0400 Received: from mail-db5eur01on0125.outbound.protection.outlook.com ([104.47.2.125]:24160 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcxLX-0007Lj-4A; Thu, 25 Aug 2016 12:17:39 -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=UmN6mWyNUIMMVtaPcj4ttLJzia64gLTIU9nBtbDj9p9e/mBARJlheKP5NLP35YtFBvi9OWlYH5+4ee4yY5rsMB8H/iB+8mvSufzCw8mRM6AHtukW8rLtP+C0QOxTgPAJnDz5nC2Yf29ljOnlTxOG+rmBUpU/z3POhj1dLDextzI= 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:32 +0000 From: Pavel Butsykin To: , Date: Thu, 25 Aug 2016 16:44:05 +0300 Message-ID: <20160825134421.20231-7-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: 1219cf36-188e-4ffd-c760-08d3ccee15c5 X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2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4kVI3lvlg=; 4:ufSCsLYN5NIm0t7ELS4NL4hX1/EJYuCXl3hRrArSgvSP2S8e/8IeARbk0jyLNnVy0jk1YOvOSoII/gLq4lHZR3grGCb9IB/E2gLgL89QVyxFc5tLOMTEOJ0mN7104AzdYSJCGbF7WKljrYs+z/7ShmKkTLfZZC/m3AjU3uRiJP/aN+38MWBmjAd5Ag+j2NW7yQRuInBqRNi4+nOYdvWezbR9vOXwhSfU8AzaGBi1DqsY094A/KLB/zd93so6OX4D3hWXg1RZ3vnF7tF6NCCTudNpkEECoCSkAokCTgCofbaVJ2QfRIZAkDanN8knkTerzPPIy0DinJ+d8gfHgWmbA1M1dRGLgnOnZnZorX86N+6AvZREvdN3O3gWVEKsi7YLE0TbgP3xUtPLxv2vYOWTxpFXSEG7nxJVnG8RDL8EfZw= 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 hos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6oThsaXp0WS8VpJbPyo1u6m1Tu0B/4QkkhvxkOcar+aEQaER5Q99xx/HqzQbFXiI4jnaXfRyWkuzDkXtfsH1zJUCwdokOYqrQtQe2fiDNalWQITYC6cykAQQHDU74ox5qo0gg2xh3PuHbOMmNiZKcfIASFKz+yKxloWeJp4VnGINLlqMC+6xfbfKytgJGbbaA3vBGmZomr9ysuBULISKPmH6gTTu7EuYl27TunRY3eMJuRCJ4+mgVRB6K SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 20:VXGyPXPeklBLs0vKEeQ9EiOwxcvqJVE1hH17HDB1wLsojGvkTYHNaoIb6y2fvDxmNoX1eh9ifkVZJmZzGZbjrpdF1ZIYruvIQxczoUkY2G7pSrcZNFremuHCTAm8XSbdJNKkEqd5Q5+BabLRpEfDn4UC7UC8LzMG8M0ktsYkpvA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2016 13:45:32.2142 (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.125 Subject: [Qemu-devel] [PATCH RFC 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, 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 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,