Optimize S2 page splitting
cover Optimize S2 page splitting
While playing with dirty-bit tracking, I decided to take a look on how page splitting works. Found out all entries are walked, even though we can infer, for instance that:
- If a level-3 entry is walked, it means the parent level-2 entry is split
- If a split just succeeded in an table entry, it means all children nodes are already split
So I tried to optimize it in a way that it does not break other users.
My main idea is to introduce positive return values that hint to the pagetable walking mechanism that either siblings or children can be skipped. That should be contained to the visitor function, that returns zero if no error was detected.
Numbers on above optimization are promising:
A 1GB VM, running on the model, splitting all at the beginning (no manual protect):
- Memory was already split (4k pages): -97.33% runtime (-172ms) - 20 runs
- THP backed memory: -19.82% runtime (-153ms) - 10 runs
- 1x1GB hugetlb memory: -20.65% runtime (-150ms) - 10 runs
This is measured with this snippet[1].
I ran at least 10 times on different 1GB VMs, to make sure the numbers are consistent.
Ideas I considered:
- Using a negative return value, using kvm_pgtable_walk_continue to filter it as a non-error, but decided that is kind of counter-intuitive
- Using the introduced return values to hint the split walker to not splitting level-2 blocks (or level-1), if by adding a new parameter in kvm_pgtable_stage2_split() and carrying it over to the walker using ctx->arg. (Splitting only up to given hugepage size)
- Looking at other walkers, and trying to think on scenarios to optimize them using the new return values.
Do you think it is worth doing this?
Please provide feedback!
Thanks!
Leo
[1]:
arch/arm64/kvm/mmu.c +4 -0
@@ -1272,22 +1273,26 @@ static void kvm_mmu_split_memory_region(struct kvm *kvm, int slot)phys_addr_t start, end;lockdep_assert_held (&kvm->slots_lock); slots =kvm_memslots (kvm); memslot =id_to_memslot (slots, slot); start = memslot->base_gfn <<PAGE_SHIFT ; end = (memslot->base_gfn + memslot->npages) <<PAGE_SHIFT ; +write_lock (&kvm->mmu_lock); +u64 sw =ktime_get_real_ns ();kvm_mmu_split_huge_pages (kvm, start, end); + sw =ktime_get_real_ns () - sw; +printk ("split from %llx to %llx took %llu ns\n" , start, end, sw);write_unlock (&kvm->mmu_lock); }
Leonardo Bras (2):
KVM: arm64: Introduce S2 walker SKIP return options
KVM: arm64: Improve splitting performance by using SKIP return values
arch/arm64/kvm/hyp/pgtable.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)
base-commit: 5d6919055dec134de3c40167a490f33c74c12581
Signature · 1 line
2.54.0
RFC PATCH 1/2 KVM: arm64: Introduce S2 walker SKIP return options
Introduce S2 walker return values:
- SKIP_CHILDREN: skip walking the children of the current node
- SKIP_SIBLINGS: skip waling the siblings of the current node
Also, modify __kvm_pgtable_visit() to fulfil the hing on above return values. Current walkers should not be impacted
--- arch/arm64/kvm/hyp/pgtable.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
arch/arm64/kvm/hyp/pgtable.c +16 -4
@@ -12,20 +12,26 @@#include <asm/stage2_pgtable.h> struct kvm_pgtable_walk_data {struct kvm_pgtable_walker *walker;const u64 start;u64 addr;const u64 end; }; +/* Positive walker return values point levels to skip */ +enum walker_return { +SKIP_CHILDREN =1 , +SKIP_SIBLINGS +}; +static bool kvm_pgtable_walk_skip_bbm_tlbi (const struct kvm_pgtable_visit_ctx *ctx) {return unlikely (ctx->flags &KVM_PGTABLE_WALK_SKIP_BBM_TLBI ); }static bool kvm_pgtable_walk_skip_cmo (const struct kvm_pgtable_visit_ctx *ctx) {return unlikely (ctx->flags &KVM_PGTABLE_WALK_SKIP_CMO ); }
@@ -134,21 +140,21 @@ static bool kvm_pgtable_walk_continue(const struct kvm_pgtable_walker *walker,* update a PTE. In the context of a fault handler this is interpreted * as a signal to retry guest execution. * * Ignore the return code altogether for walkers outside a fault handler * (e.g. write protecting a range of memory) and chug along with the * page table walk. */ if (r == -EAGAIN )return walker->flags &KVM_PGTABLE_WALK_IGNORE_EAGAIN ; -return !r; +return r >=0 ; }static int __kvm_pgtable_walk (struct kvm_pgtable_walk_data *data,struct kvm_pgtable_mm_ops *mm_ops,kvm_pteref_t pgtable,s8 level);static inline int __kvm_pgtable_visit (struct kvm_pgtable_walk_data *data,struct kvm_pgtable_mm_ops *mm_ops,kvm_pteref_t pteref,s8 level) {enum kvm_pgtable_walk_flags flags = data->walker->flags;
@@ -185,23 +191,29 @@ static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data,* into a newly installed or replaced table. */ if (reload) { ctx.old =READ_ONCE (*ptep); table =kvm_pte_table (ctx.old, level); }if (!kvm_pgtable_walk_continue (data->walker, ret)) goto out; -if (!table) { - data->addr =ALIGN_DOWN (data->addr,kvm_granule_size (level)); - data->addr +=kvm_granule_size (level); +if (!table || ret >=SKIP_CHILDREN ) { +u64 size; + +if (ret ==SKIP_SIBLINGS )/* Skip siblings */ + size =kvm_granule_size (level -1 ); +else /* Skip children */ + size =kvm_granule_size (level); + + data->addr =ALIGN_DOWN (data->addr, size) + size; goto out; } childp = (kvm_pteref_t )kvm_pte_follow (ctx.old, mm_ops); ret =__kvm_pgtable_walk (data, mm_ops, childp, level +1 );if (!kvm_pgtable_walk_continue (data->walker, ret)) goto out;if (ctx.flags &KVM_PGTABLE_WALK_TABLE_POST ) ret =kvm_pgtable_visitor_cb (data, &ctx,KVM_PGTABLE_WALK_TABLE_POST );
Signature · 1 line
2.54.0
Oliver Upton
maintainerRe: [RFC PATCH 1/2] KVM: arm64: Introduce S2 walker SKIP return options
Hi Leo,
Thanks for having a look at this.
Quoted 6 lines · Leonardo Bras
Introduce S2 walker return values:
-SKIP_CHILDREN: skip walking the children of the current node
-SKIP_SIBLINGS: skip waling the siblings of the current nodeAlso, modify
__kvm_pgtable_visit()to fulfil the hing on above return values. Current walkers should not be impacted
I'd rather see something based around new walk flags than introducing an entirely new mechanic around return values.
e.g. you could split the LEAF flag into separate flags for blocks v. pages:
KVM_PGTABLE_WALK_PAGE, KVM_PGTABLE_WALK_BLOCK,
KVM_PGTABLE_WALK_LEAF = KVM_PGTABLE_WALK_PAGE |
KVM_PGTABLE_WALK_BLOCK,
and then let __kvm_pgtable_visit() decide how to steer the walk. You may need some special handling to get the address arithmetic right when skipping over a table of page descriptors.
Thanks,
Oliver
Will Deacon
maintainerRe: [RFC PATCH 1/2] KVM: arm64: Introduce S2 walker SKIP return options
Quoted 14 lines · Oliver Upton
Quoted 6 lines · Leonardo Bras
Introduce S2 walker return values:
-SKIP_CHILDREN: skip walking the children of the current node
-SKIP_SIBLINGS: skip waling the siblings of the current nodeAlso, modify
__kvm_pgtable_visit()to fulfil the hing on above return values. Current walkers should not be impactedI'd rather see something based around new walk flags than introducing an entirely new mechanic around return values.
e.g. you could split the LEAF flag into separate flags for blocks v. pages:
Quoted 8 lines
KVM_PGTABLE_WALK_PAGE,KVM_PGTABLE_WALK_BLOCK,
KVM_PGTABLE_WALK_LEAF=KVM_PGTABLE_WALK_PAGE|
KVM_PGTABLE_WALK_BLOCK,and then let
__kvm_pgtable_visit()decide how to steer the walk. You may need some special handling to get the address arithmetic right when skipping over a table of page descriptors.
I was wondering along similar lines, but maybe it would be useful just to pass a maximum level to the walker logic? That feels like the most general case without complicating the existing logic.
Will
Re: [RFC PATCH 1/2] KVM: arm64: Introduce S2 walker SKIP return options
Hello Oliver, Will,
Thanks for reviewing!
Quoted 15 lines · Will Deacon
Quoted 14 lines · Oliver Upton
Quoted 6 lines · Leonardo Bras
Introduce S2 walker return values:
-SKIP_CHILDREN: skip walking the children of the current node
-SKIP_SIBLINGS: skip waling the siblings of the current nodeAlso, modify
__kvm_pgtable_visit()to fulfil the hing on above return values. Current walkers should not be impactedI'd rather see something based around new walk flags than introducing an entirely new mechanic around return values.
e.g. you could split the LEAF flag into separate flags for blocks v. pages:
Quoted 8 lines
Quoted 8 lines
KVM_PGTABLE_WALK_PAGE,KVM_PGTABLE_WALK_BLOCK,
KVM_PGTABLE_WALK_LEAF=KVM_PGTABLE_WALK_PAGE|
KVM_PGTABLE_WALK_BLOCK,and then let
__kvm_pgtable_visit()decide how to steer the walk. You may need some special handling to get the address arithmetic right when skipping over a table of page descriptors.
I am probably not getting the whole inner workings of this solution, but IIUC the idea would be to walk the blocks, but not the pages, right?
Blocks meaning level2- and pages being level3?
Quoted 3 lines
I was wondering along similar lines, but maybe it would be useful just to pass a maximum level to the walker logic? That feels like the most general case without complicating the existing logic.
This proposal seems simpler for me to understand, and indeed looks like a better solution than what I have proposed, taking care of the 'already split' case with better performance, as it don't even walk a single level-3 entry.
On the 'splitting' case, it also works flawlessly if the memory is given in level-2 blocks. There is only one case that I would like to address here:
- Memory given in level-1 blocks (say 1GB)
- Walker flag says 'walk down to level-2 only'
- Split Walker on level-1 will break page down to (up to) level-3 entries.
- Walker will continue to be called on level-2 entries, even though it's not necessary.
To solve this, I would like to suggest a new flag, that skips a table that has just been created. This could be easily implemented in __kvm_page_visit() on top of the max level flags suggested.
enum kvm_pgtable_walk_flags {
[...]
KVM_PGTABLE_WALK_SKIP_LEVEL3 = BIT(7), KVM_PGTABLE_WALK_SKIP_LEVEL2 = BIT(8), KVM_PGTABLE_WALK_SKIP_LEVEL1 = BIT(9), KVM_PGTABLE_WALK_SKIP_NEW_TABLE = BIT(10), };
How does that sound?
Thanks!
Leo
Will Deacon
maintainerRe: [RFC PATCH 1/2] KVM: arm64: Introduce S2 walker SKIP return options
Quoted 42 lines · Leonardo Bras
Hello Oliver, Will,
Thanks for reviewing!Quoted 15 lines · Will Deacon
Quoted 14 lines · Oliver Upton
Quoted 6 lines · Leonardo Bras
Introduce S2 walker return values:
-SKIP_CHILDREN: skip walking the children of the current node
-SKIP_SIBLINGS: skip waling the siblings of the current nodeAlso, modify
__kvm_pgtable_visit()to fulfil the hing on above return values. Current walkers should not be impactedI'd rather see something based around new walk flags than introducing an entirely new mechanic around return values.
e.g. you could split the LEAF flag into separate flags for blocks v. pages:
Quoted 8 lines
Quoted 8 lines
KVM_PGTABLE_WALK_PAGE,KVM_PGTABLE_WALK_BLOCK,
KVM_PGTABLE_WALK_LEAF=KVM_PGTABLE_WALK_PAGE|
KVM_PGTABLE_WALK_BLOCK,and then let
__kvm_pgtable_visit()decide how to steer the walk. You may need some special handling to get the address arithmetic right when skipping over a table of page descriptors.I am probably not getting the whole inner workings of this solution, but IIUC the idea would be to walk the blocks, but not the pages, right?
Blocks meaning level2- and pages being level3?
Quoted 3 lines
I was wondering along similar lines, but maybe it would be useful just to pass a maximum level to the walker logic? That feels like the most general case without complicating the existing logic.
This proposal seems simpler for me to understand, and indeed looks like a better solution than what I have proposed, taking care of the 'already split' case with better performance, as it don't even walk a single level-3 entry.
Quoted 8 lines
On the 'splitting' case, it also works flawlessly if the memory is given in level-2 blocks. There is only one case that I would like to address here:
- Memory given in level-1 blocks (say 1GB)
- Walker flag says 'walk down to level-2 only'
- Split Walker on level-1 will break page down to (up to) level-3 entries.
- Walker will continue to be called on level-2 entries, even though it's not necessary.
If you're only visiting leaves, why would it be called on the level-2 table entries?
Will
Re: [RFC PATCH 1/2] KVM: arm64: Introduce S2 walker SKIP return options
Quoted 46 lines · Will Deacon
Quoted 45 lines · Leonardo Bras
Hello Oliver, Will,
Thanks for reviewing!Quoted 15 lines · Will Deacon
Quoted 14 lines · Oliver Upton
Quoted 6 lines · Leonardo Bras
Introduce S2 walker return values:
-SKIP_CHILDREN: skip walking the children of the current node
-SKIP_SIBLINGS: skip waling the siblings of the current nodeAlso, modify
__kvm_pgtable_visit()to fulfil the hing on above return values. Current walkers should not be impactedI'd rather see something based around new walk flags than introducing an entirely new mechanic around return values.
e.g. you could split the LEAF flag into separate flags for blocks v. pages:
Quoted 8 lines
Quoted 8 lines
KVM_PGTABLE_WALK_PAGE,KVM_PGTABLE_WALK_BLOCK,
KVM_PGTABLE_WALK_LEAF=KVM_PGTABLE_WALK_PAGE|
KVM_PGTABLE_WALK_BLOCK,and then let
__kvm_pgtable_visit()decide how to steer the walk. You may need some special handling to get the address arithmetic right when skipping over a table of page descriptors.I am probably not getting the whole inner workings of this solution, but IIUC the idea would be to walk the blocks, but not the pages, right?
Blocks meaning level2- and pages being level3?
Quoted 3 lines
I was wondering along similar lines, but maybe it would be useful just to pass a maximum level to the walker logic? That feels like the most general case without complicating the existing logic.
This proposal seems simpler for me to understand, and indeed looks like a better solution than what I have proposed, taking care of the 'already split' case with better performance, as it don't even walk a single level-3 entry.
On the 'splitting' case, it also works flawlessly if the memory is given in level-2 blocks. There is only one case that I would like to address here:
Quoted 9 lines
Quoted 5 lines
- Memory given in level-1 blocks (say 1GB)
- Walker flag says 'walk down to level-2 only'
- Split Walker on level-1 will break page down to (up to) level-3 entries.
- Walker will continue to be called on level-2 entries, even though it's not necessary.If you're only visiting leaves, why would it be called on the level-2 table entries?
Because once the leaf is turned into a table by the splitting walker, it gets reloaded and walked. This is an excerpt of __kvm_pgtable_visit():
---
if (!table && (ctx.flags & KVM_PGTABLE_WALK_LEAF)) {
ret = kvm_pgtable_visitor_cb(data, &ctx, KVM_PGTABLE_WALK_LEAF);
reload = true;}
/*
* Reload the page table after invoking the walker callback for leaf
* entries or after pre-order traversal, to allow the walker to descend
* into a newly installed or replaced table.
*/
if (reload) {
ctx.old = READ_ONCE(*ptep);
table = kvm_pte_table(ctx.old, level);}
if (!kvm_pgtable_walk_continue(data->walker, ret))
goto out;
if (!table) {
data->addr = ALIGN_DOWN(data->addr, kvm_granule_size(level));
data->addr += kvm_granule_size(level);
goto out;}
childp = (kvm_pteref_t)kvm_pte_follow(ctx.old, mm_ops); ret = __kvm_pgtable_walk(data, mm_ops, childp, level + 1); if (!kvm_pgtable_walk_continue(data->walker, ret))
goto out;
---
After the leaf is visited, it makes reload=true, which causes the newly created table to be detected as such and waked down. It means even the page that just got split will be walked down to the specified level.
Example:
- Split this level-1 leave:
- Walker creates the whole structure up to given level (currently 3)
- Walker returns, gets reloaded, table detected, go down on that one
- Level 2 entries walked (which is unnecessary)
Please let me know if I am misunderstanding something.
Thanks!
Leo
Will Deacon
maintainerRe: [RFC PATCH 1/2] KVM: arm64: Introduce S2 walker SKIP return options
Quoted 19 lines · Leonardo Bras
Quoted 18 lines · Will Deacon
Quoted 17 lines
Quoted 3 lines
I was wondering along similar lines, but maybe it would be useful just to pass a maximum level to the walker logic? That feels like the most general case without complicating the existing logic.
This proposal seems simpler for me to understand, and indeed looks like a better solution than what I have proposed, taking care of the 'already split' case with better performance, as it don't even walk a single level-3 entry.
On the 'splitting' case, it also works flawlessly if the memory is given in level-2 blocks. There is only one case that I would like to address here:
- Memory given in level-1 blocks (say 1GB)
- Walker flag says 'walk down to level-2 only'
- Split Walker on level-1 will break page down to (up to) level-3 entries.
- Walker will continue to be called on level-2 entries, even though it's not necessary.
Quoted 6 lines
Quoted 3 lines
If you're only visiting leaves, why would it be called on the level-2 table entries?
Because once the leaf is turned into a table by the splitting walker, it gets reloaded and walked. This is an excerpt of
__kvm_pgtable_visit():
Sorry, I was musing about the semantics after adding something to limit the maximum level. I don't dispute what the current code would do.
Quoted 7 lines
Example:
- Split this level-1 leave:
- Walker creates the whole structure up to given level (currently 3)
- Walker returns, gets reloaded, table detected, go down on that one
- Level 2 entries walked (which is unnecessary)Please let me know if I am misunderstanding something.
I just don't grok why this would happen if we limited the maximum level to '2' _and_ said we only wanted to visit the leaf entries. In that case, I wouldn't expect to descend into any of the L2 table entries (because that would imply going beyond level 2) and I wouldn't expect to be called for the table entries either (because we're only interested in leaves).
Will
Re: [RFC PATCH 1/2] KVM: arm64: Introduce S2 walker SKIP return options
Quoted 36 lines · Will Deacon
Quoted 19 lines · Leonardo Bras
Quoted 18 lines · Will Deacon
Quoted 17 lines
Quoted 3 lines
I was wondering along similar lines, but maybe it would be useful just to pass a maximum level to the walker logic? That feels like the most general case without complicating the existing logic.
This proposal seems simpler for me to understand, and indeed looks like a better solution than what I have proposed, taking care of the 'already split' case with better performance, as it don't even walk a single level-3 entry.
On the 'splitting' case, it also works flawlessly if the memory is given in level-2 blocks. There is only one case that I would like to address here:
- Memory given in level-1 blocks (say 1GB)
- Walker flag says 'walk down to level-2 only'
- Split Walker on level-1 will break page down to (up to) level-3 entries.
- Walker will continue to be called on level-2 entries, even though it's not necessary.Quoted 6 lines
Quoted 3 lines
If you're only visiting leaves, why would it be called on the level-2 table entries?
Because once the leaf is turned into a table by the splitting walker, it gets reloaded and walked. This is an excerpt of
__kvm_pgtable_visit():Sorry, I was musing about the semantics after adding something to limit the maximum level. I don't dispute what the current code would do.
Quoted 6 lines
Example:
- Split this level-1 leave:
- Walker creates the whole structure up to given level (currently 3)
- Walker returns, gets reloaded, table detected, go down on that one
- Level 2 entries walked (which is unnecessary)
Quoted 8 lines
Quoted 1 line
Please let me know if I am misunderstanding something.
I just don't grok why this would happen if we limited the maximum level to '2' _and_ said we only wanted to visit the leaf entries. In that case, I wouldn't expect to descend into any of the L2 table entries (because that would imply going beyond level 2) and I wouldn't expect to be called for the table entries either (because we're only interested in leaves).
Agree, if we specify to skip level-3 entries, it would only walk up to level-2 entries, but take above example in detail:
- Split these level-1 leaves, up to level-3 leaves (regular)
- INFO: kvm_pgtable_walk will call walker:
- only up to level-2 entries (skip level-3)
- only on leaf entries
- Walk first level-1 leaf, calls walker
- walker will split the level-1 leaf in level-3 leaves
- walker return from that first level-1 leaf
- level-1 leaf is reloaded as a table
- level-2 entries of that table are also walked (unnecessary)
- on each of the level-2 table entries, level-3 entries are skipped
To avoid the unecessary walk of the level-2 entries above, we would need to specify 'skip level-2' that could be an issue if we have a mix of level-1 and level-2 leaves, as the level-2 leaves in that case would not be split.
That's why I suggest something like "skip recently created table" as a flag as well, so we can guarantee no newly created table gets walked unecessarily.
Please help me if I am missing something important.
Thanks!
Leo
Oliver Upton
maintainerRe: [RFC PATCH 1/2] KVM: arm64: Introduce S2 walker SKIP return options
Quoted 6 lines · Leonardo Bras
Quoted 5 lines · Will Deacon
Quoted 4 lines · Leonardo Bras
Quoted 3 lines · Will Deacon
Quoted 3 lines
Quoted 3 lines
I was wondering along similar lines, but maybe it would be useful just to pass a maximum level to the walker logic? That feels like the most general case without complicating the existing logic.
FWIW, I had considered this too but decided that it requires a bit more churn since we cannot rely on zero initialization in the existing callsites (level 0 is a valid level).
But that's extremely minor.
Quoted 56 lines
Quoted 30 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
This proposal seems simpler for me to understand, and indeed looks like a better solution than what I have proposed, taking care of the 'already split' case with better performance, as it don't even walk a single level-3 entry.
On the 'splitting' case, it also works flawlessly if the memory is given in level-2 blocks. There is only one case that I would like to address here:
- Memory given in level-1 blocks (say 1GB)
- Walker flag says 'walk down to level-2 only'
- Split Walker on level-1 will break page down to (up to) level-3 entries.
- Walker will continue to be called on level-2 entries, even though it's not necessary.Quoted 6 lines
Quoted 3 lines
If you're only visiting leaves, why would it be called on the level-2 table entries?
Because once the leaf is turned into a table by the splitting walker, it gets reloaded and walked. This is an excerpt of
__kvm_pgtable_visit():Sorry, I was musing about the semantics after adding something to limit the maximum level. I don't dispute what the current code would do.
Quoted 6 lines
Example:
- Split this level-1 leave:
- Walker creates the whole structure up to given level (currently 3)
- Walker returns, gets reloaded, table detected, go down on that one
- Level 2 entries walked (which is unnecessary)Quoted 8 lines
Quoted 1 line
Please let me know if I am misunderstanding something.
I just don't grok why this would happen if we limited the maximum level to '2' _and_ said we only wanted to visit the leaf entries. In that case, I wouldn't expect to descend into any of the L2 table entries (because that would imply going beyond level 2) and I wouldn't expect to be called for the table entries either (because we're only interested in leaves).
Agree, if we specify to skip level-3 entries, it would only walk up to level-2 entries, but take above example in detail:
- Split these level-1 leaves, up to level-3 leaves (regular)
- INFO:kvm_pgtable_walkwill call walker:
- only up to level-2 entries (skip level-3)
- only on leaf entries
- Walk first level-1 leaf, calls walker
- walker will split the level-1 leaf in level-3 leaves
- walker return from that first level-1 leaf
- level-1 leaf is reloaded as a table
- level-2 entries of that table are also walked (unnecessary)
- on each of the level-2 table entries, level-3 entries are skippedTo avoid the unecessary walk of the level-2 entries above, we would need to specify 'skip level-2' that could be an issue if we have a mix of level-1 and level-2 leaves, as the level-2 leaves in that case would not be split.
Quoted 5 lines
That's why I suggest something like "skip recently created table" as a flag as well, so we can guarantee no newly created table gets walked unecessarily.
Please help me if I am missing something important.
I'm not sure the added complexity of handling this case perfectly results in a measurable performance improvement. Just avoiding the level 3 tables would be an exponential reduction (~ 512-8192x) in the number of walk steps.
Thanks,
Oliver
Re: [RFC PATCH 1/2] KVM: arm64: Introduce S2 walker SKIP return options
Quoted 74 lines · Oliver Upton
Quoted 6 lines · Leonardo Bras
Quoted 5 lines · Will Deacon
Quoted 4 lines · Leonardo Bras
Quoted 3 lines · Will Deacon
Quoted 3 lines
Quoted 3 lines
I was wondering along similar lines, but maybe it would be useful just to pass a maximum level to the walker logic? That feels like the most general case without complicating the existing logic.
FWIW, I had considered this too but decided that it requires a bit more churn since we cannot rely on zero initialization in the existing callsites (level 0 is a valid level).
But that's extremely minor.
Quoted 60 lines
Quoted 30 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
This proposal seems simpler for me to understand, and indeed looks like a better solution than what I have proposed, taking care of the 'already split' case with better performance, as it don't even walk a single level-3 entry.
On the 'splitting' case, it also works flawlessly if the memory is given in level-2 blocks. There is only one case that I would like to address here:
- Memory given in level-1 blocks (say 1GB)
- Walker flag says 'walk down to level-2 only'
- Split Walker on level-1 will break page down to (up to) level-3 entries.
- Walker will continue to be called on level-2 entries, even though it's not necessary.Quoted 6 lines
Quoted 3 lines
If you're only visiting leaves, why would it be called on the level-2 table entries?
Because once the leaf is turned into a table by the splitting walker, it gets reloaded and walked. This is an excerpt of
__kvm_pgtable_visit():Sorry, I was musing about the semantics after adding something to limit the maximum level. I don't dispute what the current code would do.
Quoted 6 lines
Example:
- Split this level-1 leave:
- Walker creates the whole structure up to given level (currently 3)
- Walker returns, gets reloaded, table detected, go down on that one
- Level 2 entries walked (which is unnecessary)Quoted 8 lines
Quoted 1 line
Please let me know if I am misunderstanding something.
I just don't grok why this would happen if we limited the maximum level to '2' _and_ said we only wanted to visit the leaf entries. In that case, I wouldn't expect to descend into any of the L2 table entries (because that would imply going beyond level 2) and I wouldn't expect to be called for the table entries either (because we're only interested in leaves).
Agree, if we specify to skip level-3 entries, it would only walk up to level-2 entries, but take above example in detail:
- Split these level-1 leaves, up to level-3 leaves (regular)
- INFO:kvm_pgtable_walkwill call walker:
- only up to level-2 entries (skip level-3)
- only on leaf entries
- Walk first level-1 leaf, calls walker
- walker will split the level-1 leaf in level-3 leaves
- walker return from that first level-1 leaf
- level-1 leaf is reloaded as a table
- level-2 entries of that table are also walked (unnecessary)
- on each of the level-2 table entries, level-3 entries are skippedTo avoid the unecessary walk of the level-2 entries above, we would need to specify 'skip level-2' that could be an issue if we have a mix of level-1 and level-2 leaves, as the level-2 leaves in that case would not be split.
That's why I suggest something like "skip recently created table" as a flag as well, so we can guarantee no newly created table gets walked unecessarily.
Quoted 7 lines
Quoted 1 line
Please help me if I am missing something important.
I'm not sure the added complexity of handling this case perfectly results in a measurable performance improvement. Just avoiding the level 3 tables would be an exponential reduction (~ 512-8192x) in the number of walk steps.
Humm, I agree most of the improvement is due to skipping level-3 walks.
The added complexity would be, appart from a new flag, just a single line change:
---
if (!table && (ctx.flags & KVM_PGTABLE_WALK_LEAF)) {
ret = kvm_pgtable_visitor_cb(data, &ctx, KVM_PGTABLE_WALK_LEAF);
- reload = true;
+ /* Do not reload if flagged to skip new table */
+ reload = !(ctx.flags & KVM_PGTABLE_WALK_SKIP_NEW_TABLE);
}---
Even then, do you think it would not be worth having it?
Thanks!
Leo
Re: [RFC PATCH 1/2] KVM: arm64: Introduce S2 walker SKIP return options
In reply to Oliver UptonQuoted 8 lines · Oliver Upton
Quoted 6 lines · Leonardo Bras
Quoted 5 lines · Will Deacon
Quoted 4 lines · Leonardo Bras
Quoted 3 lines · Will Deacon
Quoted 3 lines
Quoted 3 lines
I was wondering along similar lines, but maybe it would be useful just to pass a maximum level to the walker logic? That feels like the most general case without complicating the existing logic.
Quoted 6 lines
FWIW, I had considered this too but decided that it requires a bit more churn since we cannot rely on zero initialization in the existing callsites (level 0 is a valid level).
But that's extremely minor.
Instead of passing a number, I implemented it in a dumber way:
+ KVM_PGTABLE_WALK_SKIP_LEVEL0 = BIT(7),
+ KVM_PGTABLE_WALK_SKIP_LEVEL1 = BIT(8), + KVM_PGTABLE_WALK_SKIP_LEVEL2 = BIT(9), + KVM_PGTABLE_WALK_SKIP_LEVEL3 = BIT(10),
And did some tests, which I commend below...
Quoted 60 lines
Quoted 60 lines
Quoted 30 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
This proposal seems simpler for me to understand, and indeed looks like a better solution than what I have proposed, taking care of the 'already split' case with better performance, as it don't even walk a single level-3 entry.
On the 'splitting' case, it also works flawlessly if the memory is given in level-2 blocks. There is only one case that I would like to address here:
- Memory given in level-1 blocks (say 1GB)
- Walker flag says 'walk down to level-2 only'
- Split Walker on level-1 will break page down to (up to) level-3 entries.
- Walker will continue to be called on level-2 entries, even though it's not necessary.Quoted 6 lines
Quoted 3 lines
If you're only visiting leaves, why would it be called on the level-2 table entries?
Because once the leaf is turned into a table by the splitting walker, it gets reloaded and walked. This is an excerpt of
__kvm_pgtable_visit():Sorry, I was musing about the semantics after adding something to limit the maximum level. I don't dispute what the current code would do.
Quoted 6 lines
Example:
- Split this level-1 leave:
- Walker creates the whole structure up to given level (currently 3)
- Walker returns, gets reloaded, table detected, go down on that one
- Level 2 entries walked (which is unnecessary)Quoted 8 lines
Quoted 1 line
Please let me know if I am misunderstanding something.
I just don't grok why this would happen if we limited the maximum level to '2' _and_ said we only wanted to visit the leaf entries. In that case, I wouldn't expect to descend into any of the L2 table entries (because that would imply going beyond level 2) and I wouldn't expect to be called for the table entries either (because we're only interested in leaves).
Agree, if we specify to skip level-3 entries, it would only walk up to level-2 entries, but take above example in detail:
- Split these level-1 leaves, up to level-3 leaves (regular)
- INFO:kvm_pgtable_walkwill call walker:
- only up to level-2 entries (skip level-3)
- only on leaf entries
- Walk first level-1 leaf, calls walker
- walker will split the level-1 leaf in level-3 leaves
- walker return from that first level-1 leaf
- level-1 leaf is reloaded as a table
- level-2 entries of that table are also walked (unnecessary)
- on each of the level-2 table entries, level-3 entries are skippedTo avoid the unecessary walk of the level-2 entries above, we would need to specify 'skip level-2' that could be an issue if we have a mix of level-1 and level-2 leaves, as the level-2 leaves in that case would not be split.
That's why I suggest something like "skip recently created table" as a flag as well, so we can guarantee no newly created table gets walked unecessarily.
Quoted 7 lines
Quoted 1 line
Please help me if I am missing something important.
I'm not sure the added complexity of handling this case perfectly results in a measurable performance improvement. Just avoiding the level 3 tables would be an exponential reduction (~ 512-8192x) in the number of walk steps.
I tested both scenarios* compared to Vanilla on an AmpereOne and the testing numbers agree with you: The added complexity of checking for the skip_child makes the routine about 1% slower.
Those tests measured the times for the whole syscall that happens to do page splitting, in this case,
1 - Manual protect and init set: On every KVM_CLEAR_DIRTY_LOG, if the page
was requested to be cleaned
2 - Otherwise, on dirty log enable (aka KVM_SET_USER_MEMORY_REGION2 with
KVM_MEM_LOG_DIRTY_PAGES set in flags), for the whole memslot
I will post the detailed results as a reply to the cover letter.
Thanks!
Leo
*scenario 1: skip level
*scenario 2: skip level + skip child
RFC PATCH 2/2 KVM: arm64: Improve splitting performance by using SKIP return values
In reply to Leonardo BrasSplitting an S2 pagetable is needed when using dirty-bit tracking.
Currently, when splitting, all the child and sibling nodes will be walked, with the walker just returning earlier if there is nothing to do. This means all pagetable entries in the splitting range get a callback from the walker function, even if it was just split, or it's a level-3 entry.
Optimize splitting in two cases:
- If a level-3 entry is walked, it means the parent level-2 entry is split, so avoid walking all level-3 siblings.
- If a split just succeeded in an table entry, it means all children nodes are already split, so skip walking this entry's children.
Optimization measured on a 1GB VM, running on the model, splitting all at the beginning (no manual protect):
- Memory was already split (4k pages): -97.33% runtime (-172ms) - 20 runs
- THP backed memory: -19.82% runtime (-153ms) - 10 runs
- 1x1GB hugetlb memory: -20.65% runtime (-150ms) - 10 runs
(Above runtime is measured on kvm_mmu_split_huge_pages(), using ktime_get_real_ns() before and after function call)
--- arch/arm64/kvm/hyp/pgtable.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
arch/arm64/kvm/hyp/pgtable.c +9 -3
@@ -1502,23 +1502,27 @@ static int stage2_split_walker(const struct kvm_pgtable_visit_ctx *ctx,struct kvm_pgtable_mm_ops *mm_ops = ctx->mm_ops;struct kvm_mmu_memory_cache *mc = ctx->arg;struct kvm_s2_mmu *mmu;kvm_pte_t pte = ctx->old, new, *childp;enum kvm_pgtable_prot prot;s8 level = ctx->level;bool force_pte;int nr_pages;u64 phys; -/* No huge-pages exist at the last level */ +/* +* No huge-pages exist at the last level +* Also, if one PTE exist in the last level, the whole block is already +* split, so skip walking it's siblings. +*/ if (level ==KVM_PGTABLE_LAST_LEVEL ) -return 0 ; +return SKIP_SIBLINGS ;/* We only split valid block mappings */ if (!kvm_pte_valid (pte))return 0 ; nr_pages =stage2_block_get_nr_page_tables (level);if (nr_pages <0 )return nr_pages;if (mc->nobjs >= nr_pages) {
@@ -1554,21 +1558,23 @@ static int stage2_split_walker(const struct kvm_pgtable_visit_ctx *ctx,return -EAGAIN ; }/* * Note, the contents of the page table are guaranteed to be made * visible before the new PTE is assigned because stage2_make_pte() * writes the PTE using smp_store_release(). */ new =kvm_init_table_pte (childp, mm_ops);stage2_make_pte (ctx, new); -return 0 ; + +/* All child entries are already split, so skip walking them */ +return SKIP_CHILDREN ; }int kvm_pgtable_stage2_split (struct kvm_pgtable *pgt,u64 addr,u64 size,struct kvm_mmu_memory_cache *mc) {struct kvm_pgtable_walker walker = { .cb = stage2_split_walker, .flags =KVM_PGTABLE_WALK_LEAF , .arg = mc, };
Signature · 1 line
2.54.0
Marc Zyngier
maintainerQuoted 15 lines · Leonardo Bras
While playing with dirty-bit tracking, I decided to take a look on how page splitting works. Found out all entries are walked, even though we can infer, for instance that:
- If a level-3 entry is walked, it means the parent level-2 entry is split
- If a split just succeeded in an table entry, it means all children nodes are already splitSo I tried to optimize it in a way that it does not break other users.
My main idea is to introduce positive return values that hint to the pagetable walking mechanism that either siblings or children can be skipped. That should be contained to the visitor function, that returns zero if no error was detected.
Quoted 7 lines
Numbers on above optimization are promising:
A 1GB VM, running on the model, splitting all at the beginning (no manual protect):
- Memory was already split (4k pages): -97.33% runtime (-172ms) - 20 runs
- THP backed memory: -19.82% runtime (-153ms) - 10 runs
- 1x1GB hugetlb memory: -20.65% runtime (-150ms) - 10 runs
I haven't looked at the changes in details, but the methodology is quite flawed. For a start, measuring anything on a software model (QEMU or FVP) doesn't mean anything performance-wise. The trade-offs are completely different from a HW implementation, and even the notion of time is pretty inconsistent.
Please run this on actual HW. I'm sure your employer can give you access to one of these mythical arm64 toys. Measure things from userspace, not from the kernel, so that you have all the overheads. Don't add console output, because that will make things far worse.
I'm sure you can hack one of the selftests for this purpose.
Thanks,
M.
Signature · 1 line
Jazz isn't dead. It just smells funny.
Quoted 25 lines · Marc Zyngier
Quoted 15 lines · Leonardo Bras
While playing with dirty-bit tracking, I decided to take a look on how page splitting works. Found out all entries are walked, even though we can infer, for instance that:
- If a level-3 entry is walked, it means the parent level-2 entry is split
- If a split just succeeded in an table entry, it means all children nodes are already splitSo I tried to optimize it in a way that it does not break other users.
My main idea is to introduce positive return values that hint to the pagetable walking mechanism that either siblings or children can be skipped. That should be contained to the visitor function, that returns zero if no error was detected.
Quoted 7 lines
Numbers on above optimization are promising:
A 1GB VM, running on the model, splitting all at the beginning (no manual protect):
- Memory was already split (4k pages): -97.33% runtime (-172ms) - 20 runs
- THP backed memory: -19.82% runtime (-153ms) - 10 runs
- 1x1GB hugetlb memory: -20.65% runtime (-150ms) - 10 runs
Quoted 8 lines
I haven't looked at the changes in details, but the methodology is quite flawed. For a start, measuring anything on a software model (QEMU or FVP) doesn't mean anything performance-wise. The trade-offs are completely different from a HW implementation, and even the notion of time is pretty inconsistent.
Please run this on actual HW. I'm sure your employer can give you access to one of these mythical arm64 toys.
Ok, will use real hardware next.
Quoted 5 lines
Measure things from
userspace, not from the kernel, so that you have all the overheads. Don't add console output, because that will make things far worse.I'm sure you can hack one of the selftests for this purpose.
I think the dirty_log_perf_test should have an config I can use for that without introducing any change.
Thanks!
Leo
Quoted 31 lines · Marc Zyngier
Quoted 15 lines · Leonardo Bras
While playing with dirty-bit tracking, I decided to take a look on how page splitting works. Found out all entries are walked, even though we can infer, for instance that:
- If a level-3 entry is walked, it means the parent level-2 entry is split
- If a split just succeeded in an table entry, it means all children nodes are already splitSo I tried to optimize it in a way that it does not break other users.
My main idea is to introduce positive return values that hint to the pagetable walking mechanism that either siblings or children can be skipped. That should be contained to the visitor function, that returns zero if no error was detected.
Quoted 7 lines
Numbers on above optimization are promising:
A 1GB VM, running on the model, splitting all at the beginning (no manual protect):
- Memory was already split (4k pages): -97.33% runtime (-172ms) - 20 runs
- THP backed memory: -19.82% runtime (-153ms) - 10 runs
- 1x1GB hugetlb memory: -20.65% runtime (-150ms) - 10 runsI haven't looked at the changes in details, but the methodology is quite flawed. For a start, measuring anything on a software model (QEMU or FVP) doesn't mean anything performance-wise. The trade-offs are completely different from a HW implementation, and even the notion of time is pretty inconsistent.
Quoted 6 lines
Please run this on actual HW. I'm sure your employer can give you access to one of these mythical arm64 toys. Measure things from userspace, not from the kernel, so that you have all the overheads. Don't add console output, because that will make things far worse.
I'm sure you can hack one of the selftests for this purpose.
Hello Marc,
I have ran some tests in real hardware (AmpereOne) and calling from userspace as you suggested.
The tests create a 64GB VM, using either regular pages (no split needed), THP backed memory or Hugetlb.
Those tests measured the times for the whole syscall that happens to do eager page splitting, in this case,
1 - Manual protect and init set: On every KVM_CLEAR_DIRTY_LOG, if the page
was requested to be cleaned, it is also split.
2 - Otherwise, on dirty log enable (aka KVM_SET_USER_MEMORY_REGION2 with
KVM_MEM_LOG_DIRTY_PAGES set in flags), for the whole memslot is split at once.
Tests reflect new suggestions I got in this patchset: instead of using return values, I am using flags to skip whole levels, or skipping children nodes. I tested those 2 kernels, on top of vanilla:
a - Skip levels
b - Skip levels, and skip children node
Results averaged across 4k, 16k and 64k pages, a percentage of time saved, compared to vanilla kernel. More is better.
For (1), we have
regular pages: 26.7% (a) and 25.3% (b)
THP: 13.2% (a) and 11.9% (b)
Hugetlb: 14.3% (a) and 13.2% (b)
For (2), we have:
regular pages: 33.1% (a) and 35.0% (b)
THP: 11.9% (a) and 10.7% (b)
Hugetlb: 13.4% (a) and 13.2% (b)
On above results, I could notice about 1% overhead showing that skipping child nodes (testing flag) ends up being counter-productive compared to just skipping levels. The only case this does not happen is (2a), but it's not clear on why that happens.
Based on that, I plan to remove the skip_child patch, and send a v2 with a flag-based mechanism, which results are shown above.
Please let me know of any thoughts, suggestions or ideas you might have about it.
Thanks!
Leo
Marc Zyngier
maintainerQuoted 80 lines · Leonardo Bras
Quoted 31 lines · Marc Zyngier
Quoted 15 lines · Leonardo Bras
While playing with dirty-bit tracking, I decided to take a look on how page splitting works. Found out all entries are walked, even though we can infer, for instance that:
- If a level-3 entry is walked, it means the parent level-2 entry is split
- If a split just succeeded in an table entry, it means all children nodes are already splitSo I tried to optimize it in a way that it does not break other users.
My main idea is to introduce positive return values that hint to the pagetable walking mechanism that either siblings or children can be skipped. That should be contained to the visitor function, that returns zero if no error was detected.
Quoted 7 lines
Numbers on above optimization are promising:
A 1GB VM, running on the model, splitting all at the beginning (no manual protect):
- Memory was already split (4k pages): -97.33% runtime (-172ms) - 20 runs
- THP backed memory: -19.82% runtime (-153ms) - 10 runs
- 1x1GB hugetlb memory: -20.65% runtime (-150ms) - 10 runsI haven't looked at the changes in details, but the methodology is quite flawed. For a start, measuring anything on a software model (QEMU or FVP) doesn't mean anything performance-wise. The trade-offs are completely different from a HW implementation, and even the notion of time is pretty inconsistent.
Quoted 6 lines
Please run this on actual HW. I'm sure your employer can give you access to one of these mythical arm64 toys. Measure things from userspace, not from the kernel, so that you have all the overheads. Don't add console output, because that will make things far worse.
I'm sure you can hack one of the selftests for this purpose.
Hello Marc,
I have ran some tests in real hardware (AmpereOne) and calling from userspace as you suggested.
The tests create a 64GB VM, using either regular pages (no split needed), THP backed memory or Hugetlb.
Those tests measured the times for the whole syscall that happens to do eager page splitting, in this case,
1 - Manual protect and init set: On everyKVM_CLEAR_DIRTY_LOG, if the page
was requested to be cleaned, it is also split.
2 - Otherwise, on dirty log enable (akaKVM_SET_USER_MEMORY_REGION2with
KVM_MEM_LOG_DIRTY_PAGESset in flags), for the whole memslot is split at once.Tests reflect new suggestions I got in this patchset: instead of using return values, I am using flags to skip whole levels, or skipping children nodes. I tested those 2 kernels, on top of vanilla:
a - Skip levels
b - Skip levels, and skip children nodeResults averaged across 4k, 16k and 64k pages, a percentage of time saved, compared to vanilla kernel. More is better.
For (1), we have
regular pages: 26.7% (a) and 25.3% (b)
THP: 13.2% (a) and 11.9% (b)
Hugetlb: 14.3% (a) and 13.2% (b)For (2), we have:
regular pages: 33.1% (a) and 35.0% (b)
THP: 11.9% (a) and 10.7% (b)
Hugetlb: 13.4% (a) and 13.2% (b)On above results, I could notice about 1% overhead showing that skipping child nodes (testing flag) ends up being counter-productive compared to just skipping levels. The only case this does not happen is (2a), but it's not clear on why that happens.
Quoted 5 lines
Based on that, I plan to remove the
skip_childpatch, and send a v2 with a flag-based mechanism, which results are shown above.Please let me know of any thoughts, suggestions or ideas you might have about it.
Right, that seems compelling. I'd suggest you send a new version with:
- a pointer to the test and its the exact invocation parameters so that people other than you can reproduce it
- these numbers with a bit of analysis explaining where the gains are
With that, we can look at it again and compare results on different workloads and HW.
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 82 lines · Marc Zyngier
Quoted 80 lines · Leonardo Bras
Quoted 31 lines · Marc Zyngier
Quoted 15 lines · Leonardo Bras
While playing with dirty-bit tracking, I decided to take a look on how page splitting works. Found out all entries are walked, even though we can infer, for instance that:
- If a level-3 entry is walked, it means the parent level-2 entry is split
- If a split just succeeded in an table entry, it means all children nodes are already splitSo I tried to optimize it in a way that it does not break other users.
My main idea is to introduce positive return values that hint to the pagetable walking mechanism that either siblings or children can be skipped. That should be contained to the visitor function, that returns zero if no error was detected.
Quoted 7 lines
Numbers on above optimization are promising:
A 1GB VM, running on the model, splitting all at the beginning (no manual protect):
- Memory was already split (4k pages): -97.33% runtime (-172ms) - 20 runs
- THP backed memory: -19.82% runtime (-153ms) - 10 runs
- 1x1GB hugetlb memory: -20.65% runtime (-150ms) - 10 runsI haven't looked at the changes in details, but the methodology is quite flawed. For a start, measuring anything on a software model (QEMU or FVP) doesn't mean anything performance-wise. The trade-offs are completely different from a HW implementation, and even the notion of time is pretty inconsistent.
Quoted 6 lines
Please run this on actual HW. I'm sure your employer can give you access to one of these mythical arm64 toys. Measure things from userspace, not from the kernel, so that you have all the overheads. Don't add console output, because that will make things far worse.
I'm sure you can hack one of the selftests for this purpose.
Hello Marc,
I have ran some tests in real hardware (AmpereOne) and calling from userspace as you suggested.
The tests create a 64GB VM, using either regular pages (no split needed), THP backed memory or Hugetlb.
Those tests measured the times for the whole syscall that happens to do eager page splitting, in this case,
1 - Manual protect and init set: On everyKVM_CLEAR_DIRTY_LOG, if the page
was requested to be cleaned, it is also split.
2 - Otherwise, on dirty log enable (akaKVM_SET_USER_MEMORY_REGION2with
KVM_MEM_LOG_DIRTY_PAGESset in flags), for the whole memslot is split at once.Tests reflect new suggestions I got in this patchset: instead of using return values, I am using flags to skip whole levels, or skipping children nodes. I tested those 2 kernels, on top of vanilla:
a - Skip levels
b - Skip levels, and skip children nodeResults averaged across 4k, 16k and 64k pages, a percentage of time saved, compared to vanilla kernel. More is better.
For (1), we have
regular pages: 26.7% (a) and 25.3% (b)
THP: 13.2% (a) and 11.9% (b)
Hugetlb: 14.3% (a) and 13.2% (b)For (2), we have:
regular pages: 33.1% (a) and 35.0% (b)
THP: 11.9% (a) and 10.7% (b)
Hugetlb: 13.4% (a) and 13.2% (b)On above results, I could notice about 1% overhead showing that skipping child nodes (testing flag) ends up being counter-productive compared to just skipping levels. The only case this does not happen is (2a), but it's not clear on why that happens.
Quoted 7 lines
Quoted 5 lines
Based on that, I plan to remove the
skip_childpatch, and send a v2 with a flag-based mechanism, which results are shown above.Please let me know of any thoughts, suggestions or ideas you might have about it.
Right, that seems compelling.
Awesome!
Quoted 10 lines
I'd suggest you send a new version with:
- a pointer to the test and its the exact invocation parameters so that people other than you can reproduce it
- these numbers with a bit of analysis explaining where the gains are
With that, we can look at it again and compare results on different workloads and HW.
Noted!
Will attach test parameters and full results, describing where the gains come from.
Thanks!
Leo