Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Baoquan He <baoquan.he@linux.dev>
To: linux-mm@kvack.org
Cc: david@kernel.org, liam@infradead.org, vbabka@kernel.org,
	rppt@kernel.org, mhocko@suse.com, akpm@linux-foundation.org,
	kasong@tencent.com, baohua@kernel.org, qi.zheng@linux.dev,
	shakeel.butt@linux.dev, baoquan.he@linux.dev,
	baolin.wang@linux.alibaba.com, hannes@cmpxchg.org,
	Baoquan He <hebaoquan@kylinos.cn>
Subject: [RFC PATCH 1/2] mm: multi-gen LRU: use Jenkins hash for Bloom filter
Date: Wed,  2 Dec 2026 16:28:40 +0800	[thread overview]
Message-ID: <20261202082841.294888-2-baoquan.he@linux.dev> (raw)
In-Reply-To: <20261202082841.294888-1-baoquan.he@linux.dev>

From: Baoquan He <hebaoquan@kylinos.cn>

get_item_key() built its two keys by splitting one 30-bit hash in half, so
the keys were adjacent slices of a single multiplication and not
independent.  The false positive rate formula assumes k independent hash
functions, so the realised rate did not follow the formula.

Build the two keys from two jhash_2words() calls with different seeds
instead.  They can then be masked to any filter width without correlating
the two keys, which is what the dynamic sizing in the next patch needs.

Signed-off-by: Baoquan He <hebaoquan@kylinos.cn>
Signed-off-by: Baoquan He <baoquan.he@linux.dev>
---
 mm/vmscan.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 7b49a27bd3cc..e46f14b666d1 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -41,6 +41,7 @@
 #include <linux/memcontrol.h>
 #include <linux/migrate.h>
 #include <linux/delayacct.h>
+#include <linux/jhash.h>
 #include <linux/sysctl.h>
 #include <linux/memory-tiers.h>
 #include <linux/oom.h>
@@ -2872,7 +2873,6 @@ static bool __maybe_unused seq_is_valid(struct lruvec *lruvec)
  * 2. And when reallocating, it's worth scaling its size according to the number
  *    of inserted entries in the other filter, to reduce the memory overhead on
  *    small systems and false positives on large systems.
- * 3. Jenkins' hash function is an alternative to Knuth's.
  */
 #define BLOOM_FILTER_SHIFT	15
 
@@ -2881,14 +2881,21 @@ static inline int filter_gen_from_seq(unsigned long seq)
 	return seq % NR_BLOOM_FILTERS;
 }
 
+/*
+ * Produce two independent hash keys within [0, BIT(BLOOM_FILTER_SHIFT))
+ * using Jenkins hash (lookup3).  Two independent 32-bit hashes with
+ * different seeds replace the single Knuth multiplicative hash produced
+ * by hash_ptr(), yielding better distribution for PMD addresses.
+ */
 static void get_item_key(void *item, int *key)
 {
-	u32 hash = hash_ptr(item, BLOOM_FILTER_SHIFT * 2);
-
-	BUILD_BUG_ON(BLOOM_FILTER_SHIFT * 2 > BITS_PER_TYPE(u32));
+	unsigned long ptr = (unsigned long)item;
+	u32 lo = (u32)ptr;
+	u32 hi = (u32)(ptr >> 32);
+	u32 mask = BIT(BLOOM_FILTER_SHIFT) - 1;
 
-	key[0] = hash & (BIT(BLOOM_FILTER_SHIFT) - 1);
-	key[1] = hash >> BLOOM_FILTER_SHIFT;
+	key[0] = jhash_2words(lo, hi, 0) & mask;
+	key[1] = jhash_2words(lo, hi, 0x9e3779b9UL) & mask;
 }
 
 static bool test_bloom_filter(struct lru_gen_mm_state *mm_state, int level,
-- 
2.52.0



  reply	other threads:[~2026-12-02  8:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  8:28 [RFC PATCH 0/2] mm: multi-gen LRU: fix the Bloom filter size and keys Baoquan He
2026-12-02  8:28 ` Baoquan He [this message]
2026-12-02  8:28 ` [RFC PATCH 2/2] mm: multi-gen LRU: scale Bloom filter size to insertion count Baoquan He

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=20261202082841.294888-2-baoquan.he@linux.dev \
    --to=baoquan.he@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=hebaoquan@kylinos.cn \
    --cc=kasong@tencent.com \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=qi.zheng@linux.dev \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=vbabka@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox