* [PATCH] signal: avoid clearing TIF_SIGPENDING in recalc_sigpending() if unset
@ 2025-03-03 13:49 Mateusz Guzik
2025-03-03 16:52 ` Oleg Nesterov
2025-03-03 22:24 ` Andrew Morton
0 siblings, 2 replies; 4+ messages in thread
From: Mateusz Guzik @ 2025-03-03 13:49 UTC (permalink / raw)
To: oleg; +Cc: akpm, linux-kernel, Mateusz Guzik
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.
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
kernel/signal.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/kernel/signal.c b/kernel/signal.c
index 081f19a24506..4727b108d842 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -176,9 +176,10 @@ static bool recalc_sigpending_tsk(struct task_struct *t)
void recalc_sigpending(void)
{
- if (!recalc_sigpending_tsk(current) && !freezing(current))
- clear_thread_flag(TIF_SIGPENDING);
-
+ if (!recalc_sigpending_tsk(current) && !freezing(current)) {
+ if (test_thread_flag(TIF_SIGPENDING))
+ clear_thread_flag(TIF_SIGPENDING);
+ }
}
EXPORT_SYMBOL(recalc_sigpending);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] signal: avoid clearing TIF_SIGPENDING in recalc_sigpending() if unset
2025-03-03 13:49 [PATCH] signal: avoid clearing TIF_SIGPENDING in recalc_sigpending() if unset Mateusz Guzik
@ 2025-03-03 16:52 ` Oleg Nesterov
2025-03-03 22:24 ` Andrew Morton
1 sibling, 0 replies; 4+ messages in thread
From: Oleg Nesterov @ 2025-03-03 16:52 UTC (permalink / raw)
To: Mateusz Guzik; +Cc: akpm, linux-kernel
On 03/03, Mateusz Guzik wrote:
>
> void recalc_sigpending(void)
> {
> - if (!recalc_sigpending_tsk(current) && !freezing(current))
> - clear_thread_flag(TIF_SIGPENDING);
> -
> + if (!recalc_sigpending_tsk(current) && !freezing(current)) {
> + if (test_thread_flag(TIF_SIGPENDING))
> + clear_thread_flag(TIF_SIGPENDING);
> + }
Acked-by: Oleg Nesterov <oleg@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] signal: avoid clearing TIF_SIGPENDING in recalc_sigpending() if unset
2025-03-03 13:49 [PATCH] signal: avoid clearing TIF_SIGPENDING in recalc_sigpending() if unset Mateusz Guzik
2025-03-03 16:52 ` Oleg Nesterov
@ 2025-03-03 22:24 ` Andrew Morton
2025-03-03 22:36 ` Mateusz Guzik
1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2025-03-03 22:24 UTC (permalink / raw)
To: Mateusz Guzik; +Cc: oleg, linux-kernel
On Mon, 3 Mar 2025 14:49:08 +0100 Mateusz Guzik <mjguzik@gmail.com> 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);
}
}
_
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] signal: avoid clearing TIF_SIGPENDING in recalc_sigpending() if unset
2025-03-03 22:24 ` Andrew Morton
@ 2025-03-03 22:36 ` Mateusz Guzik
0 siblings, 0 replies; 4+ messages in thread
From: Mateusz Guzik @ 2025-03-03 22:36 UTC (permalink / raw)
To: Andrew Morton; +Cc: oleg, linux-kernel
On Mon, Mar 3, 2025 at 11:24 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Mon, 3 Mar 2025 14:49:08 +0100 Mateusz Guzik <mjguzik@gmail.com> 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>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-03 22:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-03 13:49 [PATCH] signal: avoid clearing TIF_SIGPENDING in recalc_sigpending() if unset Mateusz Guzik
2025-03-03 16:52 ` Oleg Nesterov
2025-03-03 22:24 ` Andrew Morton
2025-03-03 22:36 ` Mateusz Guzik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox