tcp: batch tcp_net_metrics_exit

[ Upstream commit 789e6ddb0b2fb5d5024b760b178a47876e4de7a6 ]

When dealing with a list of dismantling netns, we can scan
tcp_metrics once, saving cpu cycles.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Stable-dep-of: cbc3a1532228 ("tcp_metrics: add missing barriers on delete")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
This commit is contained in:
Eric Dumazet 2024-04-17 12:25:48 -04:00 committed by Harshit Mogalapalli
parent 5069afc313
commit 9908f81a7a

View File

@ -910,10 +910,14 @@ static void tcp_metrics_flush_all(struct net *net)
for (row = 0; row < max_rows; row++, hb++) {
struct tcp_metrics_block __rcu **pp;
bool match;
spin_lock_bh(&tcp_metrics_lock);
pp = &hb->chain;
for (tm = deref_locked(*pp); tm; tm = deref_locked(*pp)) {
if (net_eq(tm_net(tm), net)) {
match = net ? net_eq(tm_net(tm), net) :
!atomic_read(&tm_net(tm)->count);
if (match) {
*pp = tm->tcpm_next;
kfree_rcu(tm, rcu_head);
} else {
@ -1036,14 +1040,14 @@ static int __net_init tcp_net_metrics_init(struct net *net)
return 0;
}
static void __net_exit tcp_net_metrics_exit(struct net *net)
static void __net_exit tcp_net_metrics_exit_batch(struct list_head *net_exit_list)
{
tcp_metrics_flush_all(net);
tcp_metrics_flush_all(NULL);
}
static __net_initdata struct pernet_operations tcp_net_metrics_ops = {
.init = tcp_net_metrics_init,
.exit = tcp_net_metrics_exit,
.exit_batch = tcp_net_metrics_exit_batch,
};
void __init tcp_metrics_init(void)