From: Peter Zijlstra <peterz@infradead.org>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: linux-kernel@vger.kernel.org,
"André Almeida" <andrealmeid@igalia.com>,
"Darren Hart" <dvhart@infradead.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"Ingo Molnar" <mingo@redhat.com>,
"Juri Lelli" <juri.lelli@redhat.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Valentin Schneider" <vschneid@redhat.com>,
"Waiman Long" <longman@redhat.com>
Subject: Re: [PATCH v9 00/11] futex: Add support task local hash maps.
Date: Mon, 3 Mar 2025 11:54:16 +0100 [thread overview]
Message-ID: <20250303105416.GY11590@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20250225170914.289358-1-bigeasy@linutronix.de>
On Tue, Feb 25, 2025 at 06:09:03PM +0100, Sebastian Andrzej Siewior wrote:
> Sebastian Andrzej Siewior (11):
> futex: fixup futex_wait_setup [fold futex: Move futex_queue() into
> futex_wait_setup()]
> futex: Create helper function to initialize a hash slot.
> futex: Add basic infrastructure for local task local hash.
> futex: Hash only the address for private futexes.
> futex: Allow automatic allocation of process wide futex hash.
> futex: Decrease the waiter count before the unlock operation.
> futex: Introduce futex_q_lockptr_lock().
> futex: Acquire a hash reference in futex_wait_multiple_setup().
> futex: Allow to re-allocate the private local hash.
> futex: Resize local futex hash table based on number of threads.
Right, I've been going over this and been poking at the patches for the
past few days, and I'm not quite sure where to start.
There's a bunch of simple things, that can be trivially fixed, but
there's also some more fundamental things.
I've written a pile of patches on top of this while playing around with
things. The latest pile sits in:
queue/locking/futex
I'm not sure I should post the patches as a reply to this email (I can,
if people want), but let me try and summarize what I did and why.
Primarily, the reason I started poking at it is that I think the prctl()
as implemented is completely useless. Notably its effect is entirely
ephemeral, one pthread_create() call can re-size the hash, destroying
the user requested size. Also, I still feel one should be able to set
the hash size to 0 and have it revert to global hash.
Finally prctl() should not return until the rehash is complete.
I think my implementation now does all that -- but I've not tested it
yet -- I've to write a prctl() testcase and it was too nice outside :-)
So, on the way to reworking the prctl(), I ran into:
- naming; hb_p is a terrible name, the way I read that is
hash-bucket-private, or hash-bucket pointer, neither make much sense,
because they're a pointer to struct futex_private_hash, which is a
hash-table.
I've very uninspired done s/hb_p/fph/g with the exception of
hb->hb_p, which is now hb->priv.
- more naming; you had:
hb = __futex_hash(key);
futex_hash_get(hb);
futex_hash_put(hb);
fph = futex_get_private_hash();
futex_put_private_hash();
which is all sorts of inconsistent, and I've made that:
hb = __futex_hash(key); /* hash, no get */
hb = futex_hash(key) /* hash and get */
futex_hash_get(hb); /* get */
futex_hash_put(hb); /* put */
fph = futex_private_hash();
futex_private_hash_get(fph);
futex_private_hash_put(fph);
- There was some superfluous state; notably, AFAICT
futex_private_hash::{initial_ref_dropped,released} are unneeded and
made the code unnecessarily complicated.
You can drop the initial ref when phash && !phash_new, eg on the
first time around when you allocate a new hash-table.
We don't need to track released because we can simply check for that
state using rcuref_read() == 0.
- As alluded to in a previous point, there was no means of only
hashing, the fph get was both non-obviously hidden inside the private
hash and unconditional. Untangled that.
My current prctl() thing does:
- reject !power-of-two and 1
- accepts 0
- returns once rehash is done
Notably, having done a prctl() disables the auto-sizing.
When allocating a new private hash table and there is already one
pending, it compares the tables. The compare function checks in order:
- custom (user provided / prctl())
- zero size
- biggest size
IOW, any user requested size always wins, a 0 size is final otherwise
go with the largest.
After that I rebased my FUTEX2_NUMA patch on top of all this and added
a new FUTEX2_MPOL, which is something Christoph Lameter asked for a
while back, and something we can now actually do sanely, since we have
lockless vma lookups working.
Anyway, the entire stack builds and boots, but is otherwise very much
untested.
WDYT?
next prev parent reply other threads:[~2025-03-03 10:54 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-25 17:09 [PATCH v9 00/11] futex: Add support task local hash maps Sebastian Andrzej Siewior
2025-02-25 17:09 ` [PATCH v9 01/11] futex: fixup futex_wait_setup [fold futex: Move futex_queue() into futex_wait_setup()] Sebastian Andrzej Siewior
2025-02-26 8:15 ` Thomas Gleixner
2025-02-26 8:40 ` Sebastian Andrzej Siewior
2025-02-25 17:09 ` [PATCH v9 02/11] futex: Create helper function to initialize a hash slot Sebastian Andrzej Siewior
2025-02-25 17:09 ` [PATCH v9 03/11] futex: Add basic infrastructure for local task local hash Sebastian Andrzej Siewior
2025-02-25 17:09 ` [PATCH v9 04/11] futex: Hash only the address for private futexes Sebastian Andrzej Siewior
2025-02-25 17:09 ` [PATCH v9 05/11] futex: Allow automatic allocation of process wide futex hash Sebastian Andrzej Siewior
2025-02-25 17:09 ` [PATCH v9 06/11] futex: Decrease the waiter count before the unlock operation Sebastian Andrzej Siewior
2025-02-25 17:09 ` [PATCH v9 07/11] futex: Introduce futex_q_lockptr_lock() Sebastian Andrzej Siewior
2025-02-25 17:09 ` [PATCH v9 08/11] futex: Acquire a hash reference in futex_wait_multiple_setup() Sebastian Andrzej Siewior
2025-02-25 17:09 ` [PATCH v9 09/11] futex: Allow to re-allocate the private local hash Sebastian Andrzej Siewior
2025-02-25 17:09 ` [PATCH v9 10/11] futex: Resize local futex hash table based on number of threads Sebastian Andrzej Siewior
2025-02-25 17:09 ` [PATCH v9 11/11] futex: Use a hashmask instead of hashsize Sebastian Andrzej Siewior
2025-02-26 8:17 ` Thomas Gleixner
2025-03-03 10:54 ` Peter Zijlstra [this message]
2025-03-03 14:17 ` [PATCH v9 00/11] futex: Add support task local hash maps Sebastian Andrzej Siewior
2025-03-03 16:40 ` Sebastian Andrzej Siewior
2025-03-04 14:58 ` Sebastian Andrzej Siewior
2025-03-05 9:02 ` Sebastian Andrzej Siewior
2025-03-10 16:01 ` Peter Zijlstra
2025-03-10 16:27 ` Sebastian Andrzej Siewior
2025-03-11 10:17 ` Peter Zijlstra
2025-03-11 10:33 ` Sebastian Andrzej Siewior
2025-03-10 15:57 ` Peter Zijlstra
2025-03-11 15:20 ` Sebastian Andrzej Siewior
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=20250303105416.GY11590@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=andrealmeid@igalia.com \
--cc=bigeasy@linutronix.de \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=vschneid@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