Re: [PATCH v3 net-next 3/3] ipv4/udp: Add 4-tuple hash for connected socket

From: Willem de Bruijn
Date: Thu Oct 10 2024 - 09:51:23 EST


Philo Lu wrote:
> Currently, the udp_table has two hash table, the port hash and portaddr
> hash. Usually for UDP servers, all sockets have the same local port and
> addr, so they are all on the same hash slot within a reuseport group.
>
> In some applications, UDP servers use connect() to manage clients. In
> particular, when firstly receiving from an unseen 4 tuple, a new socket
> is created and connect()ed to the remote addr:port, and then the fd is
> used exclusively by the client.
>
> Once there are connected sks in a reuseport group, udp has to score all
> sks in the same hash2 slot to find the best match. This could be
> inefficient with a large number of connections, resulting in high
> softirq overhead.
>
> To solve the problem, this patch implement 4-tuple hash for connected
> udp sockets. During connect(), hash4 slot is updated, as well as a
> corresponding counter, hash4_cnt, in hslot2. In __udp4_lib_lookup(),
> hslot4 will be searched firstly if the counter is non-zero. Otherwise,
> hslot2 is used like before. Note that only connected sockets enter this
> hash4 path, while un-connected ones are not affected.
>
> Signed-off-by: Philo Lu <lulie@xxxxxxxxxxxxxxxxx>
> Signed-off-by: Cambda Zhu <cambda@xxxxxxxxxxxxxxxxx>
> Signed-off-by: Fred Chen <fred.cc@xxxxxxxxxxxxxxx>
> Signed-off-by: Yubing Qiu <yubing.qiuyubing@xxxxxxxxxxxxxxx>

> diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
> index bbf3352213c4..4d3dfcb48a39 100644
> --- a/net/ipv6/udp.c
> +++ b/net/ipv6/udp.c
> @@ -111,7 +111,7 @@ void udp_v6_rehash(struct sock *sk)
> &sk->sk_v6_rcv_saddr,
> inet_sk(sk)->inet_num);
>
> - udp_lib_rehash(sk, new_hash);
> + udp_lib_rehash(sk, new_hash, 0); /* 4-tuple hash not implemented */

What is the plan for IPv6?