bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Jason Xing <kerneljasonxing@gmail.com>,
	 Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: Jakub Kicinski <kuba@kernel.org>,
	 davem@davemloft.net,  edumazet@google.com,  pabeni@redhat.com,
	 bjorn@kernel.org,  magnus.karlsson@intel.com,
	 maciej.fijalkowski@intel.com,  jonathan.lemon@gmail.com,
	 sdf@fomichev.me,  ast@kernel.org,  daniel@iogearbox.net,
	 hawk@kernel.org,  john.fastabend@gmail.com,  joe@dama.to,
	 bpf@vger.kernel.org,  netdev@vger.kernel.org,
	 Jason Xing <kernelxing@tencent.com>
Subject: Re: [PATCH net-next v3] net: xsk: introduce XDP_MAX_TX_BUDGET set/getsockopt
Date: Fri, 20 Jun 2025 18:24:07 -0400	[thread overview]
Message-ID: <6855df87665e3_1ca432948d@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <CAL+tcoAfr_3g6mD0i8dzMnm6aO+FzWRBo_eoHv7+mjDLve90Ww@mail.gmail.com>

Jason Xing wrote:
> On Fri, Jun 20, 2025 at 9:50 PM Willem de Bruijn
> <willemdebruijn.kernel@gmail.com> wrote:
> >
> > Jason Xing wrote:
> > > On Thu, Jun 19, 2025 at 11:09 PM Jakub Kicinski <kuba@kernel.org> wrote:
> > > >
> > > > On Thu, 19 Jun 2025 17:04:40 +0800 Jason Xing wrote:
> > > > > @@ -424,7 +421,9 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc)
> > > > >       rcu_read_lock();
> > > > >  again:
> > > > >       list_for_each_entry_rcu(xs, &pool->xsk_tx_list, tx_list) {
> > > > > -             if (xs->tx_budget_spent >= MAX_PER_SOCKET_BUDGET) {
> > > > > +             int max_budget = READ_ONCE(xs->max_tx_budget);
> > > > > +
> > > > > +             if (xs->tx_budget_spent >= max_budget) {
> > > > >                       budget_exhausted = true;
> > > > >                       continue;
> > > > >               }
> > > > > @@ -779,7 +778,7 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,
> > > > >  static int __xsk_generic_xmit(struct sock *sk)
> > > > >  {
> > > > >       struct xdp_sock *xs = xdp_sk(sk);
> > > > > -     u32 max_batch = TX_BATCH_SIZE;
> > > > > +     u32 max_budget = READ_ONCE(xs->max_tx_budget);
> > > >
> > > > Hm, maybe a question to Stan / Willem & other XSK experts but are these
> > > > two max values / code paths really related? Question 2 -- is generic
> > > > XSK a legit optimization target, legit enough to add uAPI?
> > >
> > > I'm not an expert but my take is:
> > > #1, I don't see the correlation actually while I don't see any reason
> > > to use the different values for both of them.
> > > #2, These two definitions are improvement points because whether to do
> > > the real send is driven by calling sendto(). Enlarging a little bit of
> > > this value could save many times of calling sendto(). As for the uAPI,
> > > I don't know if it's worth it, sorry. If not, the previous version 2
> > > patch (regarding per-netns policy) will be revived.
> > >
> > > So I will leave those two questions to XSK experts as well.
> >
> > You're proposing the code change, so I think it's on you to make
> > this argument?
> >
> > > #2 quantification
> > > It's really hard to do so mainly because of various stacks implemented
> > > in the user-space. AF_XDP is providing a fundamental mechanism only
> > > and its upper layer is prosperous.
> >
> > I think it's a hard sell to argue adding a tunable, if no plausible
> > recommendation can be given on how the tunable is to be used.
> 
> Actually I mentioned it in the commit message. One of advantages is to
> contribute to less frequencies of sendto() and overall higher
> transmission speed.

Understood. It is just informative to have more quantitative data.
What value worked for you.
 
> >
> > It's not necessary, and most cases infeasible, to give a heuristic
> > that fits all possible users. But at a minimum the one workload that
> > prompted the patch. What value do you set it to and how did you
> > arrive at that number?
> 
> One naive question from me is why the number of packets to be sent is
> definitely required to be limited within a small number by default?
> Let me set tcp as an example, a simple sendmsg call will not be
> stopped because of the hardcoded limitation.
> 
> For one application I saw, I suggested using 128 because I saw two
> limitations without changing any default configuration: 1)
> XDP_MAX_TX_BUDGET, 2) socket sndbuf which is 212992 decided by
> net.core.wmem_default. As to XDP_MAX_TX_BUDGET, the scenario behind
> this was I counted how many desc are transmitted to the driver at one
> time of sendto() based on [1] patch and then I calculated the
> possibility of hitting the upper bound. Finally I chose 128 as a
> suitable value because 1) it covers most of the cases, 2) a higher
> number would not bring evident results.
> 
> [1]: https://lore.kernel.org/all/20250619093641.70700-1-kerneljasonxing@gmail.com/

This is indeed helpful context.

Another limiting factor is the XSK TX queue length?

So even if a user passes UINT_MAX, nothing terrible will happen.

Still, it is better to not accept obviously bad input to begin with.

Normal packet processing loops give up control after tens or maybe
a few hundred packets at a time.

  reply	other threads:[~2025-06-20 22:24 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-19  9:04 [PATCH net-next v3] net: xsk: introduce XDP_MAX_TX_BUDGET set/getsockopt Jason Xing
2025-06-19 13:53 ` Willem de Bruijn
2025-06-19 23:53   ` Jason Xing
2025-06-20  0:02     ` Jason Xing
2025-06-20 13:43     ` Willem de Bruijn
2025-06-20 13:58       ` Willem de Bruijn
2025-06-20 14:37         ` Jason Xing
2025-06-20 22:21           ` Willem de Bruijn
2025-06-19 15:09 ` Jakub Kicinski
2025-06-20  0:17   ` Jason Xing
2025-06-20 13:50     ` Willem de Bruijn
2025-06-20 15:03       ` Jason Xing
2025-06-20 22:24         ` Willem de Bruijn [this message]
2025-06-21  0:40           ` Jason Xing
2025-06-21 14:43     ` Jakub Kicinski
2025-06-22  0:05       ` Jason Xing
2025-06-20 14:25   ` Stanislav Fomichev
2025-06-20 16:30     ` Jason Xing
2025-06-20 16:47       ` Stanislav Fomichev
2025-06-20 17:46         ` Jason Xing
2025-06-23 14:18           ` Stanislav Fomichev
2025-06-23 23:54             ` Jason Xing
2025-06-24  0:48               ` Stanislav Fomichev
2025-06-24  2:47                 ` Jason Xing
2025-06-20 22:20     ` Willem de Bruijn
2025-06-21  1:06       ` Jason Xing

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=6855df87665e3_1ca432948d@willemb.c.googlers.com.notmuch \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=joe@dama.to \
    --cc=john.fastabend@gmail.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=kerneljasonxing@gmail.com \
    --cc=kernelxing@tencent.com \
    --cc=kuba@kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    /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).