qcow2: do decompression in threads
Do decompression in threads, like it is already done for compression. This improves asynchronous compressed reads performance. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Alberto Garcia <berto@igalia.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
c3c10f7295
commit
e23c9d7a1c
@ -3807,19 +3807,23 @@ static ssize_t qcow2_decompress(void *dest, size_t dest_size,
|
|||||||
|
|
||||||
#define MAX_COMPRESS_THREADS 4
|
#define MAX_COMPRESS_THREADS 4
|
||||||
|
|
||||||
|
typedef ssize_t (*Qcow2CompressFunc)(void *dest, size_t dest_size,
|
||||||
|
const void *src, size_t src_size);
|
||||||
typedef struct Qcow2CompressData {
|
typedef struct Qcow2CompressData {
|
||||||
void *dest;
|
void *dest;
|
||||||
size_t dest_size;
|
size_t dest_size;
|
||||||
const void *src;
|
const void *src;
|
||||||
size_t src_size;
|
size_t src_size;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
|
Qcow2CompressFunc func;
|
||||||
} Qcow2CompressData;
|
} Qcow2CompressData;
|
||||||
|
|
||||||
static int qcow2_compress_pool_func(void *opaque)
|
static int qcow2_compress_pool_func(void *opaque)
|
||||||
{
|
{
|
||||||
Qcow2CompressData *data = opaque;
|
Qcow2CompressData *data = opaque;
|
||||||
|
|
||||||
data->ret = qcow2_compress(data->dest, data->dest_size,
|
data->ret = data->func(data->dest, data->dest_size,
|
||||||
data->src, data->src_size);
|
data->src, data->src_size);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -3830,10 +3834,9 @@ static void qcow2_compress_complete(void *opaque, int ret)
|
|||||||
qemu_coroutine_enter(opaque);
|
qemu_coroutine_enter(opaque);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See qcow2_compress definition for parameters description */
|
static ssize_t coroutine_fn
|
||||||
static ssize_t qcow2_co_compress(BlockDriverState *bs,
|
qcow2_co_do_compress(BlockDriverState *bs, void *dest, size_t dest_size,
|
||||||
void *dest, size_t dest_size,
|
const void *src, size_t src_size, Qcow2CompressFunc func)
|
||||||
const void *src, size_t src_size)
|
|
||||||
{
|
{
|
||||||
BDRVQcow2State *s = bs->opaque;
|
BDRVQcow2State *s = bs->opaque;
|
||||||
BlockAIOCB *acb;
|
BlockAIOCB *acb;
|
||||||
@ -3843,6 +3846,7 @@ static ssize_t qcow2_co_compress(BlockDriverState *bs,
|
|||||||
.dest_size = dest_size,
|
.dest_size = dest_size,
|
||||||
.src = src,
|
.src = src,
|
||||||
.src_size = src_size,
|
.src_size = src_size,
|
||||||
|
.func = func,
|
||||||
};
|
};
|
||||||
|
|
||||||
while (s->nb_compress_threads >= MAX_COMPRESS_THREADS) {
|
while (s->nb_compress_threads >= MAX_COMPRESS_THREADS) {
|
||||||
@ -3865,6 +3869,22 @@ static ssize_t qcow2_co_compress(BlockDriverState *bs,
|
|||||||
return arg.ret;
|
return arg.ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ssize_t coroutine_fn
|
||||||
|
qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size,
|
||||||
|
const void *src, size_t src_size)
|
||||||
|
{
|
||||||
|
return qcow2_co_do_compress(bs, dest, dest_size, src, src_size,
|
||||||
|
qcow2_compress);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ssize_t coroutine_fn
|
||||||
|
qcow2_co_decompress(BlockDriverState *bs, void *dest, size_t dest_size,
|
||||||
|
const void *src, size_t src_size)
|
||||||
|
{
|
||||||
|
return qcow2_co_do_compress(bs, dest, dest_size, src, src_size,
|
||||||
|
qcow2_decompress);
|
||||||
|
}
|
||||||
|
|
||||||
/* XXX: put compressed sectors first, then all the cluster aligned
|
/* XXX: put compressed sectors first, then all the cluster aligned
|
||||||
tables to avoid losing bytes in alignment */
|
tables to avoid losing bytes in alignment */
|
||||||
static coroutine_fn int
|
static coroutine_fn int
|
||||||
@ -3993,7 +4013,7 @@ qcow2_co_preadv_compressed(BlockDriverState *bs,
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qcow2_decompress(out_buf, s->cluster_size, buf, csize) < 0) {
|
if (qcow2_co_decompress(bs, out_buf, s->cluster_size, buf, csize) < 0) {
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user