]> granicus.if.org Git - procps-ng/commitdiff
libprocps: use float to calculate %use of slabtop
authorTakayuki Nagata <tnagata@redhat.com>
Thu, 4 Aug 2016 09:06:06 +0000 (18:06 +0900)
committerTakayuki Nagata <tnagata@redhat.com>
Wed, 12 Oct 2016 07:59:01 +0000 (16:59 +0900)
In some environments, 100 * nr_active_objs is calculated at first,
and the result of lower 32bits is divided by nr_objs. This occurs
even in a 64-bit architecture. So nr_active_objes > 42949672, %use
will be incorrect.

This fix casts type of nr_active_objs to float to calculate
correctly the %use in 32-bit/64-bit architectures.

Signed-off-by: Takayuki Nagata <tnagata@redhat.com>
proc/slab.c

index 444b79cc4e8ff6d9dc7f97aa2813d0479782bf50..491774163da3bf096957004d647d00f650743c26 100644 (file)
@@ -179,7 +179,7 @@ static int parse_slabinfo20(struct slab_info **list, struct slab_stat *stats,
                curr->cache_size = (unsigned long)curr->nr_slabs * curr->pages_per_slab * page_size;
 
                if (curr->nr_objs) {
-                       curr->use = 100 * curr->nr_active_objs / curr->nr_objs;
+                       curr->use = 100 * (float)curr->nr_active_objs / curr->nr_objs;
                        stats->nr_active_caches++;
                } else
                        curr->use = 0;
@@ -258,7 +258,7 @@ static int parse_slabinfo11(struct slab_info **list, struct slab_stat *stats,
                curr->cache_size = (unsigned long)curr->nr_slabs * curr->pages_per_slab * page_size;
 
                if (curr->nr_objs) {
-                       curr->use = 100 * curr->nr_active_objs / curr->nr_objs;
+                       curr->use = 100 * (float)curr->nr_active_objs / curr->nr_objs;
                        stats->nr_active_caches++;
                } else
                        curr->use = 0;