Re: [RFC PATCH 2/3] futex: Add basic infrastructure for local task local hash.
From: Sebastian Andrzej Siewior
Date: Mon Oct 28 2024 - 06:31:16 EST
On 2024-10-27 13:19:54 [+0100], Thomas Gleixner wrote:
> > + if (current->futex_hash_table)
> > + return -EALREADY;
>
> You also need to check whether a hash table exists already in the
> process. The table must be process shared to make sense. So it should
> live in current->signal, which is a valid pointer in the context of
> current.
>
> So this needs some more thoughts especially vs. automatic creation and
> sharing.
>
> The first question is whether the hash table might have been already
> created when the application reaches main(). If so then this call will
> fail.
>
> To make this work correctly, this needs proper serialization as well.
>
> Assume a situation where the application does not allocate a table
> upfront and the first futex use happens late when threads are running
> already.
>
> CPU0 CPU1
> T1 T2
> sys_futex() sys_futex()
> create_hash() create_hash()
>
> So T1 and T2 create their local hash and the subsequent usage will fail
> because they operate on different hashs. You have the same problem
> vs. your allocation scheme when two threads do prctl(ALLOC). We really
> want to make this as simple as possible.
So I moved this to struct signal_struct and limited allocation to the
group leader.
You want automated creation of this? For everyone or with a hint? This
is 64 bytes per slot due to the cache alignment but event without this
struct takes 56 bytes on PREEMPT_RT and 24 bytes on non-RT. So the four
slots are 256 bytes. Assuming 2.5k tasks it takes 625 KiB. Maybe not
that much.
Let me post v2 the signal_struct and then think about auto ON.
>
> Thanks,
>
> tglx
Sebastian