mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nathan Chancellor <nathan@kernel.org>,
	Nicolas Schier <nsc@kernel.org>,
	Julian Braha <julianbraha@gmail.com>,
	Lorenzo Stoakes <ljs@kernel.org>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Speed up KConfig - fix hashtable confusion
Date: Mon, 2 Nov 2026 19:51:14 +0000	[thread overview]
Message-ID: <20261102195114.742df19b@pumpkin> (raw)
In-Reply-To: <CAHk-=wjx9EAO50CkadGadOA_ea0D7bBBmMbFfRqyf0OriZP+tQ@mail.gmail.com>

On Mon, 2 Nov 2026 10:20:35 -0800
Linus Torvalds <torvalds@linux-foundation.org> wrote:

> On Mon, 2 Nov 2026 at 01:47, David Laight <david.laight.linux@gmail.com> wrote:
> >
> > An alternative would be:
> >         ((key) * (u64)(size)) >> 32
> > which avoids the division when size isn't a constant power of 2.  
> 
> That's certainly cleaner
> 
> Not that it should matter - afaik the size is always a constant (it
> comes from 'sizeof()'), and I would actually prefer it if
> HASHTABLE_DECLARE and HASHTABLE_DEFINE took the number of *bits* (like
> DECLARE_HASHTABLE() does for the kernel proper), and we'd just make it
> a rule that it's always a power-of-2.
> 
> It already *is* always a power-of-two, and the old code used to make
> it a slow modulus operation if it wasn't.

Ah yes, some people think hash tables need to have a prime size.
Do not doubt the sanity of the person who decided that the elf symbol
hash table size would be (IIRC) 'the prime number below the power of
2 below the number of symbols' - this makes every hash list have ~1.5
symbols so you pretty much always have to do name compares on every
shared library that gets loaded with a program in order to find a
symbol that is in libc.
I remember significantly speeding up loading of mozilla by rewriting
the elf interpreter to generate a merged symbol table for all those
libraries - no idea what the one the Linux uses does.

With a reasonable hash function (or even the crap and slow to calculate
one elf uses) a power of two sized table works just as well.

> I'd also worry a tiny bit about what the compilers do on 32-bit
> targets, although obviously hopefully (a) they'd optimize it to the
> right 32-bit code rather than do 64-bit ops and (b) it's not like we
> seriously care about 32-bit host builds anyway.

They'll probably zero-pad both sides to 64 bit and do all four multiplies.
But that isn't so bad on most systems.
At least the 32bit shift is cheap!

But yes, you are going to have trouble with a lot of builds on 32bit hosts.
objtool sat for minutes (long enough for me to think it might be stuck)
with an RSS of ~30GB on a recent build (ok it was allyesconfig - I wanted
the symbol table) - but I suspect it will hit 3GB on a reasonable kernel.

David

> 
>              Linus


  reply	other threads:[~2026-11-02 19:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-01 20:08 Linus Torvalds
2026-11-01 23:44 ` Julian Braha
2026-11-02  6:53   ` Nicolas Schier
2026-11-02  9:47 ` David Laight
2026-11-02 18:20   ` Linus Torvalds
2026-11-02 19:51     ` David Laight [this message]
2026-11-02 10:26 ` Sasha Levin
2026-11-02 12:50   ` Nicolas Schier

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=20261102195114.742df19b@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=julianbraha@gmail.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®