Skip to contentSkip to conversation

Add /proc/net/tcp_listen

PATCH In review Andi Kleen 3 participants 3 messages Jun 18, 2004

Subsystems (3)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 Add /proc/net/tcp_listen

This patch adds a /proc/net/tcp_listen. This is a performance optimization for slpd from openslp implementing the SLP protocol. A slpd regularly needs to check the LISTEN sockets on the local system to announce the services provided by them on the network. Problem is that reading /proc/net/tcp can be extremly slow, because it requires to lock/unlock hundred thousands of rwlocks. On some architectures (especially IA64 and PPC64) read_unlock seems to be quite slow and a simple cat /proc/net/tcp on a box with only a few sockets open can take over a second of systime. Doing this will also disturb network traffic severly (it makes actually a noticeable difference in SpecWeb)

For slpd this problem can be avoided completely because it only cares about LISTEN sockets and the LISTEN hash table is much smaller and can be read much cheaper. For that this patch adds a new /proc/net/tcp_listen file that only lists LISTEN sockets.

There were some proposals to make /proc/net/tcp faster too (like checking the hash bucket head first before getting the lock), but they are still all far slower than this.

The patch reuses the existing infrastructure and doesn't add much bloat.

Please consider merging.

-Andi

include/net/tcp.h renamed from include/net/tcp.h-TCPPROC +8 -0
diff -u linux-2.6.7-work/include/net/tcp.h-TCPPROC linux-2.6.7-work/include/net/tcp.h
@@ -2096,7 +2096,10 @@
 	struct module		*owner;
 	char			*name;
 	sa_family_t		family;
+	void *			(*seq_start)(struct seq_file *seq, loff_t *pos);
 	int			(*seq_show) (struct seq_file *m, void *v);
+	void *			(*seq_next)(struct seq_file *seq, void *v, loff_t *pos);
+
 	struct file_operations	*seq_fops;
 };
 
@@ -2111,6 +2114,11 @@
 extern int tcp_proc_register(struct tcp_seq_afinfo *afinfo);
 extern void tcp_proc_unregister(struct tcp_seq_afinfo *afinfo);
 
+extern void *tcp_seq_start(struct seq_file *seq, loff_t *pos);
+extern void *tcp_listen_seq_start(struct seq_file *seq, loff_t *pos);
+extern void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos);
+extern void *tcp_listen_seq_next(struct seq_file *seq, void *v, loff_t *pos);
+
 /* TCP Westwood functions and constants */
 
 #define TCP_WESTWOOD_INIT_RTT  (20*HZ)           /* maybe too conservative?! */
net/ipv4/tcp_ipv4.c renamed from net/ipv4/tcp_ipv4.c-TCPPROC +72 -19

177 lines not on this page · raw message

net/ipv6/tcp_ipv6.c renamed from net/ipv6/tcp_ipv6.c-TCPPROC +18 -1
diff -u linux-2.6.7-work/net/ipv6/tcp_ipv6.c-TCPPROC linux-2.6.7-work/net/ipv6/tcp_ipv6.c
@@ -2066,18 +2066,35 @@
 	.owner		= THIS_MODULE,
 	.name		= "tcp6",
 	.family		= AF_INET6,
+	.seq_start	= tcp_seq_start,
+	.seq_next	= tcp_seq_next,
 	.seq_show	= tcp6_seq_show,
 	.seq_fops	= &tcp6_seq_fops,
 };
 
+static struct file_operations tcp6_listen_seq_fops;
+static struct tcp_seq_afinfo tcp6_listen_seq_afinfo = {
+	.owner		= THIS_MODULE,
+	.name		= "tcp6_listen",
+	.family		= AF_INET6,
+	.seq_start	= tcp_listen_seq_start,
+	.seq_next	= tcp_listen_seq_next,
+	.seq_show	= tcp6_seq_show,
+	.seq_fops	= &tcp6_listen_seq_fops,
+};
+
 int __init tcp6_proc_init(void)
 {
-	return tcp_proc_register(&tcp6_seq_afinfo);
+	int err = tcp_proc_register(&tcp6_seq_afinfo);
+	if (err)
+		return err;
+	return tcp_proc_register(&tcp6_listen_seq_afinfo);
 }
 
 void tcp6_proc_exit(void)
 {
 	tcp_proc_unregister(&tcp6_seq_afinfo);
+	tcp_proc_unregister(&tcp6_listen_seq_afinfo);
 }
 #endif
 
#1 lore raw

In article <[email protected]> (at Fri, 18 Jun 2004 04:31:51 +0200), Andi Kleen <[email protected]> says:

Quoted 6 lines

int __init tcp4_proc_init(void)
{

net/ipv4/tcp_ipv4.c renamed from net/ipv4/tcp_ipv4.c-TCPPROC +2 -1
-	return tcp_proc_register(&tcp4_seq_afinfo);
+	int err = tcp_proc_register(&tcp4_seq_afinfo);
+	if (err) 

net/ipv4/tcp_ipv4.c line 2639

Quoted 10 lines
net/ipv4/tcp_ipv4.c renamed from net/ipv4/tcp_ipv4.c-TCPPROC +3 -0
+		return err;
+	return tcp_proc_register(&tcp4_listen_seq_afinfo);
 }
 
 void tcp4_proc_exit(void)
 {
 	tcp_proc_unregister(&tcp4_seq_afinfo);
+	tcp_proc_unregister(&tcp4_listen_seq_afinfo);
 }
 #endif /* CONFIG_PROC_FS */

If you register A then B, it is better to unregister B then A (symmetric). Yes, it does not matter in this case, but it is better coding style since there often are dependencies.

--yoshfuji

#2 lore raw
In reply to Andi Kleen

Use netlink tcp_diag. It's built specifically for this. Just pass in the suitable fuilter, state == TCP_LISTEN.

inetd and tcpd had support added, so adding support for this openslp thing should be similarly trivial.