[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 2/3] block/stream: use blk_co_pcache
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[Qemu-block] [PATCH 2/3] block/stream: use blk_co_pcache |
Date: |
Thu, 6 Jun 2019 16:48:13 +0300 |
This helps to avoid extra io, allocations and memory copying.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
block/stream.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/block/stream.c b/block/stream.c
index 1a906fd860..8478aa4a50 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -22,11 +22,11 @@
enum {
/*
- * Size of data buffer for populating the image file. This should be large
+ * Maximum chunk size to feed it to copy-on-read. This should be large
* enough to process multiple clusters in a single call, so that populating
* contiguous regions of the image is efficient.
*/
- STREAM_BUFFER_SIZE = 512 * 1024, /* in bytes */
+ STREAM_CHUNK = 512 * 1024, /* in bytes */
};
typedef struct StreamBlockJob {
@@ -39,13 +39,11 @@ typedef struct StreamBlockJob {
} StreamBlockJob;
static int coroutine_fn stream_populate(BlockBackend *blk,
- int64_t offset, uint64_t bytes,
- void *buf)
+ int64_t offset, uint64_t bytes)
{
assert(bytes < SIZE_MAX);
- /* Copy-on-read the unallocated clusters */
- return blk_co_pread(blk, offset, bytes, buf, BDRV_REQ_COPY_ON_READ);
+ return blk_co_pcache(blk, offset, bytes);
}
static void stream_abort(Job *job)
@@ -117,7 +115,6 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
int error = 0;
int ret = 0;
int64_t n = 0; /* bytes */
- void *buf;
if (!bs->backing) {
goto out;
@@ -130,8 +127,6 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
}
job_progress_set_remaining(&s->common.job, len);
- buf = qemu_blockalign(bs, STREAM_BUFFER_SIZE);
-
/* Turn on copy-on-read for the whole block device so that guest read
* requests help us make progress. Only do this when copying the entire
* backing chain since the copy-on-read operation does not take base into
@@ -154,7 +149,7 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
copy = false;
- ret = bdrv_is_allocated(bs, offset, STREAM_BUFFER_SIZE, &n);
+ ret = bdrv_is_allocated(bs, offset, STREAM_CHUNK, &n);
if (ret == 1) {
/* Allocated in the top, no need to copy. */
} else if (ret >= 0) {
@@ -172,7 +167,7 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
}
trace_stream_one_iteration(s, offset, n, ret);
if (copy) {
- ret = stream_populate(blk, offset, n, buf);
+ ret = stream_populate(blk, offset, n);
}
if (ret < 0) {
BlockErrorAction action =
@@ -206,8 +201,6 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
/* Do not remove the backing file if an error was there but ignored. */
ret = error;
- qemu_vfree(buf);
-
out:
/* Modify backing chain and close BDSes in main loop */
return ret;
--
2.18.0
- [Qemu-block] [PATCH 0/3] block: blk_co_pcache, Vladimir Sementsov-Ogievskiy, 2019/06/06
- [Qemu-block] [PATCH 1/3] block: implement blk_co_pcache, Vladimir Sementsov-Ogievskiy, 2019/06/06
- [Qemu-block] [PATCH 2/3] block/stream: use blk_co_pcache,
Vladimir Sementsov-Ogievskiy <=
- [Qemu-block] [PATCH 3/3] nbd: improve CMD_CACHE: use blk_co_pcache, Vladimir Sementsov-Ogievskiy, 2019/06/06
- Re: [Qemu-block] [PATCH 0/3] block: blk_co_pcache, Eric Blake, 2019/06/06
- Re: [Qemu-block] [PATCH 0/3] block: blk_co_pcache, Vladimir Sementsov-Ogievskiy, 2019/06/06
- Re: [Qemu-block] [PATCH 0/3] block: blk_co_pcache, Vladimir Sementsov-Ogievskiy, 2019/06/17
- Re: [Qemu-block] [PATCH 0/3] block: blk_co_pcache, Kevin Wolf, 2019/06/17
- Re: [Qemu-block] [PATCH 0/3] block: blk_co_pcache, Vladimir Sementsov-Ogievskiy, 2019/06/17
- Re: [Qemu-block] [PATCH 0/3] block: blk_co_pcache, Eric Blake, 2019/06/17
- Re: [Qemu-block] [PATCH 0/3] block: blk_co_pcache, Kevin Wolf, 2019/06/17
- Re: [Qemu-block] [PATCH 0/3] block: blk_co_pcache, Vladimir Sementsov-Ogievskiy, 2019/06/18
- Re: [Qemu-block] [PATCH 0/3] block: blk_co_pcache, Kevin Wolf, 2019/06/18