Skip to contentSkip to conversation

netfilter conntrack optimization (LIST_DELETE)

PATCH Applied Harald Welte 2 participants 2 messages Aug 24, 2003

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

PATCH 1/1 netfilter conntrack optimization (LIST_DELETE)

Hi Dave!

The following patch against 2.6.0-test4 (courtesy of Patrick McHardy) optimizes the conntrack code. In the old implementation, the hash function was passed to the LIST_DELETE macro, which resulted in it being called two times instead of one.

This patch also applies to 2.4.x - but I think we should wait for 2.4.23-preX to come up first. Do you want me to re-submit it for 2.4.23-preX, once it shows up?

Please apply, thanks!

===== net/ipv4/netfilter/ip_conntrack_core.c 1.25 vs edited =====

net/ipv4/netfilter/ip_conntrack_core.c +9 -7
@@ -291,14 +291,15 @@
 static void
 clean_from_lists(struct ip_conntrack *ct)
 {
+	unsigned int ho, hr;
+	
 	DEBUGP("clean_from_lists(%p)\n", ct);
 	MUST_BE_WRITE_LOCKED(&ip_conntrack_lock);
-	LIST_DELETE(&ip_conntrack_hash
-		    [hash_conntrack(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple)],
-		    &ct->tuplehash[IP_CT_DIR_ORIGINAL]);
-	LIST_DELETE(&ip_conntrack_hash
-		    [hash_conntrack(&ct->tuplehash[IP_CT_DIR_REPLY].tuple)],
-		    &ct->tuplehash[IP_CT_DIR_REPLY]);
+
+	ho = hash_conntrack(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
+	hr = hash_conntrack(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
+	LIST_DELETE(&ip_conntrack_hash[ho], &ct->tuplehash[IP_CT_DIR_ORIGINAL]);
+	LIST_DELETE(&ip_conntrack_hash[hr], &ct->tuplehash[IP_CT_DIR_REPLY]);
 
 	/* Destroy all un-established, pending expectations */
 	remove_expectations(ct, 1);
@@ -370,9 +371,10 @@
 		    const struct ip_conntrack *ignored_conntrack)
 {
 	struct ip_conntrack_tuple_hash *h;
+	unsigned int hash = hash_conntrack(tuple);
 
 	MUST_BE_READ_LOCKED(&ip_conntrack_lock);
-	h = LIST_FIND(&ip_conntrack_hash[hash_conntrack(tuple)],
+	h = LIST_FIND(&ip_conntrack_hash[hash],
 		      conntrack_tuple_cmp,
 		      struct ip_conntrack_tuple_hash *,
 		      tuple, ignored_conntrack);
Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#1 lore raw
Quoted 4 lines · On Sun, 24 Aug 2003 10:57:42 +0200 Harald Welte <[email protected]> wrote:

The following patch against 2.6.0-test4 (courtesy of Patrick McHardy) optimizes the conntrack code. In the old implementation, the hash function was passed to the LIST_DELETE macro, which resulted in it being called two times instead of one.

Applied to 2.6.x

Quoted 3 lines

This patch also applies to 2.4.x - but I think we should wait for 2.4.23-preX to come up first. Do you want me to re-submit it for 2.4.23-preX, once it shows up?

... and queued for 2.4.23-preX