From: Paolo Abeni <pabeni@redhat.com>
To: Alexander H Duyck <alexander.duyck@gmail.com>, netdev@vger.kernel.org
Cc: Eric Dumazet <edumazet@google.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>
Subject: Re: [PATCH net-next] net: skb: introduce and use a single page frag cache
Date: Wed, 21 Sep 2022 22:21:29 +0200 [thread overview]
Message-ID: <aaf8214cf5d73ac5564aec38e67973ef47c45b5e.camel@redhat.com> (raw)
In-Reply-To: <cb3f22f20f3ecb8b049c3e590fd99c52006ef964.camel@redhat.com>
On Wed, 2022-09-21 at 21:33 +0200, Paolo Abeni wrote:
> On Wed, 2022-09-21 at 11:11 -0700, Alexander H Duyck wrote:
[...]
>
> > > {
> > > struct napi_alloc_cache *nc;
> > > struct sk_buff *skb;
> > > + bool pfmemalloc;
> > > void *data;
> > >
> > > DEBUG_NET_WARN_ON_ONCE(!in_softirq());
> > > len += NET_SKB_PAD + NET_IP_ALIGN;
> > >
> > > + /* When the small frag allocator is available, prefer it over kmalloc
> > > + * for small fragments
> > > + */
> > > + if (NAPI_HAS_SMALL_PAGE_FRAG && len <= SKB_WITH_OVERHEAD(1024)) {
> > > + nc = this_cpu_ptr(&napi_alloc_cache);
> > > +
> > > + if (sk_memalloc_socks())
> > > + gfp_mask |= __GFP_MEMALLOC;
> > > +
> > > + /* we are artificially inflating the allocation size, but
> > > + * that is not as bad as it may look like, as:
> > > + * - 'len' less then GRO_MAX_HEAD makes little sense
> > > + * - larger 'len' values lead to fragment size above 512 bytes
> > > + * as per NAPI_HAS_SMALL_PAGE_FRAG definition
> > > + * - kmalloc would use the kmalloc-1k slab for such values
> > > + */
> > > + len = SZ_1K;
> > > +
> > > + data = page_frag_alloc_1k(&nc->page_small, gfp_mask);
> > > + pfmemalloc = nc->page_small.pfmemalloc;
> > > + goto check_data;
> > > + }
> > > +
> >
> > It might be better to place this code further down as a branch rather
> > than having to duplicate things up here such as the __GFP_MEMALLOC
> > setting.
> >
> > You could essentially just put the lines getting the napi_alloc_cache
> > and adding the shared info after the sk_memalloc_socks() check. Then it
> > could just be an if/else block either calling page_frag_alloc or your
> > page_frag_alloc_1k.
>
> I thought about that option, but I did not like it much because adds a
> conditional in the fast-path for small-size allocation, and the
> duplicate code is very little.
>
> I can change the code that way, if you have strong opinion in that
> regards.
Thinking again about the above, I now belive that what you suggest is
the right thing to do: my patch ignores the requested
__GFP_DIRECT_RECLAIM and GFP_DMA flags for small allocation - we always
need to fallback to kmalloc() when the caller ask for them.
TL;DR: I'll move the page_frag_alloc_1k() call below in v2.
Thanks!
Paolo
next prev parent reply other threads:[~2022-09-21 20:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-21 16:41 [PATCH net-next] net: skb: introduce and use a single page frag cache Paolo Abeni
2022-09-21 17:18 ` Eric Dumazet
2022-09-21 18:10 ` Paolo Abeni
2022-09-21 18:11 ` Alexander H Duyck
2022-09-21 19:33 ` Paolo Abeni
2022-09-21 20:21 ` Paolo Abeni [this message]
2022-09-21 20:23 ` Alexander H Duyck
2022-09-21 20:51 ` Paolo Abeni
2022-09-21 21:44 ` Alexander Duyck
2022-09-22 16:29 ` Paolo Abeni
2022-09-22 20:21 ` Paolo Abeni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aaf8214cf5d73ac5564aec38e67973ef47c45b5e.camel@redhat.com \
--to=pabeni@redhat.com \
--cc=alexander.duyck@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox