[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89iK-iPeGNVP5zKq4t+0vPhTsqCFeP715Z5XSfW6KdfhzKg@mail.gmail.com>
Date: Wed, 17 Sep 2025 09:07:21 -0700
From: Eric Dumazet <edumazet@...gle.com>
To: Willem de Bruijn <willemdebruijn.kernel@...il.com>
Cc: "David S . Miller" <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, Simon Horman <horms@...nel.org>,
Willem de Bruijn <willemb@...gle.com>, Kuniyuki Iwashima <kuniyu@...gle.com>, David Ahern <dsahern@...nel.org>,
netdev@...r.kernel.org, eric.dumazet@...il.com
Subject: Re: [PATCH net-next 06/10] udp: update sk_rmem_alloc before busylock acquisition
On Wed, Sep 17, 2025 at 8:01 AM Willem de Bruijn
<willemdebruijn.kernel@...il.com> wrote:
>
> Eric Dumazet wrote:
> > Avoid piling too many producers on the busylock
> > by updating sk_rmem_alloc before busylock acquisition.
> >
> > Signed-off-by: Eric Dumazet <edumazet@...gle.com>
> > ---
> > net/ipv4/udp.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> > index edd846fee90ff7850356a5cb3400ce96856e5429..658ae87827991a78c25c2172d52e772c94ea217f 100644
> > --- a/net/ipv4/udp.c
> > +++ b/net/ipv4/udp.c
> > @@ -1753,13 +1753,16 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
> > if (rmem > (rcvbuf >> 1)) {
> > skb_condense(skb);
> > size = skb->truesize;
> > + rmem = atomic_add_return(size, &sk->sk_rmem_alloc);
> > + if (rmem > rcvbuf)
> > + goto uncharge_drop;
>
> This does more than just reorganize code. Can you share some context
> on the behavioral change?
Sure : If we update sk_rmem_alloc sooner, before waiting 50usec+ on the busylock
other cpus trying to push packets might see sk_rmem_alloc being too
big already and exit early,
before even trying to acquire the spinlock.
Say you have many cpus coming there.
Before the patch :
They all spin on busylock, then update sk_rmem_alloc one at a time
(while they hold busylock)
After :
They update sk_rmem_alloc :
if too big, they immediately drop and return, no need to take any lock.
If not too big, then they acquire the busylock.
>
> > busy = busylock_acquire(sk);
> > + } else {
> > + atomic_add(size, &sk->sk_rmem_alloc);
> > }
> >
> > udp_set_dev_scratch(skb);
> >
> > - atomic_add(size, &sk->sk_rmem_alloc);
> > -
> > spin_lock(&list->lock);
> > err = udp_rmem_schedule(sk, size);
> > if (err) {
> > --
> > 2.51.0.384.g4c02a37b29-goog
> >
>
>
Powered by blists - more mailing lists