Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by David Ahern
Wed, 02 Dec 2026 01:55
[PATCH net-next 0/2] ipv6: remove dst_ops gc handler
Author: David Ahern
Date: Wed, 02 Dec 2026 01:55
Date: Wed, 02 Dec 2026 01:55
69 lines
10133 bytes
10133 bytes
IPv6 is the only address family that still uses dst_ops->gc to
limit dst entries. ip6_dst_gc() runs from dst_alloc() whenever
the entry count exceeds gc_thresh. It never fails an allocation
(max_size is already INT_MAX); it only forces a fib6_run_gc()
pass. That pass can free expired exceptions and expired routes
on the FIB6 gc list. It cannot free uncached dsts, which are
held by sockets and skbs.
Remove the handler and rely on the structural limits that
already bound the dst count, the same way IPv4 does.
How the dst count is bounded
----------------------------
Per-cpu routes are DST_NOCOUNT and are limited to one per cpu
per nexthop.
Cached exceptions (PMTU, redirect) live in a per-nexthop hash.
Each bucket is limited to a randomized depth and the oldest
entry is evicted on insert:
IPv6 IPv4
buckets 1024 (shift 10) 2048 (shift 11)
max depth FIB6_MAX_DEPTH (5) FNHE_RECLAIM_DEPTH (5)
+ random(0..4) + random(0..4)
Time-based expiry:
- IPv6: FIB6 gc timer every gc_interval (30s) while the gc
list is non-empty. It also runs on route flush, ndisc
device events and exception insert.
- IPv4: fnhe_expires is checked on lookup and update, and
fnhe_genid invalidates stale entries. There is no timer.
Uncached dsts (icmp6_dst_alloc(), FLOWI_FLAG_KNOWN_NH clones)
are counted but not capped, in both families. They are bounded
only by the users holding references. The old gc could not
reclaim them either.
Behavior changes
----------------
- dst_ops gc_thresh defaults to ~0, as in IPv4. Reading
net.ipv6.route.gc_thresh now returns -1 instead of 1024.
- gc_thresh, gc_min_interval, gc_min_interval_ms, gc_timeout and
gc_elasticity are kept so existing scripts still work. They
have no effect, and a write logs a one-time warning.
gc_interval is unchanged.
- Expired exceptions are no longer reclaimed early under
allocation pressure. They stay until the gc timer runs, up to
gc_interval plus the exception timeout. Memory is capped at
roughly 1024 x 9 entries per nexthop, the same order as IPv4.
Patches
-------
1: remove ip6_dst_gc() and its per-netns state, and mark the
gc sysctls deprecated
2: selftests: add a stress test for dst_entries
David Ahern (2):
ipv6: remove dst_ops gc handler
selftests: Add stress test for dst_entries
include/net/netns/ipv6.h | 2 -
net/ipv6/ip6_fib.c | 1 -
net/ipv6/route.c | 74 ++++++----
tools/testing/selftests/net/fib_tests.sh | 178 ++++++++++++++++++++++-
4 files changed, 219 insertions(+), 36 deletions(-)
--
2.54.0 (Apple Git-157)
[PATCH net-next 1/2] ipv6: remove dst_ops gc handler
Author: David Ahern
Date: Wed, 02 Dec 2026 01:55
Date: Wed, 02 Dec 2026 01:55
204 lines
15221 bytes
15221 bytes
From: David Ahern <dahern@nvidia.com>
Remove ip6_dst_gc(), the dst_ops->gc callback that dst_alloc() invoked
synchronously whenever the dst entry count exceeded gc_thresh, together
with its per-netns state (ip6_rt_gc_expire and ip6_rt_last_gc).
Growth of the IPv6 dst cache is instead bounded the same way IPv4
bounds it: cached exceptions live in a hash whose buckets are limited
to a randomized depth, with the oldest entry evicted on insert (see
rt6_insert_exception() and FIB6_MAX_DEPTH, cf. fnhe_remove_oldest() and
FNHE_RECLAIM_DEPTH in net/ipv4/route.c), and per-cpu routes are bounded
by the number of nexthops. Expiry is still handled by the FIB6 gc timer
(gc_interval) and the fib6_run_gc() calls on device events and route
flush. Like IPv4, set the dst_ops gc_thresh default to ~0 since no
threshold is enforced any more.
Mark the gc_thresh, gc_min_interval, gc_min_interval_ms, gc_timeout and
gc_elasticity sysctls as deprecated: they are retained so existing
scripts keep working, but a write now logs a one-time warning that the
setting has no effect. gc_interval is unchanged and still sets the
period of the FIB6 gc timer.
Signed-off-by: David Ahern <dahern@nvidia.com>
---
include/net/netns/ipv6.h | 2 --
net/ipv6/ip6_fib.c | 1 -
net/ipv6/route.c | 74 +++++++++++++++++++++++-----------------
3 files changed, 42 insertions(+), 35 deletions(-)
diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
index aefce37c04a4..ca4462353328 100644
--- a/include/net/netns/ipv6.h
+++ b/include/net/netns/ipv6.h
@@ -82,8 +82,6 @@ struct netns_ipv6 {
struct list_head fib6_walkers;
rwlock_t fib6_walker_lock;
spinlock_t fib6_gc_lock;
- atomic_t ip6_rt_gc_expire;
- unsigned long ip6_rt_last_gc;
unsigned char flowlabel_has_excl;
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
bool fib6_has_custom_rules;
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index e1d49897d6ab..2095f023c137 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -2464,7 +2464,6 @@ void fib6_run_gc(unsigned long expires, struct net *net, bool force)
fib6_gc_all(net, &gc_args);
now = jiffies;
- net->ipv6.ip6_rt_last_gc = now;
if (gc_args.more)
mod_timer(&net->ipv6.ip6_fib_timer,
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index df843178e5ec..14c95d132e1f 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -92,7 +92,6 @@ static void ip6_negative_advice(struct sock *sk,
static void ip6_dst_destroy(struct dst_entry *);
static void ip6_dst_ifdown(struct dst_entry *,
struct net_device *dev);
-static void ip6_dst_gc(struct dst_ops *ops);
static int ip6_pkt_discard(struct sk_buff *skb);
static int ip6_pkt_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb);
@@ -271,8 +270,7 @@ static void ip6_confirm_neigh(const struct dst_entry *dst, const void *daddr)
static struct dst_ops ip6_dst_ops_template = {
.family = AF_INET6,
- .gc = ip6_dst_gc,
- .gc_thresh = 1024,
+ .gc_thresh = ~0,
.check = ip6_dst_check,
.default_advmss = ip6_default_advmss,
.mtu = ip6_mtu,
@@ -3367,28 +3365,6 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
return dst;
}
-static void ip6_dst_gc(struct dst_ops *ops)
-{
- struct net *net = container_of(ops, struct net, ipv6.ip6_dst_ops);
- int rt_min_interval = READ_ONCE(net->ipv6.sysctl.ip6_rt_gc_min_interval);
- int rt_elasticity = READ_ONCE(net->ipv6.sysctl.ip6_rt_gc_elasticity);
- int rt_gc_timeout = READ_ONCE(net->ipv6.sysctl.ip6_rt_gc_timeout);
- unsigned long rt_last_gc = READ_ONCE(net->ipv6.ip6_rt_last_gc);
- unsigned int val;
- int entries;
-
- if (time_after(rt_last_gc + rt_min_interval, jiffies))
- goto out;
-
- fib6_run_gc(atomic_inc_return(&net->ipv6.ip6_rt_gc_expire), net, true);
- entries = dst_entries_get_slow(ops);
- if (entries < ops->gc_thresh)
- atomic_set(&net->ipv6.ip6_rt_gc_expire, rt_gc_timeout >> 1);
-out:
- val = atomic_read(&net->ipv6.ip6_rt_gc_expire);
- atomic_set(&net->ipv6.ip6_rt_gc_expire, val - (val >> rt_elasticity));
-}
-
static int ip6_nh_lookup_table(struct net *net, struct fib6_config *cfg,
const struct in6_addr *gw_addr, u32 tbid,
int flags, struct fib6_result *res)
@@ -6615,6 +6591,42 @@ static int ipv6_sysctl_rtcache_flush(const struct ctl_table *ctl, int write,
static unsigned int ip6_rt_gc_elasticity_max = 31;
+static void ip6_rt_gc_sysctl_warn(const struct ctl_table *ctl, int write)
+{
+ if (write)
+ pr_warn_once("%s: net.ipv6.route.%s is deprecated and has no effect\n",
+ current->comm, ctl->procname);
+}
+
+static int ip6_rt_gc_dointvec(const struct ctl_table *ctl, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ ip6_rt_gc_sysctl_warn(ctl, write);
+ return proc_dointvec(ctl, write, buffer, lenp, ppos);
+}
+
+static int ip6_rt_gc_dointvec_jiffies(const struct ctl_table *ctl, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ ip6_rt_gc_sysctl_warn(ctl, write);
+ return proc_dointvec_jiffies(ctl, write, buffer, lenp, ppos);
+}
+
+static int ip6_rt_gc_dointvec_ms_jiffies(const struct ctl_table *ctl, int write,
+ void *buffer, size_t *lenp,
+ loff_t *ppos)
+{
+ ip6_rt_gc_sysctl_warn(ctl, write);
+ return proc_dointvec_ms_jiffies(ctl, write, buffer, lenp, ppos);
+}
+
+static int ip6_rt_gc_dou8vec_minmax(const struct ctl_table *ctl, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ ip6_rt_gc_sysctl_warn(ctl, write);
+ return proc_dou8vec_minmax(ctl, write, buffer, lenp, ppos);
+}
+
static const struct ctl_table ipv6_route_table_template[] = {
{
.procname = "max_size",
@@ -6628,7 +6640,7 @@ static const struct ctl_table ipv6_route_table_template[] = {
.data = &ip6_dst_ops_template.gc_thresh,
.maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec,
+ .proc_handler = ip6_rt_gc_dointvec,
},
{
.procname = "flush",
@@ -6642,14 +6654,14 @@ static const struct ctl_table ipv6_route_table_template[] = {
.data = &init_net.ipv6.sysctl.ip6_rt_gc_min_interval,
.maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec_jiffies,
+ .proc_handler = ip6_rt_gc_dointvec_jiffies,
},
{
.procname = "gc_timeout",
.data = &init_net.ipv6.sysctl.ip6_rt_gc_timeout,
.maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec_jiffies,
+ .proc_handler = ip6_rt_gc_dointvec_jiffies,
},
{
.procname = "gc_interval",
@@ -6663,7 +6675,7 @@ static const struct ctl_table ipv6_route_table_template[] = {
.data = &init_net.ipv6.sysctl.ip6_rt_gc_elasticity,
.maxlen = sizeof(u8),
.mode = 0644,
- .proc_handler = proc_dou8vec_minmax,
+ .proc_handler = ip6_rt_gc_dou8vec_minmax,
.extra2 = &ip6_rt_gc_elasticity_max,
},
{
@@ -6685,7 +6697,7 @@ static const struct ctl_table ipv6_route_table_template[] = {
.data = &init_net.ipv6.sysctl.ip6_rt_gc_min_interval,
.maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec_ms_jiffies,
+ .proc_handler = ip6_rt_gc_dointvec_ms_jiffies,
},
{
.procname = "skip_notify_on_dev_down",
@@ -6796,8 +6808,6 @@ static int __net_init ip6_route_net_init(struct net *net)
net->ipv6.sysctl.ip6_rt_min_advmss = IPV6_MIN_MTU - 20 - 40;
net->ipv6.sysctl.skip_notify_on_dev_down = 0;
- atomic_set(&net->ipv6.ip6_rt_gc_expire, 30*HZ);
-
ret = 0;
out:
return ret;
--
2.54.0 (Apple Git-157)
[PATCH net-next 2/2] selftests: Add stress test for dst_entries
Author: David Ahern
Date: Wed, 02 Dec 2026 01:55
Date: Wed, 02 Dec 2026 01:55
213 lines
14640 bytes
14640 bytes
From: David Ahern <dahern@nvidia.com>
Signed-off-by: David Ahern <dahern@nvidia.com>
---
tools/testing/selftests/net/fib_tests.sh | 178 ++++++++++++++++++++++-
1 file changed, 177 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index d7ac3c727f70..d1686dff7a77 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -14,7 +14,8 @@ TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \
ipv4_mpath_list ipv6_mpath_list ipv4_mpath_balance ipv6_mpath_balance \
ipv4_mpath_balance_preferred ipv4_mpath_oif ipv4_mpath_oif_nh \
ipv4_mpath_oif_vrf ipv6_mpath_oif ipv6_mpath_oif_nh ipv6_mpath_oif_vrf \
- fib6_ra_to_static fib6_temp_addr_renewal"
+ fib6_ra_to_static fib6_temp_addr_renewal \
+ ipv4_dst_entries_stress ipv6_dst_entries_stress"
VERBOSE=0
PAUSE_ON_FAIL=no
@@ -3228,6 +3229,179 @@ ipv6_mpath_oif_vrf_test()
cleanup
}
+# Number of dst entries the netns' dst_ops accounts for. DST_NOCOUNT dsts
+# (pcpu routes) are not in it, but exceptions, clones and uncached dsts are.
+# The IPv4 counter belongs to the global ipv4_dst_ops, so it also sees other
+# netns.
+dst_entries()
+{
+ local family=$1 hex
+
+ if [ "$family" = "6" ]; then
+ hex=$($NS_EXEC awk '{print $6}' /proc/net/rt6_stats)
+ else
+ hex=$($NS_EXEC awk 'NR == 2 {print $1}' /proc/net/stat/rt_cache)
+ fi
+
+ echo $((16#$hex))
+}
+
+# wait up to $3 seconds for the dst entry count to drop to $2 or below
+wait_dst_entries_le()
+{
+ local family=$1
+ local limit=$2
+ local secs=$3
+ local i
+
+ for ((i = 0; i < secs * 10; i++)); do
+ [ $(dst_entries $family) -le $limit ] && return 0
+ sleep 0.1
+ done
+
+ return 1
+}
+
+# Create more PMTU exceptions than the exception tables allow and churn the
+# routes while every cpu keeps building pcpu dsts. The dst count must stay
+# within the table limits, must not grow because of the churn, and must go
+# back to where it started once the routes and nexthops are gone.
+#
+# DST_STRESS_EXC is the number of destinations to send a too big packet to
+# per route, DST_STRESS_ITERS the number of churn iterations.
+dst_entries_stress()
+{
+ local family=$1
+ local exc=${DST_STRESS_EXC:-1000}
+ local iters=${DST_STRESS_ITERS:-200}
+ local ncpus=$(nproc)
+ local base after_exc after_churn cap slack i cpu dst1 dst2 ip6=""
+ local gw1 pfx1 pfx2
+
+ [ $ncpus -gt 4 ] && ncpus=4
+
+ if [ ! -x "$(command -v taskset)" ]; then
+ echo "SKIP: taskset not installed"
+ return $ksft_skip
+ fi
+
+ setup
+
+ set -e
+ setup_ns ns2
+ $IP link add veth1 type veth peer name veth2 netns $ns2
+ $IP link set veth1 up
+ ip -netns $ns2 link set veth2 up
+ ip -netns $ns2 link add dummy0 type dummy
+ ip -netns $ns2 link set dummy0 mtu 1280 up
+ # the too big messages must not be rate limited
+ ip netns exec $ns2 sysctl -qw net.ipv4.ip_forward=1
+ ip netns exec $ns2 sysctl -qw net.ipv4.icmp_ratelimit=0
+ ip netns exec $ns2 sysctl -qw net.ipv4.icmp_msgs_per_sec=100000
+ ip netns exec $ns2 sysctl -qw net.ipv4.icmp_msgs_burst=100000
+ ip netns exec $ns2 sysctl -qw net.ipv6.conf.all.forwarding=1
+ ip netns exec $ns2 sysctl -qw net.ipv6.icmp.ratelimit=0
+
+ if [ "$family" = "6" ]; then
+ ip6="-6"
+ gw1=2001:db8:10::2
+ pfx1=2001:db8:12::/64
+ pfx2=2001:db8:13::/64
+ cap=$((2 * 1024 * 6)) # 2 fib6_nh * buckets * (depth + 1)
+ slack=16
+ $IP -6 address add 2001:db8:10::1/64 dev veth1 nodad
+ ip -netns $ns2 -6 address add 2001:db8:10::2/64 dev veth2 nodad
+ ip -netns $ns2 -6 route add $pfx1 dev dummy0
+ ip -netns $ns2 -6 route add $pfx2 dev dummy0
+ else
+ gw1=10.10.0.2
+ pfx1=10.20.0.0/16
+ pfx2=10.30.0.0/16
+ cap=$((2 * 2048 * 6))
+ slack=64 # the counter is global
+ $IP address add 10.10.0.1/24 dev veth1
+ ip -netns $ns2 address add 10.10.0.2/24 dev veth2
+ ip -netns $ns2 route add $pfx1 dev dummy0
+ ip -netns $ns2 route add $pfx2 dev dummy0
+ fi
+
+ # one route with its own nexthop, one using a nexthop object
+ $IP $ip6 nexthop add id 100 via $gw1 dev veth1
+ $IP $ip6 route add $pfx1 via $gw1 dev veth1
+ $IP $ip6 route add $pfx2 nhid 100
+ set +e
+
+ base=$(dst_entries $family)
+
+ for ((i = 1; i <= exc; i++)); do
+ if [ "$family" = "6" ]; then
+ dst1=2001:db8:12::$(printf %x $i)
+ dst2=2001:db8:13::$(printf %x $i)
+ $NS_EXEC $ping6 -c1 -W1 -s1400 $dst1 &> /dev/null
+ $NS_EXEC $ping6 -c1 -W1 -s1400 $dst2 &> /dev/null
+ else
+ dst1=10.20.$((i / 250)).$((i % 250 + 1))
+ dst2=10.30.$((i / 250)).$((i % 250 + 1))
+ $NS_EXEC ping -c1 -W1 -s1400 -M do $dst1 &> /dev/null
+ $NS_EXEC ping -c1 -W1 -s1400 -M do $dst2 &> /dev/null
+ fi
+ done
+
+ after_exc=$(dst_entries $family)
+ [ $after_exc -gt $((base + exc / 2)) ]
+ log_test $? 0 "PMTU exceptions created ($base -> $after_exc dst entries)"
+
+ [ $after_exc -le $((base + cap)) ]
+ log_test $? 0 "dst entries within the exception table limits ($after_exc <= $((base + cap)))"
+
+ # churn: every cpu builds pcpu dsts, then the routes and the nexthop
+ # change, which invalidates them
+ for ((i = 0; i < iters; i++)); do
+ for ((cpu = 0; cpu < ncpus; cpu++)); do
+ if [ "$family" = "6" ]; then
+ taskset -a -c $cpu $IP -6 route get 2001:db8:12::1 &> /dev/null
+ taskset -a -c $cpu $IP -6 route get 2001:db8:13::1 &> /dev/null
+ else
+ taskset -a -c $cpu $IP route get 10.20.0.1 &> /dev/null
+ taskset -a -c $cpu $IP route get 10.30.0.1 &> /dev/null
+ fi
+ done
+ $IP $ip6 route replace $pfx1 via $gw1 dev veth1
+ $IP $ip6 nexthop replace id 100 via $gw1 dev veth1
+ $IP $ip6 route replace $pfx2 nhid 100
+ done
+
+ # let the deferred releases run
+ sleep 2
+ after_churn=$(dst_entries $family)
+ [ $after_churn -le $((after_exc + slack)) ]
+ log_test $? 0 "dst entries do not grow with route churn ($after_exc -> $after_churn)"
+
+ $IP $ip6 route del $pfx1
+ $IP $ip6 route del $pfx2
+ $IP $ip6 nexthop del id 100
+ wait_dst_entries_le $family $((base + slack)) 10
+ log_test $? 0 "dst entries released with routes and nexthop (base $base, now $(dst_entries $family))"
+
+ cleanup
+}
+
+ipv4_dst_entries_stress_test()
+{
+ echo
+ echo "IPv4 dst entries stress test"
+
+ dst_entries_stress 4
+}
+
+ipv6_dst_entries_stress_test()
+{
+ echo
+ echo "IPv6 dst entries stress test"
+
+ dst_entries_stress 6
+}
+
################################################################################
# usage
@@ -3322,6 +3496,8 @@ do
ipv6_mpath_oif_vrf) ipv6_mpath_oif_vrf_test;;
fib6_ra_to_static) fib6_ra_to_static;;
fib6_temp_addr_renewal) fib6_temp_addr_renewal;;
+ ipv4_dst_entries_stress) ipv4_dst_entries_stress_test;;
+ ipv6_dst_entries_stress) ipv6_dst_entries_stress_test;;
help) echo "Test names: $TESTS"; exit 0;;
esac
--
2.54.0 (Apple Git-157)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads