Among the fixes merged today ahead of Linus Torvalds releasing the Linux 6.16-rc7 test kernel release is a lone patch on the “sched/urgent” side to fix possible bogus load average values. Reported system load averages within the kernel’s scheduler code could potentially be off going back to May of 2021.
The sched/urgent pull request sent out earlier today explains:
“A single fix for the scheduler. A recent commit changed the runqueue counter nr_uninterruptible to an unsigned int. Due to the fact that the counters are not updated on migration of a uninterruptble task to a different CPU, these counters can exceed INT_MAX. The counter is cast to long in the load average calculation, which means that the cast expands into negative space resulting in bogus load average values. Convert it back to unsigned long to fix this.”
The “recent” commit that introduced this potential bogus load average value reporting was this commit back in 2021 for the Linux 5.14 kernel.
Oracle’s Aruna Ramakrishna tracked down this issue and further commented on the patch:
“The commit e6fe3f422be1 (“sched: Make multiple runqueue task counters 32-bit”) changed nr_uninterruptible to an unsigned int. But the nr_uninterruptible values for each of the CPU runqueues can grow to large numbers, sometimes exceeding INT_MAX. This is valid, if, over time, a large number of tasks are migrated off of one CPU after going into an uninterruptible state. Only the sum of all nr_interruptible values across all CPUs yields the correct result, as explained in a comment in kernel/sched/loadavg.c.
Change the type of nr_uninterruptible back to unsigned long to prevent overflows, and thus the miscalculation of load average.”
After merging the code, Linus Torvalds took to commenting and questioning why the code is using an unsigned value in the first place.
That fix of changing an unsigned int to an unsigned long and a cast from an int to a long is now merged for Linux 6.16-rc7. In turn this should also be back-ported in the coming days to supported Linux LTS/stable kernels of the past four years.