Skip to content

Commit

Permalink
ipv6: fib6_new_sernum() optimization
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Nov 16, 2022
1 parent 57fc05e commit 3018980
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions net/ipv6/ip6_fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 3018980

Please sign in to comment.