Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/pmap - Don't copy the entire namecache only to look ...
details: https://anonhg.NetBSD.org/src/rev/ee76916def01
branches: trunk
changeset: 1008418:ee76916def01
user: ad <ad%NetBSD.org@localhost>
date: Sun Mar 22 14:41:32 2020 +0000
description:
- Don't copy the entire namecache only to look up a few names. Walk the
data structures like cache_revlookup().
- nchash and mb_map are gone. module_map replaced lkm_map.
diffstat:
usr.bin/pmap/main.c | 121 +++++++--------------------------------------------
usr.bin/pmap/pmap.c | 55 +++++++++++++----------
usr.bin/pmap/pmap.h | 5 +-
3 files changed, 51 insertions(+), 130 deletions(-)
diffs (truncated from 334 to 300 lines):
diff -r 1785921fb184 -r ee76916def01 usr.bin/pmap/main.c
--- a/usr.bin/pmap/main.c Sun Mar 22 14:39:28 2020 +0000
+++ b/usr.bin/pmap/main.c Sun Mar 22 14:41:32 2020 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: main.c,v 1.27 2019/09/13 13:55:24 christos Exp $ */
+/* $NetBSD: main.c,v 1.28 2020/03/22 14:41:32 ad Exp $ */
/*
- * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
+ * Copyright (c) 2002, 2003, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.27 2019/09/13 13:55:24 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.28 2020/03/22 14:41:32 ad Exp $");
#endif
#include <sys/param.h>
@@ -54,11 +54,10 @@
#include "main.h"
struct cache_head lcache;
-struct nchashhead *nchashtbl;
void *uvm_vnodeops, *uvm_deviceops, *aobj_pager, *ubc_pager;
-struct vm_map *kmem_map, *mb_map, *phys_map, *exec_map, *pager_map;
-struct vm_map *st_map, *pt_map, *lkm_map, *buf_map;
-u_long nchash_addr, nchashtbl_addr, kernel_map_addr;
+struct vm_map *kmem_map, *phys_map, *exec_map, *pager_map;
+struct vm_map *st_map, *pt_map, *module_map, *buf_map;
+u_long kernel_map_addr;
int debug, verbose, recurse, page_size;
int print_all, print_map, print_maps, print_solaris, print_ddb;
rlim_t maxssiz;
@@ -76,32 +75,26 @@
#define NL_UBC_PAGER 4
{ "_kernel_map", 0, 0, 0, 0 },
#define NL_KERNEL_MAP 5
- { "_nchashtbl", 0, 0, 0, 0 },
-#define NL_NCHASHTBL 6
- { "_nchash", 0, 0, 0, 0 },
-#define NL_NCHASH 7
{ NULL, 0, 0, 0, 0 }
};
struct nlist kmaps[] = {
{ "_kmem_map", 0, 0, 0, 0 },
#define NL_kmem_map 0
- { "_mb_map", 0, 0, 0, 0 },
-#define NL_mb_map 1
{ "_phys_map", 0, 0, 0, 0 },
-#define NL_phys_map 2
+#define NL_phys_map 1
{ "_exec_map", 0, 0, 0, 0 },
-#define NL_exec_map 3
+#define NL_exec_map 2
{ "_pager_map", 0, 0, 0, 0 },
-#define NL_pager_map 4
+#define NL_pager_map 3
{ "_st_map", 0, 0, 0, 0 },
-#define NL_st_map 5
+#define NL_st_map 4
{ "_pt_map", 0, 0, 0, 0 },
-#define NL_pt_map 6
- { "_lkm_map", 0, 0, 0, 0 },
-#define NL_lkm_map 7
+#define NL_pt_map 5
+ { "_module_map", 0, 0, 0, 0 },
+#define NL_module_map 6
{ "_buf_map", 0, 0, 0, 0 },
-#define NL_buf_map 8
+#define NL_buf_map 7
{ NULL, 0, 0, 0, 0 },
};
@@ -398,12 +391,8 @@
aobj_pager = (void*)ksyms[NL_AOBJ_PAGER].n_value;
ubc_pager = (void*)ksyms[NL_UBC_PAGER].n_value;
- nchash_addr = ksyms[NL_NCHASH].n_value;
-
_KDEREF(kd, ksyms[NL_MAXSSIZ].n_value, &maxssiz,
sizeof(maxssiz));
- _KDEREF(kd, ksyms[NL_NCHASHTBL].n_value, &nchashtbl_addr,
- sizeof(nchashtbl_addr));
_KDEREF(kd, ksyms[NL_KERNEL_MAP].n_value, &kernel_map_addr,
sizeof(kernel_map_addr));
@@ -420,13 +409,12 @@
} while (0/*CONSTCOND*/)
get_map_address(kmem_map);
- get_map_address(mb_map);
get_map_address(phys_map);
get_map_address(exec_map);
get_map_address(pager_map);
get_map_address(st_map);
get_map_address(pt_map);
- get_map_address(lkm_map);
+ get_map_address(module_map);
get_map_address(buf_map);
mib[0] = CTL_HW;
@@ -444,8 +432,6 @@
return ("kernel_map");
else if (addr == kmem_map)
return ("kmem_map");
- else if (addr == mb_map)
- return ("mb_map");
else if (addr == phys_map)
return ("phys_map");
else if (addr == exec_map)
@@ -456,83 +442,10 @@
return ("st_map");
else if (addr == pt_map)
return ("pt_map");
- else if (addr == lkm_map)
- return ("lkm_map");
+ else if (addr == module_map)
+ return ("module_map");
else if (addr == buf_map)
return ("buf_map");
else
return (NULL);
}
-
-void
-load_name_cache(kvm_t *kd)
-{
- struct namecache *ncp, *oncp;
- union {
- struct namecache ncp;
- char buf[sizeof(*ncp) + USHRT_MAX];
- } _n;
-#define _ncp _n.ncp
- struct nchashhead _ncpp, *ncpp;
- u_long lnchash;
- size_t nchash, i;
-
- LIST_INIT(&lcache);
-
- _KDEREF(kd, nchash_addr, &lnchash, sizeof(lnchash));
- nchash = (size_t)lnchash + 1;
- nchashtbl = ecalloc(nchash, sizeof(*nchashtbl));
- _KDEREF(kd, nchashtbl_addr, nchashtbl, sizeof(*nchashtbl) * nchash);
-
- ncpp = &_ncpp;
-
- for (i = 0; i < nchash; i++) {
- ncpp = &nchashtbl[i];
- oncp = NULL;
- LIST_FOREACH(ncp, ncpp, nc_hash) {
- size_t len;
-
- if (ncp == oncp ||
- ncp == (void*)0xdeadbeef)
- break;
- oncp = ncp;
- len = NCHNAMLEN;
-again:
- _KDEREF(kd, (u_long)ncp, &_ncp, (len + sizeof(*ncp)));
- if (_ncp.nc_nlen > len && _ncp.nc_nlen < 1024) {
- len = _ncp.nc_nlen;
- goto again;
- }
- ncp = &_ncp;
- if (ncp->nc_nlen > 0) {
- if (ncp->nc_nlen > 2 ||
- ncp->nc_name[0] != '.' ||
- (ncp->nc_name[1] != '.' &&
- ncp->nc_nlen != 1))
- cache_enter(i, ncp);
- }
- }
- }
-}
-
-void
-cache_enter(u_long i, struct namecache *ncp)
-{
- struct cache_entry *ce;
-
- if (debug & DUMP_NAMEI_CACHE)
- printf("[%lu] ncp->nc_vp %10p, ncp->nc_dvp %10p, "
- "ncp->nc_nlen %3d [%.*s]\n",
- i, ncp->nc_vp, ncp->nc_dvp,
- ncp->nc_nlen, ncp->nc_nlen, ncp->nc_name);
-
- ce = emalloc(sizeof(struct cache_entry));
-
- ce->ce_vp = ncp->nc_vp;
- ce->ce_pvp = ncp->nc_dvp;
- ce->ce_nlen = ncp->nc_nlen;
- strncpy(ce->ce_name, ncp->nc_name, sizeof(ce->ce_name));
- ce->ce_name[MIN(ce->ce_nlen, (int)(sizeof(ce->ce_name) - 1))] = '\0';
-
- LIST_INSERT_HEAD(&lcache, ce, ce_next);
-}
diff -r 1785921fb184 -r ee76916def01 usr.bin/pmap/pmap.c
--- a/usr.bin/pmap/pmap.c Sun Mar 22 14:39:28 2020 +0000
+++ b/usr.bin/pmap/pmap.c Sun Mar 22 14:41:32 2020 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: pmap.c,v 1.54 2018/05/09 01:04:01 christos Exp $ */
+/* $NetBSD: pmap.c,v 1.55 2020/03/22 14:41:32 ad Exp $ */
/*
- * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
+ * Copyright (c) 2002, 2003, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: pmap.c,v 1.54 2018/05/09 01:04:01 christos Exp $");
+__RCSID("$NetBSD: pmap.c,v 1.55 2020/03/22 14:41:32 ad Exp $");
#endif
#include <string.h>
@@ -43,7 +43,7 @@
static void dump_vm_anon(kvm_t *, struct vm_anon **, int);
static char *findname(kvm_t *, struct kbit *, struct kbit *, struct kbit *,
struct kbit *, struct kbit *);
-static int search_cache(kvm_t *, struct kbit *, char **, char *, size_t);
+static int search_cache(kvm_t *, struct vnode *, char **, char *, size_t);
/* when recursing, output is indented */
#define indent(n) ((n) * (recurse > 1 ? recurse - 1 : 0))
@@ -680,13 +680,15 @@
static char buf[1024], *name;
struct vm_map_entry *vme;
size_t l;
+ int rv;
vme = D(vm_map_entry, vm_map_entry);
if (UVM_ET_ISOBJ(vme)) {
if (A(vfs)) {
l = (unsigned)strlen(D(vfs, mount)->mnt_stat.f_mntonname);
- switch (search_cache(kd, vp, &name, buf, sizeof(buf))) {
+ rv = search_cache(kd, P(vp), &name, buf, sizeof(buf));
+ switch (rv) {
case 0: /* found something */
name--;
*name = '/';
@@ -776,32 +778,38 @@
}
static int
-search_cache(kvm_t *kd, struct kbit *vp, char **name, char *buf, size_t blen)
+search_cache(kvm_t *kd, struct vnode *vp, char **name, char *buf, size_t blen)
{
char *o, *e;
- struct cache_entry *ce;
- struct kbit svp;
+ struct namecache nc;
+ struct vnode_impl vi;
+ u_long vip, ncp, ncp2;
- if (nchashtbl == NULL)
- load_name_cache(kd);
-
- P(&svp) = P(vp);
- S(&svp) = sizeof(struct vnode);
-
+ vip = (u_long)vp;
e = &buf[blen - 1];
o = e;
+ ncp2 = 0;
do {
- LIST_FOREACH(ce, &lcache, ce_next)
- if (ce->ce_vp == P(&svp))
+ /* Pull down vnode_impl for vnode. */
+ _KDEREF(kd, vip, &vi, sizeof(vi));
+
+ /* From that, get first cached name for vnode. */
+ ncp = (u_long)vi.vi_nc_list.tqh_first;
+ if (ncp != 0 && ncp != ncp2) {
+ /* Pull down the cache entry. */
+ _KDEREF(kd, ncp, &nc, sizeof(nc));
+ /* Done if own parent or at the root. */
+ if ((u_long)nc.nc_dvp == vip ||
+ (vi.vi_vnode.v_vflag & VV_ROOT) != 0)
break;
- if (ce && ce->ce_vp == P(&svp)) {
+ /* Otherwise pull first NCHNAMLEN chars of name. */
if (o != e)
*(--o) = '/';
- o -= ce->ce_nlen;
- memcpy(o, ce->ce_name, (unsigned)ce->ce_nlen);
- P(&svp) = ce->ce_pvp;
- }
- else
+ o -= MIN((size_t)nc.nc_nlen, NCHNAMLEN);
+ memcpy(o, nc.nc_name, (unsigned)nc.nc_nlen);
+ vip = (u_long)nc.nc_dvp;
Home |
Main Index |
Thread Index |
Old Index