Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/vmstat For vmstat -h/-H, calculate the hash element ...



details:   https://anonhg.NetBSD.org/src/rev/9c1eb1dfd1e8
branches:  trunk
changeset: 959984:9c1eb1dfd1e8
user:      simonb <simonb%NetBSD.org@localhost>
date:      Wed Mar 03 08:25:16 2021 +0000

description:
For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq.  Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.

diffstat:

 usr.bin/vmstat/vmstat.c |  20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diffs (41 lines):

diff -r 2169d179ae38 -r 9c1eb1dfd1e8 usr.bin/vmstat/vmstat.c
--- a/usr.bin/vmstat/vmstat.c   Tue Mar 02 22:21:38 2021 +0000
+++ b/usr.bin/vmstat/vmstat.c   Wed Mar 03 08:25:16 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vmstat.c,v 1.242 2020/06/14 21:41:42 ad Exp $ */
+/* $NetBSD: vmstat.c,v 1.243 2021/03/03 08:25:16 simonb Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020
@@ -71,7 +71,7 @@
 #if 0
 static char sccsid[] = "@(#)vmstat.c   8.2 (Berkeley) 3/1/95";
 #else
-__RCSID("$NetBSD: vmstat.c,v 1.242 2020/06/14 21:41:42 ad Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.243 2021/03/03 08:25:16 simonb Exp $");
 #endif
 #endif /* not lint */
 
@@ -1964,8 +1964,20 @@
                if (hashname != NULL &&
                    strcmp(hashnl[curhash->hashsize].n_name + 1, hashname))
                        continue;
-               elemsize = curhash->type == HASH_LIST ?
-                   sizeof(*hashtbl_list) : sizeof(*hashtbl_tailq);
+               switch (curhash->type) {
+               case HASH_LIST:
+                       elemsize = sizeof(*hashtbl_list);
+                       break;
+               case HASH_SLIST:
+                       elemsize = sizeof(*hashtbl_slist);
+                       break;
+               case HASH_TAILQ:
+                       elemsize = sizeof(*hashtbl_tailq);
+                       break;
+               default:
+                       /* shouldn't get here */
+                       continue;
+               }
                deref_kptr((void *)hashnl[curhash->hashsize].n_value,
                    &hashsize, sizeof(hashsize),
                    hashnl[curhash->hashsize].n_name);



Home | Main Index | Thread Index | Old Index