Skip to content

Commit 5c972a0

Browse files
edumazetopsiff
authored andcommitted
tcp: add RCU management to inet_bind_bucket
mainline inclusion from mainline-v6.15-rc1 category: performance Add RCU protection to inet_bind_bucket structure. - Add rcu_head field to the structure definition. - Use kfree_rcu() at destroy time, and remove inet_bind_bucket_destroy() first argument. - Use hlist_del_rcu() and hlist_add_head_rcu() methods. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Jason Xing <kerneljasonxing@gmail.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://patch.msgid.link/20250302124237.3913746-4-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> (cherry picked from commit d186f40) Signed-off-by: Wentao Guan <guanwentao@uniontech.com> Change-Id: I57a0c27b179838e46c3d861bbc862dd90298fb22
1 parent 63b530d commit 5c972a0

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

include/net/inet_hashtables.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct inet_bind_bucket {
8989
bool fast_ipv6_only;
9090
struct hlist_node node;
9191
struct hlist_head bhash2;
92+
struct rcu_head rcu;
9293
};
9394

9495
struct inet_bind2_bucket {
@@ -226,8 +227,7 @@ struct inet_bind_bucket *
226227
inet_bind_bucket_create(struct kmem_cache *cachep, struct net *net,
227228
struct inet_bind_hashbucket *head,
228229
const unsigned short snum, int l3mdev);
229-
void inet_bind_bucket_destroy(struct kmem_cache *cachep,
230-
struct inet_bind_bucket *tb);
230+
void inet_bind_bucket_destroy(struct inet_bind_bucket *tb);
231231

232232
bool inet_bind_bucket_match(const struct inet_bind_bucket *tb,
233233
const struct net *net, unsigned short port,

net/ipv4/inet_connection_sock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
589589
if (bhash2_created)
590590
inet_bind2_bucket_destroy(hinfo->bind2_bucket_cachep, tb2);
591591
if (bhash_created)
592-
inet_bind_bucket_destroy(hinfo->bind_bucket_cachep, tb);
592+
inet_bind_bucket_destroy(tb);
593593
}
594594
if (head2_lock_acquired)
595595
spin_unlock(&head2->lock);

net/ipv4/inet_hashtables.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ struct inet_bind_bucket *inet_bind_bucket_create(struct kmem_cache *cachep,
7777
tb->fastreuse = 0;
7878
tb->fastreuseport = 0;
7979
INIT_HLIST_HEAD(&tb->bhash2);
80-
hlist_add_head(&tb->node, &head->chain);
80+
hlist_add_head_rcu(&tb->node, &head->chain);
8181
}
8282
return tb;
8383
}
8484

8585
/*
8686
* Caller must hold hashbucket lock for this tb with local BH disabled
8787
*/
88-
void inet_bind_bucket_destroy(struct kmem_cache *cachep, struct inet_bind_bucket *tb)
88+
void inet_bind_bucket_destroy(struct inet_bind_bucket *tb)
8989
{
9090
if (hlist_empty(&tb->bhash2)) {
91-
__hlist_del(&tb->node);
92-
kmem_cache_free(cachep, tb);
91+
hlist_del_rcu(&tb->node);
92+
kfree_rcu(tb, rcu);
9393
}
9494
}
9595

@@ -202,7 +202,7 @@ static void __inet_put_port(struct sock *sk)
202202
}
203203
spin_unlock(&head2->lock);
204204

205-
inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
205+
inet_bind_bucket_destroy(tb);
206206
spin_unlock(&head->lock);
207207
}
208208

@@ -286,7 +286,7 @@ int __inet_inherit_port(const struct sock *sk, struct sock *child)
286286

287287
error:
288288
if (created_inet_bind_bucket)
289-
inet_bind_bucket_destroy(table->bind_bucket_cachep, tb);
289+
inet_bind_bucket_destroy(tb);
290290
spin_unlock(&head2->lock);
291291
spin_unlock(&head->lock);
292292
return -ENOMEM;
@@ -1157,7 +1157,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
11571157

11581158
spin_unlock(&head2->lock);
11591159
if (tb_created)
1160-
inet_bind_bucket_destroy(hinfo->bind_bucket_cachep, tb);
1160+
inet_bind_bucket_destroy(tb);
11611161
spin_unlock(&head->lock);
11621162

11631163
if (tw)

net/ipv4/inet_timewait_sock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void inet_twsk_bind_unhash(struct inet_timewait_sock *tw,
3939
tw->tw_tb = NULL;
4040
tw->tw_tb2 = NULL;
4141
inet_bind2_bucket_destroy(hashinfo->bind2_bucket_cachep, tb2);
42-
inet_bind_bucket_destroy(hashinfo->bind_bucket_cachep, tb);
42+
inet_bind_bucket_destroy(tb);
4343

4444
__sock_put((struct sock *)tw);
4545
}

0 commit comments

Comments
 (0)