]> git.ipfire.org Git - thirdparty/linux.git/commit
ipvs: switch to per-net connection table
authorJulian Anastasov <ja@ssi.bg>
Tue, 3 Mar 2026 21:04:07 +0000 (23:04 +0200)
committerFlorian Westphal <fw@strlen.de>
Wed, 4 Mar 2026 10:45:45 +0000 (11:45 +0100)
commit2fa7cc9c70254d42a82bf82827d8d20cafe975d2
tree07f14eb227175bc7dd9cf7377a7a166c7abe277e
parent840aac3d900d09ec8fb8efe41bd7d09f9eb15538
ipvs: switch to per-net connection table

Use per-net resizable hash table for connections. The global table
is slow to walk when using many namespaces.

The table can be resized in the range of [256 - ip_vs_conn_tab_size].
Table is attached only while services are present. Resizing is done
by delayed work based on load (the number of connections).

Add a hash_key field into the connection to store the table ID in
the highest bit and the entry's hash value in the lowest bits. The
lowest part of the hash value is used as bucket ID, the remaining
part is used to filter the entries in the bucket before matching
the keys and as result, helps the lookup operation to access only
one cache line. By knowing the table ID and bucket ID for entry,
we can unlink it without calculating the hash value and doing
lookup by keys. We need only to validate the saved hash_key under
lock.

For better security switch from jhash to siphash for the default
connection hashing but the persistence engines may use their own
function. Keeping the hash table loaded with entries below the
size (12%) allows to avoid collision for 96+% of the conns.

ip_vs_conn_fill_cport() now will rehash the connection with proper
locking because unhash+hash is not safe for RCU readers.

To invalidate the templates setting just dport to 0xffff is enough,
no need to rehash them. As result, ip_vs_conn_unhash() is now
unused and removed.

Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Florian Westphal <fw@strlen.de>
include/net/ip_vs.h
net/netfilter/ipvs/ip_vs_conn.c
net/netfilter/ipvs/ip_vs_ctl.c
net/netfilter/ipvs/ip_vs_pe_sip.c
net/netfilter/ipvs/ip_vs_sync.c