block: Vectored bdrv_writev_vmstate
cover block: Vectored bdrv_writev_vmstate
This gives us back reasonable savevm performance, which regressed in commit 500f0061.
Kevin Wolf (4):
block: Introduce bdrv_writev_vmstate
savevm: Implement block_writev_buffer()
block: Introduce bdrv_pwritev() for qcow2_save_vmstate
qemu-iotests: A few more bdrv_pread/pwrite tests
block.c | 105 +++++++++++++++++++++++++++++++----------- block/qcow2.c | 6 +-- block/sheepdog.c | 13 ++++-- include/block/block.h | 3 ++ include/block/block_int.h | 4 +- include/migration/qemu-file.h | 2 +- savevm.c | 25 ++++++++-- tests/qemu-iotests/002 | 13 ++++++ tests/qemu-iotests/002.out | 26 +++++++++++ 9 files changed, 157 insertions(+), 40 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 1/4 block: Introduce bdrv_writev_vmstate
--- block.c | 25 ++++++++++++++++++++----- block/qcow2.c | 12 +++++++++--- block/sheepdog.c | 13 ++++++++++--- include/block/block.h | 1 + include/block/block_int.h | 4 ++-- 5 files changed, 42 insertions(+), 13 deletions(-)
block.c +20 -5
@@ -3187,13 +3187,28 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)int bdrv_save_vmstate (BlockDriverState *bs,const uint8_t *buf,int64_t pos,int size) { +QEMUIOVector qiov; +struct iovec iov = { + .iov_base = (void *) buf, + .iov_len = size, + }; + +qemu_iovec_init_external (&qiov, &iov,1 ); +return bdrv_writev_vmstate (bs, &qiov, pos); +} + +int bdrv_writev_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos) +{BlockDriver *drv = bs->drv; -if (!drv) + +if (!drv) {return -ENOMEDIUM ; -if (drv->bdrv_save_vmstate) -return drv->bdrv_save_vmstate (bs, buf, pos, size); -if (bs->file) -return bdrv_save_vmstate (bs->file, buf, pos, size); + }else if (drv->bdrv_save_vmstate) { +return drv->bdrv_save_vmstate (bs, qiov, pos); + }else if (bs->file) { +return bdrv_writev_vmstate (bs->file, qiov, pos); + } +return -ENOTSUP ; }
block/qcow2.c +9 -3
@@ -1652,18 +1652,24 @@ static void dump_refcounts(BlockDriverState *bs) }#endif -static int qcow2_save_vmstate (BlockDriverState *bs,const uint8_t *buf, -int64_t pos,int size) +static int qcow2_save_vmstate (BlockDriverState *bs,QEMUIOVector *qiov, +int64_t pos) {BDRVQcowState *s = bs->opaque;int growable = bs->growable;int ret; +void *buf; + + buf =qemu_blockalign (bs, qiov->size); +qemu_iovec_to_buf (qiov,0 , buf, qiov->size);BLKDBG_EVENT (bs->file,BLKDBG_VMSTATE_SAVE ); bs->growable =1 ; - ret =bdrv_pwrite (bs,qcow2_vm_state_offset (s) + pos, buf, size); + ret =bdrv_pwrite (bs,qcow2_vm_state_offset (s) + pos, buf, qiov->size); bs->growable = growable; +qemu_vfree (buf); +return ret; }
block/sheepdog.c +10 -3
@@ -2054,12 +2054,19 @@ cleanup:return ret; } -static int sd_save_vmstate (BlockDriverState *bs,const uint8_t *data, -int64_t pos,int size) +static int sd_save_vmstate (BlockDriverState *bs,QEMUIOVector *qiov, +int64_t pos) {BDRVSheepdogState *s = bs->opaque; +void *buf; +int ret; -return do_load_save_vmstate (s, (uint8_t *)data, pos, size,0 ); + buf =qemu_blockalign (bs, qiov->size); +qemu_iovec_to_buf (qiov,0 , buf, qiov->size); + ret =do_load_save_vmstate (s, (uint8_t *) buf, pos, qiov->size,0 ); +qemu_vfree (buf); + +return ret; } static int sd_load_vmstate(BlockDriverState *bs, uint8_t *data,
include/block/block.h +1 -0
@@ -348,6 +348,7 @@ void path_combine(char *dest, int dest_size,const char *base_path, const char *filename); +int bdrv_writev_vmstate (BlockDriverState *bs,QEMUIOVector *qiov,int64_t pos);int bdrv_save_vmstate (BlockDriverState *bs,const uint8_t *buf,int64_t pos,int size);
include/block/block_int.h +2 -2
@@ -164,8 +164,8 @@ struct BlockDriver { const char *snapshot_name);int (*bdrv_get_info)(BlockDriverState *bs,BlockDriverInfo *bdi); -int (*bdrv_save_vmstate)(BlockDriverState *bs,const uint8_t *buf, -int64_t pos,int size); +int (*bdrv_save_vmstate)(BlockDriverState *bs,QEMUIOVector *qiov, +int64_t pos);int (*bdrv_load_vmstate)(BlockDriverState *bs,uint8_t *buf,int64_t pos,int size);
Signature · 1 line
1.8.1.4
PATCH 2/4 savevm: Implement block_writev_buffer()
In reply to Kevin WolfInstead of breaking up RAM state into many small chunks, pass the iovec to the block layer for better performance.
--- include/migration/qemu-file.h | 2 +- savevm.c | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-)
include/migration/qemu-file.h +1 -1
@@ -55,7 +55,7 @@ typedef int (QEMUFileGetFD)(void *opaque);* This function writes an iovec to file. */ typedef ssize_t (QEMUFileWritevBufferFunc )(void *opaque,struct iovec *iov, -int iovcnt); +int iovcnt,int64_t pos); typedef struct QEMUFileOps { QEMUFilePutBufferFunc *put_buffer;
savevm.c +21 -4
@@ -176,7 +176,8 @@ static void coroutine_fn yield_until_fd_readable(int fd)qemu_coroutine_yield (); } -static ssize_t socket_writev_buffer (void *opaque,struct iovec *iov,int iovcnt) +static ssize_t socket_writev_buffer (void *opaque,struct iovec *iov,int iovcnt, +int64_t pos) {QEMUFileSocket *s = opaque;ssize_t len;
@@ -458,6 +459,21 @@ fail:return NULL ; } +static ssize_t block_writev_buffer (void *opaque,struct iovec *iov,int iovcnt, +int64_t pos) +{ +int ret; +QEMUIOVector qiov; + +qemu_iovec_init_external (&qiov, iov, iovcnt); + ret =bdrv_writev_vmstate (opaque, &qiov, pos); +if (ret <0 ) { +return ret; + } + +return qiov.size; +} +static int block_put_buffer (void *opaque,const uint8_t *buf,int64_t pos,int size) {
@@ -481,8 +497,9 @@ static const QEMUFileOps bdrv_read_ops = { };static const QEMUFileOps bdrv_write_ops = { - .put_buffer = block_put_buffer, - .close = bdrv_fclose + .put_buffer = block_put_buffer, + .writev_buffer = block_writev_buffer, + .close = bdrv_fclose };static QEMUFile *qemu_fopen_bdrv (BlockDriverState *bs,int is_writable)
@@ -533,7 +550,7 @@ static void qemu_fflush(QEMUFile *f)if (f->is_write && f->iovcnt >0 ) {if (f->ops->writev_buffer) { - ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt); + ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->pos);if (ret >=0 ) { f->pos += ret; }
Signature · 1 line
1.8.1.4
PATCH 3/4 block: Introduce bdrv_pwritev() for qcow2_save_vmstate
In reply to Kevin WolfDirectly pass the QEMUIOVector on instead of linearising it.
--- block.c | 80 +++++++++++++++++++++++++++++++++++++-------------- block/qcow2.c | 8 +----- include/block/block.h | 2 ++ 3 files changed, 61 insertions(+), 29 deletions(-)
block.c +58 -22
@@ -2134,27 +2134,21 @@ static void coroutine_fn bdrv_rw_co_entry(void *opaque) }/* -* Process a synchronous request using coroutines +* Process a vectored synchronous request using coroutines */ -static int bdrv_rw_co (BlockDriverState *bs,int64_t sector_num,uint8_t *buf, -int nb_sectors,bool is_write) +static int bdrv_rwv_co (BlockDriverState *bs,int64_t sector_num, +QEMUIOVector *qiov,bool is_write) { -QEMUIOVector qiov; -struct iovec iov = { - .iov_base = (void *)buf, - .iov_len = nb_sectors *BDRV_SECTOR_SIZE , - };Coroutine *co;RwCo rwco = { .bs = bs, .sector_num = sector_num, - .nb_sectors = nb_sectors, - .qiov = &qiov, + .nb_sectors = qiov->size >>BDRV_SECTOR_BITS , + .qiov = qiov, .is_write = is_write, .ret =NOT_DONE , }; - -qemu_iovec_init_external (&qiov, &iov,1 ); +assert ((qiov->size & (BDRV_SECTOR_SIZE -1 )) ==0 );/** * In sync call context, when the vcpu is blocked, this throttling timer
@@ -2180,6 +2174,22 @@ static int bdrv_rw_co(BlockDriverState *bs, int64_t sector_num, uint8_t *buf,return rwco.ret; } +/* +* Process a synchronous request using coroutines +*/ +static int bdrv_rw_co (BlockDriverState *bs,int64_t sector_num,uint8_t *buf, +int nb_sectors,bool is_write) +{ +QEMUIOVector qiov; +struct iovec iov = { + .iov_base = (void *)buf, + .iov_len = nb_sectors *BDRV_SECTOR_SIZE , + }; + +qemu_iovec_init_external (&qiov, &iov,1 ); +return bdrv_rwv_co (bs, sector_num, &qiov, is_write); +} +/* return < 0 if error. See bdrv_write() for the return codes */ int bdrv_read (BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors)
@@ -2213,6 +2223,11 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,return bdrv_rw_co (bs, sector_num, (uint8_t *)buf, nb_sectors, true); } +int bdrv_writev (BlockDriverState *bs,int64_t sector_num,QEMUIOVector *qiov) +{ +return bdrv_rwv_co (bs, sector_num, qiov, true); +} +int bdrv_pread (BlockDriverState *bs,int64_t offset,void *buf,int count1) {
@@ -2258,15 +2273,15 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset,return count1; } -int bdrv_pwrite (BlockDriverState *bs,int64_t offset, -const void *buf,int count1) +int bdrv_pwritev (BlockDriverState *bs,int64_t offset,QEMUIOVector *qiov) {uint8_t tmp_buf[BDRV_SECTOR_SIZE ];int len, nb_sectors, count;int64_t sector_num;int ret; - count = count1; + count = qiov->size; +/* first write to align to sector start */ len = (BDRV_SECTOR_SIZE - offset) & (BDRV_SECTOR_SIZE -1 );if (len > count)
@@ -2275,24 +2290,32 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset,if (len >0 ) {if ((ret =bdrv_read (bs, sector_num, tmp_buf,1 )) <0 )return ret; -memcpy (tmp_buf + (offset & (BDRV_SECTOR_SIZE -1 )), buf, len); +qemu_iovec_to_buf (qiov,0 , tmp_buf + (offset & (BDRV_SECTOR_SIZE -1 )), + len);if ((ret =bdrv_write (bs, sector_num, tmp_buf,1 )) <0 )return ret; count -= len;if (count ==0 ) -return count1; +return qiov->size; sector_num++; - buf += len; }/* write the sectors "in place" */ nb_sectors = count >>BDRV_SECTOR_BITS ;if (nb_sectors >0 ) { -if ((ret =bdrv_write (bs, sector_num, buf, nb_sectors)) <0 ) +QEMUIOVector qiov_inplace; + +qemu_iovec_init (&qiov_inplace, qiov->niov); +qemu_iovec_concat (&qiov_inplace, qiov, len, + nb_sectors <<BDRV_SECTOR_BITS ); + ret =bdrv_writev (bs, sector_num, &qiov_inplace); +qemu_iovec_destroy (&qiov_inplace); +if (ret <0 ) {return ret; + } + sector_num += nb_sectors; len = nb_sectors <<BDRV_SECTOR_BITS ; - buf += len; count -= len; }
@@ -2300,11 +2323,24 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset,if (count >0 ) {if ((ret =bdrv_read (bs, sector_num, tmp_buf,1 )) <0 )return ret; -memcpy (tmp_buf, buf, count); +qemu_iovec_to_buf (qiov, qiov->size - count, tmp_buf, count);if ((ret =bdrv_write (bs, sector_num, tmp_buf,1 )) <0 )return ret; } -return count1; +return qiov->size; +} + +int bdrv_pwrite (BlockDriverState *bs,int64_t offset, +const void *buf,int count1) +{ +QEMUIOVector qiov; +struct iovec iov = { + .iov_base = (void *) buf, + .iov_len = count1, + }; + +qemu_iovec_init_external (&qiov, &iov,1 ); +return bdrv_pwritev (bs, offset, &qiov); }/*
block/qcow2.c +1 -7
@@ -1658,18 +1658,12 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov,BDRVQcowState *s = bs->opaque;int growable = bs->growable;int ret; -void *buf; - - buf =qemu_blockalign (bs, qiov->size); -qemu_iovec_to_buf (qiov,0 , buf, qiov->size);BLKDBG_EVENT (bs->file,BLKDBG_VMSTATE_SAVE ); bs->growable =1 ; - ret =bdrv_pwrite (bs,qcow2_vm_state_offset (s) + pos, buf, qiov->size); + ret =bdrv_pwritev (bs,qcow2_vm_state_offset (s) + pos, qiov); bs->growable = growable; -qemu_vfree (buf); -return ret; }
include/block/block.h +2 -0
@@ -166,10 +166,12 @@ int bdrv_read_unthrottled(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors);int bdrv_write (BlockDriverState *bs,int64_t sector_num,const uint8_t *buf,int nb_sectors); +int bdrv_writev (BlockDriverState *bs,int64_t sector_num,QEMUIOVector *qiov);int bdrv_pread (BlockDriverState *bs,int64_t offset,void *buf,int count);int bdrv_pwrite (BlockDriverState *bs,int64_t offset,const void *buf,int count); +int bdrv_pwritev (BlockDriverState *bs,int64_t offset,QEMUIOVector *qiov);int bdrv_pwrite_sync (BlockDriverState *bs,int64_t offset,const void *buf,int count); int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
Signature · 1 line
1.8.1.4
PATCH 4/4 qemu-iotests: A few more bdrv_pread/pwrite tests
In reply to Kevin Wolf--- tests/qemu-iotests/002 | 13 +++++++++++++ tests/qemu-iotests/002.out | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
tests/qemu-iotests/002 +13 -0
@@ -61,10 +61,23 @@ $QEMU_IO -c "read -pP 0xa 0 $size" $TEST_IMG | _filter_qemu_io echo echo "unaligned pwrite" $QEMU_IO -c 'write -pP 0xab 66 42' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'write -pP 0xac 512 288' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'write -pP 0xad 800 224' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'write -pP 0xae 66000 128k' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'write -pP 0xaf 256k 42' $TEST_IMG | _filter_qemu_io echo echo "verify pattern" +$QEMU_IO -c 'read -pP 0xa 0 66' $TEST_IMG | _filter_qemu_io $QEMU_IO -c 'read -pP 0xab 66 42' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'read -pP 0xa 108 404' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'read -pP 0xac 512 288' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'read -pP 0xad 800 224' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'read -pP 0xa 1k 64976' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'read -pP 0xae 66000 128k' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'read -pP 0xa 197072 65072' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'read -pP 0xaf 256k 42' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'read -pP 0xa 262186 470' $TEST_IMG | _filter_qemu_io # success, all done echo "*** done"
tests/qemu-iotests/002.out +26 -0
@@ -16,8 +16,34 @@ read 134217728/134217728 bytes at offset 0 unaligned pwrite wrote 42/42 bytes at offset 66 42 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 288/288 bytes at offset 512 +288 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 224/224 bytes at offset 800 +224 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 131072/131072 bytes at offset 66000 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 42/42 bytes at offset 262144 +42 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) verify pattern +read 66/66 bytes at offset 0 +66 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 42/42 bytes at offset 66 42 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 404/404 bytes at offset 108 +404 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 288/288 bytes at offset 512 +288 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 224/224 bytes at offset 800 +224 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 64976/64976 bytes at offset 1024 +63.453 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 131072/131072 bytes at offset 66000 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65072/65072 bytes at offset 197072 +63.547 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 42/42 bytes at offset 262144 +42 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 470/470 bytes at offset 262186 +470 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done
Signature · 1 line
1.8.1.4
Quoted 9 lines · Kevin Wolf
This gives us back reasonable savevm performance, which regressed in commit
500f0061.Kevin Wolf (4):
block: Introducebdrv_writev_vmstate
savevm: Implementblock_writev_buffer()
block: Introducebdrv_pwritev()forqcow2_save_vmstate
qemu-iotests: A few more bdrv_pread/pwrite tests
Quoted 13 lines
block.c | 105 +++++++++++++++++++++++++++++++----------- block/qcow2.c | 6 +-- block/sheepdog.c | 13 ++++-- include/block/block.h | 3 ++ include/block/block_int.h | 4 +- include/migration/qemu-file.h | 2 +- savevm.c | 25 ++++++++-- tests/qemu-iotests/002 | 13 ++++++ tests/qemu-iotests/002.out | 26 +++++++++++ 9 files changed, 157 insertions(+), 40 deletions(-)Signature · 1 line
1.8.1.4
Looks fine on the block side. Perhaps Orit, Juan, or Paolo can double-check the migration side.
Il 08/04/2013 18:03, Stefan Hajnoczi ha scritto:
Quoted 4 lines
Looks fine on the block side. Perhaps Orit, Juan, or Paolo can double-check the migration side.
Reviewed-by Stefan Hajnoczi <[email protected]>
Looks good, but given there are patches to fix it, I'm not sure it's worth the trouble...
Paolo
Am 08.04.2013 um 18:18 hat Paolo Bonzini geschrieben:
Quoted 8 lines
Il 08/04/2013 18:03, Stefan Hajnoczi ha scritto:
Quoted 4 lines
Looks fine on the block side. Perhaps Orit, Juan, or Paolo can double-check the migration side.
Reviewed-by Stefan Hajnoczi <[email protected]>Looks good, but given there are patches to fix it, I'm not sure it's worth the trouble...
Shouldn't this perform even a little better? And we should get rid of non-vectored interfaces in the block layer anyway.
Kevin
Il 09/04/2013 10:04, Kevin Wolf ha scritto:
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Looks good, but given there are patches to fix it, I'm not sure it's worth the trouble...
Shouldn't this perform even a little better? And we should get rid of non-vectored interfaces in the block layer anyway.
Yes, if you have a very fast disk it should. Network throughput with Orit's patches jumped from 2.9 Gbps to 4.2 Gbps. But savevm is not live, so it is not as important to make it really fast.
Anyhow, since the patches are there to fix both the cause and the symptom, there's really no reason to hold either series.
Paolo
Quoted 10 lines · Paolo Bonzini
Il 09/04/2013 10:04, Kevin Wolf ha scritto:
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Looks good, but given there are patches to fix it, I'm not sure it's worth the trouble...
Shouldn't this perform even a little better? And we should get rid of non-vectored interfaces in the block layer anyway.
Yes, if you have a very fast disk it should. Network throughput with Orit's patches jumped from 2.9 Gbps to 4.2 Gbps. But savevm is not live, so it is not as important to make it really fast.
Users have been asking about poor savevm/loadvm performance recently. I think anything we can do it improve it, especially since these patches already exist, is good.
Stefan
Stefan Hajnoczi
AppliedQuoted 9 lines · Kevin Wolf
This gives us back reasonable savevm performance, which regressed in commit
500f0061.Kevin Wolf (4):
block: Introducebdrv_writev_vmstate
savevm: Implementblock_writev_buffer()
block: Introducebdrv_pwritev()forqcow2_save_vmstate
qemu-iotests: A few more bdrv_pread/pwrite tests
Quoted 14 lines
block.c | 105 +++++++++++++++++++++++++++++++----------- block/qcow2.c | 6 +-- block/sheepdog.c | 13 ++++-- include/block/block.h | 3 ++ include/block/block_int.h | 4 +- include/migration/qemu-file.h | 2 +- savevm.c | 25 ++++++++-- tests/qemu-iotests/002 | 13 ++++++ tests/qemu-iotests/002.out | 26 +++++++++++ 9 files changed, 157 insertions(+), 40 deletions(-)Signature · 1 line
1.8.1.4
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan