Re: [PATCH V2 4/4] posix-timers: Use RCU in posix_timer_add()

From: Eric Dumazet
Date: Wed Feb 19 2025 - 14:46:49 EST


On Wed, Feb 19, 2025 at 8:38 PM David Laight
<david.laight.linux@xxxxxxxxx> wrote:
>
> On Wed, 19 Feb 2025 12:55:22 +0000
> Eric Dumazet <edumazet@xxxxxxxxxx> wrote:
>
> > If many posix timers are hashed in posix_timers_hashtable,
> > hash_lock can be held for long durations.
> >
> > This can be really bad in some cases as Thomas
> > explained in https://lore.kernel.org/all/87ednpyyeo.ffs@tglx/
> >
> > We can perform all searches under RCU, then acquire
> > the lock only when there is a good chance to need it,
> > and after cpu caches were populated.
> >
> > Also add a cond_resched() in the possible long loop.
>
> Since this code fragment has a 'free choice' of the timer id, why not
> select an empty table slot and then pick a value that maps to it?
>
> You can run a free-list through the empty table slots so the allocate
> is (almost always) fixed cost and trivial.
> The only complexity arises when the table is full and needs to be
> reallocated twice as large.
>
> The high bits of the 'id' can be incremented every time the id is allocated
> so stale ids can be detected (until a quite large number of allocate/free).

We have to understand the RCU lookup can only fail after 2^31 timer
allocations for a given processus,
I am not sure why we would bother.

CRIU wants predictable timer_id sequences.

We have to try N, N+1, N+2 ... until we find a suitable id.

Alternative would be to add a new system call I guess.