From: Julian Braha <julianbraha@gmail.com>
To: nathan@kernel.org, nsc@kernel.org
Cc: samitolvanen@google.com, torvalds@linux-foundation.org,
ljs@kernel.org, david.laight.linux@gmail.com, sashal@kernel.org,
lzsx618@gmail.com, zuoan.penguin@gmail.com, petr.pavlu@suse.com,
jani.nikula@intel.com, xur@google.com, sidnayyar@google.com,
robertusdchris@gmail.com, acourbot@nvidia.com,
linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org,
linux-kernel@vger.kernel.org,
Julian Braha <julianbraha@gmail.com>
Subject: [PATCH 1/5] scripts: add bit count parameter back to host hash functions
Date: Fri, 27 Nov 2026 00:00:11 +0000 [thread overview]
Message-ID: <20261127000015.3662267-2-julianbraha@gmail.com> (raw)
In-Reply-To: <20261127000015.3662267-1-julianbraha@gmail.com>
This partially reverts commit f93d6bfbd2f7 ("kconfig: use hash table to
reuse expressions").
As reported by Linus [1], when the kernel's internal hash and hash table
implementations were copied over for Kconfig to use, several functions
were simplified to remove their second 'bits' parameter. But the usage of
this simplified implementation led to poor hash table performance due to
using the lower bits despite hash_32() putting the significant bits in the
high bits of the result.
Let's revert the parameter simplification: the host versions of hash_32()
and hash_ptr() will take the number of high bits, as is done in the
kernel's internal implementation.
Accordingly, adjust the callers of 'hash_32()' and 'hash_ptr()' to use
the additional parameter. This is a pure refactor (no functional changes),
so pass 32 to preserve the existing behavior.
Link: https://lore.kernel.org/all/CAHk-=wi_GuySe0L-uCAM2+nScCLYGBp5BLi6UUPR1gALmNM_3w@mail.gmail.com/ [1]
Signed-off-by: Julian Braha <julianbraha@gmail.com>
---
scripts/gendwarfksyms/cache.c | 4 ++--
scripts/gendwarfksyms/die.c | 2 +-
scripts/gendwarfksyms/gendwarfksyms.h | 2 +-
scripts/gendwarfksyms/kabi.c | 2 +-
scripts/gendwarfksyms/symbols.c | 2 +-
scripts/include/hash.h | 8 ++++----
scripts/kconfig/expr.c | 2 +-
7 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/scripts/gendwarfksyms/cache.c b/scripts/gendwarfksyms/cache.c
index 1c640db93db3..a4d18a9489e3 100644
--- a/scripts/gendwarfksyms/cache.c
+++ b/scripts/gendwarfksyms/cache.c
@@ -18,14 +18,14 @@ void cache_set(struct cache *cache, unsigned long key, int value)
ci = xmalloc(sizeof(*ci));
ci->key = key;
ci->value = value;
- hash_add(cache->cache, &ci->hash, hash_32(key));
+ hash_add(cache->cache, &ci->hash, hash_32(key, 32));
}
int cache_get(struct cache *cache, unsigned long key)
{
struct cache_item *ci;
- hash_for_each_possible(cache->cache, ci, hash, hash_32(key)) {
+ hash_for_each_possible(cache->cache, ci, hash, hash_32(key, 32)) {
if (ci->key == key)
return ci->value;
}
diff --git a/scripts/gendwarfksyms/die.c b/scripts/gendwarfksyms/die.c
index 052f7a3f975a..4e390a6295a3 100644
--- a/scripts/gendwarfksyms/die.c
+++ b/scripts/gendwarfksyms/die.c
@@ -16,7 +16,7 @@ static unsigned int map_misses;
static inline unsigned int die_hash(uintptr_t addr, enum die_state state)
{
- return hash_32(addr_hash(addr) ^ (unsigned int)state);
+ return hash_32(addr_hash(addr) ^ (unsigned int)state, 32);
}
static void init_die(struct die *cd)
diff --git a/scripts/gendwarfksyms/gendwarfksyms.h b/scripts/gendwarfksyms/gendwarfksyms.h
index 32cec8f7695a..f4f21d6090e7 100644
--- a/scripts/gendwarfksyms/gendwarfksyms.h
+++ b/scripts/gendwarfksyms/gendwarfksyms.h
@@ -95,7 +95,7 @@ extern int symtypes;
static inline unsigned int addr_hash(uintptr_t addr)
{
- return hash_ptr((const void *)addr);
+ return hash_ptr((const void *)addr, 32);
}
enum symbol_state {
diff --git a/scripts/gendwarfksyms/kabi.c b/scripts/gendwarfksyms/kabi.c
index e3c2a3ccf51a..2d941ee13c9b 100644
--- a/scripts/gendwarfksyms/kabi.c
+++ b/scripts/gendwarfksyms/kabi.c
@@ -92,7 +92,7 @@ static HASHTABLE_DEFINE(rules, 1 << RULE_HASH_BITS);
static inline unsigned int rule_values_hash(enum kabi_rule_type type,
const char *target)
{
- return hash_32(type) ^ hash_str(target);
+ return hash_32(type, 32) ^ hash_str(target);
}
static inline unsigned int rule_hash(const struct rule *rule)
diff --git a/scripts/gendwarfksyms/symbols.c b/scripts/gendwarfksyms/symbols.c
index 42cd27c9cec4..b4110b0e12ce 100644
--- a/scripts/gendwarfksyms/symbols.c
+++ b/scripts/gendwarfksyms/symbols.c
@@ -15,7 +15,7 @@ static HASHTABLE_DEFINE(symbol_names, 1 << SYMBOL_HASH_BITS);
static inline unsigned int symbol_addr_hash(const struct symbol_addr *addr)
{
- return hash_32(addr->section ^ addr_hash(addr->address));
+ return hash_32(addr->section ^ addr_hash(addr->address), 32);
}
static unsigned int __for_each_addr(struct symbol *sym, symbol_callback_t func,
diff --git a/scripts/include/hash.h b/scripts/include/hash.h
index efa904368a62..ae0d3fc8d470 100644
--- a/scripts/include/hash.h
+++ b/scripts/include/hash.h
@@ -15,14 +15,14 @@ static inline unsigned int hash_str(const char *s)
/* simplified version of functions from include/linux/hash.h */
#define GOLDEN_RATIO_32 0x61C88647
-static inline unsigned int hash_32(unsigned int val)
+static inline unsigned int hash_32(unsigned int val, unsigned int bits)
{
- return 0x61C88647 * val;
+ return bits ? (val * GOLDEN_RATIO_32) >> (32 - bits) : 0;
}
-static inline unsigned int hash_ptr(const void *ptr)
+static inline unsigned int hash_ptr(const void *ptr, unsigned int bits)
{
- return hash_32((unsigned int)(unsigned long)ptr);
+ return hash_32((unsigned int)(unsigned long)ptr, bits);
}
#endif /* HASH_H */
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index 2b91d16bf14f..ea93016b68d4 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -35,7 +35,7 @@ static struct expr *expr_lookup(enum expr_type type, void *l, void *r)
struct expr *e;
int hash;
- hash = hash_32((unsigned int)type ^ hash_ptr(l) ^ hash_ptr(r));
+ hash = hash_32((unsigned int)type ^ hash_ptr(l, 32) ^ hash_ptr(r, 32), 32);
hash_for_each_possible(expr_hashtable, e, node, hash) {
if (e->type == type && e->left._initdata == l &&
--
2.56.0
next prev parent reply other threads:[~2026-11-27 0:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 0:00 [PATCH 0/5] kconfig: fix slow 'make oldconfig' by reverting host header simplifications Julian Braha
2026-11-27 0:00 ` Julian Braha [this message]
2026-11-27 1:16 ` [PATCH 1/5] scripts: add bit count parameter back to host hash functions Linus Torvalds
2026-11-27 1:34 ` Linus Torvalds
2026-11-27 0:00 ` [PATCH 2/5] scripts: restore support for 64-bit pointers in " Julian Braha
2026-11-27 0:00 ` [PATCH 3/5] scripts: restore host hash table macro names Julian Braha
2026-11-27 0:00 ` [PATCH 4/5] scripts: add bit count parameter back to the host hash table functions Julian Braha
2026-11-27 0:00 ` [PATCH 5/5] kconfig: replace XOR with addition for expr_lookup() key generation Julian Braha
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=20261127000015.3662267-2-julianbraha@gmail.com \
--to=julianbraha@gmail.com \
--cc=acourbot@nvidia.com \
--cc=david.laight.linux@gmail.com \
--cc=jani.nikula@intel.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=lzsx618@gmail.com \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=robertusdchris@gmail.com \
--cc=samitolvanen@google.com \
--cc=sashal@kernel.org \
--cc=sidnayyar@google.com \
--cc=torvalds@linux-foundation.org \
--cc=xur@google.com \
--cc=zuoan.penguin@gmail.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
all inboxes | Powered by JetHome®