um: implement arch_sync_kernel_mappings
[email protected]
maintainerPATCH 1/1 um: implement arch_sync_kernel_mappings
From: Anton Ivanov <[email protected]>
This improves the tlb flushing behavior by syncing modified ranges out of map_kernel_range_noflush in a way which is similar to x86.
--- arch/um/include/asm/page.h | 2 ++ arch/um/kernel/tlb.c | 5 +++++ 2 files changed, 7 insertions(+)
arch/um/include/asm/page.h +2 -0
@@ -9,6 +9,8 @@#include <linux/const.h> +#define ARCH_PAGE_TABLE_SYNC_MASK PGTBL_PMD_MODIFIED +/* PAGE_SHIFT determines the page size */ #define PAGE_SHIFT 12#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
arch/um/kernel/tlb.c +5 -0
@@ -602,3 +602,8 @@ void force_flush_all(void) vma = vma->vm_next; } } + +void arch_sync_kernel_mappings (unsigned long start,unsigned long end) +{ +flush_tlb_kernel_range_common (start, end); +}
Signature · 7 lines
2.20.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerQuoted 5 lines · On Tue, 2021-03-16 at 09:58 +0000, [email protected] wrote:
From: Anton Ivanov <[email protected]>
This improves the tlb flushing behavior by syncing modified ranges out of
map_kernel_range_noflushin a way which is similar to x86.
So I take it this replaces my patch?
Want me to test it (without the kvmalloc)?
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Anton Ivanov
maintainerQuoted 8 lines · Johannes Berg
Quoted 5 lines · On Tue, 2021-03-16 at 09:58 +0000, [email protected] wrote:
From: Anton Ivanov <[email protected]>
This improves the tlb flushing behavior by syncing modified ranges out of
map_kernel_range_noflushin a way which is similar to x86.So I take it this replaces my patch?
I get slightly better performance on userspace, etc compared to your patch. It is marginal - sub 1% close to the experimental error.
I am testing different things though :)
Quoted 1 line
Want me to test it (without the kvmalloc)?
Yes :)
Quoted 4 lines
johannes
Signature · 9 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerQuoted 3 lines · Anton Ivanov
Quoted 1 line
Want me to test it (without the kvmalloc)?
Yes :)
This patch doesn't seem to improve vmalloc performance at all.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Anton Ivanov
maintainerQuoted 6 lines · Johannes Berg
Quoted 3 lines · Anton Ivanov
Quoted 1 line
Want me to test it (without the kvmalloc)?
Yes :)
This patch doesn't seem to improve vmalloc performance at all.
Bugger...
I was looking at it from this perspective.
flush_cache_vmap is invoked out of here right after a map_kernel_range_noflush():
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L320
If I understand the invocation correctly your patch results in a full flush for the mapped range each time it is mapped.
The invocation of map_kernel_range_noflush() actually has a built-in facility for a partial flush - it is exactly arch_sync_page_mappings and it is invoked here: https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L314
This makes the flush dependent on the level of modification - to be functionally equivalent to your patch it is an OR of all page levels which looked way too brutal :(
That's why I tried it using only PMD. That looks like not enough :(
Can you try tweaking the mask? Available masks are defined here: https://elixir.bootlin.com/linux/latest/source/include/linux/pgtable.h#L1474
Quoted 9 lines
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Signature · 8 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerOn Tue, 2021-03-16 at 10:30 +0000, Anton Ivanov wrote:
Quoted 6 lines · Johannes Berg
Quoted 3 lines · Anton Ivanov
Quoted 1 line
Want me to test it (without the kvmalloc)?
Yes :)
This patch doesn't seem to improve vmalloc performance at all.
Bugger...
I was looking at it from this perspective.
flush_cache_vmap is invoked out of here right after a map_kernel_range_noflush():
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L320
If I understand the invocation correctly your patch results in a full flush for the mapped range each time it is mapped.
Yes, that's how I understood/planned it.
The invocation of map_kernel_range_noflush() actually has a built-in facility for a partial flush - it is exactly arch_sync_page_mappings and it is invoked here:
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L314
Right, I saw this when you posted your patch and I looked how it would work.
This makes the flush dependent on the level of modification - to be functionally equivalent to your patch it is an OR of all page levels which looked way too brutal :(
That's why I tried it using only PMD. That looks like not enough :(
Can you try tweaking the mask? Available masks are defined here:
https://elixir.bootlin.com/linux/latest/source/include/linux/pgtable.h#L1474
Ahhh.
Well, I think you'd have to go for all of them. My workload is vmalloc'ing single pages only (for really tiny objects like 24 bytes, so it's stupid), so really you'd only get a single PTE changed, right?
And then once you do that, it becomes equivalent to my patch (though actually done _more_ often since there might be cases where _noflush() is called and not flush_cache_vmap().
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerQuoted 3 lines · Johannes Berg
Bugger...
I was looking at it from this perspective.
Sorry about the lack of quoting here. Looked sort of OK locally, but clearly got lost along the way.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Anton Ivanov
maintainerQuoted 45 lines · Johannes Berg
On Tue, 2021-03-16 at 10:30 +0000, Anton Ivanov wrote:
Quoted 4 lines · Johannes Berg
Quoted 2 lines · Anton Ivanov
Quoted 1 line
Want me to test it (without the kvmalloc)?
Yes :)
This patch doesn't seem to improve vmalloc performance at all.
Bugger...
I was looking at it from this perspective.
flush_cache_vmapis invoked out of here right after amap_kernel_range_noflush():https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L320
If I understand the invocation correctly your patch results in a full flush for the mapped range each time it is mapped.
Yes, that's how I understood/planned it.
The invocation of
map_kernel_range_noflush()actually has a built-in facility for a partial flush - it is exactlyarch_sync_page_mappingsand it is invoked here:
https://elixir.bootlin.com/linux/latest/source/mm/vmalloc.c#L314Right, I saw this when you posted your patch and I looked how it would work.
This makes the flush dependent on the level of modification - to be functionally equivalent to your patch it is an OR of all page levels which looked way too brutal :(
That's why I tried it using only PMD. That looks like not enough :(
Can you try tweaking the mask? Available masks are defined here:
https://elixir.bootlin.com/linux/latest/source/include/linux/pgtable.h#L1474Ahhh.
Quoted 7 lines
Well, I think you'd have to go for all of them. My workload is vmalloc'ing single pages only (for really tiny objects like 24 bytes, so it's stupid), so really you'd only get a single PTE changed, right?
And then once you do that, it becomes equivalent to my patch (though actually done _more_ often since there might be cases where
_noflush()is called and notflush_cache_vmap().
Ugh... OK. Let's stick with your approach.
I will +1 it in a minute.
Brgds,
Quoted 9 lines
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Signature · 9 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerQuoted 5 lines · Anton Ivanov
Quoted 4 lines · Johannes Berg
Quoted 2 lines · On Tue, 2021-03-16 at 09:58 +0000, [email protected] wrote:
From: Anton Ivanov <[email protected]>
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
This improves the tlb flushing behavior by syncing modified ranges out of
map_kernel_range_noflushin a way which is similar to x86.So I take it this replaces my patch?
I get slightly better performance on userspace,
etc compared to your patch. It is marginal -
sub 1% close to the experimental error.
Why does that even affect userspace at all, btw? We're talking about kernel mappings?
Do you see this speed up userspace relative to my patch, or relative to unpatched?
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Anton Ivanov
maintainerQuoted 9 lines · Johannes Berg
Quoted 8 lines · Anton Ivanov
Quoted 7 lines · Johannes Berg
Quoted 5 lines · On Tue, 2021-03-16 at 09:58 +0000, [email protected] wrote:
From: Anton Ivanov <[email protected]>
This improves the tlb flushing behavior by syncing modified ranges out of
map_kernel_range_noflushin a way which is similar to x86.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
So I take it this replaces my patch?
I get slightly better performance on userspace,
etc compared to your patch. It is marginal -
sub 1% close to the experimental error.Why does that even affect userspace at all, btw? We're talking about kernel mappings?
My userspace tests do heavy IO.
Quoted 13 lines
Do you see this speed up userspace relative to my patch, or relative to unpatched?
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Signature · 8 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerQuoted 8 lines · Anton Ivanov
Quoted 6 lines
Quoted 3 lines
I get slightly better performance on userspace,
etc compared to your patch. It is marginal -
sub 1% close to the experimental error.Why does that even affect userspace at all, btw? We're talking about kernel mappings?
My userspace tests do heavy IO.
OK, but even then, my patch should be an improvement on anything that needs updated ranges since it avoids the segfault(s), and not really make anything worse that *doesn't*?
But then again, I'm not sure you said that this patch was an improvement or not for your workload?
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Anton Ivanov
maintainerQuoted 8 lines · Johannes Berg
Quoted 7 lines · Anton Ivanov
Quoted 6 lines
Quoted 3 lines
I get slightly better performance on userspace,
etc compared to your patch. It is marginal -
sub 1% close to the experimental error.Why does that even affect userspace at all, btw? We're talking about kernel mappings?
Quoted 8 lines
Quoted 1 line
My userspace tests do heavy IO.
OK, but even then, my patch should be an improvement on anything that needs updated ranges since it avoids the segfault(s), and not really make anything worse that *doesn't*?
But then again, I'm not sure you said that this patch was an improvement or not for your workload?
Your patch showed no difference on heavy IO userspace. Roughly the same numbers I usually get.
Syncing pages at a PMD level change showed some marginal improvement on a heavy IO testcase but very close to the margin of error - in the realm of 0.2-0.3%
I would really need to do 20+ runs to have reliable numbers on that to confirm as it is too close to the margin of error.
Quoted 4 lines
johannes
Signature · 8 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um