Skip to contentSkip to conversation

timers: Stop hrtimer queue traversal after seq_file overflow

PATCH Applied Avi Weiss 3 participants 4 messages Nov 3 – Nov 9 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

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.

Fixes 289f480af87e ("[PATCH] Add debugging feature /proc/timer_list")
---
 kernel/time/timer_list.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/time/timer_list.c +2 -0
index 0406bf4488e9..84275b6cd2c9 100644
@@ -64,6 +64,8 @@ static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *b
 	unsigned long flags;
 
 next_one:
+	if (m && seq_has_overflowed(m))
+		return;
 	i = 0;
 
 	touch_nmi_watchdog();
Signature · 1 line
2.43.0
#1 lore raw
Quoted 25 lines · Avi Weiss

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.

Fixes 289f480af87e ("[PATCH] Add debugging feature /proc/timer_list")
---
 kernel/time/timer_list.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/time/timer_list.c +0 -0
index 0406bf4488e9..84275b6cd2c9 100644

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 *b
 	unsigned 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 -0
 	i = 0;
 
 	touch_nmi_watchdog();
Signature · 1 line
2.43.0
Signature · 2 lines
Frederic Weisbecker
SUSE Labs
author
#2 lore raw

Yes exactly - harmless, but unnecessary and wasteful.

Quoted 48 lines · Frederic Weisbecker
Quoted 25 lines · Avi Weiss

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.

Fixes 289f480af87e ("[PATCH] Add debugging feature /proc/timer_list")
---
 kernel/time/timer_list.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/time/timer_list.c +0 -0
index 0406bf4488e9..84275b6cd2c9 100644

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 *b
      unsigned 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 -1
      i = 0;
 
      touch_nmi_watchdog();
--

2.43.0

--
Frederic Weisbecker
SUSE Labs

merge bot Applied
#3 lore raw

[tip: timers/core] timer_list: Stop hrtimer queue traversal after seq_file overflow

In reply to Avi Weiss
The 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
index 0406bf4..84275b6 100644
@@ -64,6 +64,8 @@ static void print_active_timers(struct seq_file *m, struct hrtimer_clock_base *b
 	unsigned long flags;
 
 next_one:
+	if (m && seq_has_overflowed(m))
+		return;
 	i = 0;
 
 	touch_nmi_watchdog();