Netdev List
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	willemb@google.com, horms@kernel.org,
	David Ahern <dahern@nvidia.com>
Subject: [PATCH net-next 2/2] selftests: Add stress test for dst_entries
Date: Tue,  1 Dec 2026 18:55:23 -0700	[thread overview]
Message-ID: <20261202015529.7846-3-dsahern@kernel.org> (raw)
In-Reply-To: <20261202015529.7846-1-dsahern@kernel.org>

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)


      parent reply	other threads:[~2026-12-02  1:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  1:55 [PATCH net-next 0/2] ipv6: remove dst_ops gc handler David Ahern
2026-12-02  1:55 ` [PATCH net-next 1/2] " David Ahern
2026-12-02  1:55 ` David Ahern [this message]

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=20261202015529.7846-3-dsahern@kernel.org \
    --to=dsahern@kernel.org \
    --cc=dahern@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox