x86/ioreq server: Optimize p2m cleaning up code in p2m_finish_type_change().
RFC PATCH 1/1 x86/ioreq server: Optimize p2m cleaning up code in p2m_finish_type_change().
Previously, p2m_finish_type_change() is triggered to iterate and clean up the p2m table when an ioreq server unmaps from memory type HVMMEM_ioreq_server. And the current iteration number is set to 256 And after these iterations, hypercall pre-emption is checked.
But it is likely that no p2m change is performed for the just finished iterations, which means p2m_finish_type_change() will return quite soon. So in such scenario, we can allow the p2m iteration to continue, without checking the hypercall pre-emption.
---
Note: this patch shall only be accepted after previous x86/ioreq server patches be merged.
--- xen/arch/x86/hvm/dm.c | 5 ++++- xen/arch/x86/mm/p2m.c | 9 ++++++++- xen/include/asm-x86/p2m.h | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/dm.c +4 -1
@@ -411,14 +411,17 @@ static int dm_op(domid_t domid,while (read_atomic (&p2m->ioreq.entry_count) && first_gfn <= p2m->max_mapped_pfn ) { +bool changed = false; +/* Iterate p2m table for 256 gfns each time. */ p2m_finish_type_change (d,_gfn (first_gfn),256 , - p2m_ioreq_server, p2m_ram_rw); + p2m_ioreq_server, p2m_ram_rw, &changed); first_gfn +=256 ;/* Check for continuation if it's not the last iteration. */ if ( first_gfn <= p2m->max_mapped_pfn && + changed &&hypercall_preempt_check () ) { rc = -ERESTART ;
xen/arch/x86/mm/p2m.c +8 -1
@@ -1034,12 +1034,13 @@ void p2m_change_type_range(struct domain *d,/* Synchronously modify the p2m type for a range of gfns from ot to nt. */ void p2m_finish_type_change (struct domain *d,gfn_t first_gfn,unsigned long max_nr, -p2m_type_t ot,p2m_type_t nt) +p2m_type_t ot,p2m_type_t nt,bool *changed) {struct p2m_domain *p2m =p2m_get_hostp2m (d);p2m_type_t t;unsigned long gfn =gfn_x (first_gfn);unsigned long last_gfn = gfn + max_nr -1 ; +bool is_changed = false;ASSERT (ot != nt);ASSERT (p2m_is_changeable (ot) &&p2m_is_changeable (nt));
@@ -1052,12 +1053,18 @@ void p2m_finish_type_change(struct domain *d,get_gfn_query_unlocked (d, gfn, &t);if ( t == ot ) + {p2m_change_type_one (d, gfn, t, nt); + is_changed = true; + } gfn++; }p2m_unlock (p2m); + +if ( changed ) + *changed = is_changed; }/*
xen/include/asm-x86/p2m.h +1 -1
@@ -615,7 +615,7 @@ int p2m_change_type_one(struct domain *d, unsigned long gfn,void p2m_finish_type_change (struct domain *d,gfn_t first_gfn,unsigned long max_nr, -p2m_type_t ot,p2m_type_t nt); +p2m_type_t ot,p2m_type_t nt,bool *changed);/* Report a change affecting memory types. */ void p2m_memory_type_changed (struct domain *d);
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 9 lines · Yu Zhang
Previously,
p2m_finish_type_change()is triggered to iterate and clean up the p2m table when an ioreq server unmaps from memory typeHVMMEM_ioreq_server. And the current iteration number is set to 256 And after these iterations, hypercall pre-emption is checked.But it is likely that no p2m change is performed for the just finished iterations, which means
p2m_finish_type_change()will return quite soon. So in such scenario, we can allow the p2m iteration to continue, without checking the hypercall pre-emption.
Suppose you have a guest with 128TiB of RAM, and the ioreq_server p2m entries are at the very end of RAM. Won't this run for several minutes before even allowing preemption?
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 6 lines · George Dunlap
Quoted 5 lines · Yu Zhang
Previously,
p2m_finish_type_change()is triggered to iterate and clean up the p2m table when an ioreq server unmaps from memory typeHVMMEM_ioreq_server. And the current iteration number is set to 256 And after these iterations, hypercall pre-emption is checked.
Quoted 8 lines
Quoted 4 lines
But it is likely that no p2m change is performed for the just finished iterations, which means
p2m_finish_type_change()will return quite soon. So in such scenario, we can allow the p2m iteration to continue, without checking the hypercall pre-emption.Suppose you have a guest with 128TiB of RAM, and the
ioreq_serverp2m entries are at the very end of RAM. Won't this run for several minutes before even allowing preemption?
Sorry, this should be GiB. But I think you get my point. :-)
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 7 lines · George Dunlap
Quoted 6 lines · George Dunlap
Quoted 5 lines · Yu Zhang
Previously,
p2m_finish_type_change()is triggered to iterate and clean up the p2m table when an ioreq server unmaps from memory typeHVMMEM_ioreq_server. And the current iteration number is set to 256 And after these iterations, hypercall pre-emption is checked.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
But it is likely that no p2m change is performed for the just finished iterations, which means
p2m_finish_type_change()will return quite soon. So in such scenario, we can allow the p2m iteration to continue, without checking the hypercall pre-emption.Suppose you have a guest with 128TiB of RAM, and the
ioreq_serverp2m entries are at the very end of RAM. Won't this run for several minutes before even allowing preemption?Sorry, this should be GiB. But I think you get my point. :-)
Yep. I got it.
I'd better reconsider it - my head is quite dizzy now. Maybe together with your generic p2m change solution in 4.10. :-)
Thanks
Yu
Quoted 4 lines
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 05.04.17 at 10:59, <[email protected]> wrote:
xen/arch/x86/hvm/dm.c +2
-1@@ -411,14 +411,17 @@ static int dm_op(domid_t domid,while (read_atomic (&p2m->ioreq.entry_count) && first_gfn <= p2m->max_mapped_pfn ) { +bool changed = false; +/* Iterate p2m table for 256 gfns each time. */ p2m_finish_type_change(d, _gfn(first_gfn), 256, - p2m_ioreq_server, p2m_ram_rw);
xen/arch/x86/hvm/dm.c static int dm_op(domid_t domid, · line 427
Quoted 10 lines
xen/arch/x86/hvm/dm.c +2
-0+ p2m_ioreq_server, p2m_ram_rw, &changed); first_gfn +=256 ;/* Check for continuation if it's not the last iteration. */ if ( first_gfn <= p2m->max_mapped_pfn && + changed &&hypercall_preempt_check () ) { rc = -ERESTART ;
I appreciate and support the intention, but you're opening up a long lasting loop here in case very little or no changes need to be done. You need to check for preemption every so many iterations even if you've never seen "changed" come back set.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 05.04.17 at 10:59, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +4
-1@@ -1034,12 +1034,13 @@ void p2m_change_type_range(struct domain *d,/* Synchronously modify the p2m type for a range of gfns from ot to nt. */ void p2m_finish_type_change (struct domain *d,gfn_t first_gfn,unsigned long max_nr, -p2m_type_t ot,p2m_type_t nt) +p2m_type_t ot,p2m_type_t nt,bool *changed) {struct p2m_domain *p2m =p2m_get_hostp2m (d);p2m_type_t t;unsigned long gfn =gfn_x (first_gfn);unsigned long last_gfn = gfn + max_nr -1 ; +bool is_changed = false;ASSERT (ot != nt);ASSERT (p2m_is_changeable (ot) &&p2m_is_changeable (nt));@@ -1052,12 +1053,18 @@ void p2m_finish_type_change(struct domain *d,get_gfn_query_unlocked (d, gfn, &t);if ( t == ot ) + {p2m_change_type_one (d, gfn, t, nt); + is_changed = true;
xen/arch/x86/mm/p2m.c void p2m_finish_type_change(struct domain *d, · line 1068
Quoted 10 lines
xen/arch/x86/mm/p2m.c +4
-0+ } gfn++; }p2m_unlock (p2m); + +if ( changed ) + *changed = is_changed; }
Also, wouldn't it be better to return a count here? If there was just a single change in the current 256-GFN batch, surely we could take on another?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 05.04.17 at 10:59, <[email protected]> wrote:
xen/arch/x86/hvm/dm.c +3
-1@@ -411,14 +411,17 @@ static int dm_op(domid_t domid,while (read_atomic (&p2m->ioreq.entry_count) && first_gfn <= p2m->max_mapped_pfn ) { +bool changed = false; +/* Iterate p2m table for 256 gfns each time. */ p2m_finish_type_change (d,_gfn (first_gfn),256 , - p2m_ioreq_server, p2m_ram_rw); + p2m_ioreq_server, p2m_ram_rw, &changed); first_gfn +=256 ;
Quoted 10 lines
xen/arch/x86/hvm/dm.c static int dm_op(domid_t domid, · line 427
Quoted 6 lines
xen/arch/x86/hvm/dm.c +1
-0/* Check for continuation if it's not the last iteration. */ if ( first_gfn <= p2m->max_mapped_pfn && + changed &&hypercall_preempt_check () ) { rc = -ERESTART ;I appreciate and support the intention, but you're opening up a long lasting loop here in case very little or no changes need to be done. You need to check for preemption every so many iterations even if you've never seen "changed" come back set.
Thanks for your comments, Jan.
Indeed, this patch is problematic. Another thought is - since current p2m sweeping implementation disables live migration when there's ioreq server entries left, and George had proposed a generic p2m change solution previously. I'd like to leave the optimization together with the generic solution in future xen release. :-)
Yu
Quoted 7 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel