[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89iLj8hC7jgb5jDNi01nKqikGbgKMtFvbZDxWi4Qoi1y8fw@mail.gmail.com>
Date: Fri, 3 Feb 2023 09:17:55 +0100
From: Eric Dumazet <edumazet@...gle.com>
To: Paolo Abeni <pabeni@...hat.com>
Cc: "David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>, netdev@...r.kernel.org,
eric.dumazet@...il.com, Alexander Duyck <alexanderduyck@...com>,
Soheil Hassas Yeganeh <soheil@...gle.com>
Subject: Re: [PATCH net-next 4/4] net: add dedicated kmem_cache for
typical/small skb->head
On Fri, Feb 3, 2023 at 8:59 AM Paolo Abeni <pabeni@...hat.com> wrote:
>
> On Thu, 2023-02-02 at 18:58 +0000, Eric Dumazet wrote:
> > Note: after Kees Cook patches and this one, we might
> > be able to revert commit
> > dbae2b062824 ("net: skb: introduce and use a single page frag cache")
> > because GRO_MAX_HEAD is also small.
>
> I guess I'll need some time to do the relevant benchmarks, but I'm not
> able to schedule them very soon.
No worries, this can be done later.
Note the results might depend on SLUB/SLAB choice.
>
> > @@ -486,6 +499,21 @@ static void *kmalloc_reserve(unsigned int *size, gfp_t flags, int node,
> > void *obj;
> >
> > obj_size = SKB_HEAD_ALIGN(*size);
> > + if (obj_size <= SKB_SMALL_HEAD_CACHE_SIZE &&
> > + !(flags & KMALLOC_NOT_NORMAL_BITS)) {
> > +
> > + /* skb_small_head_cache has non power of two size,
> > + * likely forcing SLUB to use order-3 pages.
> > + * We deliberately attempt a NOMEMALLOC allocation only.
> > + */
> > + obj = kmem_cache_alloc_node(skb_small_head_cache,
> > + flags | __GFP_NOMEMALLOC | __GFP_NOWARN,
> > + node);
> > + if (obj) {
> > + *size = SKB_SMALL_HEAD_CACHE_SIZE;
> > + goto out;
> > + }
>
> In case kmem allocation failure, should we try to skip the 2nd
> __GFP_NOMEMALLOC attempt below?
We could, but my reasoning was that we might find an object in the
other kmem_cache freelist.
kmalloc-1 objects tend to use smaller page orders, so are more likely
to succeed if
there is no order-3 page available in the buddy allocator.(I mentioned
this in the comment)
>
> I *think* non power of two size is also required to avoid an issue
> plain (no GFP_DMA nor __GFP_ACCOUNT) allocations in case of fallback to
> kmalloc(), to prevent skb_kfree_head() mis-interpreting skb->head as
> kmem_cache allocated.
Indeed there are multiple cases explaining why SKB_SMALL_HEAD_CACHE_SIZE
needs to be a non power of two.
Powered by blists - more mailing lists