From: Pekka Enberg <penberg@cs.helsinki.fi>
To: riel@redhat.com
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC] non-resident page management
Date: Sat, 23 Apr 2005 14:25:56 +0300 [thread overview]
Message-ID: <1114255557.10805.2.camel@localhost> (raw)
Hi,
On 4/23/05, Rik van Riel <riel@redhat.com> wrote:
> Note that this code could use an actual hash function.
How about this? It computes hash for the two longs and combines them by
addition and multiplication as suggested by [Bloch01].
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---
include/linux/hash.h | 13 ++++++++++++-
mm/nonresident.c | 11 ++++++++---
2 files changed, 20 insertions(+), 4 deletions(-)
Index: 2.6/include/linux/hash.h
===================================================================
--- 2.6.orig/include/linux/hash.h 2004-12-24 23:35:39.000000000 +0200
+++ 2.6/include/linux/hash.h 2005-04-23 13:57:46.000000000 +0300
@@ -23,7 +23,7 @@
#error Define GOLDEN_RATIO_PRIME for your wordsize.
#endif
-static inline unsigned long hash_long(unsigned long val, unsigned int bits)
+static inline unsigned long hash_long_mul(unsigned long val)
{
unsigned long hash = val;
@@ -46,6 +46,17 @@
/* On some cpus multiply is faster, on others gcc will do shifts */
hash *= GOLDEN_RATIO_PRIME;
#endif
+ return hash;
+}
+
+static inline unsigned long hash_ptr_mul(void *ptr)
+{
+ return hash_long_mul((unsigned long)ptr);
+}
+
+static inline unsigned long hash_long(unsigned long val, unsigned int bits)
+{
+ unsigned long hash = hash_long_mul(val);
/* High bits are more random, so use them. */
return hash >> (BITS_PER_LONG - bits);
Index: 2.6/mm/nonresident.c
===================================================================
--- 2.6.orig/mm/nonresident.c 2005-04-23 13:46:24.000000000 +0300
+++ 2.6/mm/nonresident.c 2005-04-23 14:18:20.000000000 +0300
@@ -21,7 +21,7 @@
#include <linux/cache.h>
#include <linux/spinlock.h>
#include <linux/bootmem.h>
-#include <linux/jhash.h>
+#include <linux/hash.h>
// #include <linux/nonresident.h>
static unsigned long nr_buckets;
@@ -51,11 +51,16 @@
/* The non-resident page hash table. */
static struct nr_bucket * nr_hashtable;
-/* Wanted: a real hash function for 2 longs. */
struct nr_bucket * nr_hash(void * mapping, unsigned long offset_and_gen)
{
+ unsigned long hash;
unsigned long bucket;
- bucket = ((unsigned long)mapping + offset_and_gen) % nr_buckets;
+
+ hash = 17;
+ hash = 37 * hash + hash_ptr_mul(mapping);
+ hash = 37 * hash + hash_long_mul(offset_and_gen);
+ bucket = hash % nr_buckets;
+
return nr_hashtable + bucket;
}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>
next reply other threads:[~2005-04-23 11:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-23 11:25 Pekka Enberg [this message]
2005-04-23 11:31 ` Rik van Riel
2005-04-23 17:13 ` Rik van Riel
2005-04-23 18:55 ` Rik van Riel
-- strict thread matches above, loose matches on Subject: below --
2005-04-22 21:26 Rik van Riel
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=1114255557.10805.2.camel@localhost \
--to=penberg@cs.helsinki.fi \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=riel@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox