Commit 50e2907e authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski

tcp/dccp: bypass empty buckets in inet_twsk_purge()

TCP ehash table is often sparsely populated.

inet_twsk_purge() spends too much time calling cond_resched().

This patch can reduce time spent in inet_twsk_purge() by 20x.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Link: https://lore.kernel.org/r/20240327191206.508114-1-edumazet@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 385edf32
...@@ -266,12 +266,17 @@ EXPORT_SYMBOL_GPL(__inet_twsk_schedule); ...@@ -266,12 +266,17 @@ EXPORT_SYMBOL_GPL(__inet_twsk_schedule);
/* Remove all non full sockets (TIME_WAIT and NEW_SYN_RECV) for dead netns */ /* Remove all non full sockets (TIME_WAIT and NEW_SYN_RECV) for dead netns */
void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family) void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family)
{ {
struct inet_ehash_bucket *head = &hashinfo->ehash[0];
unsigned int ehash_mask = hashinfo->ehash_mask;
struct hlist_nulls_node *node; struct hlist_nulls_node *node;
unsigned int slot; unsigned int slot;
struct sock *sk; struct sock *sk;
for (slot = 0; slot <= hashinfo->ehash_mask; slot++) { for (slot = 0; slot <= ehash_mask; slot++, head++) {
struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
if (hlist_nulls_empty(&head->chain))
continue;
restart_rcu: restart_rcu:
cond_resched(); cond_resched();
rcu_read_lock(); rcu_read_lock();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment