migration: not send zero page header in ram bulk stage
PATCH 1/1 migration: not send zero page header in ram bulk stage
Now that VM's RAM pages are initialized to zero, (VM's RAM is allcated with the mmap() and MAP_ANONYMOUS option, or mmap() without MAP_SHARED if hugetlbfs is used.) so there is no need to send the zero page header to destination.
For guest just uses a small portions of RAM, this change can avoid allocating all the guest's RAM pages in the destination node after live migration. Another benefit is destination QEMU can save lots of CPU cycles for zero page checking.
--- migration/ram.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
migration/ram.c +6 -4
@@ -705,10 +705,12 @@ static int save_zero_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset,if (is_zero_range (p,TARGET_PAGE_SIZE )) { acct_info.dup_pages++; - *bytes_transferred +=save_page_header (f, block, - offset |RAM_SAVE_FLAG_COMPRESS ); -qemu_put_byte (f,0 ); - *bytes_transferred +=1 ; +if (!ram_bulk_stage) { + *bytes_transferred +=save_page_header (f, block, offset | +RAM_SAVE_FLAG_COMPRESS ); +qemu_put_byte (f,0 ); + *bytes_transferred +=1 ; + } pages =1 ; }
Signature · 1 line
1.9.1
Quoted 5 lines · Liang Li
Now that VM's RAM pages are initialized to zero, (VM's RAM is allcated with the
mmap()andMAP_ANONYMOUSoption, ormmap()withoutMAP_SHAREDif hugetlbfs is used.) so there is no need to send the zero page header to destination.
It seems that this patch is incorrect, if the no-zero pages are zeroed again during !ram_bulk_stage, we didn't send the new zeroed page, there will be an error.
Quoted 32 lines
For guest just uses a small portions of RAM, this change can avoid allocating all the guest's RAM pages in the destination node after live migration. Another benefit is destination QEMU can save lots of CPU cycles for zero page checking.
Signed-off-by Liang Li <[email protected]>--- migration/ram.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)migration/ram.c +6
-4@@ -705,10 +705,12 @@ static int save_zero_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset,if (is_zero_range (p,TARGET_PAGE_SIZE )) { acct_info.dup_pages++; - *bytes_transferred +=save_page_header (f, block, - offset |RAM_SAVE_FLAG_COMPRESS ); -qemu_put_byte (f,0 ); - *bytes_transferred +=1 ; +if (!ram_bulk_stage) { + *bytes_transferred +=save_page_header (f, block, offset | +RAM_SAVE_FLAG_COMPRESS ); +qemu_put_byte (f,0 ); + *bytes_transferred +=1 ; + } pages =1 ; }
Quoted 4 lines
It seems that this patch is incorrect, if the no-zero pages are zeroed again during !ram_bulk_stage, we didn't send the new zeroed page, there will be an error.
If not in ram_bulk_stage, still send the header, could you explain why it's wrong?
Liang
Quoted 36 lines
migration/ram.c static int save_zero_page(QEMUFile *f,
Quoted 15 lines
For guest just uses a small portions of RAM, this change can avoid allocating all the guest's RAM pages in the destination node after live migration. Another benefit is destination QEMU can save lots of CPU cycles for zero page checking.
Signed-off-by Liang Li <[email protected]>--- migration/ram.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)migration/ram.c index 4e606ab..c4821d1 renamed from migration/ram.c +0
-0100644
migration/ram.c +0
-0@@ -705,10 +705,12 @@ static int save_zero_page(QEMUFile *f,RAMBlock
Quoted 18 lines
migration/ram.c +6
-4*block, ram_addr_t offset, if (is_zero_range(p, TARGET_PAGE_SIZE)) { acct_info.dup_pages++; - *bytes_transferred +=save_page_header (f, block, - offset |RAM_SAVE_FLAG_COMPRESS ); -qemu_put_byte (f,0 ); - *bytes_transferred +=1 ; +if (!ram_bulk_stage) { + *bytes_transferred +=save_page_header (f, block, offset | +RAM_SAVE_FLAG_COMPRESS ); +qemu_put_byte (f,0 ); + *bytes_transferred +=1 ; + } pages =1 ; }
Hi,
Quoted 9 lines · Liang Z
Quoted 4 lines
It seems that this patch is incorrect, if the no-zero pages are zeroed again during !ram_bulk_stage, we didn't send the new zeroed page, there will be an error.
If not in
ram_bulk_stage, still send the header, could you explain why it's wrong?Liang
I have made a mistake, and yes, this patch can speed up the live migration time, especially when there are many zero pages, it will be more obvious. I like this idea. Did you test it with postcopy ? Does it break postcopy ?
Thanks,
zhanghailiang
Quoted 40 lines
Quoted 10 lines
Quoted 10 lines
For guest just uses a small portions of RAM, this change can avoid allocating all the guest's RAM pages in the destination node after live migration. Another benefit is destination QEMU can save lots of CPU cycles for zero page checking.
Signed-off-by Liang Li <[email protected]>--- migration/ram.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)Quoted 26 lines
migration/ram.c static int save_zero_page(QEMUFile *f,
Quoted 5 lines
migration/ram.c index 4e606ab..c4821d1 renamed from migration/ram.c +0
-0100644
migration/ram.c +0
-0@@ -705,10 +705,12 @@ static int save_zero_page(QEMUFile *f,RAMBlock
Quoted 18 lines
migration/ram.c +6
-4*block, ram_addr_t offset, if (is_zero_range(p, TARGET_PAGE_SIZE)) { acct_info.dup_pages++; - *bytes_transferred +=save_page_header (f, block, - offset |RAM_SAVE_FLAG_COMPRESS ); -qemu_put_byte (f,0 ); - *bytes_transferred +=1 ; +if (!ram_bulk_stage) { + *bytes_transferred +=save_page_header (f, block, offset | +RAM_SAVE_FLAG_COMPRESS ); +qemu_put_byte (f,0 ); + *bytes_transferred +=1 ; + } pages =1 ; }.
Quoted 7 lines · Liang Z
Quoted 6 lines
Quoted 4 lines
It seems that this patch is incorrect, if the no-zero pages are zeroed again during !ram_bulk_stage, we didn't send the new zeroed page, there will be an error.
If not in
ram_bulk_stage, still send the header, could you explain why it's
Quoted 9 lines
wrong?
Quoted 3 lines
Liang
I have made a mistake, and yes, this patch can speed up the live migration time, especially when there are many zero pages, it will be more obvious. I like this idea. Did you test it with postcopy ? Does it break postcopy ?
Not yet, I saw Dave's comment's, it will beak post copy, it's not hard to fix this.
A more important thing is Paolo's comments, I don't know in which case this patch will break LM. Do you have any idea about this? Hope that QEMU don't write data to the block 'pc.ram'.
Liang
Quoted 3 lines
Thanks,
zhanghailiang
Quoted 12 lines · Liang Z
Quoted 12 lines · Liang Z
Quoted 6 lines
Quoted 4 lines
It seems that this patch is incorrect, if the no-zero pages are zeroed again during !ram_bulk_stage, we didn't send the new zeroed page, there will be an error.
If not in
ram_bulk_stage, still send the header, could you explain why it'swrong?
Quoted 3 lines
Liang
Quoted 9 lines
Quoted 4 lines
I have made a mistake, and yes, this patch can speed up the live migration time, especially when there are many zero pages, it will be more obvious. I like this idea. Did you test it with postcopy ? Does it break postcopy ?
Not yet, I saw Dave's comment's, it will beak post copy, it's not hard to fix this.
A more important thing is Paolo's comments, I don't know in which case this patch will break LM. Do you have any idea about this? Hope that QEMU don't write data to the block 'pc.ram'.
Paolo is right, for VM in destination, QEMU may write VM's memory before VM starts. So your assumption that "VM's RAM pages are initialized to zero" is incorrect. This patch will break LM.
Quoted 8 lines
Liang
Quoted 3 lines
Thanks,
zhanghailiang.
Quoted 12 lines
Quoted 1 line
Not yet, I saw Dave's comment's, it will beak post copy, it's not hard to fix
this.
Quoted 1 line
A more important thing is Paolo's comments, I don't know in which case
this patch will break LM. Do you have any idea about this?
Quoted 2 lines
Hope that QEMU don't write data to the block 'pc.ram'.
Paolo is right, for VM in destination, QEMU may write VM's memory before VM starts.
So your assumption that "VM's RAM pages are initialized to zero" is incorrect. This patch will break LM.
Which portion of the VM's RAM pages will be written by QEMU? Do you know some exact information? I can't wait for Paolo's response.
Liang
Quoted 7 lines · Liang Z
Quoted 4 lines
Paolo is right, for VM in destination, QEMU may write VM's memory before VM starts.
So your assumption that "VM's RAM pages are initialized to zero" is incorrect. This patch will break LM.Which portion of the VM's RAM pages will be written by QEMU? Do you know some exact information? I can't wait for Paolo's response.
It is basically anything that uses rom_add_file_fixed or rom_add_blob_fixed with an address that points into RAM.
Paolo
This patch will break LM.
Quoted 9 lines
Quoted 2 lines
Which portion of the VM's RAM pages will be written by QEMU? Do you
know some exact information?
Quoted 1 line
I can't wait for Paolo's response.
It is basically anything that uses
rom_add_file_fixedorrom_add_blob_fixedwith an address that points into RAM.Paolo
Thanks a lot!
Liang
Quoted 18 lines · Hailiang Zhang
Quoted 17 lines · Liang Z
Quoted 16 lines · Liang Z
Quoted 6 lines
Quoted 4 lines
It seems that this patch is incorrect, if the no-zero pages are zeroed again during !ram_bulk_stage, we didn't send the new zeroed page, there will be an error.
If not in
ram_bulk_stage, still send the header, could you explain why it'swrong?
Quoted 3 lines
Liang
I have made a mistake, and yes, this patch can speed up the live migration time, especially when there are many zero pages, it will be more obvious. I like this idea. Did you test it with postcopy ? Does it break postcopy ?
Quoted 9 lines
Quoted 4 lines
Not yet, I saw Dave's comment's, it will beak post copy, it's not hard to fix this.
A more important thing is Paolo's comments, I don't know in which case this patch will break LM. Do you have any idea about this? Hope that QEMU don't write data to the block 'pc.ram'.Paolo is right, for VM in destination, QEMU may write VM's memory before VM starts. So your assumption that "VM's RAM pages are initialized to zero" is incorrect. This patch will break LM.
Actually, someone has done like that before and cause a migration bug, See commit f1c72795af573b24a7da5eb52375c9aba8a37972, and the fixing patch is
commit 9ef051e5536b6368a1076046ec6c4ec4ac12b5c6
Revert "migration: do not sent zero pages in bulk stage"
Quoted 9 lines
Quoted 8 lines
Liang
Quoted 3 lines
Thanks,
zhanghailiang.
Quoted 4 lines
Actually, someone has done like that before and cause a migration bug, See commit
f1c72795af573b24a7da5eb52375c9aba8a37972, and the fixing patch is commit9ef051e5536b6368a1076046ec6c4ec4ac12b5c6
Revert "migration: do not sent zero pages in bulk stage"
Thanks for your information, I didn't notice that before. May be there is a workaround solution instead of reverting, I need more investigation.
Liang
Quoted 11 lines · Liang Li
Now that VM's RAM pages are initialized to zero, (VM's RAM is allcated with the
mmap()andMAP_ANONYMOUSoption, ormmap()withoutMAP_SHAREDif hugetlbfs is used.) so there is no need to send the zero page header to destination.For guest just uses a small portions of RAM, this change can avoid allocating all the guest's RAM pages in the destination node after live migration. Another benefit is destination QEMU can save lots of CPU cycles for zero page checking.
Signed-off-by Liang Li <[email protected]>
This does not work. Depending on the board, some pages are written by QEMU before the guest starts. If the guest rewrites them with zeroes, this change breaks migration.
Paolo
Quoted 26 lines
--- migration/ram.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)migration/ram.c +6
-4@@ -705,10 +705,12 @@ static int save_zero_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset,if (is_zero_range (p,TARGET_PAGE_SIZE )) { acct_info.dup_pages++; - *bytes_transferred +=save_page_header (f, block, - offset |RAM_SAVE_FLAG_COMPRESS ); -qemu_put_byte (f,0 ); - *bytes_transferred +=1 ; +if (!ram_bulk_stage) { + *bytes_transferred +=save_page_header (f, block, offset | +RAM_SAVE_FLAG_COMPRESS ); +qemu_put_byte (f,0 ); + *bytes_transferred +=1 ; + } pages =1 ; }
Quoted 12 lines · Liang Li
Quoted 2 lines
Now that VM's RAM pages are initialized to zero, (VM's RAM is allcated with the
mmap()andMAP_ANONYMOUSoption, ormmap()without
MAP_SHAREDQuoted 8 lines
if hugetlbfs is used.) so there is no need to send the zero page header to destination.
For guest just uses a small portions of RAM, this change can avoid allocating all the guest's RAM pages in the destination node after live migration. Another benefit is destination QEMU can save lots of CPU cycles for zero page checking.
Quoted 7 lines
Quoted 1 line
Signed-off-by Liang Li <[email protected]>This does not work. Depending on the board, some pages are written by QEMU before the guest starts. If the guest rewrites them with zeroes, this change breaks migration.
Paolo
Hi Paolo,
Luckily I cc to you. Could you give an example in which case this patch will break migration?
Then I can understand your comments better. Much appreciate!
Liang
Quoted 29 lines
migration/ram.c static int save_zero_page(QEMUFile *f,
Quoted 10 lines
--- migration/ram.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)migration/ram.c index 4e606ab..c4821d1 renamed from migration/ram.c +0
-0100644
migration/ram.c +0
-0@@ -705,10 +705,12 @@ static int save_zero_page(QEMUFile *f,RAMBlock
Quoted 18 lines
migration/ram.c +6
-4*block, ram_addr_t offset, if (is_zero_range(p, TARGET_PAGE_SIZE)) { acct_info.dup_pages++; - *bytes_transferred +=save_page_header (f, block, - offset |RAM_SAVE_FLAG_COMPRESS ); -qemu_put_byte (f,0 ); - *bytes_transferred +=1 ; +if (!ram_bulk_stage) { + *bytes_transferred +=save_page_header (f, block, offset | +RAM_SAVE_FLAG_COMPRESS ); +qemu_put_byte (f,0 ); + *bytes_transferred +=1 ; + } pages =1 ; }
Quoted 9 lines · * Liang Li ([email protected]) wrote:
Now that VM's RAM pages are initialized to zero, (VM's RAM is allcated with the
mmap()andMAP_ANONYMOUSoption, ormmap()withoutMAP_SHAREDif hugetlbfs is used.) so there is no need to send the zero page header to destination.For guest just uses a small portions of RAM, this change can avoid allocating all the guest's RAM pages in the destination node after live migration. Another benefit is destination QEMU can save lots of CPU cycles for zero page checking.
I think this would break postcopy, because the zero pages wouldn't be filled in, so accessing them would still generate a userfault. So you'd have to disable this optimisation if postcopy is enabled (even during the precopy bulk stage).
Also, are you sure about the benefits?
Destination guests RAM should not be allocated on receiving a zero
page; see ram_handle_compressed, it doesn't write to the page if it's zero, so it shouldn't cause an allocate. I think you're probably correct about the zero page test on the destination, I wonder if we can speed that up.
Dave
Quoted 30 lines
Signed-off-by Liang Li <[email protected]>--- migration/ram.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)migration/ram.c +6
-4@@ -705,10 +705,12 @@ static int save_zero_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset,if (is_zero_range (p,TARGET_PAGE_SIZE )) { acct_info.dup_pages++; - *bytes_transferred +=save_page_header (f, block, - offset |RAM_SAVE_FLAG_COMPRESS ); -qemu_put_byte (f,0 ); - *bytes_transferred +=1 ; +if (!ram_bulk_stage) { + *bytes_transferred +=save_page_header (f, block, offset | +RAM_SAVE_FLAG_COMPRESS ); +qemu_put_byte (f,0 ); + *bytes_transferred +=1 ; + } pages =1 ; }Signature · 1 line
1.9.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 17 lines · * Liang Li ([email protected]) wrote:
Quoted 2 lines
Now that VM's RAM pages are initialized to zero, (VM's RAM is allcated with the
mmap()andMAP_ANONYMOUSoption, ormmap()without
MAP_SHAREDQuoted 7 lines
if hugetlbfs is used.) so there is no need to send the zero page header to destination.
For guest just uses a small portions of RAM, this change can avoid allocating all the guest's RAM pages in the destination node after live migration. Another benefit is destination QEMU can save lots of CPU cycles for zero page checking.
I think this would break postcopy, because the zero pages wouldn't be filled in, so accessing them would still generate a userfault.
So you'd have to disable this optimisation if postcopy is enabled (even during the precopy bulk stage).
Quoted 7 lines
Also, are you sure about the benefits?
Destination guests RAM should not be allocated on receiving a zero page;
seeram_handle_compressed, it doesn't write to the page if it's zero, so it shouldn't cause an allocate. I think you're probably correct about the zero page test on the destination, I wonder if we can speed that up.Dave
I have test the performance, with a 8G guest just booted, this patch can reduce total live migration time about 10%. Unfortunately, Paolo said this patch would break LM in some case ....
For the zero page test on the destination, if the page is really a zero page, test is faster than writing a whole page of zero.
Liang
Quoted 23 lines · * Li, Liang Z ([email protected]) wrote:
Quoted 23 lines · * Liang Li ([email protected]) wrote:
Quoted 2 lines
Now that VM's RAM pages are initialized to zero, (VM's RAM is allcated with the
mmap()andMAP_ANONYMOUSoption, ormmap()without
MAP_SHAREDQuoted 7 lines
if hugetlbfs is used.) so there is no need to send the zero page header to destination.
For guest just uses a small portions of RAM, this change can avoid allocating all the guest's RAM pages in the destination node after live migration. Another benefit is destination QEMU can save lots of CPU cycles for zero page checking.
I think this would break postcopy, because the zero pages wouldn't be filled in, so accessing them would still generate a userfault.
So you'd have to disable this optimisation if postcopy is enabled (even during the precopy bulk stage).Also, are you sure about the benefits?
Destination guests RAM should not be allocated on receiving a zero page;
seeram_handle_compressed, it doesn't write to the page if it's zero, so it shouldn't cause an allocate. I think you're probably correct about the zero page test on the destination, I wonder if we can speed that up.
Quoted 6 lines
Quoted 1 line
Dave
I have test the performance, with a 8G guest just booted, this patch can reduce total live migration time about 10%. Unfortunately, Paolo said this patch would break LM in some case ....
For the zero page test on the destination, if the page is really a zero page, test is faster than writing a whole page of zero.
There shouldn't be a write on the destination though; it does a check if the page is already zero and only if it's none-zero does it do the write; it should rarely be non-zero.
Dave
Quoted 4 lines
Liang
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 16 lines · Dr. David Alan Gilbert
Quoted 9 lines · * Liang Li ([email protected]) wrote:
Now that VM's RAM pages are initialized to zero, (VM's RAM is allcated with the
mmap()andMAP_ANONYMOUSoption, ormmap()withoutMAP_SHAREDif hugetlbfs is used.) so there is no need to send the zero page header to destination.For guest just uses a small portions of RAM, this change can avoid allocating all the guest's RAM pages in the destination node after live migration. Another benefit is destination QEMU can save lots of CPU cycles for zero page checking.
I think this would break postcopy, because the zero pages wouldn't be filled in, so accessing them would still generate a userfault. So you'd have to disable this optimisation if postcopy is enabled (even during the precopy bulk stage).
Quoted 7 lines
Also, are you sure about the benefits?
Destination guests RAM should not be allocated on receiving a zero
page; seeram_handle_compressed, it doesn't write to the page if it's zero, so it shouldn't cause an allocate. I think you're probably correct about the zero page test on the destination, I wonder if we can speed that up.
Yes, we have already optimize the zero page allocation in destination. but this patch can reduce the amount of data that transferred and the time of checking zero page, which can reduce the migration time.
Quoted 37 lines
Dave
Quoted 28 lines
Signed-off-by Liang Li <[email protected]>--- migration/ram.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)migration/ram.c +6
-5@@ -705,10 +705,12 @@ static int save_zero_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset,if (is_zero_range (p,TARGET_PAGE_SIZE )) { acct_info.dup_pages++; - *bytes_transferred +=save_page_header (f, block, - offset |RAM_SAVE_FLAG_COMPRESS ); -qemu_put_byte (f,0 ); - *bytes_transferred +=1 ; +if (!ram_bulk_stage) { + *bytes_transferred +=save_page_header (f, block, offset | +RAM_SAVE_FLAG_COMPRESS ); +qemu_put_byte (f,0 ); + *bytes_transferred +=1 ; + } pages =1 ; } --Quoted 2 lines
1.9.1
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK.