library: fix order of operations for %use of slabinfo

In some environments, 100 * nr_active_objs is calculated at first,
and lower 32bit of the result is divided by nr_objs.
If 100 * nr_active_objs > 42949672, %use will be incorrect.

Reported by Takayuki Nagata <tnagata@redhat.com> and adopted
his patch for new library (see reference)

References:
 commit 99d71ad581
 http://www.freelists.org/post/procps/PATCH-bprocps-fix-order-of-operations-for-use-of-slabinfo
This commit is contained in:
Craig Small 2016-04-25 20:24:20 +10:00
parent 9c877bf636
commit 40de1c9c7c

View File

@ -231,7 +231,7 @@ static int parse_slabinfo20 (
* page_size;
if (node->nr_objs) {
node->use = (unsigned int)100 * node->nr_active_objs / node->nr_objs;
node->use = (unsigned int)100 * (node->nr_active_objs / node->nr_objs);
stats->nr_active_caches++;
} else
node->use = 0;