Skip to content

Commit

Permalink
net: nexthop: reduce rcu synchronizations when replacing resilient gr…
Browse files Browse the repository at this point in the history
…oups

We can optimize resilient nexthop group replaces by reducing the number of
synchronize_net calls. After commit 1005f19 ("net: nexthop: release
IPv6 per-cpu dsts when replacing a nexthop group") we always do a
synchronize_net because we must ensure no new dsts can be created for the
replaced group's removed nexthops, but we already did that when replacing
resilient groups, so if we always call synchronize_net after any group
type replacement we'll take care of both cases and reduce synchronize_net
calls for resilient groups.

Suggested-by: Ido Schimmel <idosch@idosch.org>
Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Nikolay Aleksandrov authored and David S. Miller committed Nov 30, 2021
1 parent dc2724a commit 7709efa
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions net/ipv4/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1918,9 +1918,6 @@ static void nh_rt_cache_flush(struct net *net, struct nexthop *nh,
if (!replaced_nh->is_group)
return;

/* new dsts must use only the new nexthop group */
synchronize_net();

nhg = rtnl_dereference(replaced_nh->nh_grp);
for (i = 0; i < nhg->num_nh; i++) {
struct nh_grp_entry *nhge = &nhg->nh_entries[i];
Expand Down Expand Up @@ -2002,9 +1999,10 @@ static int replace_nexthop_grp(struct net *net, struct nexthop *old,

rcu_assign_pointer(old->nh_grp, newg);

/* Make sure concurrent readers are not using 'oldg' anymore. */
synchronize_net();

if (newg->resilient) {
/* Make sure concurrent readers are not using 'oldg' anymore. */
synchronize_net();
rcu_assign_pointer(oldg->res_table, tmp_table);
rcu_assign_pointer(oldg->spare->res_table, tmp_table);
}
Expand Down

0 comments on commit 7709efa

Please sign in to comment.