[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 07/29] qcow2: Constant cache size in bytes
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 07/29] qcow2: Constant cache size in bytes |
Date: |
Fri, 22 Aug 2014 16:51:31 +0200 |
From: Max Reitz <address@hidden>
Specifying the metadata cache sizes in clusters results in less clusters
(and much less bytes) covered for small cluster sizes and vice versa.
Using a constant byte size reduces this difference, and makes it
possible to manually specify the cache size in an easily comprehensible
unit.
Signed-off-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2.c | 15 +++++++++++++--
block/qcow2.h | 10 ++++++++--
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 435e0e1..0f1be2e 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -470,6 +470,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options,
int flags,
uint64_t l1_vm_state_index;
const char *opt_overlap_check;
int overlap_check_template = 0;
+ uint64_t l2_cache_size, refcount_cache_size;
ret = bdrv_pread(bs->file, 0, &header, sizeof(header));
if (ret < 0) {
@@ -707,8 +708,18 @@ static int qcow2_open(BlockDriverState *bs, QDict
*options, int flags,
}
/* alloc L2 table/refcount block cache */
- s->l2_table_cache = qcow2_cache_create(bs, L2_CACHE_SIZE);
- s->refcount_block_cache = qcow2_cache_create(bs, REFCOUNT_CACHE_SIZE);
+ l2_cache_size = DEFAULT_L2_CACHE_BYTE_SIZE / s->cluster_size;
+ if (l2_cache_size < MIN_L2_CACHE_SIZE) {
+ l2_cache_size = MIN_L2_CACHE_SIZE;
+ }
+
+ refcount_cache_size = l2_cache_size / DEFAULT_L2_REFCOUNT_SIZE_RATIO;
+ if (refcount_cache_size < MIN_REFCOUNT_CACHE_SIZE) {
+ refcount_cache_size = MIN_REFCOUNT_CACHE_SIZE;
+ }
+
+ s->l2_table_cache = qcow2_cache_create(bs, l2_cache_size);
+ s->refcount_block_cache = qcow2_cache_create(bs, refcount_cache_size);
if (s->l2_table_cache == NULL || s->refcount_block_cache == NULL) {
error_setg(errp, "Could not allocate metadata caches");
ret = -ENOMEM;
diff --git a/block/qcow2.h b/block/qcow2.h
index b49424b..671783d 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -64,10 +64,16 @@
#define MIN_CLUSTER_BITS 9
#define MAX_CLUSTER_BITS 21
-#define L2_CACHE_SIZE 16
+#define MIN_L2_CACHE_SIZE 1 /* cluster */
/* Must be at least 4 to cover all cases of refcount table growth */
-#define REFCOUNT_CACHE_SIZE 4
+#define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */
+
+#define DEFAULT_L2_CACHE_BYTE_SIZE 1048576 /* bytes */
+
+/* The refblock cache needs only a fourth of the L2 cache size to cover as many
+ * clusters */
+#define DEFAULT_L2_REFCOUNT_SIZE_RATIO 4
#define DEFAULT_CLUSTER_SIZE 65536
--
1.8.3.1
- [Qemu-devel] [PULL 00/29] Block patches, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 03/29] qemu-io-cmds: g_renew() can't fail, bury dead error handling, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 02/29] block: Use g_new() & friends to avoid multiplying sizes, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 01/29] block: Use g_new() & friends where that makes obvious sense, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 05/29] runner: Add an argument for test duration, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 04/29] block: Drop some superfluous casts from void *, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 06/29] runner: Kill a program under test by time-out, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 08/29] qcow2: Use g_try_new0() for cache array, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 07/29] qcow2: Constant cache size in bytes,
Kevin Wolf <=
- [Qemu-devel] [PULL 10/29] iotests: Add test for qcow2's cache options, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 09/29] qcow2: Add runtime options for cache sizes, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 11/29] test-coroutine: test cost introduced by coroutine, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 12/29] qemu-iotests: Fix 028 reference output for qed, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 14/29] virtio-blk: allow block_resize with dataplane, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 13/29] block: acquire AioContext in qmp_block_resize(), Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 15/29] virtio-blk: fix reference a pointer which might be freed, Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 17/29] blkdebug: Implement bdrv_refresh_filename(), Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 16/29] block: Add bdrv_refresh_filename(), Kevin Wolf, 2014/08/22
- [Qemu-devel] [PULL 18/29] blkverify: Implement bdrv_refresh_filename(), Kevin Wolf, 2014/08/22