All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] posix-timers: cond_resched() during exit_itimers()
@ 2025-02-14 22:12 Benjamin Segall
  2025-02-18  9:03 ` Thomas Gleixner
  2025-02-18  9:25 ` [tip: timers/core] posix-timers: Invoke " tip-bot2 for Benjamin Segall
  0 siblings, 2 replies; 4+ messages in thread
From: Benjamin Segall @ 2025-02-14 22:12 UTC (permalink / raw)
  To: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner,
	linux-kernel
  Cc: Eric Dumazet

exit_itimers() loops through every timer in the process to delete it.
This requires taking the system-wide hash_lock for each of these locks,
and contends with other processes trying to create or delete timers.
When a process creates hundreds of thousands of timers, and then exits
while other processes contend with it, this can trigger softlockups on
CONFIG_PREEMPT=n.

Ideally this will some day be better solved by eliminating the global
hashtable, but until that point mitigate the issue by doing
cond_resched in that loop.

Signed-off-by: Ben Segall <bsegall@google.com>
---
 kernel/time/posix-timers.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 1b675aee99a98..44ba7db07e900 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -1097,12 +1097,14 @@ void exit_itimers(struct task_struct *tsk)
 	spin_lock_irq(&tsk->sighand->siglock);
 	hlist_move_list(&tsk->signal->posix_timers, &timers);
 	spin_unlock_irq(&tsk->sighand->siglock);
 
 	/* The timers are not longer accessible via tsk::signal */
-	while (!hlist_empty(&timers))
+	while (!hlist_empty(&timers)) {
 		itimer_delete(hlist_entry(timers.first, struct k_itimer, list));
+		cond_resched();
+	}
 
 	/*
 	 * There should be no timers on the ignored list. itimer_delete() has
 	 * mopped them up.
 	 */
-- 
2.48.1.601.g30ceb7b040-goog

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-18 22:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-14 22:12 [PATCH] posix-timers: cond_resched() during exit_itimers() Benjamin Segall
2025-02-18  9:03 ` Thomas Gleixner
2025-02-18 22:34   ` Benjamin Segall
2025-02-18  9:25 ` [tip: timers/core] posix-timers: Invoke " tip-bot2 for Benjamin Segall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.