All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcus Meissner <meissner@suse.de>
To: netdev@oss.sgi.com
Subject: [patch] do not readlock all buckets in /proc/net/tcp
Date: Mon, 5 Jul 2004 13:09:49 +0200	[thread overview]
Message-ID: <20040705110949.GA1092@suse.de> (raw)

[-- 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);
 

             reply	other threads:[~2004-07-05 11:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-05 11:09 Marcus Meissner [this message]
2004-07-05 11:27 ` [patch] do not readlock all buckets in /proc/net/tcp 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 / 吉藤英明

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=20040705110949.GA1092@suse.de \
    --to=meissner@suse.de \
    --cc=netdev@oss.sgi.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.