]> granicus.if.org Git - procps-ng/commitdiff
library: fix order of operations for %use of slabinfo
authorCraig Small <csmall@enc.com.au>
Mon, 25 Apr 2016 10:24:20 +0000 (20:24 +1000)
committerCraig Small <csmall@enc.com.au>
Mon, 25 Apr 2016 10:24:20 +0000 (20:24 +1000)
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 99d71ad5810b8fbfab5c4c6be97f3e86953b6157
 http://www.freelists.org/post/procps/PATCH-bprocps-fix-order-of-operations-for-use-of-slabinfo

proc/slab.c

index 2a3c5f7dc700a9da763133a9fd59afee4da1e9b5..a3c5dca6d72827f8f906736dc2cebbffa1140652 100644 (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;