linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH net-next] Introducing lockless cache built on top of slab allocator
@ 2021-09-20 17:47 Kangmin Park
  2021-09-20 20:50 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Kangmin Park @ 2021-09-20 17:47 UTC (permalink / raw)
  To: David S. Miller
  Cc: Jakub Kicinski, Alexander Lobakin, Jonathan Lemon,
	Willem de Bruijn, Paolo Abeni, Guillaume Nault, Vasily Averin,
	Cong Wang, netdev, linux-kernel

It is just introducing and proof of concept.
The patch code is based on other RFC patches. So, the code is not
correct yet, it is just simple proof of concept.

Recently block layer implemented percpu, lockless cache on the top
of slab allocator. It can be used for IO polling.

Link: https://lwn.net/Articles/868070/
Link: https://www.spinics.net/lists/linux-block/msg71964.html

It gained some IOPS increase (performance increased by about 10%
on the block layer).

And there are attempts to implement the percpu, lockless cache.

Link: https://lore.kernel.org/linux-mm/20210920154816.31832-1-42.hyeyoo@gmail.com/T/#u

If this cache is implemented successfully,
how about use this cache to allocate skb instead of kmem_cache_alloc_bulk()
in napi_skb_cache_get()?

I want your comment/opinion.

Signed-off-by: Kangmin Park <l4stpr0gr4m@gmail.com>
---
 net/core/skbuff.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 7c2ab27fcbf9..f9a9deca423d 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -170,11 +170,15 @@ static struct sk_buff *napi_skb_cache_get(void)
 	struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache);
 	struct sk_buff *skb;
 
-	if (unlikely(!nc->skb_count))
-		nc->skb_count = kmem_cache_alloc_bulk(skbuff_head_cache,
-						      GFP_ATOMIC,
-						      NAPI_SKB_CACHE_BULK,
-						      nc->skb_cache);
+	if (unlikely(!nc->skb_count)) {
+		/* kmem_cache_alloc_cached should be changed to return the size of
+		 * the allocated cache
+		 */
+		nc->skb_cache = kmem_cache_alloc_cached(skbuff_head_cache,
+							GFP_ATOMIC | SLB_LOCKLESS_CACHE);
+		nc->skb_count = this_cpu_ptr(skbuff_head_cache)->size;
+	}
+
 	if (unlikely(!nc->skb_count))
 		return NULL;
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH net-next] Introducing lockless cache built on top of slab allocator
  2021-09-20 17:47 [RFC PATCH net-next] Introducing lockless cache built on top of slab allocator Kangmin Park
@ 2021-09-20 20:50 ` Jakub Kicinski
  2021-09-21  1:48   ` Kangmin Park
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2021-09-20 20:50 UTC (permalink / raw)
  To: Kangmin Park
  Cc: David S. Miller, Alexander Lobakin, Jonathan Lemon,
	Willem de Bruijn, Paolo Abeni, Guillaume Nault, Vasily Averin,
	Cong Wang, netdev, linux-kernel

On Tue, 21 Sep 2021 02:47:13 +0900 Kangmin Park wrote:
> It is just introducing and proof of concept.
> The patch code is based on other RFC patches. So, the code is not
> correct yet, it is just simple proof of concept.
> 
> Recently block layer implemented percpu, lockless cache on the top
> of slab allocator. It can be used for IO polling.
> 
> Link: https://lwn.net/Articles/868070/
> Link: https://www.spinics.net/lists/linux-block/msg71964.html
> 
> It gained some IOPS increase (performance increased by about 10%
> on the block layer).
> 
> And there are attempts to implement the percpu, lockless cache.
> 
> Link: https://lore.kernel.org/linux-mm/20210920154816.31832-1-42.hyeyoo@gmail.com/T/#u
> 
> If this cache is implemented successfully,
> how about use this cache to allocate skb instead of kmem_cache_alloc_bulk()
> in napi_skb_cache_get()?
> 
> I want your comment/opinion.

Please take a look at skb cache in struct napi_alloc_cache.
That should be your target here.

> Signed-off-by: Kangmin Park <l4stpr0gr4m@gmail.com>
> ---
>  net/core/skbuff.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index 7c2ab27fcbf9..f9a9deca423d 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -170,11 +170,15 @@ static struct sk_buff *napi_skb_cache_get(void)
>  	struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache);
>  	struct sk_buff *skb;
>  
> -	if (unlikely(!nc->skb_count))
> -		nc->skb_count = kmem_cache_alloc_bulk(skbuff_head_cache,
> -						      GFP_ATOMIC,
> -						      NAPI_SKB_CACHE_BULK,
> -						      nc->skb_cache);
> +	if (unlikely(!nc->skb_count)) {
> +		/* kmem_cache_alloc_cached should be changed to return the size of
> +		 * the allocated cache
> +		 */
> +		nc->skb_cache = kmem_cache_alloc_cached(skbuff_head_cache,
> +							GFP_ATOMIC | SLB_LOCKLESS_CACHE);
> +		nc->skb_count = this_cpu_ptr(skbuff_head_cache)->size;
> +	}
> +
>  	if (unlikely(!nc->skb_count))
>  		return NULL;
>  

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH net-next] Introducing lockless cache built on top of slab allocator
  2021-09-20 20:50 ` Jakub Kicinski
@ 2021-09-21  1:48   ` Kangmin Park
  0 siblings, 0 replies; 3+ messages in thread
From: Kangmin Park @ 2021-09-21  1:48 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Alexander Lobakin, Jonathan Lemon,
	Willem de Bruijn, Paolo Abeni, Guillaume Nault, Vasily Averin,
	Cong Wang, netdev, linux-kernel

2021년 9월 21일 (화) 오전 5:50, Jakub Kicinski <kuba@kernel.org>님이 작성:
>
> On Tue, 21 Sep 2021 02:47:13 +0900 Kangmin Park wrote:
> > It is just introducing and proof of concept.
> > The patch code is based on other RFC patches. So, the code is not
> > correct yet, it is just simple proof of concept.
> >
> > Recently block layer implemented percpu, lockless cache on the top
> > of slab allocator. It can be used for IO polling.
> >
> > Link: https://lwn.net/Articles/868070/
> > Link: https://www.spinics.net/lists/linux-block/msg71964.html
> >
> > It gained some IOPS increase (performance increased by about 10%
> > on the block layer).
> >
> > And there are attempts to implement the percpu, lockless cache.
> >
> > Link: https://lore.kernel.org/linux-mm/20210920154816.31832-1-42.hyeyoo@gmail.com/T/#u
> >
> > If this cache is implemented successfully,
> > how about use this cache to allocate skb instead of kmem_cache_alloc_bulk()
> > in napi_skb_cache_get()?
> >
> > I want your comment/opinion.
>
> Please take a look at skb cache in struct napi_alloc_cache.
> That should be your target here.
>

Oh, thanks for the advice.
I'll send you a v2 patch to replace/improve napi_alloc_cache
when progress is made in implementing the lockless cache.

Best Regards,
Kangmin Park

> > Signed-off-by: Kangmin Park <l4stpr0gr4m@gmail.com>
> > ---
> >  net/core/skbuff.c | 14 +++++++++-----
> >  1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> > index 7c2ab27fcbf9..f9a9deca423d 100644
> > --- a/net/core/skbuff.c
> > +++ b/net/core/skbuff.c
> > @@ -170,11 +170,15 @@ static struct sk_buff *napi_skb_cache_get(void)
> >       struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache);
> >       struct sk_buff *skb;
> >
> > -     if (unlikely(!nc->skb_count))
> > -             nc->skb_count = kmem_cache_alloc_bulk(skbuff_head_cache,
> > -                                                   GFP_ATOMIC,
> > -                                                   NAPI_SKB_CACHE_BULK,
> > -                                                   nc->skb_cache);
> > +     if (unlikely(!nc->skb_count)) {
> > +             /* kmem_cache_alloc_cached should be changed to return the size of
> > +              * the allocated cache
> > +              */
> > +             nc->skb_cache = kmem_cache_alloc_cached(skbuff_head_cache,
> > +                                                     GFP_ATOMIC | SLB_LOCKLESS_CACHE);
> > +             nc->skb_count = this_cpu_ptr(skbuff_head_cache)->size;
> > +     }
> > +
> >       if (unlikely(!nc->skb_count))
> >               return NULL;
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-21  2:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20 17:47 [RFC PATCH net-next] Introducing lockless cache built on top of slab allocator Kangmin Park
2021-09-20 20:50 ` Jakub Kicinski
2021-09-21  1:48   ` Kangmin Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).