Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Evgeniy Polyakov <zbr@ioremap.net>
Cc: Ben Greear <greearb@candelatech.com>,
	David Miller <davem@davemloft.net>,
	Gaspar Chilingarov <gasparch@gmail.com>,
	netdev <netdev@vger.kernel.org>
Subject: Re: PROBLEM: Linux kernel 2.6.31 IPv4 TCP fails to open huge amount of outgoing connections (unable to bind ... )
Date: Wed, 21 Apr 2010 07:46:39 +0200	[thread overview]
Message-ID: <1271828799.7895.1287.camel@edumazet-laptop> (raw)
In-Reply-To: <20100421003022.GA3107@ioremap.net>

Le mercredi 21 avril 2010 à 04:30 +0400, Evgeniy Polyakov a écrit :
> On Wed, Apr 21, 2010 at 02:05:14AM +0200, Eric Dumazet (eric.dumazet@gmail.com) wrote:
> > I believe the bsockets 'optimization' is a bug, we should remove it.
> > 
> > This is a stable candidate (2.6.30+)
> > 
> > [PATCH net-next-2.6] tcp: remove bsockets count
> > 
> > Counting number of bound sockets to avoid a loop is buggy, since we cant
> > know how many IP addresses are in use. When threshold is reached, we try
> > 5 random slots and can fail while there are plenty available ports.
> 
> To return back to exponential bind() times you need to revert the whole
> original patch including magic 5 number, not only bsockets.
> 
> But actual problem is not in this digit, but in a deeper logic.
> Previously we scanned the whole table, now we have 5 attempts to
> find out at least one bucket (without conflict) we will insert
> new socket into. Apparently for large number of addresses it is possible
> that all 5 times we will randomly select those buckets which conflicts.
> As dumb solution we can increase 'attempt' number to infinite one, or
> fallback to whole-table-search after several random attempts, which is a
> bit more clever I think.
> 

Hmm, maybe I am blind, but on the case the threshold is reached, we dont
have 5 attempts "to find out at least one bucket (without conflict)"

We just take the first entry from the random starting point, _without_
checking we have a conflict.

if (net_eq(ib_net(tb), net) && tb->port == rover) {
	if (tb->fastreuse > 0 &&
	    sk->sk_reuse &&
	    sk->sk_state != TCP_LISTEN &&
	    (tb->num_owners < smallest_size || smallest_size == -1)) {
		smallest_size = tb->num_owners;
		smallest_rover = rover;
		if (atomic_read(&hashinfo->bsockets) > (high-low)+1) {
			spin_unlock(&head->lock);
			snum = smallest_rover;   // We select this, without checking for
conflicts.
			goto have_snum;
		}
	}


Then we goto to "have_snum" label

Then we realize (selected_IP, randomport) is already in use.
End of first try.

We redo the thing 5 times, so we only look at 5 slots out of
32000-64000.

Maybe the fix would need to check if there is a conflict before doing
the "goto have_snum"

diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index e0a3e35..0498daf 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -120,9 +120,11 @@ again:
 						smallest_size = tb->num_owners;
 						smallest_rover = rover;
 						if (atomic_read(&hashinfo->bsockets) > (high - low) + 1) {
-							spin_unlock(&head->lock);
-							snum = smallest_rover;
-							goto have_snum;
+							if (!inet_csk(sk)->icsk_af_ops->bind_conflict(sk, tb))
+								spin_unlock(&head->lock);
+								snum = smallest_rover;
+								goto have_snum;
+							}
 						}
 					}
 					goto next;



  parent reply	other threads:[~2010-04-21  5:46 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-20 22:17 PROBLEM: Linux kernel 2.6.31 IPv4 TCP fails to open huge amount of outgoing connections (unable to bind ... ) Gaspar Chilingarov
2010-04-20 22:31 ` Eric Dumazet
2010-04-20 23:18   ` Gaspar Chilingarov
2010-04-20 23:42     ` Eric Dumazet
2010-04-21  0:14       ` Evgeniy Polyakov
2010-04-20 23:07 ` Ben Greear
2010-04-20 23:20   ` Gaspar Chilingarov
2010-04-20 23:20   ` Gaspar Chilingarov
2010-04-20 23:30     ` Ben Greear
2010-04-20 23:35       ` Gaspar Chilingarov
2010-04-20 23:49         ` Ben Greear
2010-04-20 23:57           ` Gaspar Chilingarov
2010-04-21  0:14             ` Eric Dumazet
2010-04-21  0:05           ` Eric Dumazet
2010-04-21  0:12             ` Gaspar Chilingarov
2010-04-21  0:14             ` David Miller
2010-04-21  0:30             ` Evgeniy Polyakov
2010-04-21  2:04               ` David Miller
2010-04-21  5:46               ` Eric Dumazet [this message]
2010-04-21  8:25                 ` Evgeniy Polyakov
2010-04-21  9:02                   ` Eric Dumazet
2010-04-21  9:58                     ` Evgeniy Polyakov
2010-04-21 10:21                       ` Eric Dumazet
2010-04-21 11:27                       ` Eric Dumazet
2010-04-21 16:52                         ` George B.
2010-04-21 18:27                         ` Evgeniy Polyakov
2010-04-21 18:43                           ` Eric Dumazet
2010-04-21 18:58                             ` Evgeniy Polyakov
2010-04-21 19:26                               ` Eric Dumazet
2010-04-21 20:08                                 ` Evgeniy Polyakov
2010-04-23  2:06                                   ` David Miller
2010-04-25 14:26                                 ` Michael S. Tsirkin
2010-04-25 15:56                                   ` Evgeniy Polyakov
2010-04-25 16:13                                     ` Eric Dumazet
2010-04-25 16:21                                     ` Eric Dumazet
2010-04-25 16:35                                       ` Michael S. Tsirkin
2010-04-25 22:08                                         ` David Miller
2010-04-21 19:03 ` Narendra Choyal

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=1271828799.7895.1287.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=gasparch@gmail.com \
    --cc=greearb@candelatech.com \
    --cc=netdev@vger.kernel.org \
    --cc=zbr@ioremap.net \
    /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