Skip to contentSkip to conversation

Unified dynamic storage for different socket types instead of separate hash tables.

ANN Evgeniy Polyakov 4 participants 14 messages Mar 22, 2007 – Mar 27, 2007

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

Hello.

I'm pleased to announce initial patch which replaces hash tables for different sockets types with unified multidimensional trie.

Benefits:
* unified storage which can host any socket types. Currently supported (see below about completeness):
o IP (AF_INET) sockets
* TCP established sockets
* TCP listen sockets
* TCP timewait sockets
* RAW sockets
* UDP sockets
o Unix domain sockets
o Netlink sockets
* RCU protected traversal.
* Dynamic grow.
* Constant maximum access speed designed to be faster than median hash table lookup speed
(see below for testing environment description).

As a drawback I can only say that it eats about 3 times more RAM on x86 (98mb vs. 32mb for 2^20 entries).

Lookup methods as long as insertion/deletion ones differ only in key setup part, although insert/delete methods perform some additional per-protocl steps (like cleaning private areas in netlink).

Patch is a bit ugly - it contains horrible ifdefs and known to have problems (see below), but I will clean things up and proceed (and break a lot in socket processing code - for sure) if (and only if, kevent story is enough for me to not make the same mistakes and throw half a year again) network developers decide that this approach worth doing (my personal opinion that it worth).

So, details.

1. Design.
It is a trie implementation (I call it multidimensional) which uses several bits to select a node, so each node is an array of pointers to another level(s). It is also possible that each array entry points to cached value to speed up access and reduce memory usage.
It is similar to judy tree implementation.

More design notes can be found in related blog entries [1].

2. Performance.
I created userspace implementation and ran tests only with it. Tests were performed for MDT trie (working name of this algo) and hash tables with different number of entries. Each test contained 2^20 elements inserted into storage, each element is 3 pseudo-random 32 bit value without zeroes in any byte.

The fastest hash table is of course table with 2^20 elements, its lookup speed is about 130 nanoseconds.
MDT speed is about 110 nanoseconds.
Getting into account that tests were performed on Intel Core Duo in userspace with per-4kb-tlb miss, 18% win is a good result for system, which uses 3 times more ram.
More details and graphs can be found in related blog entries [2].

3. Testing.
I only completed patch to the stage where system boots with LVM (netlink and unix sockets) and I can log into it over ssh (TCP sockets) and run tcpdump (RAW sockets). For example it crashes when connecting over loopback.

4. Unsolved problems.
a. It does not support any kind of statistics. At all. Completely. All code is commented.
Because existing stats only support blind hash table traversal, which I do not like as is, so I did not implement full trie traversal. Socket structure just does not contain hash pointers anymore (except bind_node used for netlink broadcasting, which I plan to reuse to collect all sockets for given type to be placed into single per-protocol lists, which can be accessed from statistics code).
b. code was not extensively tested and contains bugs.
c. existing hashing interfaces were not designed to work with failing conditions, so alot of them will be changed.

6. Improvements.
o Unified cache for any socket type.
o Simplified insert/delete/lookup methods.
o Faster access speed.
o Smaller socket structure.
o RCU lookup.
o Dynamic structures (no need to rehash).
o Place you favourite here.

Anyway, it was interesting project as is, but enough words for now. Feel free to ask questions.

Thank you.

1. Trie implementation and design.
http://tservice.net.ru/~s0mbre/blog/devel/networking/index.html
http://tservice.net.ru/~s0mbre/blog/devel/other/index.html

2. Performance tests.
Non-optimized trie access compared to hash tables (with graphs):
http://tservice.net.ru/~s0mbre/blog/2007/03/15#2007_03_15

Optimized one:
http://tservice.net.ru/~s0mbre/blog/2007/03/16#2007_03_16

include/linux/netlink.h +0 -1
index 2a20f48..f11b4e7 100644
@@ -151,7 +151,6 @@ struct netlink_skb_parms
 #define NETLINK_CB(skb)		(*(struct netlink_skb_parms*)&((skb)->cb))
 #define NETLINK_CREDS(skb)	(&NETLINK_CB((skb)).creds)
 
-
 extern struct sock *netlink_kernel_create(int unit, unsigned int groups, void (*input)(struct sock *sk, int len), struct module *module);
 extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
 extern int netlink_has_listeners(struct sock *sk, unsigned int group);
include/net/af_unix.h +3 -1
index c0398f5..e8e7266 100644
@@ -16,7 +16,7 @@ extern struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
 extern spinlock_t unix_table_lock;
 
 extern atomic_t unix_tot_inflight;
-
+#ifndef CONFIG_MDT_LOOKUP
 static inline struct sock *first_unix_socket(int *i)
 {
 	for (*i = 0; *i <= UNIX_HASH_SIZE; (*i)++) {
@@ -43,6 +43,8 @@ static inline struct sock *next_unix_socket(int *i, struct sock *s)
 #define forall_unix_sockets(i, s) \
 	for (s = first_unix_socket(&(i)); s; s = next_unix_socket(&(i),(s)))
 
+#endif
+
 struct unix_address {
 	atomic_t	refcnt;
 	int		len;
include/net/inet_connection_sock.h +4 -1
index 133cf30..5dbab2d 100644
@@ -244,11 +244,14 @@ extern struct request_sock *inet_csk_search_req(const struct sock *sk,
 						const __be32 laddr);
 extern int inet_csk_bind_conflict(const struct sock *sk,
 				  const struct inet_bind_bucket *tb);
+#ifndef CONFIG_MDT_LOOKUP
 extern int inet_csk_get_port(struct inet_hashinfo *hashinfo,
 			     struct sock *sk, unsigned short snum,
 			     int (*bind_conflict)(const struct sock *sk,
 						  const struct inet_bind_bucket *tb));
-
+#else
+extern int inet_csk_get_port(struct sock *sk, unsigned short snum);
+#endif
 extern struct dst_entry* inet_csk_route_req(struct sock *sk,
 					    const struct request_sock *req);
 
include/net/inet_hashtables.h +0 -5
index d27ee8c..cd77aa4 100644
@@ -266,11 +266,6 @@ out:
 		wake_up(&hashinfo->lhash_wait);
 }
 
-static inline int inet_iif(const struct sk_buff *skb)
-{
-	return ((struct rtable *)skb->dst)->rt_iif;
-}
-
 extern struct sock *__inet_lookup_listener(struct inet_hashinfo *hashinfo,
 					   const __be32 daddr,
 					   const unsigned short hnum,
include/net/inet_timewait_sock.h +12 -0
index 09a2532..50dbe1b 100644
@@ -78,7 +78,9 @@ struct inet_timewait_death_row {
 	struct timer_list	tw_timer;
 	int			slot;
 	struct hlist_head	cells[INET_TWDR_TWKILL_SLOTS];
+#ifndef CONFIG_MDT_LOOKUP
 	struct inet_hashinfo 	*hashinfo;
+#endif
 	int			sysctl_tw_recycle;
 	int			sysctl_max_tw_buckets;
 };
@@ -131,10 +133,13 @@ struct inet_timewait_sock {
 	__u16			tw_ipv6_offset;
 	int			tw_timeout;
 	unsigned long		tw_ttd;
+#ifndef CONFIG_MDT_LOOKUP
 	struct inet_bind_bucket	*tw_tb;
+#endif
 	struct hlist_node	tw_death_node;
 };
 
+#ifndef CONFIG_MDT_LOOKUP
 static inline void inet_twsk_add_node(struct inet_timewait_sock *tw,
 				      struct hlist_head *list)
 {
@@ -146,6 +151,7 @@ static inline void inet_twsk_add_bind_node(struct inet_timewait_sock *tw,
 {
 	hlist_add_head(&tw->tw_bind_node, list);
 }
+#endif
 
 static inline int inet_twsk_dead_hashed(const struct inet_timewait_sock *tw)
 {
@@ -209,12 +215,18 @@ static inline void inet_twsk_put(struct inet_timewait_sock *tw)
 extern struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk,
 						  const int state);
 
+#ifndef CONFIG_MDT_LOOKUP
 extern void __inet_twsk_kill(struct inet_timewait_sock *tw,
 			     struct inet_hashinfo *hashinfo);
 
 extern void __inet_twsk_hashdance(struct inet_timewait_sock *tw,
 				  struct sock *sk,
 				  struct inet_hashinfo *hashinfo);
+#else
+extern void __inet_twsk_kill(struct inet_timewait_sock *tw);
+extern void __inet_twsk_hashdance(struct inet_timewait_sock *tw,
+				  struct sock *sk);
+#endif
 
 extern void inet_twsk_schedule(struct inet_timewait_sock *tw,
 			       struct inet_timewait_death_row *twdr,
include/net/lookup.h new file +120 -0

120 lines not on this page · raw message

include/net/netlink.h +29 -0
index bcaf67b..37cf163 100644
@@ -1016,4 +1016,33 @@ static inline int nla_validate_nested(struct nlattr *start, int maxtype,
 #define nla_for_each_nested(pos, nla, rem) \
 	nla_for_each_attr(pos, nla_data(nla), nla_len(nla), rem)
 
+#ifdef __KERNEL__
+
+#include <net/sock.h>
+
+struct netlink_sock {
+	/* struct sock has to be the first member of netlink_sock */
+	struct sock		sk;
+	u32			pid;
+	u32			dst_pid;
+	u32			dst_group;
+	u32			flags;
+	u32			subscriptions;
+	u32			ngroups;
+	unsigned long		*groups;
+	unsigned long		state;
+	wait_queue_head_t	wait;
+	struct netlink_callback	*cb;
+	spinlock_t		cb_lock;
+	void			(*data_ready)(struct sock *sk, int bytes);
+	struct module		*module;
+};
+
+static inline struct netlink_sock *nlk_sk(struct sock *sk)
+{
+	return (struct netlink_sock *)sk;
+}
+
+#endif
+
 #endif
include/net/raw.h +1 -0
index e4af597..bec7045 100644
@@ -29,6 +29,7 @@ extern int 	raw_rcv(struct sock *, struct sk_buff *);
  *       hashing mechanism, make sure you update icmp.c as well.
  */
 #define RAWV4_HTABLE_SIZE	MAX_INET_PROTOS
+extern int raw_in_use;
 extern struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE];
 
 extern rwlock_t raw_v4_lock;
include/net/sock.h +63 -43

150 lines not on this page · raw message

include/net/tcp.h +3 -4
index 5c472f2..8301bb8 100644
@@ -32,7 +32,7 @@
 
 #include <net/inet_connection_sock.h>
 #include <net/inet_timewait_sock.h>
-#include <net/inet_hashtables.h>
+#include <net/lookup.h>
 #include <net/checksum.h>
 #include <net/request_sock.h>
 #include <net/sock.h>
@@ -42,8 +42,6 @@
 
 #include <linux/seq_file.h>
 
-extern struct inet_hashinfo tcp_hashinfo;
-
 extern atomic_t tcp_orphan_count;
 extern void tcp_time_wait(struct sock *sk, int state, int timeo);
 
@@ -408,6 +406,7 @@ extern struct sk_buff *		tcp_make_synack(struct sock *sk,
 extern int			tcp_disconnect(struct sock *sk, int flags);
 
 extern void			tcp_unhash(struct sock *sk);
+extern void 			tcp_v4_hash(struct sock *sk);
 
 /* From syncookies.c */
 extern struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, 
@@ -901,7 +900,7 @@ static inline void tcp_set_state(struct sock *sk, int state)
 		sk->sk_prot->unhash(sk);
 		if (inet_csk(sk)->icsk_bind_hash &&
 		    !(sk->sk_userlocks & SOCK_BINDPORT_LOCK))
-			inet_put_port(&tcp_hashinfo, sk);
+			proto_put_port(sk);
 		/* fall through */
 	default:
 		if (oldstate==TCP_ESTABLISHED)
include/net/udp.h +5 -0
index 1b921fa..82f9f15 100644
@@ -30,6 +30,7 @@
 #include <linux/ipv6.h>
 #include <linux/seq_file.h>
 #include <linux/poll.h>
+#include <net/lookup.h>
 
 /**
  *	struct udp_skb_cb  -  UDP(-Lite) private variables
@@ -108,12 +109,16 @@ static inline void udp_lib_hash(struct sock *sk)
 
 static inline void udp_lib_unhash(struct sock *sk)
 {
+#ifndef CONFIG_MDT_LOOKUP
 	write_lock_bh(&udp_hash_lock);
 	if (sk_del_node_init(sk)) {
 		inet_sk(sk)->num = 0;
 		sock_prot_dec_use(sk->sk_prot);
 	}
 	write_unlock_bh(&udp_hash_lock);
+#else
+	mdt_remove_sock_void(sk);
+#endif
 }
 
 static inline void udp_lib_close(struct sock *sk, long timeout)
net/core/sock.c +2 -0
index 8d65d64..abe1632 100644
@@ -901,7 +901,9 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
 		sock_copy(newsk, sk);
 
 		/* SANITY */
+#ifndef CONFIG_MDT_LOOKUP
 		sk_node_init(&newsk->sk_node);
+#endif
 		sock_lock_init(newsk);
 		bh_lock_sock(newsk);
 
net/ipv4/Kconfig +8 -0
index 9e8ef50..5bfb0dc 100644
@@ -1,6 +1,14 @@
 #
 # IP configuration
 #
+
+config MDT_LOOKUP
+	bool "Multidimensional trie socket lookup"
+	depends on !INET_TCP_DIAG
+	help
+	  This option replaces traditional hash table lookup for TCP sockets
+	  with multidimensional trie algorithm (similar to judy trie).
+
 config IP_MULTICAST
 	bool "IP: multicasting"
 	help
net/ipv4/Makefile +6 -1
index 7a06862..f1f1459 100644
@@ -4,7 +4,7 @@
 
 obj-y     := route.o inetpeer.o protocol.o \
 	     ip_input.o ip_fragment.o ip_forward.o ip_options.o \
-	     ip_output.o ip_sockglue.o inet_hashtables.o \
+	     ip_output.o ip_sockglue.o \
 	     inet_timewait_sock.o inet_connection_sock.o \
 	     tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \
 	     tcp_minisocks.o tcp_cong.o \
@@ -12,6 +12,11 @@ obj-y     := route.o inetpeer.o protocol.o \
 	     arp.o icmp.o devinet.o af_inet.o  igmp.o \
 	     sysctl_net_ipv4.o fib_frontend.o fib_semantics.o
 
+ifeq ($(CONFIG_MDT_LOOKUP),n)
+obj-y += inet_hashtables.o
+endif
+
+obj-$(CONFIG_MDT_LOOKUP) += mdt.o
 obj-$(CONFIG_IP_FIB_HASH) += fib_hash.o
 obj-$(CONFIG_IP_FIB_TRIE) += fib_trie.o
 obj-$(CONFIG_PROC_FS) += proc.o
net/ipv4/af_inet.c +7 -1
index cf358c8..8c32545 100644
@@ -1360,6 +1360,7 @@ fs_initcall(inet_init);
 /* ------------------------------------------------------------------------ */
 
 #ifdef CONFIG_PROC_FS
+#ifndef CONFIG_MDT_LOOKUP
 static int __init ipv4_proc_init(void)
 {
 	int rc = 0;
@@ -1388,7 +1389,12 @@ out_raw:
 	rc = -ENOMEM;
 	goto out;
 }
-
+#else
+static int __init ipv4_proc_init(void)
+{
+	return 0;
+}
+#endif
 #else /* CONFIG_PROC_FS */
 static int __init ipv4_proc_init(void)
 {
net/ipv4/icmp.c +10 -0
index 4b7a0d9..eaf445d 100644
@@ -698,6 +698,7 @@ static void icmp_unreach(struct sk_buff *skb)
 
 	/* Note: See raw.c and net/raw.h, RAWV4_HTABLE_SIZE==MAX_INET_PROTOS */
 	hash = protocol & (MAX_INET_PROTOS - 1);
+#ifndef CONFIG_MDT_LOOKUP
 	read_lock(&raw_v4_lock);
 	if ((raw_sk = sk_head(&raw_v4_htable[hash])) != NULL) {
 		while ((raw_sk = __raw_v4_lookup(raw_sk, protocol, iph->daddr,
@@ -709,6 +710,15 @@ static void icmp_unreach(struct sk_buff *skb)
 		}
 	}
 	read_unlock(&raw_v4_lock);
+#else
+	raw_sk = __raw_v4_lookup(NULL, protocol, iph->daddr,
+					 iph->saddr,
+					 skb->dev->ifindex);
+	if (raw_sk) {
+		raw_err(raw_sk, skb, info);
+		iph = (struct iphdr *)skb->data;
+	}
+#endif
 
 	rcu_read_lock();
 	ipprot = rcu_dereference(inet_protos[hash]);
net/ipv4/inet_connection_sock.c +5 -1
index 43fb160..ec4ae71 100644
@@ -17,7 +17,7 @@
 #include <linux/jhash.h>
 
 #include <net/inet_connection_sock.h>
-#include <net/inet_hashtables.h>
+#include <net/lookup.h>
 #include <net/inet_timewait_sock.h>
 #include <net/ip.h>
 #include <net/route.h>
@@ -36,6 +36,7 @@ EXPORT_SYMBOL(inet_csk_timer_bug_msg);
  */
 int sysctl_local_port_range[2] = { 1024, 4999 };
 
+#ifndef CONFIG_MDT_LOOKUP
 int inet_csk_bind_conflict(const struct sock *sk,
 			   const struct inet_bind_bucket *tb)
 {
@@ -159,6 +160,7 @@ fail:
 }
 
 EXPORT_SYMBOL_GPL(inet_csk_get_port);
+#endif
 
 /*
  * Wait for an incoming connection, avoid race conditions. This must be called
@@ -529,8 +531,10 @@ void inet_csk_destroy_sock(struct sock *sk)
 	BUG_TRAP(sk->sk_state == TCP_CLOSE);
 	BUG_TRAP(sock_flag(sk, SOCK_DEAD));
 
+#ifndef CONFIG_MDT_LOOKUP
 	/* It cannot be in hash table! */
 	BUG_TRAP(sk_unhashed(sk));
+#endif
 
 	/* If it has not 0 inet_sk(sk)->num, it must be bound */
 	BUG_TRAP(!inet_sk(sk)->num || inet_csk(sk)->icsk_bind_hash);
net/ipv4/inet_diag.c +8 -3
index 5df71cd..e4f9a86 100644
@@ -24,7 +24,7 @@
 #include <net/ipv6.h>
 #include <net/inet_common.h>
 #include <net/inet_connection_sock.h>
-#include <net/inet_hashtables.h>
+#include <net/lookup.h>
 #include <net/inet_timewait_sock.h>
 #include <net/inet6_hashtables.h>
 
@@ -238,9 +238,10 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
 	hashinfo = handler->idiag_hashinfo;
 
 	if (req->idiag_family == AF_INET) {
-		sk = inet_lookup(hashinfo, req->id.idiag_dst[0],
+		sk = sock_lookup(req->id.idiag_dst[0],
 				 req->id.idiag_dport, req->id.idiag_src[0],
-				 req->id.idiag_sport, req->id.idiag_if);
+				 req->id.idiag_sport, req->id.idiag_if,
+				 IPPROTO_TCP);
 	}
 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
 	else if (req->idiag_family == AF_INET6) {
@@ -670,6 +671,9 @@ out:
 
 static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
 {
+#ifdef CONFIG_MDT_LOOKUP
+	return -1;
+#else
 	int i, num;
 	int s_i, s_num;
 	struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
@@ -803,6 +807,7 @@ done:
 	cb->args[1] = i;
 	cb->args[2] = num;
 	return skb->len;
+#endif
 }
 
 static inline int inet_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
net/ipv4/inet_timewait_sock.c +34 -1
index a73cf93..e5e0fff 100644
@@ -9,10 +9,11 @@
  */
 
 
-#include <net/inet_hashtables.h>
+#include <net/lookup.h>
 #include <net/inet_timewait_sock.h>
 #include <net/ip.h>
 
+#ifndef CONFIG_MDT_LOOKUP
 /* Must be called with locally disabled BHs. */
 void __inet_twsk_kill(struct inet_timewait_sock *tw, struct inet_hashinfo *hashinfo)
 {
@@ -86,6 +87,22 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk,
 }
 
 EXPORT_SYMBOL_GPL(__inet_twsk_hashdance);
+#else
+void __inet_twsk_kill(struct inet_timewait_sock *tw)
+{
+	inet_twsk_put(tw);
+	mdt_remove_sock_tw(tw);
+}
+
+void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk)
+{
+	if (__sk_del_node_init(sk))
+		sock_prot_dec_use(sk->sk_prot);
+
+	mdt_insert_sock_tw(tw);
+	atomic_inc(&tw->tw_refcnt);
+}
+#endif
 
 struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int state)
 {
@@ -106,11 +123,15 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int stat
 		tw->tw_dport	    = inet->dport;
 		tw->tw_family	    = sk->sk_family;
 		tw->tw_reuse	    = sk->sk_reuse;
+#ifndef CONFIG_MDT_LOOKUP
 		tw->tw_hash	    = sk->sk_hash;
+#endif
 		tw->tw_ipv6only	    = 0;
 		tw->tw_prot	    = sk->sk_prot_creator;
 		atomic_set(&tw->tw_refcnt, 1);
+#ifndef CONFIG_MDT_LOOKUP
 		inet_twsk_dead_node_init(tw);
+#endif
 		__module_get(tw->tw_prot->owner);
 	}
 
@@ -140,7 +161,11 @@ rescan:
 	inet_twsk_for_each_inmate(tw, node, &twdr->cells[slot]) {
 		__inet_twsk_del_dead_node(tw);
 		spin_unlock(&twdr->death_lock);
+#ifndef CONFIG_MDT_LOOKUP
 		__inet_twsk_kill(tw, twdr->hashinfo);
+#else
+		__inet_twsk_kill(tw);
+#endif
 		inet_twsk_put(tw);
 		killed++;
 		spin_lock(&twdr->death_lock);
@@ -242,7 +267,11 @@ void inet_twsk_deschedule(struct inet_timewait_sock *tw,
 			del_timer(&twdr->tw_timer);
 	}
 	spin_unlock(&twdr->death_lock);
+#ifndef CONFIG_MDT_LOOKUP
 	__inet_twsk_kill(tw, twdr->hashinfo);
+#else
+	__inet_twsk_kill(tw);
+#endif
 }
 
 EXPORT_SYMBOL(inet_twsk_deschedule);
@@ -354,7 +383,11 @@ void inet_twdr_twcal_tick(unsigned long data)
 			inet_twsk_for_each_inmate_safe(tw, node, safe,
 						       &twdr->twcal_row[slot]) {
 				__inet_twsk_del_dead_node(tw);
+#ifndef CONFIG_MDT_LOOKUP
 				__inet_twsk_kill(tw, twdr->hashinfo);
+#else
+				__inet_twsk_kill(tw);
+#endif
 				inet_twsk_put(tw);
 				killed++;
 			}
net/ipv4/ip_input.c +4 -6
index f38e976..be3e683 100644
@@ -209,19 +209,17 @@ static inline int ip_local_deliver_finish(struct sk_buff *skb)
 	{
 		/* Note: See raw.c and net/raw.h, RAWV4_HTABLE_SIZE==MAX_INET_PROTOS */
 		int protocol = skb->nh.iph->protocol;
-		int hash;
-		struct sock *raw_sk;
+		int hash, raw = raw_in_use;
 		struct net_protocol *ipprot;
 
 	resubmit:
 		hash = protocol & (MAX_INET_PROTOS - 1);
-		raw_sk = sk_head(&raw_v4_htable[hash]);
 
 		/* If there maybe a raw socket we must check - if not we
 		 * don't care less
 		 */
-		if (raw_sk && !raw_v4_input(skb, skb->nh.iph, hash))
-			raw_sk = NULL;
+		if (raw_in_use && !raw_v4_input(skb, skb->nh.iph, hash))
+			raw = 0;
 
 		if ((ipprot = rcu_dereference(inet_protos[hash])) != NULL) {
 			int ret;
@@ -240,7 +238,7 @@ static inline int ip_local_deliver_finish(struct sk_buff *skb)
 			}
 			IP_INC_STATS_BH(IPSTATS_MIB_INDELIVERS);
 		} else {
-			if (!raw_sk) {
+			if (!raw) {
 				if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
 					IP_INC_STATS_BH(IPSTATS_MIB_INUNKNOWNPROTOS);
 					icmp_send(skb, ICMP_DEST_UNREACH,
net/ipv4/mdt.c new file +598 -0

598 lines not on this page · raw message

net/ipv4/raw.c +45 -2

93 lines not on this page · raw message

net/ipv4/tcp.c +12 -6
index 74c4d10..531eafb 100644
@@ -2389,12 +2389,15 @@ void __init tcp_init(void)
 {
 	struct sk_buff *skb = NULL;
 	unsigned long limit;
-	int order, i, max_share;
+	int order, max_share;
+#ifndef CONFIG_MDT_LOOKUP
+	int i;
+#endif
 
 	if (sizeof(struct tcp_skb_cb) > sizeof(skb->cb))
 		__skb_cb_too_small_for_tcp(sizeof(struct tcp_skb_cb),
 					   sizeof(skb->cb));
-
+#ifndef CONFIG_MDT_LOOKUP
 	tcp_hashinfo.bind_bucket_cachep =
 		kmem_cache_create("tcp_bind_bucket",
 				  sizeof(struct inet_bind_bucket), 0,
@@ -2445,6 +2448,10 @@ void __init tcp_init(void)
 			(tcp_hashinfo.bhash_size * sizeof(struct inet_bind_hashbucket));
 			order++)
 		;
+#else
+	for (order = 0; ((1 << order) << PAGE_SHIFT) < (8*(1<<20)); order++);
+#endif
+
 	if (order >= 4) {
 		sysctl_local_port_range[0] = 32768;
 		sysctl_local_port_range[1] = 61000;
@@ -2457,9 +2464,8 @@ void __init tcp_init(void)
 		sysctl_tcp_max_orphans >>= (3 - order);
 		sysctl_max_syn_backlog = 128;
 	}
-
 	/* Allow no more than 3/4 kernel memory (usually less) allocated to TCP */
-	sysctl_tcp_mem[0] = (1536 / sizeof (struct inet_bind_hashbucket)) << order;
+	sysctl_tcp_mem[0] = (1536 / 8) << order;
 	sysctl_tcp_mem[1] = sysctl_tcp_mem[0] * 4 / 3;
 	sysctl_tcp_mem[2] = sysctl_tcp_mem[0] * 2;
 
@@ -2473,11 +2479,11 @@ void __init tcp_init(void)
 	sysctl_tcp_rmem[0] = SK_STREAM_MEM_QUANTUM;
 	sysctl_tcp_rmem[1] = 87380;
 	sysctl_tcp_rmem[2] = max(87380, max_share);
-
+#ifndef CONFIG_MDT_LOOKUP
 	printk(KERN_INFO "TCP: Hash tables configured "
 	       "(established %d bind %d)\n",
 	       tcp_hashinfo.ehash_size, tcp_hashinfo.bhash_size);
-
+#endif
 	tcp_register_congestion_control(&tcp_reno);
 }
 
net/ipv4/tcp_ipv4.c +55 -11

177 lines not on this page · raw message

net/ipv4/tcp_minisocks.c +6 -0
index 6b5c64f..79485d4 100644
@@ -41,7 +41,9 @@ struct inet_timewait_death_row tcp_death_row = {
 	.sysctl_max_tw_buckets = NR_FILE * 2,
 	.period		= TCP_TIMEWAIT_LEN / INET_TWDR_TWKILL_SLOTS,
 	.death_lock	= __SPIN_LOCK_UNLOCKED(tcp_death_row.death_lock),
+#ifndef CONFIG_MDT_LOOKUP
 	.hashinfo	= &tcp_hashinfo,
+#endif
 	.tw_timer	= TIMER_INITIALIZER(inet_twdr_hangman, 0,
 					    (unsigned long)&tcp_death_row),
 	.twkill_work	= __WORK_INITIALIZER(tcp_death_row.twkill_work,
@@ -328,7 +330,11 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
 #endif
 
 		/* Linkage updates. */
+#ifndef CONFIG_MDT_LOOKUP
 		__inet_twsk_hashdance(tw, sk, &tcp_hashinfo);
+#else
+		__inet_twsk_hashdance(tw, sk);
+#endif
 
 		/* Get the TIME_WAIT timeout firing. */
 		if (timeo < rto)
net/ipv4/udp.c +84 -49

212 lines not on this page · raw message

net/ipv4/udplite.c +13 -1
index b28fe1e..e21c942 100644
@@ -16,6 +16,7 @@
 DEFINE_SNMP_STAT(struct udp_mib, udplite_statistics)	__read_mostly;
 
 struct hlist_head 	udplite_hash[UDP_HTABLE_SIZE];
+#ifndef CONFIG_MDT_LOOKUP
 static int		udplite_port_rover;
 
 int udplite_get_port(struct sock *sk, unsigned short p,
@@ -28,7 +29,12 @@ static int udplite_v4_get_port(struct sock *sk, unsigned short snum)
 {
 	return udplite_get_port(sk, snum, ipv4_rcv_saddr_equal);
 }
-
+#else
+static int udplite_v4_get_port(struct sock *sk, unsigned short snum)
+{
+	return  mdt_insert_sock_port(sk, snum);
+}
+#endif
 static int udplite_rcv(struct sk_buff *skb)
 {
 	return __udp4_lib_rcv(skb, udplite_hash, 1);
@@ -80,6 +86,7 @@ static struct inet_protosw udplite4_protosw = {
 	.flags		=  INET_PROTOSW_PERMANENT,
 };
 
+#ifndef CONFIG_MDT_LOOKUP
 #ifdef CONFIG_PROC_FS
 static struct file_operations udplite4_seq_fops;
 static struct udp_seq_afinfo udplite4_seq_afinfo = {
@@ -91,6 +98,7 @@ static struct udp_seq_afinfo udplite4_seq_afinfo = {
 	.seq_fops	= &udplite4_seq_fops,
 };
 #endif
+#endif
 
 void __init udplite4_register(void)
 {
@@ -102,10 +110,12 @@ void __init udplite4_register(void)
 
 	inet_register_protosw(&udplite4_protosw);
 
+#ifndef CONFIG_MDT_LOOKUP
 #ifdef CONFIG_PROC_FS
 	if (udp_proc_register(&udplite4_seq_afinfo)) /* udplite4_proc_init() */
 		printk(KERN_ERR "%s: Cannot register /proc!\n", __FUNCTION__);
 #endif
+#endif
 	return;
 
 out_unregister_proto:
@@ -116,4 +126,6 @@ out_register_err:
 
 EXPORT_SYMBOL(udplite_hash);
 EXPORT_SYMBOL(udplite_prot);
+#ifndef CONFIG_MDT_LOOKUP
 EXPORT_SYMBOL(udplite_get_port);
+#endif
net/netlink/af_netlink.c +129 -101

358 lines not on this page · raw message

net/packet/af_packet.c +9 -4
index 28d47e8..65dc869 100644
@@ -1465,7 +1465,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
 	return 0;
 }
 
-
+#ifndef CONFIG_MDT_LOOKUP
 static int packet_notifier(struct notifier_block *this, unsigned long msg, void *data)
 {
 	struct sock *sk;
@@ -1516,7 +1516,7 @@ static int packet_notifier(struct notifier_block *this, unsigned long msg, void
 	read_unlock(&packet_sklist_lock);
 	return NOTIFY_DONE;
 }
-
+#endif
 
 static int packet_ioctl(struct socket *sock, unsigned int cmd,
 			unsigned long arg)
@@ -1875,7 +1875,7 @@ static struct net_proto_family packet_family_ops = {
 	.create =	packet_create,
 	.owner	=	THIS_MODULE,
 };
-
+#ifndef CONFIG_MDT_LOOKUP
 static struct notifier_block packet_netdev_notifier = {
 	.notifier_call =packet_notifier,
 };
@@ -1957,13 +1957,16 @@ static const struct file_operations packet_seq_fops = {
 };
 
 #endif
+#endif
 
 static void __exit packet_exit(void)
 {
 	proc_net_remove("packet");
+#ifndef CONFIG_MDT_LOOKUP
 	unregister_netdevice_notifier(&packet_netdev_notifier);
-	sock_unregister(PF_PACKET);
 	proto_unregister(&packet_proto);
+#endif
+	sock_unregister(PF_PACKET);
 }
 
 static int __init packet_init(void)
@@ -1974,8 +1977,10 @@ static int __init packet_init(void)
 		goto out;
 
 	sock_register(&packet_family_ops);
+#ifndef CONFIG_MDT_LOOKUP
 	register_netdevice_notifier(&packet_netdev_notifier);
 	proc_net_fops_create("packet", 0, &packet_seq_fops);
+#endif
 out:
 	return rc;
 }
net/unix/af_unix.c +50 -1

110 lines not on this page · raw message

net/unix/garbage.c +8 -2
index f20b7ea..4546882 100644
@@ -170,8 +170,10 @@ static void maybe_unmark_and_push(struct sock *x)
 void unix_gc(void)
 {
 	static DEFINE_MUTEX(unix_gc_sem);
+#ifndef CONFIG_MDT_LOOKUP
 	int i;
 	struct sock *s;
+#endif
 	struct sk_buff_head hitlist;
 	struct sk_buff *skb;
 
@@ -183,11 +185,12 @@ void unix_gc(void)
 		return;
 
 	spin_lock(&unix_table_lock);
-
+#ifndef CONFIG_MDT_LOOKUP
 	forall_unix_sockets(i, s)
 	{
 		unix_sk(s)->gc_tree = GC_ORPHAN;
 	}
+#endif
 	/*
 	 *	Everything is now marked
 	 */
@@ -205,6 +208,7 @@ void unix_gc(void)
 	 *	Push root set
 	 */
 
+#ifndef CONFIG_MDT_LOOKUP
 	forall_unix_sockets(i, s)
 	{
 		int open_count = 0;
@@ -224,7 +228,7 @@ void unix_gc(void)
 		if (open_count > atomic_read(&unix_sk(s)->inflight))
 			maybe_unmark_and_push(s);
 	}
-
+#endif
 	/*
 	 *	Mark phase
 	 */
@@ -275,6 +279,7 @@ void unix_gc(void)
 
 	skb_queue_head_init(&hitlist);
 
+#ifndef CONFIG_MDT_LOOKUP
 	forall_unix_sockets(i, s)
 	{
 		struct unix_sock *u = unix_sk(s);
@@ -301,6 +306,7 @@ void unix_gc(void)
 		}
 		u->gc_tree = GC_ORPHAN;
 	}
+#endif
 	spin_unlock(&unix_table_lock);
 
 	/*
Signature · 1 line
	Evgeniy Polyakov
#1 lore raw
Quoted 7 lines
include/linux/netlink.h +0 -0
index 2a20f48..f11b4e7 100644

include/linux/netlink.h struct netlink_skb_parms · line 156

Quoted 7 lines
include/linux/netlink.h +0 -1
@@ -151,7 +151,6 @@ struct netlink_skb_parms
 #define NETLINK_CB(skb)		(*(struct netlink_skb_parms*)&((skb)->cb))
 #define NETLINK_CREDS(skb)	(&NETLINK_CB((skb)).creds)
 
-
 extern struct sock *netlink_kernel_create(int unit, unsigned int groups, void (*input)(struct sock *sk, int len), struct module *module);
 extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
 extern int netlink_has_listeners(struct sock *sk, unsigned int group);

Minor nit this a one line blank only diff, probably just editing crap.

Quoted 6 lines

static inline void udp_lib_close(struct sock *sk, long timeout)

net/core/sock.c +0 -0
index 8d65d64..abe1632 100644

net/core/sock.c struct sock *sk_clone(const struct sock *sk, const gfp_t priority) · line 908

Quoted 8 lines
net/core/sock.c +2 -0
@@ -901,7 +901,9 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
 		sock_copy(newsk, sk);
 
 		/* SANITY */
+#ifndef CONFIG_MDT_LOOKUP
 		sk_node_init(&newsk->sk_node);
+#endif
 		sock_lock_init(newsk);
 		bh_lock_sock(newsk);

I would rather not see ifdef's in code. Could you just stub out the function in the include file?

Quoted 6 lines
net/ipv4/Kconfig +0 -0
index 9e8ef50..5bfb0dc 100644

net/ipv4/Kconfig line 10

Quoted 10 lines
net/ipv4/Kconfig +7 -0
@@ -1,6 +1,14 @@
 #
 # IP configuration
 #
+
+config MDT_LOOKUP
+	bool "Multidimensional trie socket lookup"
+	depends on !INET_TCP_DIAG
+	help
+	  This option replaces traditional hash table lookup for TCP sockets
+	  with multidimensional trie algorithm (similar to judy trie).

So you had to break the TCP_DIAG output to make this work. Please fix, the ss command is useful.

Quoted 13 lines
net/ipv4/af_inet.c +1 -0
index cf358c8..8c32545 100644
@@ -1360,6 +1360,7 @@ fs_initcall(inet_init);
 /* ------------------------------------------------------------------------ */
 
 #ifdef CONFIG_PROC_FS
+#ifndef CONFIG_MDT_LOOKUP
 static int __init ipv4_proc_init(void)
 {
 	int rc = 0;

net/ipv4/af_inet.c out_raw: · line 1397

Quoted 10 lines
net/ipv4/af_inet.c +6 -1
@@ -1388,7 +1389,12 @@ out_raw:
 	rc = -ENOMEM;
 	goto out;
 }
-
+#else
+static int __init ipv4_proc_init(void)
+{
+	return 0;
+}
+#endif

If you are making it into a stub, why not get rid of it completely?

net/ipv4/af_inet.c out_raw:

Quoted 4 lines
net/ipv4/af_inet.c +4 -0
+
+#define MDT_SET_LEAF_STORAGE(leaf, ptr) do { \
+	rcu_assign_pointer((leaf), (struct mdt_node *)(((unsigned long)(ptr)) | MDT_LEAF_STRUCT_BIT)); \
+} while (0)

Macro yuckinesss.

<rest deleted>

What is the code size change with this?

Signature · 1 line
Stephen Hemminger <[email protected]>
#2 lore raw
Quoted 10 lines · Stephen Hemminger
Quoted 10 lines
include/linux/netlink.h +0 -0
index 2a20f48..f11b4e7 100644
@@ -151,7 +151,6 @@ struct netlink_skb_parms
 #define NETLINK_CB(skb)		(*(struct netlink_skb_parms*)&((skb)->cb))
 #define NETLINK_CREDS(skb)	(&NETLINK_CB((skb)).creds)
 
Quoted 6 lines

include/linux/netlink.h struct netlink_skb_parms · line 156

Quoted 4 lines
include/linux/netlink.h +0 -1
-
 extern struct sock *netlink_kernel_create(int unit, unsigned int groups, void (*input)(struct sock *sk, int len), struct module *module);
 extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
 extern int netlink_has_listeners(struct sock *sk, unsigned int group);

Minor nit this a one line blank only diff, probably just editing crap.

I tried to put there netlink socket definition, but it does not compile without major surgery, so I removed it back and dropped one line. Committed via 'git commit -a -m', so it was too late to change.

Quoted 8 lines
Quoted 8 lines

static inline void udp_lib_close(struct sock *sk, long timeout)

net/core/sock.c +0 -0
index 8d65d64..abe1632 100644
@@ -901,7 +901,9 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
 		sock_copy(newsk, sk);
 
Quoted 9 lines

net/core/sock.c struct sock *sk_clone(const struct sock *sk, const gfp_t priority) · line 908

Quoted 6 lines
net/core/sock.c +2 -0
 		/* SANITY */
+#ifndef CONFIG_MDT_LOOKUP
 		sk_node_init(&newsk->sk_node);
+#endif
 		sock_lock_init(newsk);
 		bh_lock_sock(newsk);

I would rather not see ifdef's in code. Could you just stub out the function in the include file?

I would prefer to get rid of hash tables at all - code is full of such ifdefs. But in short run it can be replaced - I even started it with TCP's inet_lookup and friends.

Quoted 11 lines
Quoted 11 lines
net/ipv4/Kconfig +2 -0
index 9e8ef50..5bfb0dc 100644
@@ -1,6 +1,14 @@
 #
 # IP configuration
 #
+
+config MDT_LOOKUP
Quoted 8 lines

net/ipv4/Kconfig line 10

Quoted 5 lines
net/ipv4/Kconfig +5 -0
+	bool "Multidimensional trie socket lookup"
+	depends on !INET_TCP_DIAG
+	help
+	  This option replaces traditional hash table lookup for TCP sockets
+	  with multidimensional trie algorithm (similar to judy trie).

So you had to break the TCP_DIAG output to make this work. Please fix, the ss command is useful.

Yes, current code does not support statistics.
Existing stats run over whole hash table, I do not like such approach, so I will introduce a per-protocol lists of all sockets, which can be accessed from statistics code, but it is next step.

Quoted 18 lines
Quoted 18 lines
net/ipv4/af_inet.c +2 -1
index cf358c8..8c32545 100644
@@ -1360,6 +1360,7 @@ fs_initcall(inet_init);
 /* ------------------------------------------------------------------------ */
 
 #ifdef CONFIG_PROC_FS
+#ifndef CONFIG_MDT_LOOKUP
 static int __init ipv4_proc_init(void)
 {
 	int rc = 0;
@@ -1388,7 +1389,12 @@ out_raw:
 	rc = -ENOMEM;
 	goto out;
 }
-
+#else
Quoted 8 lines

net/ipv4/af_inet.c out_raw: · line 1397

Quoted 5 lines
net/ipv4/af_inet.c +5 -0
+static int __init ipv4_proc_init(void)
+{
+	return 0;
+}
+#endif

If you are making it into a stub, why not get rid of it completely?

I did it for some parts, but created a stub for another. Proc insterface as long as netlink statistics is not supported, since I do not want to run over whole tree to search sockets, so I just removed it.

Quoted 6 lines

net/ipv4/af_inet.c out_raw:

Quoted 4 lines
net/ipv4/af_inet.c +4 -0
+
+#define MDT_SET_LEAF_STORAGE(leaf, ptr) do { \
+	rcu_assign_pointer((leaf), (struct mdt_node *)(((unsigned long)(ptr)) | MDT_LEAF_STRUCT_BIT)); \
+} while (0)

Macro yuckinesss.

You did not see what Rusty created...
:)

Quoted 3 lines

<rest deleted>

What is the code size change with this?

 include/linux/netlink.h            |    1 -
 include/net/af_unix.h              |    4 +-
 include/net/inet_connection_sock.h |    5 +-
 include/net/inet_hashtables.h      |    5 -
 include/net/inet_timewait_sock.h   |   12 +
 include/net/lookup.h               |  120 +++++++
 include/net/netlink.h              |   29 ++
 include/net/raw.h                  |    1 +
 include/net/sock.h                 |  106 ++++---
 include/net/tcp.h                  |    7 +-
 include/net/udp.h                  |    5 +
 net/core/sock.c                    |    2 +
 net/ipv4/Kconfig                   |    8 +
 net/ipv4/Makefile                  |    7 +-
 net/ipv4/af_inet.c                 |    8 +-
 net/ipv4/icmp.c                    |   10 +
 net/ipv4/inet_connection_sock.c    |    6 +-
 net/ipv4/inet_diag.c               |   11 +-
 net/ipv4/inet_timewait_sock.c      |   35 ++-
 net/ipv4/ip_input.c                |   10 +-
 net/ipv4/mdt.c                     |  598 ++++++++++++++++++++++++++++++++++++
 net/ipv4/raw.c                     |   47 +++-
 net/ipv4/tcp.c                     |   18 +-
 net/ipv4/tcp_ipv4.c                |   66 ++++-
 net/ipv4/tcp_minisocks.c           |    6 +
 net/ipv4/udp.c                     |  133 +++++---
 net/ipv4/udplite.c                 |   14 +-
 net/netlink/af_netlink.c           |  230 ++++++++------
 net/packet/af_packet.c             |   13 +-
 net/unix/af_unix.c                 |   51 +++-
 net/unix/garbage.c                 |   10 +-
 31 files changed, 1333 insertions(+), 245 deletions(-)

Nothing was deleted actually, but wrapped into ifdef/endif stuff all over the place and moved from one file to another - tree should even compile if config option is not set.

Thanks for quick review...

Quoted 2 lines
Signature · 1 line
Stephen Hemminger <[email protected]>
Signature · 1 line
	Evgeniy Polyakov
maintainer
#3 lore raw

From: Evgeniy Polyakov <[email protected]>
Date: Thu, 22 Mar 2007 21:59:44 +0300

Quoted 4 lines

Yes, current code does not support statistics.
Existing stats run over whole hash table, I do not like such approach, so I will introduce a per-protocol lists of all sockets, which can be accessed from statistics code, but it is next step.

We are _NOT_ bloating up the socket structure even more because your data structure does not support a "iterate over all objects" operation.

We got rid of the linked list of all sockets per-protocol precisely for this reason 10 years ago, you cannot add it back, sorry.

#4 lore raw
Quoted 8 lines · David Miller

From: Evgeniy Polyakov <[email protected]>
Date: Thu, 22 Mar 2007 21:59:44 +0300

Quoted 4 lines

Yes, current code does not support statistics.
Existing stats run over whole hash table, I do not like such approach, so I will introduce a per-protocol lists of all sockets, which can be accessed from statistics code, but it is next step.

Quoted 6 lines

We are _NOT_ bloating up the socket structure even more because your data structure does not support a "iterate over all objects" operation.

We got rid of the linked list of all sockets per-protocol precisely for this reason 10 years ago, you cannot add it back, sorry.

Hmm...
My patch _removes_ them from socket structures!

include/net/sock.h +3 -1
@@ -114,10 +114,12 @@ struct sock_common {
 	volatile unsigned char	skc_state;
 	unsigned char		skc_reuse;
 	int			skc_bound_dev_if;
-	struct hlist_node	skc_node;
 	struct hlist_node	skc_bind_node;
 	atomic_t		skc_refcnt;
+#ifndef CONFIG_MDT_LOOKUP
+	struct hlist_node	skc_node;
 	unsigned int		skc_hash;
+#endif
 	struct proto		*skc_prot;
 };
 

I specially have only one hash structure in the socket - skc_bind_node - to be used for statistics and remove hash and skc_node (and for netlink broadcasting too), so this code reduces socket structure by 12 bytes on x86 (20 bytes on x86_64).

Signature · 1 line
	Evgeniy Polyakov
maintainer
#5 lore raw

From: Evgeniy Polyakov <[email protected]>
Date: Thu, 22 Mar 2007 22:09:40 +0300

Quoted 4 lines

I specially have only one hash structure in the socket - skc_bind_node - to be used for statistics and remove hash and skc_node (and for netlink broadcasting too), so this code reduces socket structure by 12 bytes on x86 (20 bytes on x86_64).

Yes, for your trie you've removed quite a bit, but now you're going to add 2 pointers right back right?

#7 lore raw
In reply to David Miller
Quoted 11 lines · David Miller

From: Evgeniy Polyakov <[email protected]>
Date: Thu, 22 Mar 2007 21:59:44 +0300

Quoted 4 lines

Yes, current code does not support statistics.
Existing stats run over whole hash table, I do not like such approach, so I will introduce a per-protocol lists of all sockets, which can be accessed from statistics code, but it is next step.

We are _NOT_ bloating up the socket structure even more because your data structure does not support a "iterate over all objects" operation.

And to be absolutely clear - existing interface does not support it too
- we iterate over every single hash entry, and then over every single item in the chain (if it exists). I can create the same for the tree - it is not complex at all, but it is not the most optimal solution, and since I remove several entries, I think it is not that bad to remove a bit less and optimize 'iterate over all object' case a bit.

Signature · 1 line
	Evgeniy Polyakov
#6 lore raw
In reply to David Miller
Quoted 10 lines · David Miller

From: Evgeniy Polyakov <[email protected]>
Date: Thu, 22 Mar 2007 22:09:40 +0300

Quoted 4 lines

I specially have only one hash structure in the socket - skc_bind_node - to be used for statistics and remove hash and skc_node (and for netlink broadcasting too), so this code reduces socket structure by 12 bytes on x86 (20 bytes on x86_64).

Yes, for your trie you've removed quite a bit, but now you're going to add 2 pointers right back right?

No, I will use the same hlist_node pointer (skc_bind_node) which was there, and skc_node and skc_node are removed.

After all - we can traverse over the whole tree one-by one, it is even possible to attach a bitmask to each level node (since it is an array) of used/free entries and use it.

Signature · 1 line
	Evgeniy Polyakov
maintainer
#8 lore raw
In reply to Evgeniy Polyakov

From: Evgeniy Polyakov <[email protected]>
Date: Thu, 22 Mar 2007 22:14:49 +0300

Quoted 6 lines

And to be absolutely clear - existing interface does not support it too
- we iterate over every single hash entry, and then over every single item in the chain (if it exists). I can create the same for the tree - it is not complex at all, but it is not the most optimal solution, and since I remove several entries, I think it is not that bad to remove a bit less and optimize 'iterate over all object' case a bit.

This results in your trie having two new run-time costs:

1) More expensive trie insert/delete compared to hash insert/delete

2) An extra list insert/delete to give list of all sockets

So connection setup/teardown will be more expensive and therefore our connection rates will be lower.

Evgeniy, your ideas are beautiful in theory, but all the details kill all of your non-trivial work and make it useless in the end.

#9 lore raw
Quoted 10 lines · David Miller

From: Evgeniy Polyakov <[email protected]>
Date: Thu, 22 Mar 2007 22:14:49 +0300

Quoted 6 lines

And to be absolutely clear - existing interface does not support it too
- we iterate over every single hash entry, and then over every single item in the chain (if it exists). I can create the same for the tree - it is not complex at all, but it is not the most optimal solution, and since I remove several entries, I think it is not that bad to remove a bit less and optimize 'iterate over all object' case a bit.

Quoted 4 lines

This results in your trie having two new run-time costs:

1) More expensive trie insert/delete compared to hash insert/delete

That's true, it requires additional allocation, which can be combined with socket allocation though.

Quoted 1 line

2) An extra list insert/delete to give list of all sockets

That is too small price.
And as I stated in another mail - we can iterate over whole tree just like we do with hash tables - even faster, if I will attach a bitmask of used entires to each level node.

Quoted 2 lines

So connection setup/teardown will be more expensive and therefore our connection rates will be lower.

Hmm, I'm not sure - we already allocate several items during connection setup/teardown time (request socket, usual socket, timewait socket), so additional one is not absolutely sure will end up with slower times.

And do not forget about other benefits dynamic structure gives us compared to static hash table in DoS and traversal speed/locking.

Quoted 2 lines

Evgeniy, your ideas are beautiful in theory, but all the details kill all of your non-trivial work and make it useless in the end.

I especially agree with first part of the sentence :)) So far I can not see serious disadvantages in this design.

Signature · 1 line
	Evgeniy Polyakov
maintainer
#10 lore raw

From: Evgeniy Polyakov <[email protected]>
Date: Thu, 22 Mar 2007 22:30:52 +0300

Quoted 3 lines
Quoted 1 line

2) An extra list insert/delete to give list of all sockets

That is too small price.

In your imagination. Our connection rates went up significantly when I got rid of the linked list we had many years ago.

Every memory access matters.

#11 lore raw
Quoted 8 lines · David Miller
Quoted 3 lines
Quoted 1 line

2) An extra list insert/delete to give list of all sockets

That is too small price.

In your imagination. Our connection rates went up significantly when I got rid of the linked list we had many years ago.

Every memory access matters.

Ok, I never liked linked lists actually. :)

This one can be completely eliminated (hmm, it does not even exist so far) by having per-node bitmask of used/free entries - it will be even faster than existing access and will not require locks (due to RCU protection).

So, this allows to remove additional hlist_node structure from socket (and change netlink one to not use it in broadcasting, so for netlink sockets it will be moved into private netlink structure).

Signature · 1 line
	Evgeniy Polyakov
#12 lore raw
In reply to David Miller
Quoted 2 lines · David Miller

2) An extra list insert/delete to give list of all sockets

That is currently limited by readlock on the hash buckets. I suspect any change to a trie with less atomic operations will make it faster.

-Andi

#13 lore raw
Quoted 4 lines · Andi Kleen
Quoted 1 line

2) An extra list insert/delete to give list of all sockets

That is currently limited by readlock on the hash buckets. I suspect any change to a trie with less atomic operations will make it faster.

The best case for trie is to attach a bitmask of used/free slots per each trie node since it is based on arrays, so that list is not needed at all. I thought about additional list of all sockets just because I decided to not drop one of the hlist_node from sock_common, so it could be reused for other purposes.
That hlist node is used for netlink broadcasting, but netlink case can be solved by moving sk_bind_node into private area and drop additional 8/16 bytes from socket structure.

Trie nodes are protected through RCU, so it is possible to count not-yet-freed socket as long as miss just-added ones.
I do not think this information can contain anyhow correct information, since we have essentially the same problem with hash bucket locks - until bucket is locked, we can not count for just-to-be-added sockets and count those ones which will be dropped just after lock is released in case removing function spins/waits for that bucket.

Quoted 1 line

-Andi

Signature · 1 line
	Evgeniy Polyakov