* [PATCH 0/3] migration/ram: Some modifications about ram_save_host_page() @ 2021-02-23 2:16 Kunkun Jiang 2021-02-23 2:16 ` [PATCH 1/3] migration/ram: Modify the code comment of ram_save_host_page() Kunkun Jiang ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Kunkun Jiang @ 2021-02-23 2:16 UTC (permalink / raw) To: Juan Quintela, Dr . David Alan Gilbert, open list:All patches CC here Cc: Zenghui Yu, wanghaibin.wang, Keqian Zhu 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(-) -- 2.23.0 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] migration/ram: Modify the code comment of ram_save_host_page() 2021-02-23 2:16 [PATCH 0/3] migration/ram: Some modifications about ram_save_host_page() Kunkun Jiang @ 2021-02-23 2:16 ` Kunkun Jiang 2021-02-24 22:53 ` David Edmondson 2021-02-23 2:16 ` [PATCH 2/3] migration/ram: Modify ram_save_host_page() to match the comment Kunkun Jiang 2021-02-23 2:16 ` [PATCH 3/3] migration/ram: Optimize ram_save_host_page() Kunkun Jiang 2 siblings, 1 reply; 8+ messages in thread From: Kunkun Jiang @ 2021-02-23 2:16 UTC (permalink / raw) To: Juan Quintela, Dr . David Alan Gilbert, open list:All patches CC here Cc: Zenghui Yu, wanghaibin.wang, Keqian Zhu 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. Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com> Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com> --- migration/ram.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 72143da0ac..fc49c3f898 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -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 * -- 2.23.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] migration/ram: Modify the code comment of ram_save_host_page() 2021-02-23 2:16 ` [PATCH 1/3] migration/ram: Modify the code comment of ram_save_host_page() Kunkun Jiang @ 2021-02-24 22:53 ` David Edmondson 2021-02-25 8:16 ` Kunkun Jiang 0 siblings, 1 reply; 8+ messages in thread From: David Edmondson @ 2021-02-24 22:53 UTC (permalink / raw) To: Kunkun Jiang, Juan Quintela, Dr . David Alan Gilbert, open list:All patches CC here Cc: Zenghui Yu, wanghaibin.wang, Keqian Zhu On Tuesday, 2021-02-23 at 10:16:43 +08, Kunkun Jiang wrote: > 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. > > Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com> > Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com> > --- > migration/ram.c | 17 +++++++++-------- > 1 file changed, 9 insertions(+), 8 deletions(-) > > diff --git a/migration/ram.c b/migration/ram.c > index 72143da0ac..fc49c3f898 100644 > --- a/migration/ram.c > +++ b/migration/ram.c > @@ -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. 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. > * > * Returns the number of pages written or negative on error > * > -- > 2.23.0 dme. -- I'm in with the in crowd, I know every latest dance. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] migration/ram: Modify the code comment of ram_save_host_page() 2021-02-24 22:53 ` David Edmondson @ 2021-02-25 8:16 ` Kunkun Jiang 0 siblings, 0 replies; 8+ messages in thread From: Kunkun Jiang @ 2021-02-25 8:16 UTC (permalink / raw) To: David Edmondson, Juan Quintela, Dr . David Alan Gilbert, open list:All patches CC here Cc: Zenghui Yu, wanghaibin.wang, Keqian Zhu On 2021/2/25 6:53, David Edmondson wrote: > On Tuesday, 2021-02-23 at 10:16:43 +08, Kunkun Jiang wrote: > >> 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. >> >> Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com> >> Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com> >> --- >> migration/ram.c | 17 +++++++++-------- >> 1 file changed, 9 insertions(+), 8 deletions(-) >> >> diff --git a/migration/ram.c b/migration/ram.c >> index 72143da0ac..fc49c3f898 100644 >> --- a/migration/ram.c >> +++ b/migration/ram.c >> @@ -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. > 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. Thank you. It looks concise and comprehensive. Best Regards Kunkun Jiang >> * >> * Returns the number of pages written or negative on error >> * >> -- >> 2.23.0 > dme. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/3] migration/ram: Modify ram_save_host_page() to match the comment 2021-02-23 2:16 [PATCH 0/3] migration/ram: Some modifications about ram_save_host_page() Kunkun Jiang 2021-02-23 2:16 ` [PATCH 1/3] migration/ram: Modify the code comment of ram_save_host_page() Kunkun Jiang @ 2021-02-23 2:16 ` Kunkun Jiang 2021-02-23 2:16 ` [PATCH 3/3] migration/ram: Optimize ram_save_host_page() Kunkun Jiang 2 siblings, 0 replies; 8+ messages in thread From: Kunkun Jiang @ 2021-02-23 2:16 UTC (permalink / raw) To: Juan Quintela, Dr . David Alan Gilbert, open list:All patches CC here Cc: Zenghui Yu, wanghaibin.wang, Keqian Zhu According 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. Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com> Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com> --- migration/ram.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index fc49c3f898..c7e18dc2fc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -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)); -- 2.23.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] migration/ram: Optimize ram_save_host_page() 2021-02-23 2:16 [PATCH 0/3] migration/ram: Some modifications about ram_save_host_page() Kunkun Jiang 2021-02-23 2:16 ` [PATCH 1/3] migration/ram: Modify the code comment of ram_save_host_page() Kunkun Jiang 2021-02-23 2:16 ` [PATCH 2/3] migration/ram: Modify ram_save_host_page() to match the comment Kunkun Jiang @ 2021-02-23 2:16 ` Kunkun Jiang 2021-02-25 12:48 ` David Edmondson 2 siblings, 1 reply; 8+ messages in thread From: Kunkun Jiang @ 2021-02-23 2:16 UTC (permalink / raw) To: Juan Quintela, Dr . David Alan Gilbert, open list:All patches CC here Cc: Zenghui Yu, wanghaibin.wang, Keqian Zhu 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 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(). Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com> Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com> --- migration/ram.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index c7e18dc2fc..c7a2350198 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -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); -- 2.23.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] migration/ram: Optimize ram_save_host_page() 2021-02-23 2:16 ` [PATCH 3/3] migration/ram: Optimize ram_save_host_page() Kunkun Jiang @ 2021-02-25 12:48 ` David Edmondson 2021-03-01 7:33 ` Kunkun Jiang 0 siblings, 1 reply; 8+ messages in thread From: David Edmondson @ 2021-02-25 12:48 UTC (permalink / raw) To: Kunkun Jiang, Juan Quintela, Dr . David Alan Gilbert, open list:All patches CC here Cc: Zenghui Yu, wanghaibin.wang, Keqian Zhu On Tuesday, 2021-02-23 at 10:16:45 +08, Kunkun Jiang wrote: > 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 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(). > > Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com> > Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com> > --- > migration/ram.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/migration/ram.c b/migration/ram.c > index c7e18dc2fc..c7a2350198 100644 > --- a/migration/ram.c > +++ b/migration/ram.c > @@ -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)); 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? > - /* 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); > -- > 2.23.0 dme. -- Oliver darling, call Mister Haney, I think our speakers are blown. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] migration/ram: Optimize ram_save_host_page() 2021-02-25 12:48 ` David Edmondson @ 2021-03-01 7:33 ` Kunkun Jiang 0 siblings, 0 replies; 8+ messages in thread From: Kunkun Jiang @ 2021-03-01 7:33 UTC (permalink / raw) To: David Edmondson, Juan Quintela, Dr . David Alan Gilbert, open list:All patches CC here Cc: Zenghui Yu, wanghaibin.wang, Keqian Zhu On 2021/2/25 20:48, David Edmondson wrote: > On Tuesday, 2021-02-23 at 10:16:45 +08, Kunkun Jiang wrote: > >> 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 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(). >> >> Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com> >> Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com> >> --- >> migration/ram.c | 14 ++++++++------ >> 1 file changed, 8 insertions(+), 6 deletions(-) >> >> diff --git a/migration/ram.c b/migration/ram.c >> index c7e18dc2fc..c7a2350198 100644 >> --- a/migration/ram.c >> +++ b/migration/ram.c >> @@ -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)); > 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? Sorry for the late reply. Thanks for your advice. I will post a v2 as soon as possible. Best Regards. Kunkun Jiang >> - /* 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); >> -- >> 2.23.0 > dme. ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-03-01 7:35 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-02-23 2:16 [PATCH 0/3] migration/ram: Some modifications about ram_save_host_page() Kunkun Jiang 2021-02-23 2:16 ` [PATCH 1/3] migration/ram: Modify the code comment of ram_save_host_page() Kunkun Jiang 2021-02-24 22:53 ` David Edmondson 2021-02-25 8:16 ` Kunkun Jiang 2021-02-23 2:16 ` [PATCH 2/3] migration/ram: Modify ram_save_host_page() to match the comment Kunkun Jiang 2021-02-23 2:16 ` [PATCH 3/3] migration/ram: Optimize ram_save_host_page() Kunkun Jiang 2021-02-25 12:48 ` David Edmondson 2021-03-01 7:33 ` Kunkun Jiang
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.