From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Eric Dumazet <edumazet@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>
Cc: Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, Eric Dumazet <edumazet@kernel.org>
Subject: Re: [PATCH net-next] net/packet: wait for a single RCU grace period in packet_release()
Date: Thu, 19 Nov 2026 12:59:13 -0500 [thread overview]
Message-ID: <willemdebruijn.kernel.68d88e182760@gmail.com> (raw)
In-Reply-To: <20261118211439.1453635-1-edumazet@kernel.org>
Eric Dumazet wrote:
> Closing an AF_PACKET socket waits for one RCU grace period per ring
> in packet_set_ring(), then for another one at the end of
> packet_release(). A socket with an rx ring (libpcap, tcpdump) pays for
> two grace periods, a socket with both rx and tx rings for three.
>
> All the RCU unpublishing is done at the beginning of packet_release(),
> when unregister_prot_hook() removes the socket from the ptype lists or
> from its fanout group. Nothing is unpublished after that point:
>
> - When closing, packet_set_ring() finds the socket not running and
> does not touch the hooks.
>
> - fanout_release() only clears po->fanout and unlinks the group from
> fanout_list, both under fanout_mutex. If it drops the last reference
> on the group, all members have already been unlinked, so the fanout
> hook was removed by __fanout_unlink().
>
> Call fanout_release() and synchronize_net() right after the socket has
> been detached, before the rings are torn down, and skip the wait in
> packet_set_ring() when closing. That single grace period covers the
> rings, po->rollover and the fanout group.
>
> The setsockopt() path of packet_set_ring() is unchanged.
>
> Average close() duration over 20 sockets bound to lo, in a 4 vCPU
> virtme-ng guest:
>
> before after
> no ring 7.86 ms 7.76 ms
> rx ring 8.01 ms 4.01 ms
> tx ring 8.00 ms 4.00 ms
> rx + tx rings 11.96 ms 4.00 ms
> rx + tx rings, fanout 12.02 ms 4.01 ms
Just curious, any idea why no ring seems to take twice as long?
Don't spend time on it. It's just not obvious to me.
>
> Tested with tools/testing/selftests/net/run_afpackettests
> (psock_fanout, psock_tpacket, txring_overwrite) on a kernel without
> KASAN or lockdep.
>
> Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Reviewed-by: Willem de Bruijn <willemb@google.com>
next prev parent reply other threads:[~2026-11-19 17:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 21:14 [PATCH net-next] net/packet: wait for a single RCU grace period in packet_release() Eric Dumazet
2026-11-19 17:59 ` Willem de Bruijn [this message]
2026-11-19 18:25 ` Eric Dumazet
2026-11-20 3:20 ` 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=willemdebruijn.kernel.68d88e182760@gmail.com \
--to=willemdebruijn.kernel@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.