A little gadget to dump the contents of the vfs name cache.

This commit is contained in:
Poul-Henning Kamp 1997-09-04 08:28:55 +00:00
parent 4d1122bdd6
commit c9e186fb37
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=29095
3 changed files with 137 additions and 0 deletions

View File

@ -0,0 +1,11 @@
PROG= dumpvfscache
LDADD= -lkvm -lmd
NOMAN= 1
test: ${PROG}
./${PROG} > a
.include <bsd.prog.mk>

View File

@ -0,0 +1,6 @@
This is a little C-program that can be used to examine the contents of
the vfs name cache. It's very likely to loop and crash if you use it
on an active system.
Poul-Henning Kamp
4 sep 1997

View File

@ -0,0 +1,120 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <kvm.h>
#include <nlist.h>
#include <sys/uio.h>
#include <sys/namei.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/vnode.h>
/*----------------------------------*/
static u_int crc16_table[16] = {
0x0000, 0xCC01, 0xD801, 0x1400,
0xF001, 0x3C00, 0x2800, 0xE401,
0xA001, 0x6C00, 0x7800, 0xB401,
0x5000, 0x9C01, 0x8801, 0x4400
};
static u_short
wlpsacrc(u_char *buf, u_int len)
{
u_short crc = 0;
int i, r1;
for (i = 0; i < len; i++, buf++) {
/* lower 4 bits */
r1 = crc16_table[crc & 0xF];
crc = (crc >> 4) & 0x0FFF;
crc = crc ^ r1 ^ crc16_table[*buf & 0xF];
/* upper 4 bits */
r1 = crc16_table[crc & 0xF];
crc = (crc >> 4) & 0x0FFF;
crc = crc ^ r1 ^ crc16_table[(*buf >> 4) & 0xF];
}
return(crc);
}
/*----------------------------------*/
struct nlist nl[] = {
{ "_nchash", 0},
{ "_nchashtbl", 0},
{ 0, 0 },
};
int histo[2047];
int histn[2047];
int *newbucket;
int
main(int argc, char **argv)
{
int nchash, i, j, k, kn;
int nb, p1, p2;
u_long p;
LIST_HEAD(nchashhead, namecache) *nchashtbl;
struct namecache *nc;
struct vnode vn;
kvm_t *kvm = kvm_open(0, 0, 0, O_RDONLY, 0);
printf("kvm: %p\n", kvm);
printf("kvm_nlist: %d\n", kvm_nlist(kvm, nl));
kvm_read(kvm, nl[0].n_value, &nchash, sizeof nchash);
nchash++;
nchashtbl = malloc(nchash * sizeof *nchashtbl);
nc = malloc(sizeof *nc + 400);
newbucket = malloc(nchash * sizeof (int));
memset(newbucket, 0, nchash * sizeof (int));
kvm_read(kvm, nl[1].n_value, &p, sizeof p);
kvm_read(kvm, p, nchashtbl, nchash * sizeof *nchashtbl);
for (i=0; i < nchash; i++) {
#if 0
printf("%d\n", i);
#endif
nb=0;
p = (u_long)LIST_FIRST(nchashtbl+i);
while (p) {
nb++;
kvm_read(kvm, p, nc, sizeof *nc + 400);
kvm_read(kvm, (u_long)nc->nc_dvp, &vn, sizeof vn);
nc->nc_name[nc->nc_nlen] = '\0';
for (j=k=kn=0;nc->nc_name[j];j++) {
k+= nc->nc_name[j];
kn <<= 1;
kn+= nc->nc_name[j];
}
/*
kn = k;
*/
kn = wlpsacrc(nc->nc_name,nc->nc_nlen);
/* kn += (u_long)vn.v_data >> 8; */
/* kn += (u_long)nc->nc_dvp >> 7; */
kn += vn.v_id;
kn &= (nchash - 1);
newbucket[kn]++;
#if 1
printf("%4d dvp %08x hash %08x vp %08x id %08x name <%s>\n",
i,nc->nc_dvp, k, nc->nc_vp, vn.v_id, nc->nc_name);
#endif
p = (u_long)LIST_NEXT(nc, nc_hash);
}
histo[nb]++;
}
for (i=0; i < nchash; i++) {
histn[newbucket[i]]++;
}
p1=p2 = 0;
for (i=0;i<30;i++) {
p1 += histo[i] * i;
p2 += histn[i] * i;
if (histo[i] || histn[i])
printf("H%02d %4d %4d / %4d %4d\n",i,histo[i], p1 , histn[i], p2);
}
return (0);
}