netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] do not readlock all buckets in /proc/net/tcp
@ 2004-07-05 11:09 Marcus Meissner
  2004-07-05 11:27 ` Herbert Xu
  0 siblings, 1 reply; 7+ messages in thread
From: Marcus Meissner @ 2004-07-05 11:09 UTC (permalink / raw)
  To: netdev

[-- Attachment #1: Type: text/plain, Size: 466 bytes --]

Hi,

This patch makes the files /proc/net/tcp and /proc/net/tcp6 not acquire
the readlock for every bucket.

On ppc64 and ia64 the readlocks are so expensive, that reading /proc/net/tcp
takes 0.25 seconds on a usual p670 LPAR.

And it locks 65536 buckets where just 20 chains are used at all in a normal
non-netserver setup.

Ciao, Marcus

Changelog:
	Readlock only non-empty hash chains to avoid 65536 readlocks.

	Signed-Off-By: Marcus Meissner <meissner@suse.de>

[-- Attachment #2: tcp-proc-walk --]
[-- Type: text/plain, Size: 1255 bytes --]

--- linux-2.6.5/net/ipv4/tcp_ipv4.c.xx	2004-07-04 13:39:51.000000000 +0200
+++ linux-2.6.5/net/ipv4/tcp_ipv4.c	2004-07-04 13:51:57.000000000 +0200
@@ -2255,6 +2255,12 @@
 		struct hlist_node *node;
 		struct tcp_tw_bucket *tw;
 	       
+		/* Avoid taking the readlock cost if we know the chain is empty,
+		 * we have a lot of buckets.
+		 */
+		if (hlist_empty(&tcp_ehash[st->bucket].chain) &&
+		    hlist_empty(&tcp_ehash[st->bucket+tcp_ehash_size].chain))
+			continue;
 		read_lock(&tcp_ehash[st->bucket].lock);
 		sk_for_each(sk, node, &tcp_ehash[st->bucket].chain) {
 			if (sk->sk_family != st->family) {
@@ -2301,13 +2307,17 @@
 		}
 		read_unlock(&tcp_ehash[st->bucket].lock);
 		st->state = TCP_SEQ_STATE_ESTABLISHED;
-		if (++st->bucket < tcp_ehash_size) {
-			read_lock(&tcp_ehash[st->bucket].lock);
-			sk = sk_head(&tcp_ehash[st->bucket].chain);
-		} else {
+
+		while ((++st->bucket < tcp_ehash_size) &&
+		       hlist_empty(&tcp_ehash[st->bucket].chain) &&
+		       hlist_empty(&tcp_ehash[st->bucket+tcp_ehash_size].chain))
+			/*empty*/;
+		if (st->bucket >= tcp_ehash_size) {
 			cur = NULL;
 			goto out;
 		}
+		read_lock(&tcp_ehash[st->bucket].lock);
+		sk = sk_head(&tcp_ehash[st->bucket].chain);
 	} else
 		sk = sk_next(sk);
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-07-05 13:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-05 11:09 [patch] do not readlock all buckets in /proc/net/tcp Marcus Meissner
2004-07-05 11:27 ` Herbert Xu
2004-07-05 11:35   ` Marcus Meissner
2004-07-05 12:06     ` Herbert Xu
2004-07-05 12:25       ` YOSHIFUJI Hideaki / 吉藤英明
2004-07-05 12:45         ` Marcus Meissner
2004-07-05 13:25           ` YOSHIFUJI Hideaki / 吉藤英明

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).