Re: [PATCH] signal: avoid clearing TIF_SIGPENDING in recalc_sigpending() if unset

From: Mateusz Guzik
Date: Mon Mar 03 2025 - 17:36:53 EST


On Mon, Mar 3, 2025 at 11:24 PM Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Mon, 3 Mar 2025 14:49:08 +0100 Mateusz Guzik <mjguzik@xxxxxxxxx> wrote:
>
> > Clearing is an atomic op and the flag is not set most of the time.
> >
> > When creating and destroying threads in the same process with the
> > pthread family, the primary bottleneck is calls to sigprocmask which
> > take the process-wide sighand lock.
> >
> > Avoiding the atomic gives me a 2% bump in start/teardown rate at 24-core
> > scale.
> >
>
> Neat. Perhaps add an unlikely() also?
>
> --- a/kernel/signal.c~signal-avoid-clearing-tif_sigpending-in-recalc_sigpending-if-unset-fix
> +++ a/kernel/signal.c
> @@ -177,7 +177,7 @@ static bool recalc_sigpending_tsk(struct
> void recalc_sigpending(void)
> {
> if (!recalc_sigpending_tsk(current) && !freezing(current)) {
> - if (test_thread_flag(TIF_SIGPENDING))
> + if (unlikely(test_thread_flag(TIF_SIGPENDING)))
> clear_thread_flag(TIF_SIGPENDING);
> }
> }
> _
>

Ye that makes sense, I don't think Oleg is going to object :)

Thanks for a quick turn around to you both,

--
Mateusz Guzik <mjguzik gmail.com>