From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: Pavel Butsykin Date: Mon, 29 Aug 2016 20:10:05 +0300 Message-ID: <20160829171021.4902-7-pbutsykin@virtuozzo.com> In-Reply-To: <20160829171021.4902-1-pbutsykin@virtuozzo.com> References: <20160829171021.4902-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH RFC v2 06/22] block/pcache: restrict cache size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com, eblake@redhat.com, famz@redhat.com 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, -- 2.8.3