block: Introduce qemu-img bench
cover block: Introduce qemu-img bench
After merging Den's qcow2 patch to avoid duplicated flushes, I thought I would be nice to reproduce the problem and I remembered 'qemu-img bench', which I had posted before as part of more than one RFC series, but which never made it to master somehow. So here is a rebased and cleaned up version of it, just by itself, so that it hopefully can be merged finally.
Of course, I failed to actually reproduce the problem on my laptop. Who knows, something on my system might be more intelligent about useless flushes, or maybe I just misunderstood what the problematic scenario looks like at the block level. Doesn't make the tool less useful, though, and I already did the rebasing.
Kevin Wolf (5):
qemu-img bench
qemu-img bench: Sequential writes
qemu-img bench: Make start offset configurable
qemu-img bench: Implement -S (step size)
qemu-img bench: Add --flush-interval
qemu-img-cmds.hx | 6 ++ qemu-img.c | 289 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-img.texi | 19 ++++ 3 files changed, 314 insertions(+)
Signature · 1 line
1.8.3.1
PATCH 1/5 qemu-img bench
This adds a qemu-img command that allows doing some simple benchmarks for the block layer without involving guest devices and a real VM.
For the start, this implements only a test of sequential reads.
--- qemu-img-cmds.hx | 6 ++ qemu-img.c | 190 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-img.texi | 10 +++ 3 files changed, 206 insertions(+)
qemu-img-cmds.hx +6 -0
@@ -9,6 +9,12 @@ STEXI @table @option ETEXI +DEF("bench", img_bench, + "bench [-c count] [-d depth] [-f fmt] [-n] [-q] [-s buffer_size] [-t cache] filename") +STEXI +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] @var{filename} +ETEXI + DEF("check", img_check, "check [-q] [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] filename") STEXI
qemu-img.c +190 -0
196 lines not on this page · raw message
qemu-img.texi +10 -0
@@ -131,6 +131,16 @@ Skip the creation of the target volume Command description: @table @option +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] @var{filename} + +Run a simple sequential read benchmark on the specified image. A total number +of @var{count} I/O requests is performed, each @var{buffer_size} bytes in size, +and with @var{depth} requests in parallel. + +If @code{-n} is specified, the native AIO backend is used if possible. On +Linux, this option only works if @code{-t none} or @code{-t directsync} is +specified as well. + @item check [-f @var{fmt}] [--output=@var{ofmt}] [-r [leaks | all]] [-T @var{src_cache}] @var{filename} Perform a consistency check on the disk image @var{filename}. The command can
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 1/5] qemu-img bench
Quoted 241 lines · Kevin Wolf
This adds a qemu-img command that allows doing some simple benchmarks for the block layer without involving guest devices and a real VM.
For the start, this implements only a test of sequential reads.
Signed-off-by Kevin Wolf <[email protected]>--- qemu-img-cmds.hx | 6 ++ qemu-img.c | 190 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-img.texi | 10 +++ 3 files changed, 206 insertions(+)qemu-img-cmds.hx +6
-0@@ -9,6 +9,12 @@ STEXI @table @option ETEXI +DEF("bench", img_bench, + "bench [-c count] [-d depth] [-f fmt] [-n] [-q] [-s buffer_size] [-t cache] filename") +STEXI +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] @var{filename} +ETEXI + DEF("check", img_check, "check [-q] [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] filename") STEXIqemu-img.c +190
-0@@ -3459,6 +3459,196 @@ out_no_progress:return 0 ; } +typedef struct BenchData { +BlockBackend *blk; +uint64_t image_size; +int bufsize; +int nrreq; +int n; +uint8_t *buf; +QEMUIOVector *qiov; + +int in_flight; +uint64_t offset; +}BenchData ; + +static void bench_cb (void *opaque,int ret) +{ +BenchData *b = opaque; +BlockAIOCB *acb; + +if (ret <0 ) { +error_report ("Failed request: %s\n" ,strerror (-ret)); +exit (EXIT_FAILURE ); + } +if (b->in_flight >0 ) { + b->n--; + b->in_flight--; + } + +while (b->n > b->in_flight && b->in_flight < b->nrreq) { + acb =blk_aio_preadv (b->blk, b->offset, b->qiov,0 , + bench_cb, b); +if (!acb) { +error_report ("Failed to issue request" ); +exit (EXIT_FAILURE ); + } + b->in_flight++; + b->offset += b->bufsize; + b->offset %= b->image_size; + } +} + +static int img_bench (int argc,char **argv) +{ +int c, ret =0 ; +const char *fmt =NULL , *filename; +bool quiet = false; +bool image_opts = false; +int count =75000 ; +int depth =64 ; +size_t bufsize =4096 ; +int64_t image_size; +BlockBackend *blk =NULL ; +BenchData data = {}; +int flags =0 ; +bool writethrough; +struct timeval t1, t2; +int i; + +for (;;) { +static const struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"image-opts" , no_argument,0 ,OPTION_IMAGE_OPTS }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hc:d:f:nqs:t:" , long_options,NULL ); +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'h' : +case '?' : +help (); +break ; +case 'c' : + { +char *end; + errno =0 ; + count =strtoul (optarg, &end,0 ); +if (errno || *end || count >INT_MAX ) { +error_report ("Invalid request count specified" ); +return 1 ; + } +break ; + } +case 'd' : + { +char *end; + errno =0 ; + depth =strtoul (optarg, &end,0 ); +if (errno || *end || depth >INT_MAX ) { +error_report ("Invalid queue depth specified" ); +return 1 ; + } +break ; + } +case 'f' : + fmt = optarg; +break ; +case 'n' : + flags |=BDRV_O_NATIVE_AIO ; +break ; +case 'q' : + quiet = true; +break ; +case 's' : + { +int64_t sval; +char *end; + + sval =qemu_strtosz_suffix (optarg, &end,QEMU_STRTOSZ_DEFSUFFIX_B ); +if (sval <0 || sval >INT_MAX || *end) { +error_report ("Invalid buffer size specified" ); +return 1 ; + } + + bufsize = sval; +break ; + } +case 't' : + ret =bdrv_parse_cache_mode (optarg, &flags, &writethrough); +if (ret <0 ) { +error_report ("Invalid cache mode" ); + ret =-1 ; + goto out; + } +break ; +case OPTION_IMAGE_OPTS : + image_opts = true; +break ; + } + } + +if (optind != argc -1 ) { +error_exit ("Expecting one image file name" ); + } + filename = argv[argc -1 ]; + + blk =img_open (image_opts, filename, fmt, flags, writethrough, quiet); +if (!blk) { + ret =-1 ; + goto out; + } + + image_size =blk_getlength (blk); +if (image_size <0 ) { + ret = image_size; + goto out; + } + + data = (BenchData ) { + .blk = blk, + .image_size = image_size, + .bufsize = bufsize, + .nrreq = depth, + .n = count, + }; +printf ("Sending %d requests, %d bytes each, %d in parallel\n" , + data.n, data.bufsize, data.nrreq); + + data.buf =blk_blockalign (blk, data.nrreq * data.bufsize); + data.qiov =g_new (QEMUIOVector, data.nrreq); +for (i =0 ; i < data.nrreq; i++) { +qemu_iovec_init (&data.qiov[i],1 ); +qemu_iovec_add (&data.qiov[i], + data.buf + i * data.bufsize, data.bufsize); + } + +gettimeofday (&t1,NULL ); +bench_cb (&data,0 ); + +while (data.n >0 ) { +main_loop_wait (false); + } +gettimeofday (&t2,NULL ); + +printf ("Run completed in %3.3f seconds.\n" , + (t2.tv_sec - t1.tv_sec) + + ((double )(t2.tv_usec - t1.tv_usec) /1000000 )); + +out: +qemu_vfree (data.buf); +blk_unref (blk); + +if (ret) { +return 1 ; + } +return 0 ; +} + +static const img_cmd_t img_cmds[] = { #define DEF(option, callback, arg_string) \ { option, callback },qemu-img.texi +3
-0@@ -131,6 +131,16 @@ Skip the creation of the target volume Command description: @table @option +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] @var{filename} + +Run a simple sequential read benchmark on the specified image. A total number
qemu-img.texi Skip the creation of the target volume · line 146
Quoted 10 lines
qemu-img.texi +7
-0+of @var{count} I/O requests is performed, each @var{buffer_size} bytes in size, +and with @var{depth} requests in parallel. + +If @code{-n} is specified, the native AIO backend is used if possible. On +Linux, this option only works if @code{-t none} or @code{-t directsync} is +specified as well. + @item check [-f @var{fmt}] [--output=@var{ofmt}] [-r [leaks | all]] [-T @var{src_cache}] @var{filename} Perform a consistency check on the disk image @var{filename}. The command can
PATCH 2/5 qemu-img bench: Sequential writes
In reply to Kevin WolfThis extends qemu-img bench with an option that makes it use sequential writes instead of reads for the test run.
--- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 24 +++++++++++++++++++----- qemu-img.texi | 10 ++++++---- 3 files changed, 27 insertions(+), 11 deletions(-)
qemu-img-cmds.hx +2 -2
@@ -10,9 +10,9 @@ STEXI ETEXI DEF("bench", img_bench, - "bench [-c count] [-d depth] [-f fmt] [-n] [-q] [-s buffer_size] [-t cache] filename") + "bench [-c count] [-d depth] [-f fmt] [-n] [-q] [-s buffer_size] [-t cache] [-w] filename") STEXI -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} ETEXI DEF("check", img_check,
qemu-img.c +19 -5
@@ -3462,6 +3462,7 @@ out_no_progress: typedef struct BenchData { BlockBackend *blk; uint64_t image_size; + bool write; int bufsize; int nrreq; int n;
@@ -3487,8 +3488,13 @@ static void bench_cb(void *opaque, int ret) }while (b->n > b->in_flight && b->in_flight < b->nrreq) { - acb =blk_aio_preadv (b->blk, b->offset, b->qiov,0 , - bench_cb, b); +if (b->write) { + acb =blk_aio_pwritev (b->blk, b->offset, b->qiov,0 , + bench_cb, b); + }else { + acb =blk_aio_preadv (b->blk, b->offset, b->qiov,0 , + bench_cb, b); + }if (!acb) {error_report ("Failed to issue request" );exit (EXIT_FAILURE );
@@ -3505,6 +3511,7 @@ static int img_bench(int argc, char **argv)const char *fmt =NULL , *filename;bool quiet = false;bool image_opts = false; +bool is_write = false;int count =75000 ;int depth =64 ;size_t bufsize =4096 ;
@@ -3522,7 +3529,7 @@ static int img_bench(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =getopt_long (argc, argv,"hc:d:f:nqs:t:" , long_options,NULL ); + c =getopt_long (argc, argv,"hc:d:f:nqs:t:w" , long_options,NULL );if (c ==-1 ) {break ; }
@@ -3585,6 +3592,10 @@ static int img_bench(int argc, char **argv) goto out; }break ; +case 'w' : + flags |=BDRV_O_RDWR ; + is_write = true; +break ;case OPTION_IMAGE_OPTS : image_opts = true;break ;
@@ -3614,11 +3625,14 @@ static int img_bench(int argc, char **argv) .bufsize = bufsize, .nrreq = depth, .n = count, + .write = is_write, }; -printf ("Sending %d requests, %d bytes each, %d in parallel\n" , - data.n, data.bufsize, data.nrreq); +printf ("Sending %d %s requests, %d bytes each, %d in parallel\n" , + data.n, data.write ?"write" :"read" , data.bufsize, data.nrreq); data.buf =blk_blockalign (blk, data.nrreq * data.bufsize); +memset (data.buf,0 , data.nrreq * data.bufsize); + data.qiov =g_new (QEMUIOVector, data.nrreq);for (i =0 ; i < data.nrreq; i++) {qemu_iovec_init (&data.qiov[i],1 );
qemu-img.texi +6 -4
@@ -131,11 +131,13 @@ Skip the creation of the target volume Command description: @table @option -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} -Run a simple sequential read benchmark on the specified image. A total number -of @var{count} I/O requests is performed, each @var{buffer_size} bytes in size, -and with @var{depth} requests in parallel. +Run a simple sequential I/O benchmark on the specified image. If @code{-w} is +specified, a write test is performed, otherwise a read test is performed. + +A total number of @var{count} I/O requests is performed, each @var{buffer_size} +bytes in size, and with @var{depth} requests in parallel. If @code{-n} is specified, the native AIO backend is used if possible. On Linux, this option only works if @code{-t none} or @code{-t directsync} is
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 2/5] qemu-img bench: Sequential writes
Quoted 86 lines · Kevin Wolf
This extends qemu-img bench with an option that makes it use sequential writes instead of reads for the test run.
Signed-off-by Kevin Wolf <[email protected]>--- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 24 +++++++++++++++++++----- qemu-img.texi | 10 ++++++---- 3 files changed, 27 insertions(+), 11 deletions(-)qemu-img-cmds.hx +2
-2@@ -10,9 +10,9 @@ STEXI ETEXI DEF("bench", img_bench, - "bench [-c count] [-d depth] [-f fmt] [-n] [-q] [-s buffer_size] [-t cache] filename") + "bench [-c count] [-d depth] [-f fmt] [-n] [-q] [-s buffer_size] [-t cache] [-w] filename") STEXI -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} ETEXI DEF("check", img_check,qemu-img.c +14
-3@@ -3462,6 +3462,7 @@ out_no_progress: typedef struct BenchData { BlockBackend *blk; uint64_t image_size; + bool write; int bufsize; int nrreq; int n;@@ -3487,8 +3488,13 @@ static void bench_cb(void *opaque, int ret) }while (b->n > b->in_flight && b->in_flight < b->nrreq) { - acb =blk_aio_preadv (b->blk, b->offset, b->qiov,0 , - bench_cb, b); +if (b->write) { + acb =blk_aio_pwritev (b->blk, b->offset, b->qiov,0 , + bench_cb, b); + }else { + acb =blk_aio_preadv (b->blk, b->offset, b->qiov,0 , + bench_cb, b); + }if (!acb) {error_report ("Failed to issue request" );exit (EXIT_FAILURE );@@ -3505,6 +3511,7 @@ static int img_bench(int argc, char **argv)const char *fmt =NULL , *filename;bool quiet = false;bool image_opts = false; +bool is_write = false;int count =75000 ;int depth =64 ;size_t bufsize =4096 ;@@ -3522,7 +3529,7 @@ static int img_bench(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =getopt_long (argc, argv,"hc:d:f:nqs:t:" , long_options,NULL ); + c =getopt_long (argc, argv,"hc:d:f:nqs:t:w" , long_options,NULL );if (c ==-1 ) {break ; }@@ -3585,6 +3592,10 @@ static int img_bench(int argc, char **argv) goto out; }break ; +case 'w' : + flags |=BDRV_O_RDWR ; + is_write = true; +break ;case OPTION_IMAGE_OPTS : image_opts = true;break ;@@ -3614,11 +3625,14 @@ static int img_bench(int argc, char **argv) .bufsize = bufsize, .nrreq = depth, .n = count,
qemu-img.c static int img_bench(int argc, char **argv) · line 3635
Quoted 10 lines
qemu-img.c +5
-2+ .write = is_write, }; -printf ("Sending %d requests, %d bytes each, %d in parallel\n" , - data.n, data.bufsize, data.nrreq); +printf ("Sending %d %s requests, %d bytes each, %d in parallel\n" , + data.n, data.write ?"write" :"read" , data.bufsize, data.nrreq); data.buf =blk_blockalign (blk, data.nrreq * data.bufsize); +memset (data.buf,0 , data.nrreq * data.bufsize); +
using 0 could be controversal. Can you add -P option like one in qemu-io to fill the pattern?
PATCH 3/5 qemu-img bench: Make start offset configurable
In reply to Kevin WolfThis patch adds an option the specify the offset of the first request made by qemu-img bench. This allows to benchmark misaligned requests.
--- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 23 ++++++++++++++++++++--- qemu-img.texi | 5 +++-- 3 files changed, 25 insertions(+), 7 deletions(-)
qemu-img-cmds.hx +2 -2
@@ -10,9 +10,9 @@ STEXI ETEXI DEF("bench", img_bench, - "bench [-c count] [-d depth] [-f fmt] [-n] [-q] [-s buffer_size] [-t cache] [-w] filename") + "bench [-c count] [-d depth] [-f fmt] [-n] [-o offset] [-q] [-s buffer_size] [-t cache] [-w] filename") STEXI -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} ETEXI DEF("check", img_check,
qemu-img.c +20 -3
@@ -3514,6 +3514,7 @@ static int img_bench(int argc, char **argv)bool is_write = false;int count =75000 ;int depth =64 ; +int64_t offset =0 ;size_t bufsize =4096 ;int64_t image_size;BlockBackend *blk =NULL ;
@@ -3529,7 +3530,7 @@ static int img_bench(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =getopt_long (argc, argv,"hc:d:f:nqs:t:w" , long_options,NULL ); + c =getopt_long (argc, argv,"hc:d:f:no:qs:t:w" , long_options,NULL );if (c ==-1 ) {break ; }
@@ -3567,6 +3568,19 @@ static int img_bench(int argc, char **argv)case 'n' : flags |=BDRV_O_NATIVE_AIO ;break ; +case 'o' : + { +char *end; + errno =0 ; + offset =qemu_strtosz_suffix (optarg, &end, +QEMU_STRTOSZ_DEFSUFFIX_B ); +if (offset <0 || *end) { +error_report ("Invalid offset specified" ); +return 1 ; + } +break ; + } +break ;case 'q' : quiet = true;break ;
@@ -3625,10 +3639,13 @@ static int img_bench(int argc, char **argv) .bufsize = bufsize, .nrreq = depth, .n = count, + .offset = offset, .write = is_write, }; -printf ("Sending %d %s requests, %d bytes each, %d in parallel\n" , - data.n, data.write ?"write" :"read" , data.bufsize, data.nrreq); +printf ("Sending %d %s requests, %d bytes each, %d in parallel " +"(starting at offset %" PRId64")\n" , + data.n, data.write ?"write" :"read" , data.bufsize, data.nrreq, + data.offset); data.buf =blk_blockalign (blk, data.nrreq * data.bufsize);memset (data.buf,0 , data.nrreq * data.bufsize);
qemu-img.texi +3 -2
@@ -131,13 +131,14 @@ Skip the creation of the target volume Command description: @table @option -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} Run a simple sequential I/O benchmark on the specified image. If @code{-w} is specified, a write test is performed, otherwise a read test is performed. A total number of @var{count} I/O requests is performed, each @var{buffer_size} -bytes in size, and with @var{depth} requests in parallel. +bytes in size, and with @var{depth} requests in parallel. The first request +starts at the position given by @var{offset}. If @code{-n} is specified, the native AIO backend is used if possible. On Linux, this option only works if @code{-t none} or @code{-t directsync} is
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 3/5] qemu-img bench: Make start offset configurable
Quoted 94 lines · Kevin Wolf
This patch adds an option the specify the offset of the first request made by qemu-img bench. This allows to benchmark misaligned requests.
Signed-off-by Kevin Wolf <[email protected]>--- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 23 ++++++++++++++++++++--- qemu-img.texi | 5 +++-- 3 files changed, 25 insertions(+), 7 deletions(-)qemu-img-cmds.hx +2
-2@@ -10,9 +10,9 @@ STEXI ETEXI DEF("bench", img_bench, - "bench [-c count] [-d depth] [-f fmt] [-n] [-q] [-s buffer_size] [-t cache] [-w] filename") + "bench [-c count] [-d depth] [-f fmt] [-n] [-o offset] [-q] [-s buffer_size] [-t cache] [-w] filename") STEXI -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} ETEXI DEF("check", img_check,qemu-img.c +20
-3@@ -3514,6 +3514,7 @@ static int img_bench(int argc, char **argv)bool is_write = false;int count =75000 ;int depth =64 ; +int64_t offset =0 ;size_t bufsize =4096 ;int64_t image_size;BlockBackend *blk =NULL ;@@ -3529,7 +3530,7 @@ static int img_bench(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =getopt_long (argc, argv,"hc:d:f:nqs:t:w" , long_options,NULL ); + c =getopt_long (argc, argv,"hc:d:f:no:qs:t:w" , long_options,NULL );if (c ==-1 ) {break ; }@@ -3567,6 +3568,19 @@ static int img_bench(int argc, char **argv)case 'n' : flags |=BDRV_O_NATIVE_AIO ;break ; +case 'o' : + { +char *end; + errno =0 ; + offset =qemu_strtosz_suffix (optarg, &end, +QEMU_STRTOSZ_DEFSUFFIX_B ); +if (offset <0 || *end) { +error_report ("Invalid offset specified" ); +return 1 ; + } +break ; + } +break ;case 'q' : quiet = true;break ;@@ -3625,10 +3639,13 @@ static int img_bench(int argc, char **argv) .bufsize = bufsize, .nrreq = depth, .n = count, + .offset = offset, .write = is_write, }; -printf ("Sending %d %s requests, %d bytes each, %d in parallel\n" , - data.n, data.write ?"write" :"read" , data.bufsize, data.nrreq); +printf ("Sending %d %s requests, %d bytes each, %d in parallel " +"(starting at offset %" PRId64")\n" , + data.n, data.write ?"write" :"read" , data.bufsize, data.nrreq, + data.offset); data.buf =blk_blockalign (blk, data.nrreq * data.bufsize);memset (data.buf,0 , data.nrreq * data.bufsize);qemu-img.texi +1
-1@@ -131,13 +131,14 @@ Skip the creation of the target volume Command description: @table @option -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename}
qemu-img.texi Skip the creation of the target volume · line 144
Quoted 10 lines
qemu-img.texi +2
-1Run a simple sequential I/O benchmark on the specified image. If @code{-w} is specified, a write test is performed, otherwise a read test is performed. A total number of @var{count} I/O requests is performed, each @var{buffer_size} -bytes in size, and with @var{depth} requests in parallel. +bytes in size, and with @var{depth} requests in parallel. The first request +starts at the position given by @var{offset}. If @code{-n} is specified, the native AIO backend is used if possible. On Linux, this option only works if @code{-t none} or @code{-t directsync} is
PATCH 4/5 qemu-img bench: Implement -S (step size)
In reply to Kevin WolfWith this new option, qemu-img bench can be told to advance the current offset after each request by a different value than the buffer size. This is useful for controlling the conditions for cluster allocation in image formats (e.g. qcow2 cluster allocation with COW in front of the request, or COW areas that aren't overwritten immediately).
--- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 25 +++++++++++++++++++++---- qemu-img.texi | 6 ++++-- 3 files changed, 27 insertions(+), 8 deletions(-)
qemu-img-cmds.hx +2 -2
@@ -10,9 +10,9 @@ STEXI ETEXI DEF("bench", img_bench, - "bench [-c count] [-d depth] [-f fmt] [-n] [-o offset] [-q] [-s buffer_size] [-t cache] [-w] filename") + "bench [-c count] [-d depth] [-f fmt] [-n] [-o offset] [-q] [-s buffer_size] [-S step_size] [-t cache] [-w] filename") STEXI -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t @var{cache}] [-w] @var{filename} ETEXI DEF("check", img_check,
qemu-img.c +21 -4
@@ -3464,6 +3464,7 @@ typedef struct BenchData {uint64_t image_size;bool write;int bufsize; +int step;int nrreq;int n;uint8_t *buf;
@@ -3500,7 +3501,7 @@ static void bench_cb(void *opaque, int ret)exit (EXIT_FAILURE ); } b->in_flight++; - b->offset += b->bufsize; + b->offset += b->step; b->offset %= b->image_size; } }
@@ -3516,6 +3517,7 @@ static int img_bench(int argc, char **argv)int depth =64 ;int64_t offset =0 ;size_t bufsize =4096 ; +size_t step =0 ;int64_t image_size;BlockBackend *blk =NULL ;BenchData data = {};
@@ -3530,7 +3532,7 @@ static int img_bench(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =getopt_long (argc, argv,"hc:d:f:no:qs:t:w" , long_options,NULL ); + c =getopt_long (argc, argv,"hc:d:f:no:qs:S:t:w" , long_options,NULL );if (c ==-1 ) {break ; }
@@ -3598,6 +3600,20 @@ static int img_bench(int argc, char **argv) bufsize = sval;break ; } +case 'S' : + { +int64_t sval; +char *end; + + sval =qemu_strtosz_suffix (optarg, &end,QEMU_STRTOSZ_DEFSUFFIX_B ); +if (sval <0 || sval >INT_MAX || *end) { +error_report ("Invalid step size specified" ); +return 1 ; + } + + step = sval; +break ; + }case 't' : ret =bdrv_parse_cache_mode (optarg, &flags, &writethrough);if (ret <0 ) {
@@ -3637,15 +3653,16 @@ static int img_bench(int argc, char **argv) .blk = blk, .image_size = image_size, .bufsize = bufsize, + .step = step ?: bufsize, .nrreq = depth, .n = count, .offset = offset, .write = is_write, };printf ("Sending %d %s requests, %d bytes each, %d in parallel " -"(starting at offset %" PRId64")\n" , +"(starting at offset %" PRId64", step size %d)\n" , data.n, data.write ?"write" :"read" , data.bufsize, data.nrreq, - data.offset); + data.offset, data.step); data.buf =blk_blockalign (blk, data.nrreq * data.bufsize);memset (data.buf,0 , data.nrreq * data.bufsize);
qemu-img.texi +4 -2
@@ -131,14 +131,16 @@ Skip the creation of the target volume Command description: @table @option -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t @var{cache}] [-w] @var{filename} Run a simple sequential I/O benchmark on the specified image. If @code{-w} is specified, a write test is performed, otherwise a read test is performed. A total number of @var{count} I/O requests is performed, each @var{buffer_size} bytes in size, and with @var{depth} requests in parallel. The first request -starts at the position given by @var{offset}. +starts at the position given by @var{offset}, each following request increases +the current position by @var{step_size}. If @var{step_size} is not given, +@var{buffer_size} is used for its value. If @code{-n} is specified, the native AIO backend is used if possible. On Linux, this option only works if @code{-t none} or @code{-t directsync} is
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 4/5] qemu-img bench: Implement -S (step size)
Quoted 120 lines · Kevin Wolf
With this new option, qemu-img bench can be told to advance the current offset after each request by a different value than the buffer size. This is useful for controlling the conditions for cluster allocation in image formats (e.g. qcow2 cluster allocation with COW in front of the request, or COW areas that aren't overwritten immediately).
Signed-off-by Kevin Wolf <[email protected]>--- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 25 +++++++++++++++++++++---- qemu-img.texi | 6 ++++-- 3 files changed, 27 insertions(+), 8 deletions(-)qemu-img-cmds.hx +2
-2@@ -10,9 +10,9 @@ STEXI ETEXI DEF("bench", img_bench, - "bench [-c count] [-d depth] [-f fmt] [-n] [-o offset] [-q] [-s buffer_size] [-t cache] [-w] filename") + "bench [-c count] [-d depth] [-f fmt] [-n] [-o offset] [-q] [-s buffer_size] [-S step_size] [-t cache] [-w] filename") STEXI -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t @var{cache}] [-w] @var{filename} ETEXI DEF("check", img_check,qemu-img.c +21
-4@@ -3464,6 +3464,7 @@ typedef struct BenchData {uint64_t image_size;bool write;int bufsize; +int step;int nrreq;int n;uint8_t *buf;@@ -3500,7 +3501,7 @@ static void bench_cb(void *opaque, int ret)exit (EXIT_FAILURE ); } b->in_flight++; - b->offset += b->bufsize; + b->offset += b->step; b->offset %= b->image_size; } }@@ -3516,6 +3517,7 @@ static int img_bench(int argc, char **argv)int depth =64 ;int64_t offset =0 ;size_t bufsize =4096 ; +size_t step =0 ;int64_t image_size;BlockBackend *blk =NULL ;BenchData data = {};@@ -3530,7 +3532,7 @@ static int img_bench(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c =getopt_long (argc, argv,"hc:d:f:no:qs:t:w" , long_options,NULL ); + c =getopt_long (argc, argv,"hc:d:f:no:qs:S:t:w" , long_options,NULL );if (c ==-1 ) {break ; }@@ -3598,6 +3600,20 @@ static int img_bench(int argc, char **argv) bufsize = sval;break ; } +case 'S' : + { +int64_t sval; +char *end; + + sval =qemu_strtosz_suffix (optarg, &end,QEMU_STRTOSZ_DEFSUFFIX_B ); +if (sval <0 || sval >INT_MAX || *end) { +error_report ("Invalid step size specified" ); +return 1 ; + } + + step = sval; +break ; + }case 't' : ret =bdrv_parse_cache_mode (optarg, &flags, &writethrough);if (ret <0 ) {@@ -3637,15 +3653,16 @@ static int img_bench(int argc, char **argv) .blk = blk, .image_size = image_size, .bufsize = bufsize, + .step = step ?: bufsize, .nrreq = depth, .n = count, .offset = offset, .write = is_write, };printf ("Sending %d %s requests, %d bytes each, %d in parallel " -"(starting at offset %" PRId64")\n" , +"(starting at offset %" PRId64", step size %d)\n" , data.n, data.write ?"write" :"read" , data.bufsize, data.nrreq, - data.offset); + data.offset, data.step); data.buf =blk_blockalign (blk, data.nrreq * data.bufsize);memset (data.buf,0 , data.nrreq * data.bufsize);qemu-img.texi +1
-1@@ -131,14 +131,16 @@ Skip the creation of the target volume Command description: @table @option -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-t @var{cache}] [-w] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t @var{cache}] [-w] @var{filename} Run a simple sequential I/O benchmark on the specified image. If @code{-w} is specified, a write test is performed, otherwise a read test is performed.
qemu-img.texi Skip the creation of the target volume · line 146
Quoted 10 lines
qemu-img.texi +3
-1A total number of @var{count} I/O requests is performed, each @var{buffer_size} bytes in size, and with @var{depth} requests in parallel. The first request -starts at the position given by @var{offset}. +starts at the position given by @var{offset}, each following request increases +the current position by @var{step_size}. If @var{step_size} is not given, +@var{buffer_size} is used for its value. If @code{-n} is specified, the native AIO backend is used if possible. On Linux, this option only works if @code{-t none} or @code{-t directsync} is
PATCH 5/5 qemu-img bench: Add --flush-interval
In reply to Kevin WolfThis options allows to flush the image periodically during write tests.
--- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++-------- qemu-img.texi | 6 ++++- 3 files changed, 67 insertions(+), 12 deletions(-)
qemu-img-cmds.hx +2 -2
@@ -10,9 +10,9 @@ STEXI ETEXI DEF("bench", img_bench, - "bench [-c count] [-d depth] [-f fmt] [-n] [-o offset] [-q] [-s buffer_size] [-S step_size] [-t cache] [-w] filename") + "bench [-c count] [-d depth] [-f fmt] [--flush-interval=flush_interval] [-n] [-o offset] [-q] [-s buffer_size] [-S step_size] [-t cache] [-w] filename") STEXI -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t @var{cache}] [-w] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [--flush-interval=@var{flush_interval}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t @var{cache}] [-w] @var{filename} ETEXI DEF("check", img_check,
qemu-img.c +60 -9
128 lines not on this page · raw message
qemu-img.texi +5 -1
@@ -131,7 +131,7 @@ Skip the creation of the target volume Command description: @table @option -@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t @var{cache}] [-w] @var{filename} +@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] [--flush-interval=@var{flush_interval}] [-n] [-o @var{offset}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t @var{cache}] [-w] @var{filename} Run a simple sequential I/O benchmark on the specified image. If @code{-w} is specified, a write test is performed, otherwise a read test is performed.
@@ -142,6 +142,10 @@ starts at the position given by @var{offset}, each following request increases the current position by @var{step_size}. If @var{step_size} is not given, @var{buffer_size} is used for its value. +If @var{flush_interval} is specified for a write test, the queue is drained and +a flush is issued before new writes are made whenever the number of remaining +requests is a multiple of @var{flush_interval}. + If @code{-n} is specified, the native AIO backend is used if possible. On Linux, this option only works if @code{-t none} or @code{-t directsync} is specified as well.
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 5/5] qemu-img bench: Add --flush-interval
Quoted 3 lines · Kevin Wolf
This options allows to flush the image periodically during write tests.
Signed-off-by Kevin Wolf <[email protected]>
This pattern could be a bit different - you wait requests to finish and after that start flush. In this case there is no gain with my patch ;)
You should treat flush as ordinary write request i.e. place request immediately without waiting for writes to finish. May be this could be specified as an operation mode.
Den
Re: [Qemu-devel] [PATCH 5/5] qemu-img bench: Add --flush-interval
Am 03.06.2016 um 17:01 hat Denis V. Lunev geschrieben:
Quoted 11 lines · Kevin Wolf
Quoted 3 lines
This options allows to flush the image periodically during write tests.
Signed-off-by Kevin Wolf <[email protected]>This pattern could be a bit different - you wait requests to finish and after that start flush. In this case there is no gain with my patch ;)
You should treat flush as ordinary write request i.e. place request immediately without waiting for writes to finish. May be this could be specified as an operation mode.
Hm, okay, I can try that.
What OS is running on your guest? Because I seem to remember that Linux drains the queue before sending a flush command. This is why I implemented it this way here. Maybe it changed in Linux, though.
Kevin
Re: [Qemu-devel] [Qemu-block] [PATCH 5/5] qemu-img bench: Add --flush-interval
Am 03.06.2016 um 17:16 hat Kevin Wolf geschrieben:
Quoted 9 lines
Am 03.06.2016 um 17:01 hat Denis V. Lunev geschrieben:
Quoted 8 lines · Kevin Wolf
Quoted 3 lines
This options allows to flush the image periodically during write tests.
Signed-off-by Kevin Wolf <[email protected]>This pattern could be a bit different - you wait requests to finish and after that start flush. In this case there is no gain with my patch ;)
Quoted 5 lines
Quoted 3 lines
You should treat flush as ordinary write request i.e. place request immediately without waiting for writes to finish. May be this could be specified as an operation mode.
Hm, okay, I can try that.
Doesn't make a difference for me. But I'll include the option in v2 anyway.
Kevin