Skip to content

vmstat: Errors in calculations

Roman Žilka requested to merge rz-contrib/procps:issue252 into master

In src/vmstat.c:

  1. It seems that cpu_gue may be calculated incorrectly in the second and subsequent lines of wide VM-mode output: stat_GST and stat_GNI are interpreted as llu instead of ld. Also, looks like a possible UB.
  2. There's a type mismatch in the global and local output repetition counters.
  3. I cannot reproduce #252, but the constraining of cpu_* into an unsigned in VM-mode printf seems unnecessary, at least. Outputting them as lld may shed some more light on the issue. There's unchecked arithmetic all over the place on signed types. According to linux/Documentation/filesystems/proc.rst, iowait, for instance, is unreliable in /proc/stat and may decrease over time. That may produce a negative Div as well.

In library/stat.c:

  1. In the macro TICsetH for calculating value deltas a huge ULL can be assigned to a smaller int (signed or unsigned) when new_value < previous_value. May affect #252, because iowait can decrease.
Edited by Roman Žilka

Merge request reports