mbox series

[v2,net-next,0/4] net: core: use a dedicated kmem_cache for skb head allocs

Message ID 20230206173103.2617121-1-edumazet@google.com (mailing list archive)
Headers show
Series net: core: use a dedicated kmem_cache for skb head allocs | expand

Message

Eric Dumazet Feb. 6, 2023, 5:30 p.m. UTC
Our profile data show that using kmalloc(non_const_size)/kfree(ptr)
has a certain cost, because kfree(ptr) has to pull a 'struct page'
in cpu caches.

Using a dedicated kmem_cache for TCP skb->head allocations makes
a difference, both in cpu cycles and memory savings.

This kmem_cache could also be used for GRO skb allocations,
this is left as a future exercise.

v2: addressed compile error with CONFIG_SLOB=y (kernel bots)
    Changed comment (Jakub)

Eric Dumazet (4):
  net: add SKB_HEAD_ALIGN() helper
  net: remove osize variable in __alloc_skb()
  net: factorize code in kmalloc_reserve()
  net: add dedicated kmem_cache for typical/small skb->head

 include/linux/skbuff.h |   8 +++
 net/core/skbuff.c      | 115 +++++++++++++++++++++++++++++------------
 2 files changed, 90 insertions(+), 33 deletions(-)

Comments

Alexander Duyck Feb. 7, 2023, 4:58 p.m. UTC | #1
On Mon, 2023-02-06 at 17:30 +0000, Eric Dumazet wrote:
> Our profile data show that using kmalloc(non_const_size)/kfree(ptr)
> has a certain cost, because kfree(ptr) has to pull a 'struct page'
> in cpu caches.
> 
> Using a dedicated kmem_cache for TCP skb->head allocations makes
> a difference, both in cpu cycles and memory savings.
> 
> This kmem_cache could also be used for GRO skb allocations,
> this is left as a future exercise.
> 
> v2: addressed compile error with CONFIG_SLOB=y (kernel bots)
>     Changed comment (Jakub)
> 
> Eric Dumazet (4):
>   net: add SKB_HEAD_ALIGN() helper
>   net: remove osize variable in __alloc_skb()
>   net: factorize code in kmalloc_reserve()
>   net: add dedicated kmem_cache for typical/small skb->head
> 
>  include/linux/skbuff.h |   8 +++
>  net/core/skbuff.c      | 115 +++++++++++++++++++++++++++++------------
>  2 files changed, 90 insertions(+), 33 deletions(-)
> 

Looks good to me.

Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
patchwork-bot+netdevbpf@kernel.org Feb. 8, 2023, 12:20 a.m. UTC | #2
Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  6 Feb 2023 17:30:59 +0000 you wrote:
> Our profile data show that using kmalloc(non_const_size)/kfree(ptr)
> has a certain cost, because kfree(ptr) has to pull a 'struct page'
> in cpu caches.
> 
> Using a dedicated kmem_cache for TCP skb->head allocations makes
> a difference, both in cpu cycles and memory savings.
> 
> [...]

Here is the summary with links:
  - [v2,net-next,1/4] net: add SKB_HEAD_ALIGN() helper
    https://git.kernel.org/netdev/net-next/c/115f1a5c42bd
  - [v2,net-next,2/4] net: remove osize variable in __alloc_skb()
    https://git.kernel.org/netdev/net-next/c/65998d2bf857
  - [v2,net-next,3/4] net: factorize code in kmalloc_reserve()
    https://git.kernel.org/netdev/net-next/c/5c0e820cbbbe
  - [v2,net-next,4/4] net: add dedicated kmem_cache for typical/small skb->head
    https://git.kernel.org/netdev/net-next/c/bf9f1baa279f

You are awesome, thank you!