[PATCH 2/6][INET]: Consolidate inet(6)_hash_connect.

2008-01-31 Thread Pavel Emelyanov
These two functions are the same except for what they call
to check_established and hash for a socket.

This saves half-a-kilo for ipv4 and ipv6.

 add/remove: 1/0 grow/shrink: 1/4 up/down: 582/-1128 (-546)
 function old new   delta
 __inet_hash_connect- 577+577
 arp_ignore   108 113  +5
 static.hint8   4  -4
 rt_worker_func   376 372  -4
 inet6_hash_connect   584  25-559
 inet_hash_connect586  25-561

Signed-off-by: Pavel Emelyanov [EMAIL PROTECTED]

---
 include/net/inet_hashtables.h |5 ++
 net/ipv4/inet_hashtables.c|   32 +-
 net/ipv6/inet6_hashtables.c   |   93 +
 3 files changed, 28 insertions(+), 102 deletions(-)

diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index 761bdc0..a34a8f2 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -413,6 +413,11 @@ static inline struct sock *inet_lookup(struct 
inet_hashinfo *hashinfo,
return sk;
 }
 
+extern int __inet_hash_connect(struct inet_timewait_death_row *death_row,
+   struct sock *sk,
+   int (*check_established)(struct inet_timewait_death_row *,
+   struct sock *, __u16, struct inet_timewait_sock **),
+   void (*hash)(struct inet_hashinfo *, struct sock *));
 extern int inet_hash_connect(struct inet_timewait_death_row *death_row,
 struct sock *sk);
 #endif /* _INET_HASHTABLES_H */
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 619c63c..b93d40f 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -348,11 +348,11 @@ void __inet_hash(struct inet_hashinfo *hashinfo, struct 
sock *sk)
 }
 EXPORT_SYMBOL_GPL(__inet_hash);
 
-/*
- * Bind a port for a connect operation and hash it.
- */
-int inet_hash_connect(struct inet_timewait_death_row *death_row,
- struct sock *sk)
+int __inet_hash_connect(struct inet_timewait_death_row *death_row,
+   struct sock *sk,
+   int (*check_established)(struct inet_timewait_death_row *,
+   struct sock *, __u16, struct inet_timewait_sock **),
+   void (*hash)(struct inet_hashinfo *, struct sock *))
 {
struct inet_hashinfo *hinfo = death_row-hashinfo;
const unsigned short snum = inet_sk(sk)-num;
@@ -385,9 +385,8 @@ int inet_hash_connect(struct inet_timewait_death_row 
*death_row,
BUG_TRAP(!hlist_empty(tb-owners));
if (tb-fastreuse = 0)
goto next_port;
-   if (!__inet_check_established(death_row,
- sk, port,
- tw))
+   if (!check_established(death_row, sk,
+   port, tw))
goto ok;
goto next_port;
}
@@ -415,7 +414,7 @@ ok:
inet_bind_hash(sk, tb, port);
if (sk_unhashed(sk)) {
inet_sk(sk)-sport = htons(port);
-   __inet_hash_nolisten(hinfo, sk);
+   hash(hinfo, sk);
}
spin_unlock(head-lock);
 
@@ -432,17 +431,28 @@ ok:
tb  = inet_csk(sk)-icsk_bind_hash;
spin_lock_bh(head-lock);
if (sk_head(tb-owners) == sk  !sk-sk_bind_node.next) {
-   __inet_hash_nolisten(hinfo, sk);
+   hash(hinfo, sk);
spin_unlock_bh(head-lock);
return 0;
} else {
spin_unlock(head-lock);
/* No definite answer... Walk to established hash table */
-   ret = __inet_check_established(death_row, sk, snum, NULL);
+   ret = check_established(death_row, sk, snum, NULL);
 out:
local_bh_enable();
return ret;
}
 }
+EXPORT_SYMBOL_GPL(__inet_hash_connect);
+
+/*
+ * Bind a port for a connect operation and hash it.
+ */
+int inet_hash_connect(struct inet_timewait_death_row *death_row,
+ struct sock *sk)
+{
+   return __inet_hash_connect(death_row, sk,
+   __inet_check_established, __inet_hash_nolisten);
+}
 
 EXPORT_SYMBOL_GPL(inet_hash_connect);
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index 06b01be..ece6d0e 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ 

Re: [PATCH 2/6][INET]: Consolidate inet(6)_hash_connect.

2008-01-31 Thread Arnaldo Carvalho de Melo
Em Thu, Jan 31, 2008 at 03:32:09PM +0300, Pavel Emelyanov escreveu:
 These two functions are the same except for what they call
 to check_established and hash for a socket.
 
 This saves half-a-kilo for ipv4 and ipv6.

Good stuff!

Yesterday I was perusing tcp_hash and I think we could have the hashinfo
pointer stored perhaps in sk-sk_prot.

That way we would be able to kill tcp_hash(), inet_put_port() could
receive just sk, etc.

What do you think?

- Arnaldo
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/6][INET]: Consolidate inet(6)_hash_connect.

2008-01-31 Thread David Miller
From: Pavel Emelyanov [EMAIL PROTECTED]
Date: Thu, 31 Jan 2008 15:32:09 +0300

 These two functions are the same except for what they call
 to check_established and hash for a socket.
 
 This saves half-a-kilo for ipv4 and ipv6.
 
  add/remove: 1/0 grow/shrink: 1/4 up/down: 582/-1128 (-546)
  function old new   delta
  __inet_hash_connect- 577+577
  arp_ignore   108 113  +5
  static.hint8   4  -4
  rt_worker_func   376 372  -4
  inet6_hash_connect   584  25-559
  inet_hash_connect586  25-561
 
 Signed-off-by: Pavel Emelyanov [EMAIL PROTECTED]

Applied.
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/6][INET]: Consolidate inet(6)_hash_connect.

2008-01-31 Thread David Miller
From: Arnaldo Carvalho de Melo [EMAIL PROTECTED]
Date: Thu, 31 Jan 2008 11:01:53 -0200

 Em Thu, Jan 31, 2008 at 03:32:09PM +0300, Pavel Emelyanov escreveu:
  These two functions are the same except for what they call
  to check_established and hash for a socket.
  
  This saves half-a-kilo for ipv4 and ipv6.
 
 Good stuff!
 
 Yesterday I was perusing tcp_hash and I think we could have the hashinfo
 pointer stored perhaps in sk-sk_prot.
 
 That way we would be able to kill tcp_hash(), inet_put_port() could
 receive just sk, etc.
 
 What do you think?

Sounds good to me.
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/6][INET]: Consolidate inet(6)_hash_connect.

2008-01-31 Thread Pavel Emelyanov
Arnaldo Carvalho de Melo wrote:
 Em Thu, Jan 31, 2008 at 03:32:09PM +0300, Pavel Emelyanov escreveu:
 These two functions are the same except for what they call
 to check_established and hash for a socket.

 This saves half-a-kilo for ipv4 and ipv6.
 
 Good stuff!
 
 Yesterday I was perusing tcp_hash and I think we could have the hashinfo
 pointer stored perhaps in sk-sk_prot.
 
 That way we would be able to kill tcp_hash(), inet_put_port() could
 receive just sk, etc.

But each proto will still have its own hashfn, so proto's 
callbacks will be called to hash/unhash sockets, so this will 
give us just one extra dereference. No?

 What do you think?

Hmmm... Even raw_hash, etc may become simpler. On the other hand
maybe this is a good idea, but I'm not very common with this code
yet to foresee such things in advance... I think that we should
try to prepare a patch and look, but if you have smth ready, then
it's better to review your stuff first.

 - Arnaldo
 

Thanks,
Pavel
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/6][INET]: Consolidate inet(6)_hash_connect.

2008-01-31 Thread Arnaldo Carvalho de Melo
Em Thu, Jan 31, 2008 at 04:18:51PM +0300, Pavel Emelyanov escreveu:
 Arnaldo Carvalho de Melo wrote:
  Em Thu, Jan 31, 2008 at 03:32:09PM +0300, Pavel Emelyanov escreveu:
  These two functions are the same except for what they call
  to check_established and hash for a socket.
 
  This saves half-a-kilo for ipv4 and ipv6.
  
  Good stuff!
  
  Yesterday I was perusing tcp_hash and I think we could have the hashinfo
  pointer stored perhaps in sk-sk_prot.
  
  That way we would be able to kill tcp_hash(), inet_put_port() could
  receive just sk, etc.
 
 But each proto will still have its own hashfn, so proto's 
 callbacks will be called to hash/unhash sockets, so this will 
 give us just one extra dereference. No?
 
  What do you think?
 
 Hmmm... Even raw_hash, etc may become simpler. On the other hand
 maybe this is a good idea, but I'm not very common with this code
 yet to foresee such things in advance... I think that we should
 try to prepare a patch and look, but if you have smth ready, then
 it's better to review your stuff first.

gimme some minutes

- Arnaldo
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/6][INET]: Consolidate inet(6)_hash_connect.

2008-01-31 Thread Arnaldo Carvalho de Melo
Em Thu, Jan 31, 2008 at 11:39:55AM -0200, Arnaldo Carvalho de Melo escreveu:
 Em Thu, Jan 31, 2008 at 04:18:51PM +0300, Pavel Emelyanov escreveu:
  Arnaldo Carvalho de Melo wrote:
   Em Thu, Jan 31, 2008 at 03:32:09PM +0300, Pavel Emelyanov escreveu:
   These two functions are the same except for what they call
   to check_established and hash for a socket.
  
   This saves half-a-kilo for ipv4 and ipv6.
   
   Good stuff!
   
   Yesterday I was perusing tcp_hash and I think we could have the hashinfo
   pointer stored perhaps in sk-sk_prot.
   
   That way we would be able to kill tcp_hash(), inet_put_port() could
   receive just sk, etc.
  
  But each proto will still have its own hashfn, so proto's 
  callbacks will be called to hash/unhash sockets, so this will 
  give us just one extra dereference. No?
  
   What do you think?
  
  Hmmm... Even raw_hash, etc may become simpler. On the other hand
  maybe this is a good idea, but I'm not very common with this code
  yet to foresee such things in advance... I think that we should
  try to prepare a patch and look, but if you have smth ready, then
  it's better to review your stuff first.
 
 gimme some minutes

A bit more than minutes tho, but here it is, I'm testing it now.

Take a look and if testing is ok I'll submit it with a proper
description.

- Arnaldo

diff --git a/include/net/inet6_hashtables.h b/include/net/inet6_hashtables.h
index fdff630..62a5b69 100644
--- a/include/net/inet6_hashtables.h
+++ b/include/net/inet6_hashtables.h
@@ -49,7 +49,7 @@ static inline int inet6_sk_ehashfn(const struct sock *sk)
return inet6_ehashfn(laddr, lport, faddr, fport);
 }
 
-extern void __inet6_hash(struct inet_hashinfo *hashinfo, struct sock *sk);
+extern void __inet6_hash(struct sock *sk);
 
 /*
  * Sockets in TCP_CLOSE state are _always_ taken out of the hash, so
diff --git a/include/net/inet_connection_sock.h 
b/include/net/inet_connection_sock.h
index 133cf30..f00f057 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -29,7 +29,6 @@
 #undef INET_CSK_CLEAR_TIMERS
 
 struct inet_bind_bucket;
-struct inet_hashinfo;
 struct tcp_congestion_ops;
 
 /*
@@ -59,6 +58,8 @@ struct inet_connection_sock_af_ops {
int level, int optname,
char __user *optval, int __user *optlen);
void(*addr2sockaddr)(struct sock *sk, struct sockaddr *);
+   int (*bind_conflict)(const struct sock *sk,
+const struct inet_bind_bucket *tb);
 };
 
 /** inet_connection_sock - INET connection oriented sock
@@ -244,10 +245,7 @@ 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);
-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));
+extern int inet_csk_get_port(struct sock *sk, unsigned short snum);
 
 extern struct dst_entry* inet_csk_route_req(struct sock *sk,
const struct request_sock *req);
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index c23c4ed..48ac620 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -221,9 +221,9 @@ static inline int inet_sk_listen_hashfn(const struct sock 
*sk)
 }
 
 /* Caller must disable local BH processing. */
-static inline void __inet_inherit_port(struct inet_hashinfo *table,
-  struct sock *sk, struct sock *child)
+static inline void __inet_inherit_port(struct sock *sk, struct sock *child)
 {
+   struct inet_hashinfo *table = sk-sk_prot-hashinfo;
const int bhash = inet_bhashfn(inet_sk(child)-num, table-bhash_size);
struct inet_bind_hashbucket *head = table-bhash[bhash];
struct inet_bind_bucket *tb;
@@ -235,15 +235,14 @@ static inline void __inet_inherit_port(struct 
inet_hashinfo *table,
spin_unlock(head-lock);
 }
 
-static inline void inet_inherit_port(struct inet_hashinfo *table,
-struct sock *sk, struct sock *child)
+static inline void inet_inherit_port(struct sock *sk, struct sock *child)
 {
local_bh_disable();
-   __inet_inherit_port(table, sk, child);
+   __inet_inherit_port(sk, child);
local_bh_enable();
 }
 
-extern void inet_put_port(struct inet_hashinfo *table, struct sock *sk);
+extern void inet_put_port(struct sock *sk);
 
 extern void inet_listen_wlock(struct inet_hashinfo *hashinfo);
 
@@ -266,41 +265,9 @@ static inline void inet_listen_unlock(struct inet_hashinfo 
*hashinfo)