migration/ram: Some modifications about ram_save_host_page()
cover migration/ram: Some modifications about ram_save_host_page()
Hi,
This series include patches as below:
Patch 1-2:
- modified the comment and code of ram_save_host_page() to make them match each other
Patch 3:
- optimized ram_save_host_page() by using migration_bitmap_find_dirty() to find dirty pages
Best Regards
Kunkun Jiang
Kunkun Jiang (3):
migration/ram: Modify the code comment of ram_save_host_page() migration/ram: Modify ram_save_host_page() to match the comment migration/ram: Optimize ram_save_host_page()
migration/ram.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-)
Signature · 1 line
2.23.0
PATCH 1/3 migration/ram: Modify the code comment of ram_save_host_page()
The ram_save_host_page() has been modified several times since its birth. But the comment hasn't been modified as it should be. It'd better to modify the comment to explain ram_save_host_page() more clearly.
--- migration/ram.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
migration/ram.c +9 -8
@@ -1970,15 +1970,16 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss, }/** -* ram_save_host_page: save a whole host page +* ram_save_host_page: save a whole host page or the rest of a block * -* Starting at *offset send pages up to the end of the current host -* page. It's valid for the initial offset to point into the middle of -* a host page in which case the remainder of the hostpage is sent. -* Only dirty target pages are sent. Note that the host page size may -* be a huge page for this block. -* The saving stops at the boundary of the used_length of the block -* if the RAMBlock isn't a multiple of the host page size. +* Starting at pss->page send pages up to the end of the current host +* page or the boundary of used_length of the block (if the RAMBlock +* isn't a multiple of the host page size). The min one is selected. +* Only dirty target pages are sent. +* +* Note that the host page size may be a huge page for this block, it's +* valid for the initial offset to point into the middle of a host page +* in which case the remainder of the hostpage is sent. * * Returns the number of pages written or negative on error *
Signature · 1 line
2.23.0
Re: [PATCH 1/3] migration/ram: Modify the code comment of ram_save_host_page()
Quoted 27 lines · Kunkun Jiang
The
ram_save_host_page()has been modified several times since its birth. But the comment hasn't been modified as it should be. It'd better to modify the comment to explainram_save_host_page()more clearly.Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Kunkun Jiang <[email protected]>--- migration/ram.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)migration/ram.c +1
-6@@ -1970,15 +1970,16 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss, }/** -* ram_save_host_page: save a whole host page +* ram_save_host_page: save a whole host page or the rest of a block * -* Starting at *offset send pages up to the end of the current host -* page. It's valid for the initial offset to point into the middle of -* a host page in which case the remainder of the hostpage is sent. -* Only dirty target pages are sent. Note that the host page size may -* be a huge page for this block.
migration/ram.c static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss, · line 1982
Quoted 10 lines
migration/ram.c +8
-2-* The saving stops at the boundary of the used_length of the block -* if the RAMBlock isn't a multiple of the host page size. +* Starting at pss->page send pages up to the end of the current host +* page or the boundary of used_length of the block (if the RAMBlock +* isn't a multiple of the host page size). The min one is selected. +* Only dirty target pages are sent. +* +* Note that the host page size may be a huge page for this block, it's +* valid for the initial offset to point into the middle of a host page +* in which case the remainder of the hostpage is sent.
How about:
* Send dirty pages between pss->page and either the end of that page or
* the used_length of the RAMBlock, whichever is smaller.
*
* Note that if the host page is a huge page, pss->page may be in the
* middle of that page.
Quoted 5 lines
migration/ram.c +0
-0* * Returns the number of pages written or negative on error * Signature · 1 line
2.23.0
dme.
Signature · 1 line
I'm in with the in crowd, I know every latest dance.
Re: [PATCH 1/3] migration/ram: Modify the code comment of ram_save_host_page()
Quoted 41 lines · David Edmondson
Quoted 27 lines · Kunkun Jiang
The
ram_save_host_page()has been modified several times since its birth. But the comment hasn't been modified as it should be. It'd better to modify the comment to explainram_save_host_page()more clearly.Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Kunkun Jiang <[email protected]>--- migration/ram.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)migration/ram.c +1
-6@@ -1970,15 +1970,16 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss, }/** -* ram_save_host_page: save a whole host page +* ram_save_host_page: save a whole host page or the rest of a block * -* Starting at *offset send pages up to the end of the current host -* page. It's valid for the initial offset to point into the middle of -* a host page in which case the remainder of the hostpage is sent. -* Only dirty target pages are sent. Note that the host page size may -* be a huge page for this block. migration/ram.c static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss, · line 1982
Quoted 10 lines
migration/ram.c +8
-2-* The saving stops at the boundary of the used_length of the block -* if the RAMBlock isn't a multiple of the host page size. +* Starting at pss->page send pages up to the end of the current host +* page or the boundary of used_length of the block (if the RAMBlock +* isn't a multiple of the host page size). The min one is selected. +* Only dirty target pages are sent. +* +* Note that the host page size may be a huge page for this block, it's +* valid for the initial offset to point into the middle of a host page +* in which case the remainder of the hostpage is sent. How about:
Quoted 5 lines
* Send dirty pages between
pss->pageand either the end of that page or
* theused_lengthof the RAMBlock, whichever is smaller.
*
* Note that if the host page is a huge page,pss->pagemay be in the
* middle of that page.
Thank you. It looks concise and comprehensive.
Best Regards
Kunkun Jiang
Quoted 6 lines
Quoted 5 lines
migration/ram.c +0
-0* * Returns the number of pages written or negative on error * Signature · 1 line
2.23.0dme.
PATCH 2/3 migration/ram: Modify ram_save_host_page() to match the comment
In reply to Kunkun JiangAccording to the comment, when the host page is a huge page, the migration_rate_limit() should be executed. If not, this function can be omitted to save time.
--- migration/ram.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
migration/ram.c +3 -1
@@ -2017,7 +2017,9 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, pages += tmppages; pss->page++;/* Allow rate limiting to happen in the middle of huge pages */ -migration_rate_limit (); +if (pagesize_bits >1 ) { +migration_rate_limit (); + } }while ((pss->page & (pagesize_bits -1 )) &&offset_in_ramblock (pss->block, ((ram_addr_t )pss->page) <<TARGET_PAGE_BITS ));
Signature · 1 line
2.23.0
PATCH 3/3 migration/ram: Optimize ram_save_host_page()
In reply to Kunkun JiangStarting from pss->page, ram_save_host_page() will check every page and send the dirty pages up to the end of the current host page or the boundary of used_length of the block. If the host page size is a huge page, the step "check" will take a lot of time.
This will improve performance to use migration_bitmap_find_dirty().
--- migration/ram.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
migration/ram.c +8 -6
@@ -1994,6 +1994,8 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss,int tmppages, pages =0 ;size_t pagesize_bits =qemu_ram_pagesize (pss->block) >>TARGET_PAGE_BITS ; +unsigned long hostpage_boundary = +QEMU_ALIGN_UP (pss->page +1 , pagesize_bits);unsigned long start_page = pss->page;int res;
@@ -2005,8 +2007,7 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, do { /* Check the pages is dirty and if it is send it */ if (!migration_bitmap_clear_dirty(rs, pss->block, pss->page)) { - pss->page++; - continue; + goto find_next; } tmppages = ram_save_target_page(rs, pss, last_stage);
@@ -2015,16 +2016,17 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, } pages += tmppages; - pss->page++;/* Allow rate limiting to happen in the middle of huge pages */ if (pagesize_bits >1 ) {migration_rate_limit (); } - }while ((pss->page & (pagesize_bits -1 )) && +find_next: + pss->page =migration_bitmap_find_dirty (rs, pss->block, pss->page); + }while ((pss->page < hostpage_boundary) &&offset_in_ramblock (pss->block, ((ram_addr_t )pss->page) <<TARGET_PAGE_BITS )); -/* The offset we leave with is the last one we looked at */ - pss->page--; +/* The offset we leave with is the min boundary of host page and block */ + pss->page =MIN (pss->page, hostpage_boundary) -1 ; res =ram_save_release_protection (rs, pss, start_page);return (res <0 ? res : pages);
Signature · 1 line
2.23.0
Re: [PATCH 3/3] migration/ram: Optimize ram_save_host_page()
Quoted 41 lines · Kunkun Jiang
Starting from
pss->page,ram_save_host_page()will check every page and send the dirty pages up to the end of the current host page or the boundary ofused_lengthof the block. If the host page size is a huge page, the step "check" will take a lot of time.This will improve performance to use
migration_bitmap_find_dirty().Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Kunkun Jiang <[email protected]>--- migration/ram.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)migration/ram.c +3
-3@@ -1994,6 +1994,8 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss,int tmppages, pages =0 ;size_t pagesize_bits =qemu_ram_pagesize (pss->block) >>TARGET_PAGE_BITS ; +unsigned long hostpage_boundary = +QEMU_ALIGN_UP (pss->page +1 , pagesize_bits);unsigned long start_page = pss->page;int res;@@ -2005,8 +2007,7 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, do { /* Check the pages is dirty and if it is send it */ if (!migration_bitmap_clear_dirty(rs, pss->block, pss->page)) { - pss->page++; - continue; + goto find_next; } tmppages = ram_save_target_page(rs, pss, last_stage);@@ -2015,16 +2016,17 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, } pages += tmppages; - pss->page++;
migration/ram.c static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, · line 2027
Quoted 10 lines
migration/ram.c +3
-1/* Allow rate limiting to happen in the middle of huge pages */ if (pagesize_bits >1 ) {migration_rate_limit (); } - }while ((pss->page & (pagesize_bits -1 )) && +find_next: + pss->page =migration_bitmap_find_dirty (rs, pss->block, pss->page); + }while ((pss->page < hostpage_boundary) &&offset_in_ramblock (pss->block, ((ram_addr_t )pss->page) <<TARGET_PAGE_BITS ));
This ends up looking very messy, with a goto inside the loop.
Wouldn't it be cleaner to invert the sense of the migration_bitmap_clear_dirty() test, such that migration_bitmap_find_dirty() is called after the body of the test?
Quoted 9 lines
migration/ram.c +2
-2-/* The offset we leave with is the last one we looked at */ - pss->page--; +/* The offset we leave with is the min boundary of host page and block */ + pss->page =MIN (pss->page, hostpage_boundary) -1 ; res =ram_save_release_protection (rs, pss, start_page);return (res <0 ? res : pages);Signature · 1 line
2.23.0
dme.
Signature · 1 line
Oliver darling, call Mister Haney, I think our speakers are blown.
Re: [PATCH 3/3] migration/ram: Optimize ram_save_host_page()
Quoted 55 lines · David Edmondson
Quoted 41 lines · Kunkun Jiang
Starting from
pss->page,ram_save_host_page()will check every page and send the dirty pages up to the end of the current host page or the boundary ofused_lengthof the block. If the host page size is a huge page, the step "check" will take a lot of time.This will improve performance to use
migration_bitmap_find_dirty().Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Kunkun Jiang <[email protected]>--- migration/ram.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)migration/ram.c +3
-3@@ -1994,6 +1994,8 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss,int tmppages, pages =0 ;size_t pagesize_bits =qemu_ram_pagesize (pss->block) >>TARGET_PAGE_BITS ; +unsigned long hostpage_boundary = +QEMU_ALIGN_UP (pss->page +1 , pagesize_bits);unsigned long start_page = pss->page;int res;@@ -2005,8 +2007,7 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, do { /* Check the pages is dirty and if it is send it */ if (!migration_bitmap_clear_dirty(rs, pss->block, pss->page)) { - pss->page++; - continue; + goto find_next; } tmppages = ram_save_target_page(rs, pss, last_stage);@@ -2015,16 +2016,17 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, } pages += tmppages; - pss->page++;migration/ram.c static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, · line 2027
Quoted 10 lines
migration/ram.c +3
-1/* Allow rate limiting to happen in the middle of huge pages */ if (pagesize_bits >1 ) {migration_rate_limit (); } - }while ((pss->page & (pagesize_bits -1 )) && +find_next: + pss->page =migration_bitmap_find_dirty (rs, pss->block, pss->page); + }while ((pss->page < hostpage_boundary) &&offset_in_ramblock (pss->block, ((ram_addr_t )pss->page) <<TARGET_PAGE_BITS ));This ends up looking very messy, with a goto inside the loop.
Quoted 3 lines
Wouldn't it be cleaner to invert the sense of the
migration_bitmap_clear_dirty()test, such thatmigration_bitmap_find_dirty()is called after the body of the test?
Sorry for the late reply.
Thanks for your advice. I will post a v2 as soon as possible.
Best Regards.
Kunkun Jiang
Quoted 10 lines
Quoted 9 lines
migration/ram.c +2
-2-/* The offset we leave with is the last one we looked at */ - pss->page--; +/* The offset we leave with is the min boundary of host page and block */ + pss->page =MIN (pss->page, hostpage_boundary) -1 ; res =ram_save_release_protection (rs, pss, start_page);return (res <0 ? res : pages);Signature · 1 line
2.23.0dme.