mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julian Braha <julianbraha@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: nathan@kernel.org, nsc@kernel.org, samitolvanen@google.com,
	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
Subject: Re: [PATCH 1/5] scripts: add bit count parameter back to host hash functions
Date: Fri, 27 Nov 2026 12:50:08 +0000	[thread overview]
Message-ID: <d9151015-1316-42fc-89b1-d93cb0249d6e@gmail.com> (raw)
In-Reply-To: <CAHk-=wjcmmgrJy6rknMOTJ76O92QSAMSUaUPKC6N=pASPsxPmA@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 2082 bytes --]

On 11/27/26 01:16, Linus Torvalds wrote:
> On Thu, 26 Nov 2026 at 16:00, Julian Braha <julianbraha@gmail.com> wrote:
>> 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.
> I think this is the wrong approach.
> 
> I'd suggest hiding the size of the hash table in the table itself, sinc
> ethey are all constant sizes.
> 
> You can do it with some typedef tricks - not exactly pretty macros, but
> the end result ends up pretty nice from a user standpoint.
> 
> Something like the appended TOTALLY UNTESTED patch.  It builds, but it's
> literally a quick hack.
> 
> What it does is to turn each hashtable into a 'union' type that has the
> hashtable head array (as 'hlist[]'), and then a special 'hash_bits[]'
> array.
> 
> And the 'hash_bits[]' array isn't actually used as an array, it's
> literally just used for its size: it's the number of bits the hash table
> has.
> 
> So now you can take such a hashtable type, and always turn it into the
> number of bits with just
> 
>    sizeof(hashtable.hash_bits)
> 
> so now the hash table itself inherently carries its size in bits with it
> - no need for 'ilog2()' or any other crap to calculate the bits.
> 
> And at that point, you can now just use the high bits of the hased
> value, and you don't need to pass in any hash table sizes.
> 
> You can actually even pass pointers to these things around, but you have
> to do it with that original named type, because the size is carried in
> the *type* itself, and it's not just an anonymous array.  Nothing in the
> tree does that
> 
> We can't use this trick in the kernel, because the kernel hash tables
> aren't all fixed sizes.  But for the scripting code, this should make
> the hashing really syntactically simple because the size is always
> there.
It's a fair point - I see why it was simplified in the first place.

Will take a close look at your code. Thanks!

- Julian Braha

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

  parent reply	other threads:[~2026-11-27 12:50 UTC|newest]

Thread overview: 9+ 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 ` [PATCH 1/5] scripts: add bit count parameter back to host hash functions Julian Braha
2026-11-27  1:16   ` Linus Torvalds
2026-11-27  1:34     ` Linus Torvalds
2026-11-27 12:50     ` Julian Braha [this message]
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=d9151015-1316-42fc-89b1-d93cb0249d6e@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®