corrected calculation for swap on openbsd
authorTobias Tschinkowitz <he4d@posteo.de>
Wed, 16 May 2018 11:26:34 +0000 (13:26 +0200)
committerAaron Marcher <me@drkhsh.at>
Wed, 16 May 2018 17:17:49 +0000 (19:17 +0200)
The swapctl(2) function fills the swapent struct with 512KB blocks.
As we want to display in GB, i just modified the calculation for this to
get the expected output.

components/swap.c

index 031b713f27b8eb8d6dfd163d195d4dfea366d5f9..caa478857bf519d4e54e31f98f6f247a16e22522 100644 (file)
        #include <sys/types.h>
        #include <unistd.h>
 
-       #define dbtoqb(b) dbtob((int64_t)(b))
-
        static void
        getstats(int *total, int *used)
        {
                *used = 0;
 
                for (i = 0; i < rnswap; i++) {
-                       *total += dbtoqb(sep->se_nblks);
-                       *used += dbtoqb(sep->se_inuse);
+                       *total += sep->se_nblks >> 1;
+                       *used += sep->se_inuse >> 1;
                }
 
                free(fsep);
 
                getstats(&total, &used);
 
-               return bprintf("%f", (float)(total - used) / 1024 / 1024 / 1024);
+               return bprintf("%f", (float)(total - used) / 1024 / 1024);
        }
 
        const char *
 
                getstats(&total, &used);
 
-               return bprintf("%f", (float)total / 1024 / 1024 / 1024);
+               return bprintf("%f", (float)total / 1024 / 1024);
        }
 
        const char *
 
                getstats(&total, &used);
 
-               return bprintf("%f", (float)used / 1024 / 1024 / 1024);
+               return bprintf("%f", (float)used / 1024 / 1024);
        }
 #endif