bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

vmstat cleanups


From: James A Morrison
Subject: vmstat cleanups
Date: Sun, 16 Jun 2002 12:04:55 -0400 (EDT)

 Hi,

  I noticed vmstat wasn't reporting the total amount of memory on my system.
I'm not sure if it is the Hurd or Mach that is incorrectly counting memory
some where, but I suspect it is Mach.  Anyway, here is the patch.

James A. Morrison

2002-06-16  James A. Morrison  <ja2morri@uwaterloo.ca>

        * Makefile (vmstat): Give vmstat it's own target so it can link against
        libps.
        * vmstat.c: Include <ps.h> 
        (get_size): Return the actual memory size of the system, if it is 
        available.
        (fields): Set offset to -1 for computed values.
        (vm_state_refresh): Use memset instead of bzero.
        (main): Likewise.

Index: Makefile
===================================================================
RCS file: /cvsroot/hurd/hurd/utils/Makefile,v
retrieving revision 1.78
diff -u -r1.78 Makefile
--- Makefile    4 May 2002 23:31:20 -0000       1.78
+++ Makefile    16 Jun 2002 15:55:13 -0000
@@ -63,10 +63,12 @@
 # We must include libthreads because of a bug in the way shared libraries
 # work: all libraries that *any* routine in libfshelp uses must be defined.
 settrans: ../libfshelp/libfshelp.a ../libports/libports.a 
../libthreads/libthreads.a
-ps w ids settrans syncfs showtrans fsysopts storeinfo login vmstat portinfo \
+ps w ids settrans syncfs showtrans fsysopts storeinfo login portinfo \
   devprobe vminfo addauth rmauth setauth unsu ftpcp ftpdir storeread \
   storecat msgport mount: \
        ../libshouldbeinlibc/libshouldbeinlibc.a
+
+vmstat: ../libshouldbeinlibc/libshouldbeinlibc.a ../libps/libps.a
 
 $(filter-out $(special-targets), $(targets)): %: %.o
 
Index: vmstat.c
===================================================================
RCS file: /cvsroot/hurd/hurd/utils/vmstat.c,v
retrieving revision 1.20
diff -u -r1.20 vmstat.c
--- vmstat.c    28 May 2002 23:56:34 -0000      1.20
+++ vmstat.c    16 Jun 2002 15:55:15 -0000
@@ -30,6 +30,7 @@
 #include <mach/vm_statistics.h>
 #include <mach/default_pager.h>
 #include <hurd.h>
+#include <ps.h>
 
 const char *argp_program_version = STANDARD_HURD_VERSION (vmstat);
 
@@ -197,7 +198,7 @@
     return err;
 
   /* Mark the info as invalid, but leave DEF_PAGER alone.  */
-  bzero (&state->def_pager_info, sizeof state->def_pager_info);
+  memset (&state->def_pager_info, 0, sizeof state->def_pager_info);
 
   return 0;
 }
@@ -215,10 +216,17 @@
 static val_t
 get_size (struct vm_state *state, const struct field *field)
 {
-  return
-    (state->vmstats.free_count + state->vmstats.active_count
-     + state->vmstats.inactive_count + state->vmstats.wire_count)
-    * state->vmstats.pagesize;
+  error_t err;
+  static host_basic_info_t basic_info;
+  err = ps_host_basic_info (&basic_info);
+
+  if (err)
+    return
+      (state->vmstats.free_count + state->vmstats.active_count
+       + state->vmstats.inactive_count + state->vmstats.wire_count)
+      * state->vmstats.pagesize;
+  else
+    return basic_info->memory_size;
 }
 
 static val_t
@@ -301,7 +309,7 @@
   {"pagesize",    "pgsz", "System pagesize",
    CONST, PAGESZ, 16*K,                1, _F (pagesize) },
   {"size",        "size", "Usable physical memory",
-   CONST, SIZE,   VAL_MAX_MEM, 1, 0, get_size },
+   CONST, SIZE,   VAL_MAX_MEM, 1, -1, get_size },
   {"free",        "free", "Unused physical memory",
    VARY,  SIZE,   VAL_MAX_MEM, 1, _F (free_count) },
   {"active",      "actv", "Physical memory in active use",
@@ -329,13 +337,13 @@
   {"memobj hit ratio","hrat","Percentage of memory-object lookups with active 
pagers",
    VARY, PCENT,   99,          1, -1, get_memobj_hit_ratio },
   {"swap size",           "swsize", "Size of the default-pager swap area",
-   CONST, SIZE,   VAL_MAX_SWAP,        1, 0 ,get_swap_size },
+   CONST, SIZE,   VAL_MAX_SWAP,        1, -1 ,get_swap_size },
   {"swap active",  "swactv", "Default-pager swap area in use",
-   VARY,  SIZE,   VAL_MAX_SWAP,        0, 0 ,get_swap_active },
+   VARY,  SIZE,   VAL_MAX_SWAP,        0, -1,get_swap_active },
   {"swap free",           "swfree", "Default-pager swap area available for 
swapping",
-   VARY,  SIZE,   VAL_MAX_SWAP,        1, 0 ,get_swap_free },
+   VARY,  SIZE,   VAL_MAX_SWAP,        1, -1,get_swap_free },
   {"swap pagesize","swpgsz", "Units used for swapping to the default pager",
-   CONST, PAGESZ, 16*K,                0, 0 ,get_swap_page_size },
+   CONST, PAGESZ, 16*K,                0, -1,get_swap_page_size },
   {0}
 };
 #undef _F
@@ -416,7 +424,7 @@
   /* Construct an options vector for them.  */
   field_opts_size = ((num_fields + 1) * sizeof (struct argp_option));
   field_opts = alloca (field_opts_size);
-  bzero (field_opts, field_opts_size);
+  memset (field_opts, 0, field_opts_size);
 
   for (field = fields; field->name; field++)
     {
@@ -428,7 +436,7 @@
       opt->doc = field->doc;
       opt->group = 2;
     }
-  /* No need to terminate FIELD_OPTS because the bzero above's done so.  */
+  /* No need to terminate FIELD_OPTS because the memset above has done so.  */
 
   field_argp.options = field_opts;
 
@@ -461,7 +469,7 @@
               (field)->type, SIZE_UNITS (field))
 
   /* Actually fetch the statistics.  */
-  bzero (&state, sizeof (state)); /* Initialize STATE.  */
+  memset (&state, 0, sizeof (state)); /* Initialize STATE.  */
   err = vm_state_refresh (&state);
   if (err)
     error (2, err, "vm_state_refresh");



reply via email to

[Prev in Thread] Current Thread [Next in Thread]