[Crash-utility] [PATCH] Fix for swap used percentage reporting when totalswap_pages is 0.

John Siddle jsiddle at redhat.com
Wed Aug 17 17:59:39 UTC 2016


Without the patch, when totalswap_pages is 0, swap used percentage
reports as 100%. This is confusing on first glance as it seems to
indicate potential memory pressure. Fix this and also fix indentation on
'pct' calculations to improve readability.
---
 memory.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/memory.c b/memory.c
index e994d13..f39c667 100644
--- a/memory.c
+++ b/memory.c
@@ -8302,12 +8302,12 @@ dump_kmeminfo(void)
 			fprintf(fp, "%13s  %7ld  %11s         ----\n", 
 				"TOTAL SWAP", totalswap_pages, 
 				pages_to_size(totalswap_pages, buf));
-				pct = totalswap_pages ? (totalused_pages * 100) /
-				totalswap_pages : 100;
+			pct = totalswap_pages ? (totalused_pages * 100) /
+				totalswap_pages : 0;
 			fprintf(fp, "%13s  %7ld  %11s  %3ld%% of TOTAL SWAP\n",
 				"SWAP USED", totalused_pages,
 				pages_to_size(totalused_pages, buf), pct);
-		 		pct = totalswap_pages ? 
+	 		pct = totalswap_pages ? 
 				((totalswap_pages - totalused_pages) *
 				100) / totalswap_pages : 0;
 			fprintf(fp, "%13s  %7ld  %11s  %3ld%% of TOTAL SWAP\n", 
-- 
2.7.4




More information about the Crash-utility mailing list