sched/numa: Fix time unit mismatch in scan staggering
PATCH 1/1 sched/numa: Fix time unit mismatch in scan staggering
init_numa_balancing() stores node_stamp in nanoseconds, but task_scan_max() and numa_scan_period are in milliseconds. The existing min_t() compares task_scan_max() in milliseconds with a nanosecond value, so it can initialize node_stamp far too small and defeat staggering for new threads sharing an mm.
For example, with the default scan periods and two mm users, the intended stagger is 2000 ms. The existing code instead computes a 60000 ns delay; after adding the two-tick offset, node_stamp is about 2.06 ms with HZ=1000.
Moreover, min_t() and delay use unsigned int, so nanosecond values above UINT_MAX are truncated. On 32-bit systems, the multiplication can also overflow before the value is converted.
Compare the delay in milliseconds using u64 and convert to nanoseconds after the minimum is selected. This preserves the intended cap and keeps node_stamp in the unit consumed by task_tick_numa().
This prevents NUMA balancing scans from being concentrated for multithreaded workloads and avoids shortening the initial stagger through integer truncation.
--- kernel/sched/fair.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
kernel/sched/fair.c +4 -5
@@ -4413,12 +4413,11 @@ void init_numa_balancing(u64 clone_flags, struct task_struct *p)* already by arch_dup_task_struct but stagger when scans start. */ if (mm) { -unsigned int delay; +u64 delay_ms; - delay = min_t(unsigned int, task_scan_max(current), - current->numa_scan_period * mm_users *NSEC_PER_MSEC ); - delay +=2 *TICK_NSEC ; - p->node_stamp = delay; + delay_ms = (u64 )current->numa_scan_period * mm_users; + delay_ms =min_t (u64, delay_ms,task_scan_max (current)); + p->node_stamp = delay_ms *NSEC_PER_MSEC +2 *TICK_NSEC ; } }
Signature · 1 line
2.54.0