timers: Stop hrtimer queue traversal after seq_file overflow
PATCH 1/1 timers: Stop hrtimer queue traversal after seq_file overflow
When /proc/timer_list overflows its seq_file buffer, seq_file retries formatting with a larger buffer. print_active_timers() nevertheless continues scanning the remaining hrtimers, restarting its quadratic traversal even though the overflowing attempt will be discarded.
Stop traversing at next_one when the seq_file has overflowed. Preserve the SysRq console path, which passes a NULL seq_file pointer.
In a (virtual) two-CPU KVM guest with 2,048 timerfds pinned to one CPU, median reader CPU time for a complete /proc/timer_list read fell from 51.1 ms to 14.6 ms. Repeated tests showed no material slowdown for non-overflowing reads (13.7us before versus 13.8 after). Short reads, seek-to-start, and SysRq-Q tests also look fine.
--- kernel/time/timer_list.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/time/timer_list.c +2 -0
@@ -64,6 +64,8 @@ static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *bunsigned long flags; next_one: +if (m &&seq_has_overflowed (m)) +return ; i =0 ;touch_nmi_watchdog ();
Signature · 1 line
2.43.0
Frederic Weisbecker
maintainerQuoted 25 lines · Avi Weiss
When
/proc/timer_listoverflows itsseq_filebuffer,seq_fileretries formatting with a larger buffer.print_active_timers()nevertheless continues scanning the remaining hrtimers, restarting its quadratic traversal even though the overflowing attempt will be discarded.Stop traversing at
next_onewhen theseq_filehas overflowed. Preserve the SysRq console path, which passes a NULLseq_filepointer.In a (virtual) two-CPU KVM guest with 2,048 timerfds pinned to one CPU, median reader CPU time for a complete
/proc/timer_listread fell from 51.1 ms to 14.6 ms. Repeated tests showed no material slowdown for non-overflowing reads (13.7us before versus 13.8 after). Short reads, seek-to-start, and SysRq-Q tests also look fine.Fixes 289f480af87e ("[PATCH] Add debugging feature /proc/timer_list")Signed-off-by Avi Weiss <[email protected]>--- kernel/time/timer_list.c | 2 ++ 1 file changed, 2 insertions(+)kernel/time/timer_list.c +0
-0
kernel/time/timer_list.c static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *b · line 68
Quoted 5 lines
kernel/time/timer_list.c +2
-0@@ -64,6 +64,8 @@ static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *bunsigned long flags; next_one: +if (m &&seq_has_overflowed (m)) +return ;
But it's harmless, right? I mean the bad outcome is just to spend useless cycles seeking and storing?
Still probably makes sense though.
Quoted 6 lines
kernel/time/timer_list.c +0
-0i =0 ;touch_nmi_watchdog ();Signature · 1 line
2.43.0
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Yes exactly - harmless, but unnecessary and wasteful.
Quoted 48 lines · Frederic Weisbecker
Quoted 25 lines · Avi Weiss
When
/proc/timer_listoverflows itsseq_filebuffer,seq_fileretries formatting with a larger buffer.print_active_timers()nevertheless continues scanning the remaining hrtimers, restarting its quadratic traversal even though the overflowing attempt will be discarded.Stop traversing at
next_onewhen theseq_filehas overflowed. Preserve the SysRq console path, which passes a NULLseq_filepointer.In a (virtual) two-CPU KVM guest with 2,048 timerfds pinned to one CPU, median reader CPU time for a complete
/proc/timer_listread fell from 51.1 ms to 14.6 ms. Repeated tests showed no material slowdown for non-overflowing reads (13.7us before versus 13.8 after). Short reads, seek-to-start, and SysRq-Q tests also look fine.Fixes 289f480af87e ("[PATCH] Add debugging feature /proc/timer_list")Signed-off-by Avi Weiss <[email protected]>--- kernel/time/timer_list.c | 2 ++ 1 file changed, 2 insertions(+)kernel/time/timer_list.c +0
-0kernel/time/timer_list.c static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *b · line 68
Quoted 5 lines
kernel/time/timer_list.c +2
-0@@ -64,6 +64,8 @@ static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *bunsigned long flags; next_one: +if (m &&seq_has_overflowed (m)) +return ;But it's harmless, right? I mean the bad outcome is just to spend useless cycles seeking and storing?
Still probably makes sense though.
Quoted 6 lines
kernel/time/timer_list.c +0
-1i =0 ;touch_nmi_watchdog (); --2.43.0
--
Frederic Weisbecker
SUSE Labs
[tip: timers/core] timer_list: Stop hrtimer queue traversal after seq_file overflow
In reply to Avi WeissThe following commit has been merged into the timers/core branch of tip:
The following commit has been merged into the timers/core branch of tip:
Commit-ID: f6fb9be3bfc9a42e478e7fd7e37408be86a95b9d Gitweb: https://git.kernel.org/tip/f6fb9be3bfc9a42e478e7fd7e37408be86a95b9d Author: Avi Weiss <[email protected]> AuthorDate: Tue, 03 Nov 2026 12:34:39 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 09 Nov 2026 20:25:25 +01:00
timer_list: Stop hrtimer queue traversal after seq_file overflow
When /proc/timer_list overflows its seq_file buffer, seq_file retries formatting with a larger buffer. print_active_timers() nevertheless continues scanning the remaining hrtimers, restarting its quadratic traversal even though the overflowing attempt will be discarded.
Stop traversing at next_one when the seq_file has overflowed. Preserve the SysRq console path, which passes a NULL seq_file pointer.
In a (virtual) two-CPU KVM guest with 2,048 timerfds pinned to one CPU, median reader CPU time for a complete /proc/timer_list read fell from 51.1 ms to 14.6 ms. Repeated tests showed no material slowdown for non-overflowing reads (13.7us before versus 13.8 after). Short reads, seek-to-start, and SysRq-Q tests also look fine.
--- kernel/time/timer_list.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/time/timer_list.c +2 -0
@@ -64,6 +64,8 @@ static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *bunsigned long flags; next_one: +if (m &&seq_has_overflowed (m)) +return ; i =0 ;touch_nmi_watchdog ();