ipv6: fib6_new_sernum() optimization
authorEric Dumazet <edumazet@google.com>
Tue, 15 Nov 2022 09:10:57 +0000 (09:10 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 16 Nov 2022 12:42:00 +0000 (12:42 +0000)
Adopt atomic_try_cmpxchg() which is slightly more efficient.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv6/ip6_fib.c

index 413f667..2438da5 100644 (file)
@@ -91,13 +91,12 @@ static void fib6_walker_unlink(struct net *net, struct fib6_walker *w)
 
 static int fib6_new_sernum(struct net *net)
 {
-       int new, old;
+       int new, old = atomic_read(&net->ipv6.fib6_sernum);
 
        do {
-               old = atomic_read(&net->ipv6.fib6_sernum);
                new = old < INT_MAX ? old + 1 : 1;
-       } while (atomic_cmpxchg(&net->ipv6.fib6_sernum,
-                               old, new) != old);
+       } while (!atomic_try_cmpxchg(&net->ipv6.fib6_sernum, &old, new));
+
        return new;
 }