OSSP CVS Repository

ossp - Check-in [3619]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3619
Date: 2003-Sep-20 12:33:17 (local)
2003-Sep-20 10:33:17 (UTC)
User:rse
Branch:
Comment: Reimplement the FreeBSD sysVMRam* variables because the vmstat->avm is totally bogus and cannot be used for RAM usage determination at all. Instead calculate the stuff through the only reliable source: the vm.stats.vm* sysctl(8) variables which directly came from the kernel variables of the VM subsystem. The used calculation in sysVM.pm is now derived from a larger basic research on this topic resulting in a script which gives this output:

SYSTEM MEMORY INFORMATION: mem_wire: 179642368 ( 171MB) [ 8%] Wired: disabled for paging out mem_active: + 158838784 ( 151MB) [ 7%] Active: recently referenced mem_inactive:+ 1147584512 ( 1094MB) [ 54%] Inactive: recently not referenced mem_cache: + 71606272 ( 68MB) [ 3%] Cached: almost avail. for allocation mem_free: + 549912576 ( 524MB) [ 26%] Free: fully available for allocation mem_gap_vm: + 364544 ( 0MB) [ 0%] Memory gap: UNKNOWN

Tickets:
Inspections:
Files:
ossp-pkg/snmpdx/snmpdx.d/sysVM.pm      1.8 -> 1.9     33 inserted, 18 deleted

ossp-pkg/snmpdx/snmpdx.d/sysVM.pm 1.8 -> 1.9

--- sysVM.pm     2003/09/20 10:11:22     1.8
+++ sysVM.pm     2003/09/20 10:33:17     1.9
@@ -40,9 +40,9 @@
         ##
         ##  FreeBSD 4/5
         ##
-        ##  sysVMRamMax   "/sbin/sysctl -n hw.physmem", convert bytes to MB
+        ##  sysVMRamMax   "/sbin/sysctl -a", "hw.physmem", convert bytes to MB
         ##  sysVMRamUsed  sysVMRamMax - sysVMRamFree
-        ##  sysVMRamFree  "/usr/bin/vmstat", avm, convert KB to MB
+        ##  sysVMRamFree  "/sbin/sysctl -a", "vm.stats.vm.*", convert pages to MB
         ##  sysVMSwapMax  "/usr/sbin/swapinfo -k", 1K-blocks, last line, convert KB to MB
         ##  sysVMSwapUsed "/usr/sbin/swapinfo -k", Used, last line, convert KB to MB
         ##  sysVMSwapFree sysVMSwapMax - sysVMSwapUsed
@@ -53,28 +53,26 @@
             my $sysVMRamUsed = undef;
             my $sysVMRamFree = undef;
 
-            #   determine sysVMRamMax
-            my $out = $self->{-ctx}->{-sys}->run("/sbin/sysctl -n hw.physmem", "forever");
-            my $raw = $out->{-stdout};
-            if ($raw =~ m/^(\d+)$/) {
-                $sysVMRamMax = int($1 / (1024*1024));
+            #   query system for sysctl(8) variables
+            my $out = $self->{-ctx}->{-sys}->run("/sbin/sysctl -a", "1m");
+            my $sysctl = {};
+            foreach my $line (split(/\n/, $out->{-stdout})) {
+                $sysctl->{$1} = $2 if ($line =~ m/^([^:]+):\s+(.+)\s*$/s);
             }
 
+            #   determine sysVMRamMax
+            $sysVMRamMax = int(&mem_rounded($sysctl->{"hw.physmem"}) / (1024*1024));
+
             #   determine sysVMRamFree
-            $out = $self->{-ctx}->{-sys}->run("/usr/bin/vmstat", "1m");
-            $raw = $out->{-stdout};
-            my $n2i = {};
-            if ($raw =~ m/^[^\n]*\n *([^\n]*\bavm\b[^\n]*)\n *([^\n]*)\n$/s) {
-                $n2i = &mkn2i(split(/\s+/, $1));
-            }
-            if (defined($n2i->{avm})) {
-                my @dat = split(/\s+/, $2);
-                $sysVMRamFree = int(@dat[$n2i->{avm}] / 1024);
-            }
+            my $sysVMRamFree =
+                int((  $sysctl->{"hw.pagesize"}
+                     * (  $sysctl->{"vm.stats.vm.v_inactive_count"} 
+                        + $sysctl->{"vm.stats.vm.v_cache_count"}
+                        + $sysctl->{"vm.stats.vm.v_free_count"}    )) / (1024*1024));
 
             #   determine sysVMRamUsed
             if (defined($sysVMRamMax) and defined($sysVMRamFree)) {
-                $sysVMRamUsed = $sysVMRamMax - $sysVMRamFree;
+                $sysVMRamUsed = ($sysVMRamMax - $sysVMRamFree);
             }
 
             #   provide result
@@ -352,5 +350,22 @@
     return $rc;
 }
 
+#   round the physical memory size to the next power of two which is
+#   reasonable for memory cards. We do this by first determining the
+#   guessed memory card size under the assumption that usual computer
+#   hardware has an average of a maximally eight memory cards installed
+#   and those are usually of equal size.
+sub mem_rounded {
+    my ($mem_size) = @_;
+    my $chip_size  = 1;
+    my $chip_guess = ($mem_size / 8) - 1;
+    while ($chip_guess != 0) {
+        $chip_guess >>= 1;
+        $chip_size  <<= 1;
+    }
+    my $mem_round = (int($mem_size / $chip_size) + 1) * $chip_size;
+    return $mem_round;
+}
+
 1;
 

CVSTrac 2.0.1