Re: [PATCH net v2] tcp: Fix fastreuse cache initialization on first bind

From: Kuniyuki Iwashima

Date: Mon Oct 26 2026 - 22:05:02 EST


On Mon, 26 Oct 2026 09:52:07 +0000, Zhewei Yuan wrote:
> inet_csk_update_fastreuse() initializes the reuse caches only when
> tb->bhash2 is empty, but both inet_csk_get_port() and
> __inet_inherit_port() link tb2 before calling it, so the first-bind
> branch is never taken.
>
> As a result, SO_REUSEADDR binds never get fastreuse=1 and keep
> scanning existing owners, and SO_REUSEPORT starts in STRICT instead
> of ANY.
>
> Initialize the caches when tb2 is the only entry in tb->bhash2 and has
> no owners. Timewait sockets are also linked on tb2->owners, so this is
> equivalent to the old hlist_empty(&tb->owners) test.
>
> Found by manual code inspection and confirmed with GDB. Binding 16000
> SO_REUSEADDR sockets to one address/port in a KVM guest takes 4.18 s
> before and 19.4 ms after this patch. Existing bind/reuse selftests
> pass. Analysis and testing were assisted by an AI tool (Codex).
>
> Fixes: 8002d44fe84d ("tcp: Check hlist_empty(&tb->bhash2) instead of hlist_empty(&tb->owners).")
> Reviewed-by: Eric Dumazet <edumazet@xxxxxxxxxx>
> Signed-off-by: Zhewei Yuan <yzwlhm@xxxxxxxxx>

Good catch, thanks !

Reviewed-by: Kuniyuki Iwashima <kuniyu@xxxxxxxxxx>