linux/net/ipv4
Tom Herbert a8b690f98b tcp: Fix slowness in read /proc/net/tcp
This patch address a serious performance issue in reading the
TCP sockets table (/proc/net/tcp).

Reading the full table is done by a number of sequential read
operations.  At each read operation, a seek is done to find the
last socket that was previously read.  This seek operation requires
that the sockets in the table need to be counted up to the current
file position, and to count each of these requires taking a lock for
each non-empty bucket.  The whole algorithm is O(n^2).

The fix is to cache the last bucket value, offset within the bucket,
and the file position returned by the last read operation.   On the
next sequential read, the bucket and offset are used to find the
last read socket immediately without needing ot scan the previous
buckets  the table.  This algorithm t read the whole table is O(n).

The improvement offered by this patch is easily show by performing
cat'ing /proc/net/tcp on a machine with a lot of connections.  With
about 182K connections in the table, I see the following:

- Without patch
time cat /proc/net/tcp > /dev/null

real	1m56.729s
user	0m0.214s
sys	1m56.344s

- With patch
time cat /proc/net/tcp > /dev/null

real	0m0.894s
user	0m0.290s
sys	0m0.594s

Signed-off-by: Tom Herbert <therbert@google.com>
Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-06-07 00:43:42 -07:00
..
netfilter netfilter: xtables: stackptr should be percpu 2010-05-31 16:41:35 +02:00
af_inet.c net: reserve ports for applications using fixed port numbers 2010-05-15 23:28:40 -07:00
ah4.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
arp.c arp: RCU changes 2010-06-03 20:01:52 -07:00
cipso_ipv4.c net: Remove unnecessary returns from void function()s 2010-05-17 23:23:14 -07:00
datagram.c inet: rename some inet_sock fields 2009-10-18 18:52:53 -07:00
devinet.c arp_notify: allow drivers to explicitly request a notification event. 2010-05-31 00:27:44 -07:00
esp4.c xfrm: SA lookups signature with mark 2010-02-22 16:20:22 -08:00
fib_frontend.c ipv4: add LINUX_MIB_IPRPFILTER snmp counter 2010-06-03 03:18:19 -07:00
fib_hash.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
fib_lookup.h
fib_rules.c net: rtnetlink: decouple rtnetlink address families from real address families 2010-04-26 16:13:54 +02:00
fib_semantics.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
fib_trie.c net: Remove unnecessary returns from void function()s 2010-05-17 23:23:14 -07:00
icmp.c net: add a noref bit on skb dst 2010-05-17 17:18:50 -07:00
igmp.c net/ipv4/igmp.c: Remove unnecessary kmalloc casts 2010-06-01 00:15:54 -07:00
inet_connection_sock.c net: reserve ports for applications using fixed port numbers 2010-05-15 23:28:40 -07:00
inet_diag.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
inet_fragment.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
inet_hashtables.c net: reserve ports for applications using fixed port numbers 2010-05-15 23:28:40 -07:00
inet_lro.c net/ipv4: Move && and || to end of previous line 2009-11-23 10:41:23 -08:00
inet_timewait_sock.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
inetpeer.c inetpeer: Optimize inet_getid() 2009-11-13 20:46:58 -08:00
ip_forward.c Merge branch 'master' of /repos/git/net-next-2.6 2010-04-20 16:02:01 +02:00
ip_fragment.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
ip_gre.c net: Remove unnecessary returns from void function()s 2010-05-17 23:23:14 -07:00
ip_input.c ipv4: add LINUX_MIB_IPRPFILTER snmp counter 2010-06-03 03:18:19 -07:00
ip_options.c net: Remove unnecessary returns from void function()s 2010-05-17 23:23:14 -07:00
ip_output.c net: No dst refcounting in ip_queue_xmit() 2010-05-17 17:18:52 -07:00
ip_sockglue.c net: ip_queue_rcv_skb() helper 2010-04-28 15:31:51 -07:00
ipcomp.c xfrm: SA lookups signature with mark 2010-02-22 16:20:22 -08:00
ipconfig.c ipconfig: send host-name in DHCP requests 2010-06-02 07:05:03 -07:00
ipip.c net: Introduce skb_tunnel_rx() helper 2010-05-17 22:36:55 -07:00
ipmr.c ipmr: off by one in __ipmr_fill_mroute() 2010-05-26 00:38:56 -07:00
Kconfig syncookies: remove Kconfig text line about disabled-by-default 2010-06-04 15:56:01 -07:00
Makefile
netfilter.c net: add a noref bit on skb dst 2010-05-17 17:18:50 -07:00
proc.c ipv4: add LINUX_MIB_IPRPFILTER snmp counter 2010-06-03 03:18:19 -07:00
protocol.c net: constify struct net_protocol 2009-09-14 17:03:01 -07:00
raw.c Merge branch 'master' of /repos/git/net-next-2.6 2010-05-10 18:39:28 +02:00
route.c ipv4: RCU changes in __mkroute_input() 2010-06-03 20:01:51 -07:00
syncookies.c Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6 2010-06-06 17:42:02 -07:00
sysctl_net_ipv4.c net: reserve ports for applications using fixed port numbers 2010-05-15 23:28:40 -07:00
tcp.c tcp: tcp_md5_hash_skb_data() frag_list handling 2010-05-31 00:24:02 -07:00
tcp_bic.c
tcp_cong.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
tcp_cubic.c
tcp_diag.c tcp: diag: Dont report negative values for rx queue 2009-12-03 16:06:13 -08:00
tcp_highspeed.c
tcp_htcp.c net/ipv4: Move && and || to end of previous line 2009-11-23 10:41:23 -08:00
tcp_hybla.c TCP: tcp_hybla: Fix integer overflow in slow start increment 2010-06-02 07:15:48 -07:00
tcp_illinois.c
tcp_input.c net/ipv4/tcp_input.c: fix compilation breakage when FASTRETRANS_DEBUG > 1 2010-05-31 23:52:39 -07:00
tcp_ipv4.c tcp: Fix slowness in read /proc/net/tcp 2010-06-07 00:43:42 -07:00
tcp_lp.c net/ipv4: Move && and || to end of previous line 2009-11-23 10:41:23 -08:00
tcp_minisocks.c Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6 2010-04-11 14:53:53 -07:00
tcp_output.c tcp: tcp_synack_options() fix 2010-05-17 22:35:36 -07:00
tcp_probe.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
tcp_scalable.c
tcp_timer.c TCP: avoid to send keepalive probes if receiving data 2010-04-27 12:53:25 -07:00
tcp_vegas.c
tcp_vegas.h
tcp_veno.c net/ipv4: Move && and || to end of previous line 2009-11-23 10:41:23 -08:00
tcp_westwood.c
tcp_yeah.c net/ipv4: Move && and || to end of previous line 2009-11-23 10:41:23 -08:00
tunnel4.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
udp.c net: sock_queue_err_skb() dont mess with sk_forward_alloc 2010-05-31 23:44:05 -07:00
udp_impl.h net: Make setsockopt() optlen be unsigned. 2009-09-30 16:12:20 -07:00
udplite.c net: spread __net_init, __net_exit 2010-01-17 19:16:02 -08:00
xfrm4_input.c net: Use ip_route_input_noref() in input path 2010-05-17 17:18:51 -07:00
xfrm4_mode_beet.c
xfrm4_mode_transport.c
xfrm4_mode_tunnel.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
xfrm4_output.c netfilter: ipv4: use NFPROTO values for NF_HOOK invocation 2010-03-25 16:00:30 +01:00
xfrm4_policy.c xfrm: cache bundles instead of policies for outgoing flows 2010-04-07 03:43:19 -07:00
xfrm4_state.c
xfrm4_tunnel.c