Skip to contentSkip to conversation

migration/block: use blk_pwrite_zeroes for each zero cluster

PATCH Superseded [email protected] 2 participants 6 messages Apr 7, 2017 – Apr 10, 2017

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 migration/block: use blk_pwrite_zeroes for each zero cluster

From: Lidong Chen <[email protected]>

BLOCK_SIZE is (1 << 20), qcow2 cluster size is 65536 by default, this maybe cause the qcow2 file size is bigger after migration. This patch check each cluster, use blk_pwrite_zeroes for each zero cluster.

---
 migration/block.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
migration/block.c +35 -2
index 7734ff7..c32e046 100644
@@ -885,6 +885,11 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
     int64_t total_sectors = 0;
     int nr_sectors;
     int ret;
+    int i;
+    int64_t addr_offset;
+    uint8_t *buf_offset;
+    BlockDriverInfo bdi;
+    int cluster_size;
 
     do {
         addr = qemu_get_be64(f);
@@ -934,8 +939,36 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
             } else {
                 buf = g_malloc(BLOCK_SIZE);
                 qemu_get_buffer(f, buf, BLOCK_SIZE);
-                ret = blk_pwrite(blk, addr * BDRV_SECTOR_SIZE, buf,
-                                 nr_sectors * BDRV_SECTOR_SIZE, 0);
+
+                ret = bdrv_get_info(blk_bs(blk), &bdi);
+                cluster_size = bdi.cluster_size;
+
+                if (ret == 0 && cluster_size > 0 &&
+                    cluster_size < BLOCK_SIZE &&
+                    BLOCK_SIZE % cluster_size == 0) {
+                    for (i = 0; i < BLOCK_SIZE / cluster_size; i++) {
+                        addr_offset = addr * BDRV_SECTOR_SIZE
+                                        + i * cluster_size;
+                        buf_offset = buf + i * cluster_size;
+
+                        if (buffer_is_zero(buf_offset, cluster_size)) {
+                            ret = blk_pwrite_zeroes(blk, addr_offset,
+                                                    cluster_size,
+                                                    BDRV_REQ_MAY_UNMAP);
+                        } else {
+                             ret = blk_pwrite(blk, addr_offset, buf_offset,
+                                              cluster_size, 0);
+                        }
+
+                        if (ret < 0) {
+                            g_free(buf);
+                            return ret;
+                        }
+                    }
+                } else {
+                    ret = blk_pwrite(blk, addr * BDRV_SECTOR_SIZE, buf,
+                                     nr_sectors * BDRV_SECTOR_SIZE, 0);
+                }
                 g_free(buf);
             }
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 17 lines · On Fri, 04/07 16:44, [email protected] wrote:

From: Lidong Chen <[email protected]>

BLOCK_SIZE is (1 << 20), qcow2 cluster size is 65536 by default, this maybe cause the qcow2 file size is bigger after migration. This patch check each cluster, use blk_pwrite_zeroes for each zero cluster.

---
 migration/block.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
migration/block.c +0 -0
index 7734ff7..c32e046 100644

migration/block.c static int block_load(QEMUFile *f, void *opaque, int version_id) · line 890

Quoted 6 lines
migration/block.c +3 -0
@@ -885,6 +885,11 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
     int64_t total_sectors = 0;
     int nr_sectors;
     int ret;
+    int i;
+    int64_t addr_offset;
+    uint8_t *buf_offset;

Poor variable names, they are not offset, maybe "cur_addr" and "cur_buf"? And they can be moved to the loop block below.

Quoted 7 lines
migration/block.c +2 -0
+    BlockDriverInfo bdi;
+    int cluster_size;
 
     do {
         addr = qemu_get_be64(f);
@@ -934,8 +939,36 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
             } else {

migration/block.c static int block_load(QEMUFile *f, void *opaque, int version_id) · line 947

Quoted 10 lines
migration/block.c +6 -2
                 buf = g_malloc(BLOCK_SIZE);
                 qemu_get_buffer(f, buf, BLOCK_SIZE);
-                ret = blk_pwrite(blk, addr * BDRV_SECTOR_SIZE, buf,
-                                 nr_sectors * BDRV_SECTOR_SIZE, 0);
+
+                ret = bdrv_get_info(blk_bs(blk), &bdi);
+                cluster_size = bdi.cluster_size;
+
+                if (ret == 0 && cluster_size > 0 &&
+                    cluster_size < BLOCK_SIZE &&

I think cluster_size == BLOCK_SIZE should work too.

Quoted 30 lines
migration/block.c +24 -0
+                    BLOCK_SIZE % cluster_size == 0) {
+                    for (i = 0; i < BLOCK_SIZE / cluster_size; i++) {
+                        addr_offset = addr * BDRV_SECTOR_SIZE
+                                        + i * cluster_size;
+                        buf_offset = buf + i * cluster_size;
+
+                        if (buffer_is_zero(buf_offset, cluster_size)) {
+                            ret = blk_pwrite_zeroes(blk, addr_offset,
+                                                    cluster_size,
+                                                    BDRV_REQ_MAY_UNMAP);
+                        } else {
+                             ret = blk_pwrite(blk, addr_offset, buf_offset,
+                                              cluster_size, 0);
+                        }
+
+                        if (ret < 0) {
+                            g_free(buf);
+                            return ret;
+                        }
+                    }
+                } else {
+                    ret = blk_pwrite(blk, addr * BDRV_SECTOR_SIZE, buf,
+                                     nr_sectors * BDRV_SECTOR_SIZE, 0);
+                }
                 g_free(buf);
             }
 
Signature · 1 line
1.8.3.1

Is it possible use (source) cluster size as the transfer chunk size, instead of BDRV_SECTORS_PER_DIRTY_CHUNK? Then the existing BLK_MIG_FLAG_ZERO_BLOCK logic can help and you don't need to send zero bytes on the wire. This may still not be optimal if dest has larger cluster, but it should cover the common use case well.

Fam

#2 lore raw
Quoted 13 lines · Fam Zheng
Quoted 12 lines · On Fri, 04/07 16:44, [email protected] wrote:

From: Lidong Chen <[email protected]>

BLOCK_SIZE is (1 << 20), qcow2 cluster size is 65536 by default, this maybe cause the qcow2 file size is bigger after migration. This patch check each cluster, use blk_pwrite_zeroes for each zero cluster.

---
 migration/block.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
Quoted 14 lines

migration/block.c static int block_load(QEMUFile *f, void *opaque, int version_id) · line 890

Quoted 11 lines
migration/block.c +3 -0
index 7734ff7..c32e046 100644
@@ -885,6 +885,11 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
     int64_t total_sectors = 0;
     int nr_sectors;
     int ret;
+    int i;
+    int64_t addr_offset;
+    uint8_t *buf_offset;

Poor variable names, they are not offset, maybe "cur_addr" and "cur_buf"? And they can be moved to the loop block below.

ok, i will change.

Quoted 4 lines
Quoted 4 lines
migration/block.c +2 -0
+    BlockDriverInfo bdi;
+    int cluster_size;
 
Quoted 16 lines
Quoted 4 lines
migration/block.c +0 -0
     do {
         addr = qemu_get_be64(f);
@@ -934,8 +939,36 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
             } else {

migration/block.c static int block_load(QEMUFile *f, void *opaque, int version_id) · line 947

Quoted 10 lines
migration/block.c +6 -2
                 buf = g_malloc(BLOCK_SIZE);
                 qemu_get_buffer(f, buf, BLOCK_SIZE);
-                ret = blk_pwrite(blk, addr * BDRV_SECTOR_SIZE, buf,
-                                 nr_sectors * BDRV_SECTOR_SIZE, 0);
+
+                ret = bdrv_get_info(blk_bs(blk), &bdi);
+                cluster_size = bdi.cluster_size;
+
+                if (ret == 0 && cluster_size > 0 &&
+                    cluster_size < BLOCK_SIZE &&

I think cluster_size == BLOCK_SIZE should work too.

This case the (flags & BLK_MIG_FLAG_ZERO_BLOCK) should be true, and will invoke blk_pwrite_zeroes before apply this patch. but maybe the source qemu maybe not enabled zero flag. so i think cluster_size <= BLOCK_SIZE is ok.

Quoted 28 lines
Quoted 28 lines
migration/block.c +24 -0
+                    BLOCK_SIZE % cluster_size == 0) {
+                    for (i = 0; i < BLOCK_SIZE / cluster_size; i++) {
+                        addr_offset = addr * BDRV_SECTOR_SIZE
+                                        + i * cluster_size;
+                        buf_offset = buf + i * cluster_size;
+
+                        if (buffer_is_zero(buf_offset, cluster_size)) {
+                            ret = blk_pwrite_zeroes(blk, addr_offset,
+                                                    cluster_size,
+                                                    BDRV_REQ_MAY_UNMAP);
+                        } else {
+                             ret = blk_pwrite(blk, addr_offset, buf_offset,
+                                              cluster_size, 0);
+                        }
+
+                        if (ret < 0) {
+                            g_free(buf);
+                            return ret;
+                        }
+                    }
+                } else {
+                    ret = blk_pwrite(blk, addr * BDRV_SECTOR_SIZE, buf,
+                                     nr_sectors * BDRV_SECTOR_SIZE, 0);
+                }
                 g_free(buf);
             }
 
Quoted 9 lines
Quoted 3 lines

--
1.8.3.1

Is it possible use (source) cluster size as the transfer chunk size, instead of BDRV_SECTORS_PER_DIRTY_CHUNK? Then the existing BLK_MIG_FLAG_ZERO_BLOCK logic can help and you don't need to send zero bytes on the wire. This may still not be optimal if dest has larger cluster, but it should cover the common use case well.

yes, i also think BDRV_SECTORS_PER_DIRTY_CHUNK is too large. This have two disadvantage:
1. it will cause the dest qcow2 file size is bigger after migration.
2. it will cause transfer not necessary data, and maybe cause the migration can't be successful.

in my production environment, some vm only write 2MB/s, the dirty block migrate speed is 70MB/s.
but it still migration timeout.

but if we change the size of BDRV_SECTORS_PER_DIRTY_CHUNK, it will break the protocol.
the old version qemu will not be able to migrate to new version qemu. there are not information about the length about the migration buffer.

so i think we should add new flags to indicate that there are an additional byte about the length
of migration buffer. i will send another patch later, and test the result.

this patch is also valuable, there are many old version qemu in my production environment.
and will be benefit with this patch.

Quoted 2 lines

Fam

#3 lore raw
Quoted 103 lines · On Sat, Apr 8, 2017 at 12:52 PM, 858585 jemmy <[email protected]> wrote:
Quoted 13 lines · Fam Zheng
Quoted 12 lines · On Fri, 04/07 16:44, [email protected] wrote:

From: Lidong Chen <[email protected]>

BLOCK_SIZE is (1 << 20), qcow2 cluster size is 65536 by default, this maybe cause the qcow2 file size is bigger after migration. This patch check each cluster, use blk_pwrite_zeroes for each zero cluster.

---
 migration/block.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
Quoted 14 lines

migration/block.c static int block_load(QEMUFile *f, void *opaque, int version_id) · line 890

Quoted 11 lines
migration/block.c +3 -0
index 7734ff7..c32e046 100644
@@ -885,6 +885,11 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
     int64_t total_sectors = 0;
     int nr_sectors;
     int ret;
+    int i;
+    int64_t addr_offset;
+    uint8_t *buf_offset;

Poor variable names, they are not offset, maybe "cur_addr" and "cur_buf"? And they can be moved to the loop block below.

ok, i will change.

Quoted 4 lines
Quoted 4 lines
migration/block.c +2 -0
+    BlockDriverInfo bdi;
+    int cluster_size;
 
Quoted 16 lines
Quoted 4 lines
migration/block.c +0 -0
     do {
         addr = qemu_get_be64(f);
@@ -934,8 +939,36 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
             } else {

migration/block.c static int block_load(QEMUFile *f, void *opaque, int version_id) · line 947

Quoted 10 lines
migration/block.c +6 -2
                 buf = g_malloc(BLOCK_SIZE);
                 qemu_get_buffer(f, buf, BLOCK_SIZE);
-                ret = blk_pwrite(blk, addr * BDRV_SECTOR_SIZE, buf,
-                                 nr_sectors * BDRV_SECTOR_SIZE, 0);
+
+                ret = bdrv_get_info(blk_bs(blk), &bdi);
+                cluster_size = bdi.cluster_size;
+
+                if (ret == 0 && cluster_size > 0 &&
+                    cluster_size < BLOCK_SIZE &&

I think cluster_size == BLOCK_SIZE should work too.

This case the (flags & BLK_MIG_FLAG_ZERO_BLOCK) should be true, and will invoke blk_pwrite_zeroes before apply this patch. but maybe the source qemu maybe not enabled zero flag. so i think cluster_size <= BLOCK_SIZE is ok.

Quoted 28 lines
Quoted 28 lines
migration/block.c +24 -0
+                    BLOCK_SIZE % cluster_size == 0) {
+                    for (i = 0; i < BLOCK_SIZE / cluster_size; i++) {
+                        addr_offset = addr * BDRV_SECTOR_SIZE
+                                        + i * cluster_size;
+                        buf_offset = buf + i * cluster_size;
+
+                        if (buffer_is_zero(buf_offset, cluster_size)) {
+                            ret = blk_pwrite_zeroes(blk, addr_offset,
+                                                    cluster_size,
+                                                    BDRV_REQ_MAY_UNMAP);
+                        } else {
+                             ret = blk_pwrite(blk, addr_offset, buf_offset,
+                                              cluster_size, 0);
+                        }
+
+                        if (ret < 0) {
+                            g_free(buf);
+                            return ret;
+                        }
+                    }
+                } else {
+                    ret = blk_pwrite(blk, addr * BDRV_SECTOR_SIZE, buf,
+                                     nr_sectors * BDRV_SECTOR_SIZE, 0);
+                }
                 g_free(buf);
             }
 
Quoted 9 lines
Quoted 3 lines

--
1.8.3.1

Is it possible use (source) cluster size as the transfer chunk size, instead of BDRV_SECTORS_PER_DIRTY_CHUNK? Then the existing BLK_MIG_FLAG_ZERO_BLOCK logic can help and you don't need to send zero bytes on the wire. This may still not be optimal if dest has larger cluster, but it should cover the common use case well.

yes, i also think BDRV_SECTORS_PER_DIRTY_CHUNK is too large. This have two disadvantage:
1. it will cause the dest qcow2 file size is bigger after migration.
2. it will cause transfer not necessary data, and maybe cause the migration can't be successful.

in my production environment, some vm only write 2MB/s, the dirty block migrate speed is 70MB/s.
but it still migration timeout.

Quoted 8 lines

but if we change the size of BDRV_SECTORS_PER_DIRTY_CHUNK, it will break the protocol.
the old version qemu will not be able to migrate to new version qemu. there are not information about the length about the migration buffer.

so i think we should add new flags to indicate that there are an additional byte about the length
of migration buffer. i will send another patch later, and test the result.

Hi Fam:
Do we need consider the circumstances than migrate from new qemu version to old qemu version?

Quoted 7 lines

this patch is also valuable, there are many old version qemu in my production environment.
and will be benefit with this patch.

Quoted 2 lines

Fam

#4 lore raw
Quoted 109 lines · On Sat, 04/08 21:29, 858585 jemmy wrote:
Quoted 108 lines · On Sat, Apr 8, 2017 at 12:52 PM, 858585 jemmy <[email protected]> wrote:
Quoted 13 lines · Fam Zheng
Quoted 12 lines · On Fri, 04/07 16:44, [email protected] wrote:

From: Lidong Chen <[email protected]>

BLOCK_SIZE is (1 << 20), qcow2 cluster size is 65536 by default, this maybe cause the qcow2 file size is bigger after migration. This patch check each cluster, use blk_pwrite_zeroes for each zero cluster.

---
 migration/block.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
Quoted 14 lines

migration/block.c static int block_load(QEMUFile *f, void *opaque, int version_id) · line 890

Quoted 11 lines
migration/block.c +3 -0
index 7734ff7..c32e046 100644
@@ -885,6 +885,11 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
     int64_t total_sectors = 0;
     int nr_sectors;
     int ret;
+    int i;
+    int64_t addr_offset;
+    uint8_t *buf_offset;

Poor variable names, they are not offset, maybe "cur_addr" and "cur_buf"? And they can be moved to the loop block below.

ok, i will change.

Quoted 4 lines
Quoted 4 lines
migration/block.c +2 -0
+    BlockDriverInfo bdi;
+    int cluster_size;
 
Quoted 16 lines
Quoted 4 lines
migration/block.c +0 -0
     do {
         addr = qemu_get_be64(f);
@@ -934,8 +939,36 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
             } else {

migration/block.c static int block_load(QEMUFile *f, void *opaque, int version_id) · line 947

Quoted 10 lines
migration/block.c +6 -2
                 buf = g_malloc(BLOCK_SIZE);
                 qemu_get_buffer(f, buf, BLOCK_SIZE);
-                ret = blk_pwrite(blk, addr * BDRV_SECTOR_SIZE, buf,
-                                 nr_sectors * BDRV_SECTOR_SIZE, 0);
+
+                ret = bdrv_get_info(blk_bs(blk), &bdi);
+                cluster_size = bdi.cluster_size;
+
+                if (ret == 0 && cluster_size > 0 &&
+                    cluster_size < BLOCK_SIZE &&

I think cluster_size == BLOCK_SIZE should work too.

This case the (flags & BLK_MIG_FLAG_ZERO_BLOCK) should be true, and will invoke blk_pwrite_zeroes before apply this patch. but maybe the source qemu maybe not enabled zero flag. so i think cluster_size <= BLOCK_SIZE is ok.

Quoted 28 lines
Quoted 28 lines
migration/block.c +24 -0
+                    BLOCK_SIZE % cluster_size == 0) {
+                    for (i = 0; i < BLOCK_SIZE / cluster_size; i++) {
+                        addr_offset = addr * BDRV_SECTOR_SIZE
+                                        + i * cluster_size;
+                        buf_offset = buf + i * cluster_size;
+
+                        if (buffer_is_zero(buf_offset, cluster_size)) {
+                            ret = blk_pwrite_zeroes(blk, addr_offset,
+                                                    cluster_size,
+                                                    BDRV_REQ_MAY_UNMAP);
+                        } else {
+                             ret = blk_pwrite(blk, addr_offset, buf_offset,
+                                              cluster_size, 0);
+                        }
+
+                        if (ret < 0) {
+                            g_free(buf);
+                            return ret;
+                        }
+                    }
+                } else {
+                    ret = blk_pwrite(blk, addr * BDRV_SECTOR_SIZE, buf,
+                                     nr_sectors * BDRV_SECTOR_SIZE, 0);
+                }
                 g_free(buf);
             }
 
Quoted 9 lines
Quoted 3 lines

--
1.8.3.1

Is it possible use (source) cluster size as the transfer chunk size, instead of BDRV_SECTORS_PER_DIRTY_CHUNK? Then the existing BLK_MIG_FLAG_ZERO_BLOCK logic can help and you don't need to send zero bytes on the wire. This may still not be optimal if dest has larger cluster, but it should cover the common use case well.

yes, i also think BDRV_SECTORS_PER_DIRTY_CHUNK is too large. This have two disadvantage:
1. it will cause the dest qcow2 file size is bigger after migration.
2. it will cause transfer not necessary data, and maybe cause the migration can't be successful.

in my production environment, some vm only write 2MB/s, the dirty block migrate speed is 70MB/s.
but it still migration timeout.

but if we change the size of BDRV_SECTORS_PER_DIRTY_CHUNK, it will break the protocol.
the old version qemu will not be able to migrate to new version qemu. there are not information about the length about the migration buffer.

Quoted 7 lines
Quoted 3 lines

so i think we should add new flags to indicate that there are an additional byte about the length
of migration buffer. i will send another patch later, and test the result.

Hi Fam:
Do we need consider the circumstances than migrate from new qemu version to old qemu version?

Yes, usually we use a subsection to achieve that - missing the "chunk size" field should result in using the old BDRV_SECTORS_PER_DIRTY_CHUNK value.

Fam

Quoted 9 lines
Quoted 8 lines

this patch is also valuable, there are many old version qemu in my production environment.
and will be benefit with this patch.

Quoted 2 lines

Fam

#5 lore raw
Quoted 114 lines · Fam Zheng
Quoted 113 lines · On Sat, 04/08 21:29, 858585 jemmy wrote:
Quoted 111 lines · On Sat, Apr 8, 2017 at 12:52 PM, 858585 jemmy <[email protected]> wrote:
Quoted 13 lines · Fam Zheng
Quoted 12 lines · On Fri, 04/07 16:44, [email protected] wrote:

From: Lidong Chen <[email protected]>

BLOCK_SIZE is (1 << 20), qcow2 cluster size is 65536 by default, this maybe cause the qcow2 file size is bigger after migration. This patch check each cluster, use blk_pwrite_zeroes for each zero cluster.

---
 migration/block.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
Quoted 14 lines

migration/block.c static int block_load(QEMUFile *f, void *opaque, int version_id) · line 890

Quoted 11 lines
migration/block.c +3 -0
index 7734ff7..c32e046 100644
@@ -885,6 +885,11 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
     int64_t total_sectors = 0;
     int nr_sectors;
     int ret;
+    int i;
+    int64_t addr_offset;
+    uint8_t *buf_offset;

Poor variable names, they are not offset, maybe "cur_addr" and "cur_buf"? And they can be moved to the loop block below.

ok, i will change.

Quoted 4 lines
Quoted 4 lines
migration/block.c +2 -0
+    BlockDriverInfo bdi;
+    int cluster_size;
 
Quoted 16 lines
Quoted 4 lines
migration/block.c +0 -0
     do {
         addr = qemu_get_be64(f);
@@ -934,8 +939,36 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
             } else {

migration/block.c static int block_load(QEMUFile *f, void *opaque, int version_id) · line 947

Quoted 10 lines
migration/block.c +6 -2
                 buf = g_malloc(BLOCK_SIZE);
                 qemu_get_buffer(f, buf, BLOCK_SIZE);
-                ret = blk_pwrite(blk, addr * BDRV_SECTOR_SIZE, buf,
-                                 nr_sectors * BDRV_SECTOR_SIZE, 0);
+
+                ret = bdrv_get_info(blk_bs(blk), &bdi);
+                cluster_size = bdi.cluster_size;
+
+                if (ret == 0 && cluster_size > 0 &&
+                    cluster_size < BLOCK_SIZE &&

I think cluster_size == BLOCK_SIZE should work too.

This case the (flags & BLK_MIG_FLAG_ZERO_BLOCK) should be true, and will invoke blk_pwrite_zeroes before apply this patch. but maybe the source qemu maybe not enabled zero flag. so i think cluster_size <= BLOCK_SIZE is ok.

Quoted 28 lines
Quoted 28 lines
migration/block.c +24 -0
+                    BLOCK_SIZE % cluster_size == 0) {
+                    for (i = 0; i < BLOCK_SIZE / cluster_size; i++) {
+                        addr_offset = addr * BDRV_SECTOR_SIZE
+                                        + i * cluster_size;
+                        buf_offset = buf + i * cluster_size;
+
+                        if (buffer_is_zero(buf_offset, cluster_size)) {
+                            ret = blk_pwrite_zeroes(blk, addr_offset,
+                                                    cluster_size,
+                                                    BDRV_REQ_MAY_UNMAP);
+                        } else {
+                             ret = blk_pwrite(blk, addr_offset, buf_offset,
+                                              cluster_size, 0);
+                        }
+
+                        if (ret < 0) {
+                            g_free(buf);
+                            return ret;
+                        }
+                    }
+                } else {
+                    ret = blk_pwrite(blk, addr * BDRV_SECTOR_SIZE, buf,
+                                     nr_sectors * BDRV_SECTOR_SIZE, 0);
+                }
                 g_free(buf);
             }
 
Quoted 9 lines
Quoted 3 lines

--
1.8.3.1

Is it possible use (source) cluster size as the transfer chunk size, instead of BDRV_SECTORS_PER_DIRTY_CHUNK? Then the existing BLK_MIG_FLAG_ZERO_BLOCK logic can help and you don't need to send zero bytes on the wire. This may still not be optimal if dest has larger cluster, but it should cover the common use case well.

yes, i also think BDRV_SECTORS_PER_DIRTY_CHUNK is too large. This have two disadvantage:
1. it will cause the dest qcow2 file size is bigger after migration.
2. it will cause transfer not necessary data, and maybe cause the migration can't be successful.

in my production environment, some vm only write 2MB/s, the dirty block migrate speed is 70MB/s.
but it still migration timeout.

but if we change the size of BDRV_SECTORS_PER_DIRTY_CHUNK, it will break the protocol.
the old version qemu will not be able to migrate to new version qemu. there are not information about the length about the migration buffer.

so i think we should add new flags to indicate that there are an additional byte about the length
of migration buffer. i will send another patch later, and test the result.

Quoted 6 lines
Quoted 3 lines

Hi Fam:
Do we need consider the circumstances than migrate from new qemu version to old qemu version?

Yes, usually we use a subsection to achieve that - missing the "chunk size" field should result in using the old BDRV_SECTORS_PER_DIRTY_CHUNK value.

ok, i will develop a prototype firstly, and send out the performance test result later.

Quoted 12 lines

Fam

Quoted 9 lines
Quoted 8 lines

this patch is also valuable, there are many old version qemu in my production environment.
and will be benefit with this patch.

Quoted 2 lines

Fam