diff mbox series

[net-next,v2,2/2] selftests: fib_tests: Add a test case for IPv6 garbage collection

Message ID 20230718180321.294721-3-kuifeng@meta.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Remove expired routes with a | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers warning 2 maintainers not CCed: shuah@kernel.org linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success net selftest script(s) already in Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 9 this patch: 9
netdev/checkpatch warning WARNING: From:/Signed-off-by: email address mismatch: 'From: Kui-Feng Lee <thinker.li@gmail.com>' != 'Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>' WARNING: line length of 255 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Kui-Feng Lee July 18, 2023, 6:03 p.m. UTC
Add 10 IPv6 routes with expiration time.  Wait for a few seconds
to make sure they are removed correctly.

Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
---
 tools/testing/selftests/net/fib_tests.sh | 49 +++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

Comments

Paolo Abeni July 20, 2023, 9:32 a.m. UTC | #1
On Tue, 2023-07-18 at 11:03 -0700, Kui-Feng Lee wrote:
> Add 10 IPv6 routes with expiration time.  Wait for a few seconds
> to make sure they are removed correctly.
> 
> Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>

Same thing as the previous patch.

> ---
>  tools/testing/selftests/net/fib_tests.sh | 49 +++++++++++++++++++++++-
>  1 file changed, 48 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
> index 35d89dfa6f11..55bc6897513a 100755
> --- a/tools/testing/selftests/net/fib_tests.sh
> +++ b/tools/testing/selftests/net/fib_tests.sh
> @@ -9,7 +9,7 @@ ret=0
>  ksft_skip=4
>  
>  # all tests in this script. Can be overridden with -t option
> -TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh"
> +TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test"

At this point is likely worthy splitting the above line in multiple
ones, something alike:

TESTS="unregister down carrier nexthop suppress ipv6_notify \
	ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric
\
	ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw \
	rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh \
	fib6_gc_test"

>  
>  VERBOSE=0
>  PAUSE_ON_FAIL=no
> @@ -747,6 +747,52 @@ fib_notify_test()
>  	cleanup &> /dev/null
>  }
>  
> +fib6_gc_test()
> +{
> +	setup
> +
> +	echo
> +	echo "Fib6 garbage collection test"
> +	set -e
> +
> +	OLD_INTERVAL=$(sysctl -n net.ipv6.route.gc_interval)
> +	# Check expiration of routes every 3 seconds (GC)
> +	$NS_EXEC sysctl -wq net.ipv6.route.gc_interval=3
> +
> +	$IP link add dummy_10 type dummy
> +	$IP link set dev dummy_10 up
> +	$IP -6 address add 2001:10::1/64 dev dummy_10
> +
> +	for i in 0 1 2 3 4 5 6 7 8 9; do
		$(seq 0 9)

> +	    # Expire route after 2 seconds
> +	    $IP -6 route add 2001:20::1$i \
> +		via 2001:10::2 dev dummy_10 expires 2
> +	done
> +	N_EXP=$($IP -6 route list |grep expires|wc -l)
> +	if [ $N_EXP -ne 10 ]; then
> +		echo "FAIL: expected 10 routes with expires, got $N_EXP"
> +		ret=1
> +	else
> +	    sleep 4
> +	    N_EXP_s20=$($IP -6 route list |grep expires|wc -l)
> +
> +	    if [ $N_EXP_s20 -ne 0 ]; then
> +		echo "FAIL: expected 0 routes with expires, got $N_EXP_s20"
> +		ret=1
> +	    else
> +		ret=0
> +	    fi
> +	fi

Possibly also worth trying with a few K of permanent routes, and dump
the time required in both cases?

> +
> +	set +e
> +
> +	log_test $ret 0 "ipv6 route garbage collection"
> +
> +	sysctl -wq net.ipv6.route.gc_interval=$OLD_INTERVAL

No need to restore, gc_interval is a per namespace param specific
>
Kui-Feng Lee July 20, 2023, 4:32 p.m. UTC | #2
On 7/20/23 02:32, Paolo Abeni wrote:
> On Tue, 2023-07-18 at 11:03 -0700, Kui-Feng Lee wrote:
>> Add 10 IPv6 routes with expiration time.  Wait for a few seconds
>> to make sure they are removed correctly.
>>
>> Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
> 
> Same thing as the previous patch.
> 
>> ---
>>   tools/testing/selftests/net/fib_tests.sh | 49 +++++++++++++++++++++++-
>>   1 file changed, 48 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
>> index 35d89dfa6f11..55bc6897513a 100755
>> --- a/tools/testing/selftests/net/fib_tests.sh
>> +++ b/tools/testing/selftests/net/fib_tests.sh
>> @@ -9,7 +9,7 @@ ret=0
>>   ksft_skip=4
>>   
>>   # all tests in this script. Can be overridden with -t option
>> -TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh"
>> +TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test"
> 
> At this point is likely worthy splitting the above line in multiple
> ones, something alike:
> 
> TESTS="unregister down carrier nexthop suppress ipv6_notify \
> 	ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric
> \
> 	ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw \
> 	rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh \
> 	fib6_gc_test"
> 

Ok!

>>   
>>   VERBOSE=0
>>   PAUSE_ON_FAIL=no
>> @@ -747,6 +747,52 @@ fib_notify_test()
>>   	cleanup &> /dev/null
>>   }
>>   
>> +fib6_gc_test()
>> +{
>> +	setup
>> +
>> +	echo
>> +	echo "Fib6 garbage collection test"
>> +	set -e
>> +
>> +	OLD_INTERVAL=$(sysctl -n net.ipv6.route.gc_interval)
>> +	# Check expiration of routes every 3 seconds (GC)
>> +	$NS_EXEC sysctl -wq net.ipv6.route.gc_interval=3
>> +
>> +	$IP link add dummy_10 type dummy
>> +	$IP link set dev dummy_10 up
>> +	$IP -6 address add 2001:10::1/64 dev dummy_10
>> +
>> +	for i in 0 1 2 3 4 5 6 7 8 9; do
> 		$(seq 0 9)
> 
>> +	    # Expire route after 2 seconds
>> +	    $IP -6 route add 2001:20::1$i \
>> +		via 2001:10::2 dev dummy_10 expires 2
>> +	done
>> +	N_EXP=$($IP -6 route list |grep expires|wc -l)
>> +	if [ $N_EXP -ne 10 ]; then
>> +		echo "FAIL: expected 10 routes with expires, got $N_EXP"
>> +		ret=1
>> +	else
>> +	    sleep 4
>> +	    N_EXP_s20=$($IP -6 route list |grep expires|wc -l)
>> +
>> +	    if [ $N_EXP_s20 -ne 0 ]; then
>> +		echo "FAIL: expected 0 routes with expires, got $N_EXP_s20"
>> +		ret=1
>> +	    else
>> +		ret=0
>> +	    fi
>> +	fi
> 
> Possibly also worth trying with a few K of permanent routes, and dump
> the time required in both cases?

Sure!

> 
>> +
>> +	set +e
>> +
>> +	log_test $ret 0 "ipv6 route garbage collection"
>> +
>> +	sysctl -wq net.ipv6.route.gc_interval=$OLD_INTERVAL
> 
> No need to restore, gc_interval is a per namespace param specific
>>
> 
>
Kui-Feng Lee July 20, 2023, 9:36 p.m. UTC | #3
On 7/20/23 02:32, Paolo Abeni wrote:
> On Tue, 2023-07-18 at 11:03 -0700, Kui-Feng Lee wrote:
>> Add 10 IPv6 routes with expiration time.  Wait for a few seconds
>> to make sure they are removed correctly.
>>
>> Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
> 
> Same thing as the previous patch.
> 
>> ---
>>   tools/testing/selftests/net/fib_tests.sh | 49 +++++++++++++++++++++++-
>>   1 file changed, 48 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
>> index 35d89dfa6f11..55bc6897513a 100755
>> --- a/tools/testing/selftests/net/fib_tests.sh
>> +++ b/tools/testing/selftests/net/fib_tests.sh
>> @@ -9,7 +9,7 @@ ret=0
>>   ksft_skip=4
>>   
>>   # all tests in this script. Can be overridden with -t option
>> -TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh"
>> +TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test"
> 
> At this point is likely worthy splitting the above line in multiple
> ones, something alike:
> 
> TESTS="unregister down carrier nexthop suppress ipv6_notify \
> 	ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric
> \
> 	ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw \
> 	rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh \
> 	fib6_gc_test"
> 
>>   
>>   VERBOSE=0
>>   PAUSE_ON_FAIL=no
>> @@ -747,6 +747,52 @@ fib_notify_test()
>>   	cleanup &> /dev/null
>>   }
>>   
>> +fib6_gc_test()
>> +{
>> +	setup
>> +
>> +	echo
>> +	echo "Fib6 garbage collection test"
>> +	set -e
>> +
>> +	OLD_INTERVAL=$(sysctl -n net.ipv6.route.gc_interval)
>> +	# Check expiration of routes every 3 seconds (GC)
>> +	$NS_EXEC sysctl -wq net.ipv6.route.gc_interval=3
>> +
>> +	$IP link add dummy_10 type dummy
>> +	$IP link set dev dummy_10 up
>> +	$IP -6 address add 2001:10::1/64 dev dummy_10
>> +
>> +	for i in 0 1 2 3 4 5 6 7 8 9; do
> 		$(seq 0 9)
> 
>> +	    # Expire route after 2 seconds
>> +	    $IP -6 route add 2001:20::1$i \
>> +		via 2001:10::2 dev dummy_10 expires 2
>> +	done
>> +	N_EXP=$($IP -6 route list |grep expires|wc -l)
>> +	if [ $N_EXP -ne 10 ]; then
>> +		echo "FAIL: expected 10 routes with expires, got $N_EXP"
>> +		ret=1
>> +	else
>> +	    sleep 4
>> +	    N_EXP_s20=$($IP -6 route list |grep expires|wc -l)
>> +
>> +	    if [ $N_EXP_s20 -ne 0 ]; then
>> +		echo "FAIL: expected 0 routes with expires, got $N_EXP_s20"
>> +		ret=1
>> +	    else
>> +		ret=0
>> +	    fi
>> +	fi
> 
> Possibly also worth trying with a few K of permanent routes, and dump
> the time required in both cases?

I just realized that I don't know how to measure the time required to do 
GC without providing additional APIs or exposing numbers to procfs or 
sysfs. Do you have any idea about this?

> 
>> +
>> +	set +e
>> +
>> +	log_test $ret 0 "ipv6 route garbage collection"
>> +
>> +	sysctl -wq net.ipv6.route.gc_interval=$OLD_INTERVAL
> 
> No need to restore, gc_interval is a per namespace param specific
>>
> 
>
Paolo Abeni July 21, 2023, 7:14 a.m. UTC | #4
On Thu, 2023-07-20 at 14:36 -0700, Kui-Feng Lee wrote:
> 
> On 7/20/23 02:32, Paolo Abeni wrote:
> > On Tue, 2023-07-18 at 11:03 -0700, Kui-Feng Lee wrote:
> > > Add 10 IPv6 routes with expiration time.  Wait for a few seconds
> > > to make sure they are removed correctly.
> > > 
> > > Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
> > 
> > Same thing as the previous patch.
> > 
> > > ---
> > >   tools/testing/selftests/net/fib_tests.sh | 49 +++++++++++++++++++++++-
> > >   1 file changed, 48 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
> > > index 35d89dfa6f11..55bc6897513a 100755
> > > --- a/tools/testing/selftests/net/fib_tests.sh
> > > +++ b/tools/testing/selftests/net/fib_tests.sh
> > > @@ -9,7 +9,7 @@ ret=0
> > >   ksft_skip=4
> > >   
> > >   # all tests in this script. Can be overridden with -t option
> > > -TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh"
> > > +TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test"
> > 
> > At this point is likely worthy splitting the above line in multiple
> > ones, something alike:
> > 
> > TESTS="unregister down carrier nexthop suppress ipv6_notify \
> > 	ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric
> > \
> > 	ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw \
> > 	rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh \
> > 	fib6_gc_test"
> > 
> > >   
> > >   VERBOSE=0
> > >   PAUSE_ON_FAIL=no
> > > @@ -747,6 +747,52 @@ fib_notify_test()
> > >   	cleanup &> /dev/null
> > >   }
> > >   
> > > +fib6_gc_test()
> > > +{
> > > +	setup
> > > +
> > > +	echo
> > > +	echo "Fib6 garbage collection test"
> > > +	set -e
> > > +
> > > +	OLD_INTERVAL=$(sysctl -n net.ipv6.route.gc_interval)
> > > +	# Check expiration of routes every 3 seconds (GC)
> > > +	$NS_EXEC sysctl -wq net.ipv6.route.gc_interval=3
> > > +
> > > +	$IP link add dummy_10 type dummy
> > > +	$IP link set dev dummy_10 up
> > > +	$IP -6 address add 2001:10::1/64 dev dummy_10
> > > +
> > > +	for i in 0 1 2 3 4 5 6 7 8 9; do
> > 		$(seq 0 9)
> > 
> > > +	    # Expire route after 2 seconds
> > > +	    $IP -6 route add 2001:20::1$i \
> > > +		via 2001:10::2 dev dummy_10 expires 2
> > > +	done
> > > +	N_EXP=$($IP -6 route list |grep expires|wc -l)
> > > +	if [ $N_EXP -ne 10 ]; then
> > > +		echo "FAIL: expected 10 routes with expires, got $N_EXP"
> > > +		ret=1
> > > +	else
> > > +	    sleep 4
> > > +	    N_EXP_s20=$($IP -6 route list |grep expires|wc -l)
> > > +
> > > +	    if [ $N_EXP_s20 -ne 0 ]; then
> > > +		echo "FAIL: expected 0 routes with expires, got $N_EXP_s20"
> > > +		ret=1
> > > +	    else
> > > +		ret=0
> > > +	    fi
> > > +	fi
> > 
> > Possibly also worth trying with a few K of permanent routes, and dump
> > the time required in both cases?
> 
> I just realized that I don't know how to measure the time required to do 
> GC without providing additional APIs or exposing numbers to procfs or 
> sysfs. Do you have any idea about this?

Something like this should do the trick

sysctl -wq net.ipv6.route.flush=1

# add routes 
#...

# delete expired routes synchronously
sysctl -wq net.ipv6.route.flush=1

Note that the net.ipv6.route.flush handler uses the 'old' flush value.

Cheers,

Paolo
Kui-Feng Lee July 21, 2023, 6:31 p.m. UTC | #5
On 7/21/23 00:14, Paolo Abeni wrote:
> On Thu, 2023-07-20 at 14:36 -0700, Kui-Feng Lee wrote:
>>
>> On 7/20/23 02:32, Paolo Abeni wrote:
>>> On Tue, 2023-07-18 at 11:03 -0700, Kui-Feng Lee wrote:
>>>> Add 10 IPv6 routes with expiration time.  Wait for a few seconds
>>>> to make sure they are removed correctly.
>>>>
>>>> Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
>>>
>>> Same thing as the previous patch.
>>>
>>>> ---
>>>>    tools/testing/selftests/net/fib_tests.sh | 49 +++++++++++++++++++++++-
>>>>    1 file changed, 48 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
>>>> index 35d89dfa6f11..55bc6897513a 100755
>>>> --- a/tools/testing/selftests/net/fib_tests.sh
>>>> +++ b/tools/testing/selftests/net/fib_tests.sh
>>>> @@ -9,7 +9,7 @@ ret=0
>>>>    ksft_skip=4
>>>>    
>>>>    # all tests in this script. Can be overridden with -t option
>>>> -TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh"
>>>> +TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test"
>>>
>>> At this point is likely worthy splitting the above line in multiple
>>> ones, something alike:
>>>
>>> TESTS="unregister down carrier nexthop suppress ipv6_notify \
>>> 	ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric
>>> \
>>> 	ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw \
>>> 	rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh \
>>> 	fib6_gc_test"
>>>
>>>>    
>>>>    VERBOSE=0
>>>>    PAUSE_ON_FAIL=no
>>>> @@ -747,6 +747,52 @@ fib_notify_test()
>>>>    	cleanup &> /dev/null
>>>>    }
>>>>    
>>>> +fib6_gc_test()
>>>> +{
>>>> +	setup
>>>> +
>>>> +	echo
>>>> +	echo "Fib6 garbage collection test"
>>>> +	set -e
>>>> +
>>>> +	OLD_INTERVAL=$(sysctl -n net.ipv6.route.gc_interval)
>>>> +	# Check expiration of routes every 3 seconds (GC)
>>>> +	$NS_EXEC sysctl -wq net.ipv6.route.gc_interval=3
>>>> +
>>>> +	$IP link add dummy_10 type dummy
>>>> +	$IP link set dev dummy_10 up
>>>> +	$IP -6 address add 2001:10::1/64 dev dummy_10
>>>> +
>>>> +	for i in 0 1 2 3 4 5 6 7 8 9; do
>>> 		$(seq 0 9)
>>>
>>>> +	    # Expire route after 2 seconds
>>>> +	    $IP -6 route add 2001:20::1$i \
>>>> +		via 2001:10::2 dev dummy_10 expires 2
>>>> +	done
>>>> +	N_EXP=$($IP -6 route list |grep expires|wc -l)
>>>> +	if [ $N_EXP -ne 10 ]; then
>>>> +		echo "FAIL: expected 10 routes with expires, got $N_EXP"
>>>> +		ret=1
>>>> +	else
>>>> +	    sleep 4
>>>> +	    N_EXP_s20=$($IP -6 route list |grep expires|wc -l)
>>>> +
>>>> +	    if [ $N_EXP_s20 -ne 0 ]; then
>>>> +		echo "FAIL: expected 0 routes with expires, got $N_EXP_s20"
>>>> +		ret=1
>>>> +	    else
>>>> +		ret=0
>>>> +	    fi
>>>> +	fi
>>>
>>> Possibly also worth trying with a few K of permanent routes, and dump
>>> the time required in both cases?
>>
>> I just realized that I don't know how to measure the time required to do
>> GC without providing additional APIs or exposing numbers to procfs or
>> sysfs. Do you have any idea about this?
> 
> Something like this should do the trick
> 
> sysctl -wq net.ipv6.route.flush=1
> 
> # add routes
> #...
> 
> # delete expired routes synchronously
> sysctl -wq net.ipv6.route.flush=1
> 
> Note that the net.ipv6.route.flush handler uses the 'old' flush value.

May I use bpftrace to measure time spending on writing to procfs?
It is in the order of microseconds. time command doesn't work.

> 
> Cheers,
> 
> Paolo
>
David Ahern July 21, 2023, 8:01 p.m. UTC | #6
On 7/21/23 12:31 PM, Kui-Feng Lee wrote:
>>
>> sysctl -wq net.ipv6.route.flush=1
>>
>> # add routes
>> #...
>>
>> # delete expired routes synchronously
>> sysctl -wq net.ipv6.route.flush=1
>>
>> Note that the net.ipv6.route.flush handler uses the 'old' flush value.
> 
> May I use bpftrace to measure time spending on writing to procfs?
> It is in the order of microseconds. time command doesn't work.
> 

Both before this patch and after this patch are in microseconds?
Kui-Feng Lee July 21, 2023, 8:57 p.m. UTC | #7
On 7/21/23 13:01, David Ahern wrote:
> On 7/21/23 12:31 PM, Kui-Feng Lee wrote:
>>>
>>> sysctl -wq net.ipv6.route.flush=1
>>>
>>> # add routes
>>> #...
>>>
>>> # delete expired routes synchronously
>>> sysctl -wq net.ipv6.route.flush=1
>>>
>>> Note that the net.ipv6.route.flush handler uses the 'old' flush value.
>>
>> May I use bpftrace to measure time spending on writing to procfs?
>> It is in the order of microseconds. time command doesn't work.
>>
> 
> Both before this patch and after this patch are in microseconds?
> 

The test case includes two parts. First part, add 1k temporary routes
only. Second part, add 5k permanent routes before adding 1k temporary
routes. In both cases, they wait for a few second and run sysctl -wq
net.ipv6.route.flush=1 to force gc. I use bpftrace to measure the time
the syscalls that write to procfs. Following are the numbers (5 times 
average) I got.

Without the patch
  1k temp w/o 5k perm: ~588us
  1k temp w/  5k perm: ~1055us
With the patch
  1k temp w/o 5k perm: ~550us
  1k temp w/  5k perm: ~561us
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index 35d89dfa6f11..55bc6897513a 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -9,7 +9,7 @@  ret=0
 ksft_skip=4
 
 # all tests in this script. Can be overridden with -t option
-TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh"
+TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test"
 
 VERBOSE=0
 PAUSE_ON_FAIL=no
@@ -747,6 +747,52 @@  fib_notify_test()
 	cleanup &> /dev/null
 }
 
+fib6_gc_test()
+{
+	setup
+
+	echo
+	echo "Fib6 garbage collection test"
+	set -e
+
+	OLD_INTERVAL=$(sysctl -n net.ipv6.route.gc_interval)
+	# Check expiration of routes every 3 seconds (GC)
+	$NS_EXEC sysctl -wq net.ipv6.route.gc_interval=3
+
+	$IP link add dummy_10 type dummy
+	$IP link set dev dummy_10 up
+	$IP -6 address add 2001:10::1/64 dev dummy_10
+
+	for i in 0 1 2 3 4 5 6 7 8 9; do
+	    # Expire route after 2 seconds
+	    $IP -6 route add 2001:20::1$i \
+		via 2001:10::2 dev dummy_10 expires 2
+	done
+	N_EXP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP -ne 10 ]; then
+		echo "FAIL: expected 10 routes with expires, got $N_EXP"
+		ret=1
+	else
+	    sleep 4
+	    N_EXP_s20=$($IP -6 route list |grep expires|wc -l)
+
+	    if [ $N_EXP_s20 -ne 0 ]; then
+		echo "FAIL: expected 0 routes with expires, got $N_EXP_s20"
+		ret=1
+	    else
+		ret=0
+	    fi
+	fi
+
+	set +e
+
+	log_test $ret 0 "ipv6 route garbage collection"
+
+	sysctl -wq net.ipv6.route.gc_interval=$OLD_INTERVAL
+
+	cleanup &> /dev/null
+}
+
 fib_suppress_test()
 {
 	echo
@@ -2217,6 +2263,7 @@  do
 	ipv4_mangle)			ipv4_mangle_test;;
 	ipv6_mangle)			ipv6_mangle_test;;
 	ipv4_bcast_neigh)		ipv4_bcast_neigh_test;;
+	fib6_gc_test|ipv6_gc)		fib6_gc_test;;
 
 	help) echo "Test names: $TESTS"; exit 0;;
 	esac