[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 18/55] qcow2: Add table size field to Qcow2Cache
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 18/55] qcow2: Add table size field to Qcow2Cache |
Date: |
Tue, 13 Feb 2018 18:04:52 +0100 |
From: Alberto Garcia <address@hidden>
The table size in the qcow2 cache is currently equal to the cluster
size. This doesn't allow us to use the cache memory efficiently,
particularly with large cluster sizes, so we need to be able to have
smaller cache tables that are independent from the cluster size. This
patch adds a new field to Qcow2Cache that we can use instead of the
cluster size.
The current table size is still being initialized to the cluster size,
so there are no semantic changes yet, but this patch will allow us to
prepare the rest of the code and simplify a few function calls.
Signed-off-by: Alberto Garcia <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block/qcow2-cache.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index c48ffebd8f..38c03770b4 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -39,6 +39,7 @@ struct Qcow2Cache {
Qcow2CachedTable *entries;
struct Qcow2Cache *depends;
int size;
+ int table_size;
bool depends_on_flush;
void *table_array;
uint64_t lru_counter;
@@ -48,17 +49,15 @@ struct Qcow2Cache {
static inline void *qcow2_cache_get_table_addr(BlockDriverState *bs,
Qcow2Cache *c, int table)
{
- BDRVQcow2State *s = bs->opaque;
- return (uint8_t *) c->table_array + (size_t) table * s->cluster_size;
+ return (uint8_t *) c->table_array + (size_t) table * c->table_size;
}
static inline int qcow2_cache_get_table_idx(BlockDriverState *bs,
Qcow2Cache *c, void *table)
{
- BDRVQcow2State *s = bs->opaque;
ptrdiff_t table_offset = (uint8_t *) table - (uint8_t *) c->table_array;
- int idx = table_offset / s->cluster_size;
- assert(idx >= 0 && idx < c->size && table_offset % s->cluster_size == 0);
+ int idx = table_offset / c->table_size;
+ assert(idx >= 0 && idx < c->size && table_offset % c->table_size == 0);
return idx;
}
@@ -79,10 +78,9 @@ static void qcow2_cache_table_release(BlockDriverState *bs,
Qcow2Cache *c,
{
/* Using MADV_DONTNEED to discard memory is a Linux-specific feature */
#ifdef CONFIG_LINUX
- BDRVQcow2State *s = bs->opaque;
void *t = qcow2_cache_get_table_addr(bs, c, i);
int align = getpagesize();
- size_t mem_size = (size_t) s->cluster_size * num_tables;
+ size_t mem_size = (size_t) c->table_size * num_tables;
size_t offset = QEMU_ALIGN_UP((uintptr_t) t, align) - (uintptr_t) t;
size_t length = QEMU_ALIGN_DOWN(mem_size - offset, align);
if (mem_size > offset && length > 0) {
@@ -132,9 +130,10 @@ Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int
num_tables)
c = g_new0(Qcow2Cache, 1);
c->size = num_tables;
+ c->table_size = s->cluster_size;
c->entries = g_try_new0(Qcow2CachedTable, num_tables);
c->table_array = qemu_try_blockalign(bs->file->bs,
- (size_t) num_tables *
s->cluster_size);
+ (size_t) num_tables * c->table_size);
if (!c->entries || !c->table_array) {
qemu_vfree(c->table_array);
@@ -203,13 +202,13 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs,
Qcow2Cache *c, int i)
if (c == s->refcount_block_cache) {
ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_REFCOUNT_BLOCK,
- c->entries[i].offset, s->cluster_size);
+ c->entries[i].offset, c->table_size);
} else if (c == s->l2_table_cache) {
ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_ACTIVE_L2,
- c->entries[i].offset, s->cluster_size);
+ c->entries[i].offset, c->table_size);
} else {
ret = qcow2_pre_write_overlap_check(bs, 0,
- c->entries[i].offset, s->cluster_size);
+ c->entries[i].offset, c->table_size);
}
if (ret < 0) {
@@ -223,7 +222,7 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs,
Qcow2Cache *c, int i)
}
ret = bdrv_pwrite(bs->file, c->entries[i].offset,
- qcow2_cache_get_table_addr(bs, c, i), s->cluster_size);
+ qcow2_cache_get_table_addr(bs, c, i), c->table_size);
if (ret < 0) {
return ret;
}
@@ -331,7 +330,7 @@ static int qcow2_cache_do_get(BlockDriverState *bs,
Qcow2Cache *c,
trace_qcow2_cache_get(qemu_coroutine_self(), c == s->l2_table_cache,
offset, read_from_disk);
- if (offset_into_cluster(s, offset)) {
+ if (!QEMU_IS_ALIGNED(offset, c->table_size)) {
qcow2_signal_corruption(bs, true, -1, -1, "Cannot get entry from %s "
"cache: Offset %#" PRIx64 " is unaligned",
qcow2_cache_get_name(s, c), offset);
@@ -339,7 +338,7 @@ static int qcow2_cache_do_get(BlockDriverState *bs,
Qcow2Cache *c,
}
/* Check if the table is already cached */
- i = lookup_index = (offset / s->cluster_size * 4) % c->size;
+ i = lookup_index = (offset / c->table_size * 4) % c->size;
do {
const Qcow2CachedTable *t = &c->entries[i];
if (t->offset == offset) {
@@ -380,7 +379,7 @@ static int qcow2_cache_do_get(BlockDriverState *bs,
Qcow2Cache *c,
ret = bdrv_pread(bs->file, offset,
qcow2_cache_get_table_addr(bs, c, i),
- s->cluster_size);
+ c->table_size);
if (ret < 0) {
return ret;
}
--
2.13.6
- [Qemu-block] [PULL 10/55] gluster: Pull truncation from qemu_gluster_create, (continued)
- [Qemu-block] [PULL 10/55] gluster: Pull truncation from qemu_gluster_create, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 06/55] block: early check for blockers on drive-mirror, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 05/55] qcow2: Use g_try_realloc() in qcow2_expand_zero_clusters(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 08/55] qemu-io: fix EOF Ctrl-D handling in qemu-io readline code, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 07/55] iotests: Use virtio-blk in 155, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 15/55] sheepdog: Allow fully preallocated truncation, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 13/55] sheepdog: Make sd_prealloc() take a BDS, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 17/55] qcow2: Fix documentation of get_cluster_table(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 14/55] sheepdog: Pass old and new size to sd_prealloc(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 12/55] gluster: Add preallocated truncation, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 18/55] qcow2: Add table size field to Qcow2Cache,
Kevin Wolf <=
- [Qemu-block] [PULL 19/55] qcow2: Remove BDS parameter from qcow2_cache_get_table_addr(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 20/55] qcow2: Remove BDS parameter from qcow2_cache_get_table_idx(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 21/55] qcow2: Remove BDS parameter from qcow2_cache_table_release(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 26/55] qcow2: Remove BDS parameter from qcow2_cache_discard(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 16/55] block: maintain persistent disabled bitmaps, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 23/55] qcow2: Remove BDS parameter from qcow2_cache_put(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 22/55] qcow2: Remove BDS parameter from qcow2_cache_entry_mark_dirty(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 29/55] qcow2: Add l2_slice_size field to BDRVQcow2State, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 24/55] qcow2: Remove BDS parameter from qcow2_cache_destroy(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 28/55] qcow2: Add offset_to_l1_index(), Kevin Wolf, 2018/02/13