Xinqi Bao's Git

consistent calculation of ram_* on openbsd
authorTobias Tschinkowitz <[email protected]>
Wed, 16 May 2018 07:57:38 +0000 (09:57 +0200)
committerAaron Marcher <[email protected]>
Wed, 16 May 2018 10:24:43 +0000 (12:24 +0200)
components/ram.c

index 1178837..57081d2 100644 (file)
@@ -60,6 +60,7 @@
        #include <unistd.h>
 
        #define LOG1024         10
+       #define pagetok(size, pageshift) ((size) << (pageshift - LOG1024))
 
        inline int
        load_uvmexp(struct uvmexp *uvmexp)
@@ -81,7 +82,7 @@
 
                if (load_uvmexp(&uvmexp)) {
                        free_pages = uvmexp.npages - uvmexp.active;
-                       free = (float)(free_pages << (uvmexp.pageshift - LOG1024)) / 1024 / 1024; 
+                       free = (float)(pagetok(free_pages, uvmexp.pageshift)) / 1024 / 1024;
                        return bprintf("%f", free);
                }
 
                float total;
 
                if (load_uvmexp(&uvmexp)) {
-                       total = (float)(uvmexp.npages << (uvmexp.pageshift - LOG1024)) / 1024 / 1024; 
+                       total = (float)(pagetok(uvmexp.npages, uvmexp.pageshift)) / 1024 / 1024;
                        return bprintf("%f", total);
                }
 
                float used;
 
                if (load_uvmexp(&uvmexp)) {
-                       used = (double) (uvmexp.active * uvmexp.pagesize) /
-                              1024 / 1024 / 1024;
+                       used = (float)(pagetok(uvmexp.active, uvmexp.pageshift)) / 1024 / 1024;
                        return bprintf("%f", used);
                }