Xinqi Bao's Git

updated ram_total and ram_free (obsd)
authorTobias Tschinkowitz <[email protected]>
Tue, 15 May 2018 22:45:41 +0000 (00:45 +0200)
committerAaron Marcher <[email protected]>
Wed, 16 May 2018 06:08:48 +0000 (08:08 +0200)
components/ram.c

index 62e9807..1178837 100644 (file)
@@ -59,6 +59,8 @@
        #include <sys/types.h>
        #include <unistd.h>
 
        #include <sys/types.h>
        #include <unistd.h>
 
+       #define LOG1024         10
+
        inline int
        load_uvmexp(struct uvmexp *uvmexp)
        {
        inline int
        load_uvmexp(struct uvmexp *uvmexp)
        {
@@ -79,8 +81,7 @@
 
                if (load_uvmexp(&uvmexp)) {
                        free_pages = uvmexp.npages - uvmexp.active;
 
                if (load_uvmexp(&uvmexp)) {
                        free_pages = uvmexp.npages - uvmexp.active;
-                       free = (double) (free_pages * uvmexp.pagesize) / 1024 /
-                              1024 / 1024;
+                       free = (float)(free_pages << (uvmexp.pageshift - LOG1024)) / 1024 / 1024; 
                        return bprintf("%f", free);
                }
 
                        return bprintf("%f", free);
                }
 
                float total;
 
                if (load_uvmexp(&uvmexp)) {
                float total;
 
                if (load_uvmexp(&uvmexp)) {
-                       total = (double) (uvmexp.npages * uvmexp.pagesize) /
-                               1024 / 1024 / 1024;
+                       total = (float)(uvmexp.npages << (uvmexp.pageshift - LOG1024)) / 1024 / 1024; 
                        return bprintf("%f", total);
                }
 
                        return bprintf("%f", total);
                }