net: adopt SLUB sheaves for skbuff_small_head
Subsystems (2)
PATCH 1/1 net: adopt SLUB sheaves for skbuff_small_head
skbuff_small_head is used both on receive and send paths, serving potentially 80 million allocations and frees per second.
Tuning it on large servers has been problematic, especially on AMD Turins platforms, where "lock cmpxch16b" latency can be over 30,000 cycles.
Switching to SLUB sheaves fixes the issue nicely.
tcp_rr benchmark with 10,000 flows goes from 25 Mpps to 40 Mpps on AMD Turin.
Other platforms show benefits with tcp_rr with more than 30,000 flows.
--- net/core/skbuff.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
net/core/skbuff.c +20 -11
@@ -5174,6 +5174,19 @@ static void skb_extensions_init(void) {}void __init skb_init (void ) { +struct kmem_cache_args kmem_args_small_head = { + .align =0 , + .ctor =NULL , +/* usercopy should only access first SKB_SMALL_HEAD_HEADROOM +* bytes. +* struct skb_shared_info is located at the end of skb->head, +* and should not be copied to/from user. +*/ + .useroffset =0 , + .usersize =SKB_SMALL_HEAD_HEADROOM , + .sheaf_capacity =32 , + }; + net_hotdata.skbuff_cache = kmem_cache_create_usercopy("skbuff_head_cache", sizeof(struct sk_buff), 0,
@@ -5189,17 +5202,13 @@ void __init skb_init(void)0 ,SLAB_HWCACHE_ALIGN |SLAB_PANIC , NULL); -/* usercopy should only access first SKB_SMALL_HEAD_HEADROOM bytes. -* struct skb_shared_info is located at the end of skb->head, -* and should not be copied to/from user. -*/ - net_hotdata.skb_small_head_cache =kmem_cache_create_usercopy ("skbuff_small_head" , -SKB_SMALL_HEAD_CACHE_SIZE , -0 , -SLAB_HWCACHE_ALIGN |SLAB_PANIC , -0 , -SKB_SMALL_HEAD_HEADROOM , -NULL ); + + net_hotdata.skb_small_head_cache =kmem_cache_create ( +"skbuff_small_head" , +SKB_SMALL_HEAD_CACHE_SIZE , + &kmem_args_small_head, +SLAB_HWCACHE_ALIGN |SLAB_PANIC ); +skb_extensions_init (); }
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
Quoted 10 lines · Eric Dumazet
skbuff_small_headis used both on receive and send paths, serving potentially 80 million allocations and frees per second.Tuning it on large servers has been problematic, especially on AMD Turins platforms, where "lock cmpxch16b" latency can be over 30,000 cycles.
Switching to SLUB sheaves fixes the issue nicely.
Quoted 7 lines
tcp_rrbenchmark with 10,000 flows goes from 25 Mpps to 40 Mpps on AMD Turin.Other platforms show benefits with
tcp_rrwith more than 30,000 flows.Signed-off-by Eric Dumazet <[email protected]>
Thanks !
Quoted 13 lines · Eric Dumazet
skbuff_small_headis used both on receive and send paths, serving potentially 80 million allocations and frees per second.Tuning it on large servers has been problematic, especially on AMD Turins platforms, where "lock cmpxch16b" latency can be over 30,000 cycles.
Switching to SLUB sheaves fixes the issue nicely.
tcp_rrbenchmark with 10,000 flows goes from 25 Mpps to 40 Mpps on AMD Turin.
Quoted 7 lines
Other platforms show benefits with
tcp_rrwith more than 30,000 flows.Signed-off-by Eric Dumazet <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Rientjes <[email protected]>Cc Roman Gushchin <[email protected]>
Thanks!
Quoted 16 lines
--- net/core/skbuff.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)net/core/skbuff.c +4
-0@@ -5174,6 +5174,19 @@ static void skb_extensions_init(void) {}void __init skb_init (void ) { +struct kmem_cache_args kmem_args_small_head = { + .align =0 , + .ctor =NULL , +/* usercopy should only access first SKB_SMALL_HEAD_HEADROOM
net/core/skbuff.c static void skb_extensions_init(void) {} · line 5190
Quoted 10 lines
net/core/skbuff.c +9
-0+* bytes. +* struct skb_shared_info is located at the end of skb->head, +* and should not be copied to/from user. +*/ + .useroffset = 0, + .usersize = SKB_SMALL_HEAD_HEADROOM, + .sheaf_capacity = 32, + }; + net_hotdata.skbuff_cache = kmem_cache_create_usercopy("skbuff_head_cache",
Looking at the comment of kmem_cache_create_usercopy[1], I realize that skbuff_head_cache() can also be switched to kmem_cache_create() as well?
[1]
"This is a legacy wrapper, new code should use either KMEM_CACHE_USERCOPY()...kmem_cache_create()..."
Thanks,
Jason
Quoted 6 lines · Eric Dumazet
skbuff_small_headis used both on receive and send paths, serving potentially 80 million allocations and frees per second.Tuning it on large servers has been problematic, especially on AMD Turins platforms, where "lock cmpxch16b" latency can be over 30,000 cycles.
Huh, really? That sounds insane. Any pointers about that?
Quoted 7 lines
Switching to SLUB sheaves fixes the issue nicely.
tcp_rrbenchmark with 10,000 flows goes from 25 Mpps to 40 Mpps on AMD Turin.Other platforms show benefits with
tcp_rrwith more than 30,000 flows.
That's nice, thanks!
However I must point out some caveates. I assume you did this on 6.19, where sheaves are still opt-in. But also, when you opt-in, the pre-existing per-cpu caching layer of percpu slab and percpu partial slabs is also still there, so effectively the amount of percpu cached slab objects increase, which can be the main performance difference for some workloads, and not the difference between sheaves and percpu (partial) slabs implementation.
Note: but hopefully for your workload it's really the implementation. "(lock) cmpxch16b" should be avoided, until you start freeing NUMA-remote (to the freeing cpu) objects in significant volumes.
In 7.0-rc1 sheaves are enabled for every cache automatically, and cpu (partial) caches are gone completely. Their size is calculated to roughly match the average amount of percpu caching the old scheme achieved (but that effectively depended on the workload too, so can't be exactly translated) and the result is visible in /sys/kernel/slab/$cache/sheaf_capacity the args.sheaf_capacity can override that automatic sizing, if the specified one is larger.
So what I would suggest is checking the performance betwen 6.19 and 7.0-rc1 without this patch (hope there won't be any other factors in the upgrade influencing this much), noting the auto-calculated capacity. If it still looks good, you don't need to do anything, otherwise you can try making the capacity larger and see what happens.
Quoted 57 lines
Signed-off-by Eric Dumazet <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Rientjes <[email protected]>Cc Roman Gushchin <[email protected]>--- net/core/skbuff.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)net/core/skbuff.c +20
-11@@ -5174,6 +5174,19 @@ static void skb_extensions_init(void) {}void __init skb_init (void ) { +struct kmem_cache_args kmem_args_small_head = { + .align =0 , + .ctor =NULL , +/* usercopy should only access first SKB_SMALL_HEAD_HEADROOM +* bytes. +* struct skb_shared_info is located at the end of skb->head, +* and should not be copied to/from user. +*/ + .useroffset =0 , + .usersize =SKB_SMALL_HEAD_HEADROOM , + .sheaf_capacity =32 , + }; + net_hotdata.skbuff_cache = kmem_cache_create_usercopy("skbuff_head_cache", sizeof(struct sk_buff), 0,@@ -5189,17 +5202,13 @@ void __init skb_init(void)0 ,SLAB_HWCACHE_ALIGN |SLAB_PANIC , NULL); -/* usercopy should only access first SKB_SMALL_HEAD_HEADROOM bytes. -* struct skb_shared_info is located at the end of skb->head, -* and should not be copied to/from user. -*/ - net_hotdata.skb_small_head_cache =kmem_cache_create_usercopy ("skbuff_small_head" , -SKB_SMALL_HEAD_CACHE_SIZE , -0 , -SLAB_HWCACHE_ALIGN |SLAB_PANIC , -0 , -SKB_SMALL_HEAD_HEADROOM , -NULL ); + + net_hotdata.skb_small_head_cache =kmem_cache_create ( +"skbuff_small_head" , +SKB_SMALL_HEAD_CACHE_SIZE , + &kmem_args_small_head, +SLAB_HWCACHE_ALIGN |SLAB_PANIC ); +skb_extensions_init (); }
Quoted 10 lines · Vlastimil Babka
Quoted 6 lines · Eric Dumazet
skbuff_small_headis used both on receive and send paths, serving potentially 80 million allocations and frees per second.Tuning it on large servers has been problematic, especially on AMD Turins platforms, where "lock cmpxch16b" latency can be over 30,000 cycles.
Huh, really? That sounds insane. Any pointers about that?
Yes, obviously on semi-contended cache lines.
Quoted 9 lines
Quoted 8 lines
Switching to SLUB sheaves fixes the issue nicely.
tcp_rrbenchmark with 10,000 flows goes from 25 Mpps to 40 Mpps on AMD Turin.Other platforms show benefits with
tcp_rrwith more than 30,000 flows.
Quoted 9 lines
That's nice, thanks!
However I must point out some caveates. I assume you did this on 6.19, where sheaves are still opt-in. But also, when you opt-in, the pre-existing per-cpu caching layer of percpu slab and percpu partial slabs is also still there, so effectively the amount of percpu cached slab objects increase, which can be the main performance difference for some workloads, and not the difference between sheaves and percpu (partial) slabs implementation.
Tests are on 6.18 LTS kernel, on which our latest production kernel is based.
Quoted 3 lines
Note: but hopefully for your workload it's really the implementation. "(lock) cmpxch16b" should be avoided, until you start freeing NUMA-remote (to the freeing cpu) objects in significant volumes.
Right, __slab_free() is absolutely not 'slow path' when we have ~80,000 in-flight objects
on a 512 cpu host.
Quoted 9 lines
In 7.0-rc1 sheaves are enabled for every cache automatically, and cpu (partial) caches are gone completely. Their size is calculated to roughly match the average amount of percpu caching the old scheme achieved (but that effectively depended on the workload too, so can't be exactly translated) and the result is visible in
/sys/kernel/slab/$cache/sheaf_capacitythe args.sheaf_capacity can override that automatic sizing, if the specified one is larger.
Nice, I did not know that (I am not following lkml traffic)
Quoted 5 lines
So what I would suggest is checking the performance betwen 6.19 and 7.0-rc1 without this patch (hope there won't be any other factors in the upgrade influencing this much), noting the auto-calculated capacity. If it still looks good, you don't need to do anything, otherwise you can try making the capacity larger and see what happens.
I can not test this yet using 7.0-rc1.
I guess we will carry this patch privately, and will come back in a few months when
I can get our infra ready.
Thanks.
Quoted 61 lines · Eric Dumazet
Quoted 10 lines · Vlastimil Babka
Quoted 6 lines · Eric Dumazet
skbuff_small_headis used both on receive and send paths, serving potentially 80 million allocations and frees per second.Tuning it on large servers has been problematic, especially on AMD Turins platforms, where "lock cmpxch16b" latency can be over 30,000 cycles.
Huh, really? That sounds insane. Any pointers about that?
Yes, obviously on semi-contended cache lines.
Quoted 9 lines
Quoted 8 lines
Switching to SLUB sheaves fixes the issue nicely.
tcp_rrbenchmark with 10,000 flows goes from 25 Mpps to 40 Mpps on AMD Turin.Other platforms show benefits with
tcp_rrwith more than 30,000 flows.Quoted 9 lines
That's nice, thanks!
However I must point out some caveates. I assume you did this on 6.19, where sheaves are still opt-in. But also, when you opt-in, the pre-existing per-cpu caching layer of percpu slab and percpu partial slabs is also still there, so effectively the amount of percpu cached slab objects increase, which can be the main performance difference for some workloads, and not the difference between sheaves and percpu (partial) slabs implementation.
Tests are on 6.18 LTS kernel, on which our latest production kernel is based.
Quoted 3 lines
Note: but hopefully for your workload it's really the implementation. "(lock) cmpxch16b" should be avoided, until you start freeing NUMA-remote (to the freeing cpu) objects in significant volumes.
Right,
__slab_free()is absolutely not 'slow path' when we have ~80,000 in-flight objects
on a 512 cpu host.Quoted 9 lines
In 7.0-rc1 sheaves are enabled for every cache automatically, and cpu (partial) caches are gone completely. Their size is calculated to roughly match the average amount of percpu caching the old scheme achieved (but that effectively depended on the workload too, so can't be exactly translated) and the result is visible in
/sys/kernel/slab/$cache/sheaf_capacitythe args.sheaf_capacity can override that automatic sizing, if the specified one is larger.Nice, I did not know that (I am not following lkml traffic)
Quoted 5 lines
So what I would suggest is checking the performance betwen 6.19 and 7.0-rc1 without this patch (hope there won't be any other factors in the upgrade influencing this much), noting the auto-calculated capacity. If it still looks good, you don't need to do anything, otherwise you can try making the capacity larger and see what happens.
Quoted 5 lines
I can not test this yet using 7.0-rc1.
I guess we will carry this patch privately, and will come back in a few months when
I can get our infra ready.
Hi, just wondering if since then you were able to test a 7.0+ kernel and thus see if the refactoring of all caches to use sheaves had the same benefit as your patch on top of 6.18?
Thanks,
Vlastimil
Quoted 1 line
Thanks.