All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Netfilter Developer Mailing List <netfilter-devel@lists.netfilter.org>
Subject: [NETFILTER]: nf_conntrack: round up hashsize to next multiple of PAGE_SIZE
Date: Tue, 26 Jun 2007 15:59:39 +0200	[thread overview]
Message-ID: <46811BCB.7080502@trash.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 146 bytes --]

I've added these four patches to my tree to improve
the conntrack hashing behaviour and use a hash for
expectations instead of the global list.



[-- Attachment #2: 01.diff --]
[-- Type: text/x-diff, Size: 2993 bytes --]

[NETFILTER]: nf_conntrack: round up hashsize to next multiple of PAGE_SIZE

Besides letting the rest of the page go to waste, this has the nice
side-effect that it assures that the hash size is a power of two,
so we can replace the modulo operation during hashing by a binary and.

Signed-off-by: Patrick McHardy <kaber@trash.net>

---
commit 1b54b00d69fd371821949bf429642dfc98153bcb
tree 83853e7e8d280c88ffbb7eab0a794d1ac0624045
parent 07d16ab092ef4fb4b29037573a28bbfd9e2a6e4b
author Patrick McHardy <kaber@trash.net> Tue, 26 Jun 2007 15:42:28 +0200
committer Patrick McHardy <kaber@trash.net> Tue, 26 Jun 2007 15:42:28 +0200

 net/netfilter/nf_conntrack_core.c |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 035eb9f..ee9f825 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -87,7 +87,7 @@ static u_int32_t __hash_conntrack(const struct nf_conntrack_tuple *tuple,
 	b = jhash2(tuple->dst.u3.all, ARRAY_SIZE(tuple->dst.u3.all),
 		   (tuple->src.u.all << 16) | tuple->dst.u.all);
 
-	return jhash_2words(a, b, rnd) % size;
+	return jhash_2words(a, b, rnd) & size;
 }
 
 static inline u_int32_t hash_conntrack(const struct nf_conntrack_tuple *tuple)
@@ -965,12 +965,14 @@ void nf_conntrack_cleanup(void)
 	nf_conntrack_helper_fini();
 }
 
-static struct list_head *alloc_hashtable(int size, int *vmalloced)
+static struct list_head *alloc_hashtable(int *sizep, int *vmalloced)
 {
 	struct list_head *hash;
-	unsigned int i;
+	unsigned int size, i;
 
 	*vmalloced = 0;
+
+	size = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct list_head));
 	hash = (void*)__get_free_pages(GFP_KERNEL,
 				       get_order(sizeof(struct list_head)
 						 * size));
@@ -1003,7 +1005,7 @@ int set_hashsize(const char *val, struct kernel_param *kp)
 	if (!hashsize)
 		return -EINVAL;
 
-	hash = alloc_hashtable(hashsize, &vmalloced);
+	hash = alloc_hashtable(&hashsize, &vmalloced);
 	if (!hash)
 		return -ENOMEM;
 
@@ -1053,19 +1055,19 @@ int __init nf_conntrack_init(void)
 		if (nf_conntrack_htable_size < 16)
 			nf_conntrack_htable_size = 16;
 	}
-	nf_conntrack_max = 8 * nf_conntrack_htable_size;
-
-	printk("nf_conntrack version %s (%u buckets, %d max)\n",
-	       NF_CONNTRACK_VERSION, nf_conntrack_htable_size,
-	       nf_conntrack_max);
-
-	nf_conntrack_hash = alloc_hashtable(nf_conntrack_htable_size,
+	nf_conntrack_hash = alloc_hashtable(&nf_conntrack_htable_size,
 					    &nf_conntrack_vmalloc);
 	if (!nf_conntrack_hash) {
 		printk(KERN_ERR "Unable to create nf_conntrack_hash\n");
 		goto err_out;
 	}
 
+	nf_conntrack_max = 8 * nf_conntrack_htable_size;
+
+	printk("nf_conntrack version %s (%u buckets, %d max)\n",
+	       NF_CONNTRACK_VERSION, nf_conntrack_htable_size,
+	       nf_conntrack_max);
+
 	nf_conntrack_cachep = kmem_cache_create("nf_conntrack",
 						sizeof(struct nf_conn),
 						0, 0, NULL, NULL);

             reply	other threads:[~2007-06-26 13:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-26 13:59 Patrick McHardy [this message]
2007-06-26 14:00 ` [NETFILTER]: nf_conntrack: round up hashsize to next multiple of PAGE_SIZE Patrick McHardy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46811BCB.7080502@trash.net \
    --to=kaber@trash.net \
    --cc=netfilter-devel@lists.netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.