[procps] fix regression created by 99d71ad

  • From: Takayuki Nagata <tnagata@xxxxxxxxxx>
  • To: procps@xxxxxxxxxxxxx
  • Date: Thu, 4 Aug 2016 06:04:04 -0400 (EDT)

Hi,

I have found a regression created by my 99d71ad.
I have fixed it, and have tested again.

[Test Results]

With 99d71ad:
# slabtop -o
 Active / Total Objects (% used)    : 51108440 / 51120763 (100.0%)
 Active / Total Slabs (% used)      : 129448 / 129448 (100.0%)
 Active / Total Caches (% used)     : 76 / 110 (69.1%)
 Active / Total Size (% used)       : 550881.62K / 556812.11K (98.9%)
 Minimum / Average / Maximum Object : 0.01K / 0.01K / 8.00K

  OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME                   
50085888 50085888 100%    0.01K  97824      512    391296K kmalloc-8          
<-- correct %use (fixed original issue)
399483 399483 100%    0.19K  19023       21     76092K dentry                 
129536 128653   0%    0.03K   1012      128      4048K kmalloc-32             
<-- wrong %use (created regression)
127500 127500 100%    0.02K    750      170      3000K scsi_data_buffer       
 99200  99200 100%    0.06K   1550       64      6200K kmalloc-64             
 57344  57344 100%    0.02K    224      256       896K kmalloc-16             
 49011  49011 100%    0.08K    961       51      3844K Acpi-State             
 36735  32637   0%    1.06K   2449       15     39184K xfs_inode              
<-- wrong %use (created regression)
 29068  23208   0%    0.15K   1118       26      4472K xfs_ili                
<-- wrong %use (created regression)
 29055  29055 100%    0.10K    745       39      2980K buffer_head            
 17272  17272 100%    0.12K    508       34      2032K kernfs_node_cache      
 14308  14308 100%    0.55K   1022       14      8176K inode_cache            
  5754   5754 100%    0.57K    411       14      3288K radix_tree_node        
  5250   5250 100%    0.09K    125       42       500K kmalloc-96             
  4116   3988   0%    0.19K    196       21       784K cred_jar               
<-- wrong %use (created regression)
  3072   3072 100%    0.06K     48       64       192K anon_vma_chain         

Without 99d71ad:
# slabtop -o
 Active / Total Objects (% used)    : 51111248 / 51123147 (100.0%)
 Active / Total Slabs (% used)      : 129522 / 129522 (100.0%)
 Active / Total Caches (% used)     : 76 / 110 (69.1%)
 Active / Total Size (% used)       : 551429.75K / 557128.55K (99.0%)
 Minimum / Average / Maximum Object : 0.01K / 0.01K / 8.00K

  OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME                   
50085888 50085888  14%    0.01K  97824      512    391296K kmalloc-8          
<-- wrong %use (original issue)
400029 400029 100%    0.19K  19049       21     76196K dentry                 
129536 128653  99%    0.03K   1012      128      4048K kmalloc-32             
<-- correct %use (no regression)
127500 127500 100%    0.02K    750      170      3000K scsi_data_buffer       
 99584  99584 100%    0.06K   1556       64      6224K kmalloc-64             
 57600  57600 100%    0.02K    225      256       900K kmalloc-16             
 49215  49215 100%    0.08K    965       51      3860K Acpi-State             
 36735  32812  89%    1.06K   2449       15     39184K xfs_inode              
<-- correct %use (no regression)
 29640  29640 100%    0.10K    760       39      3040K buffer_head            
 29068  23381  80%    0.15K   1118       26      4472K xfs_ili                
<-- correct %use (no regression)
 17272  17272 100%    0.12K    508       34      2032K kernfs_node_cache      
 14308  14308 100%    0.55K   1022       14      8176K inode_cache            
  5838   5838 100%    0.57K    417       14      3336K radix_tree_node        
  5250   5250 100%    0.09K    125       42       500K kmalloc-96             
  4431   4347  98%    0.19K    211       21       844K cred_jar               
<-- correct %use (no regression)
  3072   3072 100%    0.06K     48       64       192K anon_vma_chain         

This fix:
# slabtop -o
 Active / Total Objects (% used)    : 51166965 / 51177637 (100.0%)
 Active / Total Slabs (% used)      : 132006 / 132006 (100.0%)
 Active / Total Caches (% used)     : 76 / 110 (69.1%)
 Active / Total Size (% used)       : 561516.01K / 566932.82K (99.0%)
 Minimum / Average / Maximum Object : 0.01K / 0.01K / 8.00K

  OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME                   
50085888 50085888 100%    0.01K  97824      512    391296K kmalloc-8          
<-- correct %use (fixed original issue)
450744 450744 100%    0.19K  21464       21     85856K dentry                 
130944 130632  99%    0.03K   1023      128      4092K kmalloc-32             
<-- correct %use (fixed regression)
127500 127500 100%    0.02K    750      170      3000K scsi_data_buffer       
100032 100032 100%    0.06K   1563       64      6252K kmalloc-64             
 57600  57600 100%    0.02K    225      256       900K kmalloc-16             
 49419  49419 100%    0.08K    969       51      3876K Acpi-State             
 36735  32951  89%    1.06K   2449       15     39184K xfs_inode              
<-- correct %use (fixed regression)
 31122  31122 100%    0.10K    798       39      3192K buffer_head            
 29068  23868  82%    0.15K   1118       26      4472K xfs_ili                
<-- correct %use (fixed regression)
 17272  17272 100%    0.12K    508       34      2032K kernfs_node_cache      
 14308  14308 100%    0.55K   1022       14      8176K inode_cache            
  6076   6076 100%    0.57K    434       14      3472K radix_tree_node        
  5292   5292 100%    0.09K    126       42       504K kmalloc-96             
  4305   4204  97%    0.19K    205       21       820K cred_jar               
<-- correct %use (fixed regression)
  3200   3200 100%    0.06K     50       64       200K anon_vma_chain         

Thanks,
Takayuki NagataFrom 991ed5b25d2604ad8e4106861f88816d31e96a13 Mon Sep 17 00:00:00 2001
From: Takayuki Nagata <tnagata@xxxxxxxxxx>
Date: Wed, 27 Jul 2016 17:29:15 +0900
Subject: [PATCH 1/2] Revert "bprocps: fix order of operations for %use of
 slabinfo"

This reverts commit 99d71ad5810b8fbfab5c4c6be97f3e86953b6157.

When nr_active_objs / nr_objs is calculated, the result will be 1
or 0 since the variables are integer. So the commit is wrong.
---
 proc/slab.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/proc/slab.c b/proc/slab.c
index 2d7f967..444b79c 100644
--- a/proc/slab.c
+++ b/proc/slab.c
@@ -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 * curr->nr_active_objs / curr->nr_objs;
                        stats->nr_active_caches++;
                } else
                        curr->use = 0;
-- 
2.7.4

From 40fd010ff285a0ef3762f60c4eb3caceb6a795f1 Mon Sep 17 00:00:00 2001
From: Takayuki Nagata <tnagata@xxxxxxxxxx>
Date: Thu, 4 Aug 2016 18:06:06 +0900
Subject: [PATCH 2/2] libprocps: use float to calculate %use of slabtop

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@xxxxxxxxxx>
---
 proc/slab.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/proc/slab.c b/proc/slab.c
index 444b79c..4917741 100644
--- a/proc/slab.c
+++ b/proc/slab.c
@@ -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;
-- 
2.7.4

Other related posts: