[vbox-dev] [patch] FreeBSD: fix getHostMemoryUsage

Bernhard Froehlich decke at bluelife.at
Thu Sep 17 12:05:03 PDT 2009


A few users had problems starting VMs on FreeBSD because the available memory
seems to be calculated wrong. Available memory on FreeBSD means Free + Inactive +
Cached if i'm not totally wrong.

This patch is under the MIT License.

http://home.bluelife.at/ports/virtualbox/vbox-freebsd-fix-getHostMemoryUsage.patch

-- 
Bernhard Froehlich
http://www.bluelife.at/


--- src/VBox/Main/freebsd/PerformanceFreeBSD.cpp.orig	2009-04-21 13:43:22.000000000 +0200
+++ src/VBox/Main/freebsd/PerformanceFreeBSD.cpp	2009-09-17 20:11:05.000000000 +0200
@@ -65,6 +65,8 @@
     int rc = VINF_SUCCESS;
     u_long cbMemPhys = 0;
     u_int cPagesMemFree = 0;
+    u_int cPagesMemInactive = 0;
+    u_int cPagesMemCached = 0;
     u_int cPagesMemUsed = 0;
     int cbPage = 0;
     size_t cbParameter = sizeof(cbMemPhys);
@@ -79,15 +81,21 @@
     cbParameter = sizeof(cPagesMemUsed);
     if (!sysctlbyname("vm.stats.vm.v_active_count", &cPagesMemUsed, &cbParameter, NULL, 0))
         cProcessed++;
+    cbParameter = sizeof(cPagesMemInactive);
+    if (!sysctlbyname("vm.stats.vm.v_inactive_count", &cPagesMemInactive, &cbParameter, NULL, 0))
+        cProcessed++;
+    cbParameter = sizeof(cPagesMemCached);
+    if (!sysctlbyname("vm.stats.vm.v_cache_count", &cPagesMemCached, &cbParameter, NULL, 0))
+        cProcessed++;
     cbParameter = sizeof(cbPage);
     if (!sysctlbyname("hw.pagesize", &cbPage, &cbParameter, NULL, 0))
         cProcessed++;
 
-    if (cProcessed == 4)
+    if (cProcessed == 6)
     {
         *total     = cbMemPhys / _1K;
         *used      = cPagesMemUsed * (cbPage / _1K);
-        *available = cPagesMemFree * (cbPage / _1K);
+        *available = (cPagesMemFree + cPagesMemInactive + cPagesMemCached ) * (cbPage / _1K);
     }
     else
         rc = VERR_NOT_SUPPORTED;




More information about the vbox-dev mailing list