netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] improvement on net/sched/cls_fw.c's hash function
@ 2005-04-05  5:35 Wang Jian
  2005-04-05  5:37 ` David S. Miller
  0 siblings, 1 reply; 33+ messages in thread
From: Wang Jian @ 2005-04-05  5:35 UTC (permalink / raw)
  To: netdev

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

Hi,

This is a simple patch against net/sched/cls_fw.c. The idea of this
patch is discussed in this thread

https://lists.netfilter.org/pipermail/netfilter-devel/2005-March/018762.html

I chose 509 for FW_FILTER_HSIZE. If you feel it is waste of memory, then
251 is good too.

BTW: I don't know much about hash performance and hash distribution of
jhash. This is a quick fix.



-- 
  lark

[-- Attachment #2: hash-cls_fw.diff --]
[-- Type: application/octet-stream, Size: 1029 bytes --]

Index: cls_fw.c
===================================================================
--- cls_fw.c	(revision 1)
+++ cls_fw.c	(working copy)
@@ -45,10 +45,13 @@
 #include <net/sock.h>
 #include <net/act_api.h>
 #include <net/pkt_cls.h>
+#include <linux/jhash.h>
 
+#define FW_FILTER_HSIZE		509
+
 struct fw_head
 {
-	struct fw_filter *ht[256];
+	struct fw_filter *ht[FW_FILTER_HSIZE];
 };
 
 struct fw_filter
@@ -69,7 +72,7 @@
 
 static __inline__ int fw_hash(u32 handle)
 {
-	return handle&0xFF;
+	return (jhash_1word(handle, 0xF30A7129) % FW_FILTER_HSIZE);
 }
 
 static int fw_classify(struct sk_buff *skb, struct tcf_proto *tp,
@@ -152,7 +155,7 @@
 	if (head == NULL)
 		return;
 
-	for (h=0; h<256; h++) {
+	for (h=0; h<FW_FILTER_HSIZE; h++) {
 		while ((f=head->ht[h]) != NULL) {
 			head->ht[h] = f->next;
 			fw_delete_filter(tp, f);
@@ -291,7 +294,7 @@
 	if (arg->stop)
 		return;
 
-	for (h = 0; h < 256; h++) {
+	for (h = 0; h < FW_FILTER_HSIZE; h++) {
 		struct fw_filter *f;
 
 		for (f = head->ht[h]; f; f = f->next) {

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2005-04-07 14:03 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-05  5:35 [PATCH] improvement on net/sched/cls_fw.c's hash function Wang Jian
2005-04-05  5:37 ` David S. Miller
2005-04-05  6:05   ` Wang Jian
2005-04-05 10:25     ` jamal
2005-04-05 10:38     ` Thomas Graf
2005-04-05 11:25       ` Wang Jian
2005-04-05 12:16         ` Thomas Graf
2005-04-05 12:39           ` Wang Jian
2005-04-05 12:52             ` Thomas Graf
2005-04-05 13:29               ` Wang Jian
2005-04-05 12:54             ` jamal
2005-04-05 14:18               ` Wang Jian
2005-04-05 16:11                 ` jamal
2005-04-06  6:45                   ` Wang Jian
2005-04-06 12:16                     ` jamal
2005-04-06 12:30                     ` Thomas Graf
2005-04-06 13:01                       ` Wang Jian
2005-04-06 13:34                       ` jamal
2005-04-06 13:45                         ` Thomas Graf
2005-04-06 14:10                           ` Thomas Graf
2005-04-06 18:15                             ` David S. Miller
2005-04-06 18:31                               ` Thomas Graf
2005-04-07  0:55                                 ` [RFC] dynamic hash table size & xor hash function for cls_fw Thomas Graf
2005-04-07 10:38                                   ` jamal
2005-04-07 10:47                                     ` Wang Jian
2005-04-07 10:51                                     ` Thomas Graf
2005-04-07 11:07                                       ` jamal
2005-04-07 13:09                                         ` [PATCH] [PKT_SCHED]: improve hashing performance of cls_fw Thomas Graf
2005-04-07 13:31                                           ` Wang Jian
2005-04-07 13:52                                             ` Thomas Graf
2005-04-07 14:03                                               ` Wang Jian
2005-04-06 13:36                       ` [PATCH] improvement on net/sched/cls_fw.c's hash function Eran Mann
2005-04-06 13:53                         ` Wang Jian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).