netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Eric Dumazet <edumazet@google.com>,
	 Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	 Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>,
	 Willem de Bruijn <willemb@google.com>,
	 Tahsin Erdogan <trdgn@amazon.com>,
	 netdev@vger.kernel.org,  eric.dumazet@gmail.com
Subject: Re: [PATCH net-next 1/4] net: allow alloc_skb_with_frags() to allocate bigger packets
Date: Tue, 01 Aug 2023 13:56:39 -0400	[thread overview]
Message-ID: <64c947578a8c7_1c9eb8294e6@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <CANn89iJwP_Ar57Te0EG2fAjM=JNL+N0mYwnEZDrJME4nhe4WTg@mail.gmail.com>

Eric Dumazet wrote:
> On Tue, Aug 1, 2023 at 5:44 PM Willem de Bruijn
> <willemdebruijn.kernel@gmail.com> wrote:
> >
> > Eric Dumazet wrote:
> > > Refactor alloc_skb_with_frags() to allow bigger packets allocations.
> > >
> > > Instead of assuming that only order-0 allocations will be attempted,
> > > use the caller supplied max order.
> > >
> > > Signed-off-by: Eric Dumazet <edumazet@google.com>
> > > Cc: Tahsin Erdogan <trdgn@amazon.com>
> > > ---
> > >  net/core/skbuff.c | 56 +++++++++++++++++++++--------------------------
> > >  1 file changed, 25 insertions(+), 31 deletions(-)
> > >
> > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> > > index a298992060e6efdecb87c7ffc8290eafe330583f..0ac70a0144a7c1f4e7824ddc19980aee73e4c121 100644
> > > --- a/net/core/skbuff.c
> > > +++ b/net/core/skbuff.c
> > > @@ -6204,7 +6204,7 @@ EXPORT_SYMBOL_GPL(skb_mpls_dec_ttl);
> > >   *
> > >   * @header_len: size of linear part
> > >   * @data_len: needed length in frags
> > > - * @max_page_order: max page order desired.
> > > + * @order: max page order desired.
> > >   * @errcode: pointer to error code if any
> > >   * @gfp_mask: allocation mask
> > >   *
> > > @@ -6212,21 +6212,17 @@ EXPORT_SYMBOL_GPL(skb_mpls_dec_ttl);
> > >   */
> > >  struct sk_buff *alloc_skb_with_frags(unsigned long header_len,
> > >                                    unsigned long data_len,
> > > -                                  int max_page_order,
> > > +                                  int order,
> > >                                    int *errcode,
> > >                                    gfp_t gfp_mask)
> > >  {
> > > -     int npages = (data_len + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
> > >       unsigned long chunk;
> > >       struct sk_buff *skb;
> > >       struct page *page;
> > > -     int i;
> > > +     int nr_frags = 0;
> > >
> > >       *errcode = -EMSGSIZE;
> > > -     /* Note this test could be relaxed, if we succeed to allocate
> > > -      * high order pages...
> > > -      */
> > > -     if (npages > MAX_SKB_FRAGS)
> > > +     if (unlikely(data_len > MAX_SKB_FRAGS * (PAGE_SIZE << order)))
> > >               return NULL;
> > >
> > >       *errcode = -ENOBUFS;
> > > @@ -6234,34 +6230,32 @@ struct sk_buff *alloc_skb_with_frags(unsigned long header_len,
> > >       if (!skb)
> > >               return NULL;
> > >
> > > -     skb->truesize += npages << PAGE_SHIFT;
> > > -
> > > -     for (i = 0; npages > 0; i++) {
> > > -             int order = max_page_order;
> > > -
> > > -             while (order) {
> > > -                     if (npages >= 1 << order) {
> > > -                             page = alloc_pages((gfp_mask & ~__GFP_DIRECT_RECLAIM) |
> > > -                                                __GFP_COMP |
> > > -                                                __GFP_NOWARN,
> > > -                                                order);
> > > -                             if (page)
> > > -                                     goto fill_page;
> > > -                             /* Do not retry other high order allocations */
> >
> > Is this heuristic to only try one type of compound pages and else
> > fall back onto regular pages still relevant? I don't know the story
> > behind it.
> 
> I keep doing high-order attempts without direct reclaim,
> they should be fine and we eventually fallback to order-2 pages
> if we have plenty of them.
> 
> Immediate fallback to order-0 seems pessimistic.
> 
> >
> > > -                             order = 1;
> > > -                             max_page_order = 0;
> > > -                     }
> > > +     while (data_len) {
> > > +             if (nr_frags == MAX_SKB_FRAGS - 1)
> > > +                     goto failure;
> > > +             while (order && data_len < (PAGE_SIZE << order))
> > >                       order--;
> >
> > Why decrement order on every iteration through the loop, not just when
> > alloc_pages fails?
> 
> Say we enter the function with initial @data_len == 4000, and @order==3
> 
> We do not want to allocate/waste an order-3 page (32768 bytes on x86)
> while an order-0 one should be good enough to fit the expected
> payload.
> 
> Same story if initial data_len = 33000:
> - We should allocate one order-3 page, and one order-0 one, instead of
> two order-3 pages.

Thanks for the explanation. For @data_len == 5000, you would want to
allocate an order-1?




  reply	other threads:[~2023-08-01 17:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01 13:54 [PATCH net-next 0/4] net: relax alloc_skb_with_frags() max size Eric Dumazet
2023-08-01 13:54 ` [PATCH net-next 1/4] net: allow alloc_skb_with_frags() to allocate bigger packets Eric Dumazet
2023-08-01 15:44   ` Willem de Bruijn
2023-08-01 16:33     ` Eric Dumazet
2023-08-01 17:56       ` Willem de Bruijn [this message]
2023-08-01 18:10         ` Eric Dumazet
2023-08-01 18:21           ` Eric Dumazet
2023-08-01 18:39             ` Willem de Bruijn
2023-08-01 13:54 ` [PATCH net-next 2/4] net: tun: change tun_alloc_skb() to allow bigger paged allocations Eric Dumazet
2023-08-01 13:54 ` [PATCH net-next 3/4] net/packet: change packet_alloc_skb() " Eric Dumazet
2023-08-01 13:54 ` [PATCH net-next 4/4] net: tap: change tap_alloc_skb() " Eric Dumazet
2023-08-03  1:50 ` [PATCH net-next 0/4] net: relax alloc_skb_with_frags() max size patchwork-bot+netdevbpf

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=64c947578a8c7_1c9eb8294e6@willemb.c.googlers.com.notmuch \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=trdgn@amazon.com \
    --cc=willemb@google.com \
    /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;
as well as URLs for NNTP newsgroup(s).