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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility



[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux