Netdev List
 help / color / mirror / Atom feed
From: Liu Yu <liuyu924@gmail.com>
To: netdev@vger.kernel.org
Cc: "\"David" "S." "Miller\"" "<davem@davemloft.net>;Alexey"
	Kuznetsov "<kuznet@ms2.inr.ac.ru>;Hideaki" YOSHIFUJI
	<yoshfuji@linux-ipv6.org>
Subject: [PATCH] reduce the spinlock conflict during massive connect
Date: Mon, 6 Nov 2017 10:28:21 +0800	[thread overview]
Message-ID: <9b38c346-0035-4c12-21e7-dbde9f961c8a@gmail.com> (raw)
In-Reply-To: <aa7eecb5-83de-0c90-6c03-34046e7ce212@gmail.com>

From: Liu Yu <allanyuliu@tencent.com>

When a mount of processes connect to the same port at the same address
simultaneously, they are likely getting the same bhash and therefore
conflict with each other.

The more the cpu number, the worse in this case.

Use spin_trylock instead for this scene, which seems doesn't matter
for common case.

Signed-off-by: Liu Yu <allanyuliu@tencent.com>
---
 net/ipv4/inet_hashtables.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index e7d15fb..cc11ec7 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -581,13 +581,17 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
 other_parity_scan:
 	port = low + offset;
 	for (i = 0; i < remaining; i += 2, port += 2) {
+		int ret;
+
 		if (unlikely(port >= high))
 			port -= remaining;
 		if (inet_is_local_reserved_port(net, port))
 			continue;
 		head = &hinfo->bhash[inet_bhashfn(net, port,
 						  hinfo->bhash_size)];
-		spin_lock_bh(&head->lock);
+		ret = spin_trylock(&head->lock);
+		if (unlikely(!ret))
+			continue;
 
 		/* Does not bother with rcv_saddr checks, because
 		 * the established check is already unique enough.
-- 
1.7.1

       reply	other threads:[~2017-11-06  2:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <aa7eecb5-83de-0c90-6c03-34046e7ce212@gmail.com>
2017-11-06  2:28 ` Liu Yu [this message]
2017-11-06  4:12   ` [PATCH] reduce the spinlock conflict during massive connect Cong Wang
2017-11-06  6:47     ` Liu Yu
2017-11-06  5:27   ` Eric Dumazet
2017-11-06  6:48     ` Liu Yu
2017-11-06  6:58       ` Eric Dumazet
2017-11-06  8:14   ` bd2e1bcd9a: BUG:sleeping_function_called_from_invalid_context_at_mm/slab.h kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9b38c346-0035-4c12-21e7-dbde9f961c8a@gmail.com \
    --to=liuyu924@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=yoshfuji@linux-ipv6.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox