1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include "umem.h" 30*0Sstevel@tonic-gate #include <libproc.h> 31*0Sstevel@tonic-gate #include <mdb/mdb_modapi.h> 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include "kgrep.h" 34*0Sstevel@tonic-gate #include "leaky.h" 35*0Sstevel@tonic-gate #include "misc.h" 36*0Sstevel@tonic-gate #include "proc_kludges.h" 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate #include <umem_impl.h> 39*0Sstevel@tonic-gate #include <sys/vmem_impl_user.h> 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate #include "umem_pagesize.h" 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate typedef struct datafmt { 44*0Sstevel@tonic-gate char *hdr1; 45*0Sstevel@tonic-gate char *hdr2; 46*0Sstevel@tonic-gate char *dashes; 47*0Sstevel@tonic-gate char *fmt; 48*0Sstevel@tonic-gate } datafmt_t; 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate static datafmt_t umemfmt[] = { 51*0Sstevel@tonic-gate { "cache ", "name ", 52*0Sstevel@tonic-gate "-------------------------", "%-25s " }, 53*0Sstevel@tonic-gate { " buf", " size", "------", "%6u " }, 54*0Sstevel@tonic-gate { " buf", "in use", "------", "%6u " }, 55*0Sstevel@tonic-gate { " buf", " total", "------", "%6u " }, 56*0Sstevel@tonic-gate { " memory", " in use", "---------", "%9u " }, 57*0Sstevel@tonic-gate { " alloc", " succeed", "---------", "%9u " }, 58*0Sstevel@tonic-gate { "alloc", " fail", "-----", "%5llu " }, 59*0Sstevel@tonic-gate { NULL, NULL, NULL, NULL } 60*0Sstevel@tonic-gate }; 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate static datafmt_t vmemfmt[] = { 63*0Sstevel@tonic-gate { "vmem ", "name ", 64*0Sstevel@tonic-gate "-------------------------", "%-*s " }, 65*0Sstevel@tonic-gate { " memory", " in use", "---------", "%9llu " }, 66*0Sstevel@tonic-gate { " memory", " total", "----------", "%10llu " }, 67*0Sstevel@tonic-gate { " memory", " import", "---------", "%9llu " }, 68*0Sstevel@tonic-gate { " alloc", " succeed", "---------", "%9llu " }, 69*0Sstevel@tonic-gate { "alloc", " fail", "-----", "%5llu " }, 70*0Sstevel@tonic-gate { NULL, NULL, NULL, NULL } 71*0Sstevel@tonic-gate }; 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate /*ARGSUSED*/ 74*0Sstevel@tonic-gate static int 75*0Sstevel@tonic-gate umastat_cpu_avail(uintptr_t addr, const umem_cpu_cache_t *ccp, int *avail) 76*0Sstevel@tonic-gate { 77*0Sstevel@tonic-gate if (ccp->cc_rounds > 0) 78*0Sstevel@tonic-gate *avail += ccp->cc_rounds; 79*0Sstevel@tonic-gate if (ccp->cc_prounds > 0) 80*0Sstevel@tonic-gate *avail += ccp->cc_prounds; 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate return (WALK_NEXT); 83*0Sstevel@tonic-gate } 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate /*ARGSUSED*/ 86*0Sstevel@tonic-gate static int 87*0Sstevel@tonic-gate umastat_cpu_alloc(uintptr_t addr, const umem_cpu_cache_t *ccp, int *alloc) 88*0Sstevel@tonic-gate { 89*0Sstevel@tonic-gate *alloc += ccp->cc_alloc; 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate return (WALK_NEXT); 92*0Sstevel@tonic-gate } 93*0Sstevel@tonic-gate 94*0Sstevel@tonic-gate /*ARGSUSED*/ 95*0Sstevel@tonic-gate static int 96*0Sstevel@tonic-gate umastat_slab_avail(uintptr_t addr, const umem_slab_t *sp, int *avail) 97*0Sstevel@tonic-gate { 98*0Sstevel@tonic-gate *avail += sp->slab_chunks - sp->slab_refcnt; 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate return (WALK_NEXT); 101*0Sstevel@tonic-gate } 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate typedef struct umastat_vmem { 104*0Sstevel@tonic-gate uintptr_t kv_addr; 105*0Sstevel@tonic-gate struct umastat_vmem *kv_next; 106*0Sstevel@tonic-gate int kv_meminuse; 107*0Sstevel@tonic-gate int kv_alloc; 108*0Sstevel@tonic-gate int kv_fail; 109*0Sstevel@tonic-gate } umastat_vmem_t; 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate static int 112*0Sstevel@tonic-gate umastat_cache(uintptr_t addr, const umem_cache_t *cp, umastat_vmem_t **kvp) 113*0Sstevel@tonic-gate { 114*0Sstevel@tonic-gate umastat_vmem_t *kv; 115*0Sstevel@tonic-gate datafmt_t *dfp = umemfmt; 116*0Sstevel@tonic-gate int magsize; 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate int avail, alloc, total; 119*0Sstevel@tonic-gate size_t meminuse = (cp->cache_slab_create - cp->cache_slab_destroy) * 120*0Sstevel@tonic-gate cp->cache_slabsize; 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate mdb_walk_cb_t cpu_avail = (mdb_walk_cb_t)umastat_cpu_avail; 123*0Sstevel@tonic-gate mdb_walk_cb_t cpu_alloc = (mdb_walk_cb_t)umastat_cpu_alloc; 124*0Sstevel@tonic-gate mdb_walk_cb_t slab_avail = (mdb_walk_cb_t)umastat_slab_avail; 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate magsize = umem_get_magsize(cp); 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate alloc = cp->cache_slab_alloc + cp->cache_full.ml_alloc; 129*0Sstevel@tonic-gate avail = cp->cache_full.ml_total * magsize; 130*0Sstevel@tonic-gate total = cp->cache_buftotal; 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate (void) mdb_pwalk("umem_cpu_cache", cpu_alloc, &alloc, addr); 133*0Sstevel@tonic-gate (void) mdb_pwalk("umem_cpu_cache", cpu_avail, &avail, addr); 134*0Sstevel@tonic-gate (void) mdb_pwalk("umem_slab_partial", slab_avail, &avail, addr); 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate for (kv = *kvp; kv != NULL; kv = kv->kv_next) { 137*0Sstevel@tonic-gate if (kv->kv_addr == (uintptr_t)cp->cache_arena) 138*0Sstevel@tonic-gate goto out; 139*0Sstevel@tonic-gate } 140*0Sstevel@tonic-gate 141*0Sstevel@tonic-gate kv = mdb_zalloc(sizeof (umastat_vmem_t), UM_SLEEP | UM_GC); 142*0Sstevel@tonic-gate kv->kv_next = *kvp; 143*0Sstevel@tonic-gate kv->kv_addr = (uintptr_t)cp->cache_arena; 144*0Sstevel@tonic-gate *kvp = kv; 145*0Sstevel@tonic-gate out: 146*0Sstevel@tonic-gate kv->kv_meminuse += meminuse; 147*0Sstevel@tonic-gate kv->kv_alloc += alloc; 148*0Sstevel@tonic-gate kv->kv_fail += cp->cache_alloc_fail; 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_name); 151*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_bufsize); 152*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, total - avail); 153*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, total); 154*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, meminuse); 155*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, alloc); 156*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_alloc_fail); 157*0Sstevel@tonic-gate mdb_printf("\n"); 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gate return (WALK_NEXT); 160*0Sstevel@tonic-gate } 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate static int 163*0Sstevel@tonic-gate umastat_vmem_totals(uintptr_t addr, const vmem_t *v, umastat_vmem_t *kv) 164*0Sstevel@tonic-gate { 165*0Sstevel@tonic-gate while (kv != NULL && kv->kv_addr != addr) 166*0Sstevel@tonic-gate kv = kv->kv_next; 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate if (kv == NULL || kv->kv_alloc == 0) 169*0Sstevel@tonic-gate return (WALK_NEXT); 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate mdb_printf("Total [%s]%*s %6s %6s %6s %9u %9u %5u\n", v->vm_name, 172*0Sstevel@tonic-gate 17 - strlen(v->vm_name), "", "", "", "", 173*0Sstevel@tonic-gate kv->kv_meminuse, kv->kv_alloc, kv->kv_fail); 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate return (WALK_NEXT); 176*0Sstevel@tonic-gate } 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate /*ARGSUSED*/ 179*0Sstevel@tonic-gate static int 180*0Sstevel@tonic-gate umastat_vmem(uintptr_t addr, const vmem_t *v, void *ignored) 181*0Sstevel@tonic-gate { 182*0Sstevel@tonic-gate datafmt_t *dfp = vmemfmt; 183*0Sstevel@tonic-gate uintptr_t paddr; 184*0Sstevel@tonic-gate vmem_t parent; 185*0Sstevel@tonic-gate int ident = 0; 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate for (paddr = (uintptr_t)v->vm_source; paddr != NULL; ident += 4) { 188*0Sstevel@tonic-gate if (mdb_vread(&parent, sizeof (parent), paddr) == -1) { 189*0Sstevel@tonic-gate mdb_warn("couldn't trace %p's ancestry", addr); 190*0Sstevel@tonic-gate ident = 0; 191*0Sstevel@tonic-gate break; 192*0Sstevel@tonic-gate } 193*0Sstevel@tonic-gate paddr = (uintptr_t)parent.vm_source; 194*0Sstevel@tonic-gate } 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate mdb_printf("%*s", ident, ""); 197*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, 25 - ident, v->vm_name); 198*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, v->vm_kstat.vk_mem_inuse); 199*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, v->vm_kstat.vk_mem_total); 200*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, v->vm_kstat.vk_mem_import); 201*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, v->vm_kstat.vk_alloc); 202*0Sstevel@tonic-gate mdb_printf((dfp++)->fmt, v->vm_kstat.vk_fail); 203*0Sstevel@tonic-gate 204*0Sstevel@tonic-gate mdb_printf("\n"); 205*0Sstevel@tonic-gate 206*0Sstevel@tonic-gate return (WALK_NEXT); 207*0Sstevel@tonic-gate } 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gate /*ARGSUSED*/ 210*0Sstevel@tonic-gate int 211*0Sstevel@tonic-gate umastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 212*0Sstevel@tonic-gate { 213*0Sstevel@tonic-gate umastat_vmem_t *kv = NULL; 214*0Sstevel@tonic-gate datafmt_t *dfp; 215*0Sstevel@tonic-gate 216*0Sstevel@tonic-gate if (argc != 0) 217*0Sstevel@tonic-gate return (DCMD_USAGE); 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++) 220*0Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr1); 221*0Sstevel@tonic-gate mdb_printf("\n"); 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++) 224*0Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr2); 225*0Sstevel@tonic-gate mdb_printf("\n"); 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++) 228*0Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 229*0Sstevel@tonic-gate mdb_printf("\n"); 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate if (mdb_walk("umem_cache", (mdb_walk_cb_t)umastat_cache, &kv) == -1) { 232*0Sstevel@tonic-gate mdb_warn("can't walk 'umem_cache'"); 233*0Sstevel@tonic-gate return (DCMD_ERR); 234*0Sstevel@tonic-gate } 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gate for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++) 237*0Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 238*0Sstevel@tonic-gate mdb_printf("\n"); 239*0Sstevel@tonic-gate 240*0Sstevel@tonic-gate if (mdb_walk("vmem", (mdb_walk_cb_t)umastat_vmem_totals, kv) == -1) { 241*0Sstevel@tonic-gate mdb_warn("can't walk 'vmem'"); 242*0Sstevel@tonic-gate return (DCMD_ERR); 243*0Sstevel@tonic-gate } 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gate for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++) 246*0Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 247*0Sstevel@tonic-gate mdb_printf("\n"); 248*0Sstevel@tonic-gate 249*0Sstevel@tonic-gate mdb_printf("\n"); 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 252*0Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr1); 253*0Sstevel@tonic-gate mdb_printf("\n"); 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 256*0Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr2); 257*0Sstevel@tonic-gate mdb_printf("\n"); 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 260*0Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 261*0Sstevel@tonic-gate mdb_printf("\n"); 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate if (mdb_walk("vmem", (mdb_walk_cb_t)umastat_vmem, NULL) == -1) { 264*0Sstevel@tonic-gate mdb_warn("can't walk 'vmem'"); 265*0Sstevel@tonic-gate return (DCMD_ERR); 266*0Sstevel@tonic-gate } 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 269*0Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 270*0Sstevel@tonic-gate mdb_printf("\n"); 271*0Sstevel@tonic-gate return (DCMD_OK); 272*0Sstevel@tonic-gate } 273*0Sstevel@tonic-gate 274*0Sstevel@tonic-gate /* 275*0Sstevel@tonic-gate * kmdb doesn't use libproc, and thus doesn't have any prmap_t's to walk. 276*0Sstevel@tonic-gate * We have other ways to grep kmdb's address range. 277*0Sstevel@tonic-gate */ 278*0Sstevel@tonic-gate #ifndef _KMDB 279*0Sstevel@tonic-gate 280*0Sstevel@tonic-gate typedef struct ugrep_walk_data { 281*0Sstevel@tonic-gate kgrep_cb_func *ug_cb; 282*0Sstevel@tonic-gate void *ug_cbdata; 283*0Sstevel@tonic-gate } ugrep_walk_data_t; 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gate /*ARGSUSED*/ 286*0Sstevel@tonic-gate int 287*0Sstevel@tonic-gate ugrep_mapping_cb(uintptr_t addr, const void *prm_arg, void *data) 288*0Sstevel@tonic-gate { 289*0Sstevel@tonic-gate ugrep_walk_data_t *ug = data; 290*0Sstevel@tonic-gate const prmap_t *prm = prm_arg; 291*0Sstevel@tonic-gate 292*0Sstevel@tonic-gate return (ug->ug_cb(prm->pr_vaddr, prm->pr_vaddr + prm->pr_size, 293*0Sstevel@tonic-gate ug->ug_cbdata)); 294*0Sstevel@tonic-gate } 295*0Sstevel@tonic-gate 296*0Sstevel@tonic-gate int 297*0Sstevel@tonic-gate kgrep_subr(kgrep_cb_func *cb, void *cbdata) 298*0Sstevel@tonic-gate { 299*0Sstevel@tonic-gate ugrep_walk_data_t ug; 300*0Sstevel@tonic-gate 301*0Sstevel@tonic-gate prockludge_add_walkers(); 302*0Sstevel@tonic-gate 303*0Sstevel@tonic-gate ug.ug_cb = cb; 304*0Sstevel@tonic-gate ug.ug_cbdata = cbdata; 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gate if (mdb_walk(KLUDGE_MAPWALK_NAME, ugrep_mapping_cb, &ug) == -1) { 307*0Sstevel@tonic-gate mdb_warn("Unable to walk "KLUDGE_MAPWALK_NAME); 308*0Sstevel@tonic-gate return (DCMD_ERR); 309*0Sstevel@tonic-gate } 310*0Sstevel@tonic-gate 311*0Sstevel@tonic-gate prockludge_remove_walkers(); 312*0Sstevel@tonic-gate return (DCMD_OK); 313*0Sstevel@tonic-gate } 314*0Sstevel@tonic-gate 315*0Sstevel@tonic-gate size_t 316*0Sstevel@tonic-gate kgrep_subr_pagesize(void) 317*0Sstevel@tonic-gate { 318*0Sstevel@tonic-gate return (PAGESIZE); 319*0Sstevel@tonic-gate } 320*0Sstevel@tonic-gate 321*0Sstevel@tonic-gate #endif /* !_KMDB */ 322*0Sstevel@tonic-gate 323*0Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 324*0Sstevel@tonic-gate 325*0Sstevel@tonic-gate /* from libumem.c */ 326*0Sstevel@tonic-gate { "umastat", NULL, "umem allocator stats", umastat }, 327*0Sstevel@tonic-gate 328*0Sstevel@tonic-gate /* from misc.c */ 329*0Sstevel@tonic-gate { "umem_debug", NULL, "toggle umem dcmd/walk debugging", umem_debug}, 330*0Sstevel@tonic-gate 331*0Sstevel@tonic-gate /* from umem.c */ 332*0Sstevel@tonic-gate { "umem_status", NULL, "Print umem status and message buffer", 333*0Sstevel@tonic-gate umem_status }, 334*0Sstevel@tonic-gate { "allocdby", ":", "given a thread, print its allocated buffers", 335*0Sstevel@tonic-gate allocdby }, 336*0Sstevel@tonic-gate { "bufctl", ":[-vh] [-a addr] [-c caller] [-e earliest] [-l latest] " 337*0Sstevel@tonic-gate "[-t thd]", "print or filter a bufctl", bufctl, bufctl_help }, 338*0Sstevel@tonic-gate { "bufctl_audit", ":", "print a bufctl_audit", bufctl_audit }, 339*0Sstevel@tonic-gate { "freedby", ":", "given a thread, print its freed buffers", freedby }, 340*0Sstevel@tonic-gate { "umalog", "[ fail | slab ]", 341*0Sstevel@tonic-gate "display umem transaction log and stack traces", umalog }, 342*0Sstevel@tonic-gate { "umausers", "[-ef] [cache ...]", "display current medium and large " 343*0Sstevel@tonic-gate "users of the umem allocator", umausers }, 344*0Sstevel@tonic-gate { "umem_cache", "?", "print a umem cache", umem_cache }, 345*0Sstevel@tonic-gate { "umem_log", "?", "dump umem transaction log", umem_log }, 346*0Sstevel@tonic-gate { "umem_verify", "?", "check integrity of umem-managed memory", 347*0Sstevel@tonic-gate umem_verify }, 348*0Sstevel@tonic-gate { "vmem", "?", "print a vmem_t", vmem }, 349*0Sstevel@tonic-gate { "vmem_seg", ":[-sv] [-c caller] [-e earliest] [-l latest] " 350*0Sstevel@tonic-gate "[-m minsize] [-M maxsize] [-t thread] [-T type]", 351*0Sstevel@tonic-gate "print or filter a vmem_seg", vmem_seg, vmem_seg_help }, 352*0Sstevel@tonic-gate { "whatis", ":[-abv]", "given an address, return information", whatis }, 353*0Sstevel@tonic-gate 354*0Sstevel@tonic-gate #ifndef _KMDB 355*0Sstevel@tonic-gate /* from ../genunix/kgrep.c + libumem.c */ 356*0Sstevel@tonic-gate { "ugrep", KGREP_USAGE, "search user address space for a pointer", 357*0Sstevel@tonic-gate kgrep }, 358*0Sstevel@tonic-gate 359*0Sstevel@tonic-gate /* from ../genunix/leaky.c + leaky_subr.c */ 360*0Sstevel@tonic-gate { "findleaks", FINDLEAKS_USAGE, "search for potential memory leaks", 361*0Sstevel@tonic-gate findleaks, findleaks_help }, 362*0Sstevel@tonic-gate #endif 363*0Sstevel@tonic-gate 364*0Sstevel@tonic-gate { NULL } 365*0Sstevel@tonic-gate }; 366*0Sstevel@tonic-gate 367*0Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 368*0Sstevel@tonic-gate 369*0Sstevel@tonic-gate /* from umem.c */ 370*0Sstevel@tonic-gate { "allocdby", "given a thread, walk its allocated bufctls", 371*0Sstevel@tonic-gate allocdby_walk_init, allocdby_walk_step, allocdby_walk_fini }, 372*0Sstevel@tonic-gate { "bufctl", "walk a umem cache's bufctls", 373*0Sstevel@tonic-gate bufctl_walk_init, umem_walk_step, umem_walk_fini }, 374*0Sstevel@tonic-gate { "bufctl_history", "walk the available history of a bufctl", 375*0Sstevel@tonic-gate bufctl_history_walk_init, bufctl_history_walk_step, 376*0Sstevel@tonic-gate bufctl_history_walk_fini }, 377*0Sstevel@tonic-gate { "freectl", "walk a umem cache's free bufctls", 378*0Sstevel@tonic-gate freectl_walk_init, umem_walk_step, umem_walk_fini }, 379*0Sstevel@tonic-gate { "freedby", "given a thread, walk its freed bufctls", 380*0Sstevel@tonic-gate freedby_walk_init, allocdby_walk_step, allocdby_walk_fini }, 381*0Sstevel@tonic-gate { "freemem", "walk a umem cache's free memory", 382*0Sstevel@tonic-gate freemem_walk_init, umem_walk_step, umem_walk_fini }, 383*0Sstevel@tonic-gate { "umem", "walk a umem cache", 384*0Sstevel@tonic-gate umem_walk_init, umem_walk_step, umem_walk_fini }, 385*0Sstevel@tonic-gate { "umem_cpu", "walk the umem CPU structures", 386*0Sstevel@tonic-gate umem_cpu_walk_init, umem_cpu_walk_step, umem_cpu_walk_fini }, 387*0Sstevel@tonic-gate { "umem_cpu_cache", "given a umem cache, walk its per-CPU caches", 388*0Sstevel@tonic-gate umem_cpu_cache_walk_init, umem_cpu_cache_walk_step, NULL }, 389*0Sstevel@tonic-gate { "umem_hash", "given a umem cache, walk its allocated hash table", 390*0Sstevel@tonic-gate umem_hash_walk_init, umem_hash_walk_step, umem_hash_walk_fini }, 391*0Sstevel@tonic-gate { "umem_log", "walk the umem transaction log", 392*0Sstevel@tonic-gate umem_log_walk_init, umem_log_walk_step, umem_log_walk_fini }, 393*0Sstevel@tonic-gate { "umem_slab", "given a umem cache, walk its slabs", 394*0Sstevel@tonic-gate umem_slab_walk_init, umem_slab_walk_step, NULL }, 395*0Sstevel@tonic-gate { "umem_slab_partial", 396*0Sstevel@tonic-gate "given a umem cache, walk its partially allocated slabs (min 1)", 397*0Sstevel@tonic-gate umem_slab_walk_partial_init, umem_slab_walk_step, NULL }, 398*0Sstevel@tonic-gate { "vmem", "walk vmem structures in pre-fix, depth-first order", 399*0Sstevel@tonic-gate vmem_walk_init, vmem_walk_step, vmem_walk_fini }, 400*0Sstevel@tonic-gate { "vmem_alloc", "given a vmem_t, walk its allocated vmem_segs", 401*0Sstevel@tonic-gate vmem_alloc_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 402*0Sstevel@tonic-gate { "vmem_free", "given a vmem_t, walk its free vmem_segs", 403*0Sstevel@tonic-gate vmem_free_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 404*0Sstevel@tonic-gate { "vmem_postfix", "walk vmem structures in post-fix, depth-first order", 405*0Sstevel@tonic-gate vmem_walk_init, vmem_postfix_walk_step, vmem_walk_fini }, 406*0Sstevel@tonic-gate { "vmem_seg", "given a vmem_t, walk all of its vmem_segs", 407*0Sstevel@tonic-gate vmem_seg_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 408*0Sstevel@tonic-gate { "vmem_span", "given a vmem_t, walk its spanning vmem_segs", 409*0Sstevel@tonic-gate vmem_span_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 410*0Sstevel@tonic-gate 411*0Sstevel@tonic-gate #ifndef _KMDB 412*0Sstevel@tonic-gate /* from ../genunix/leaky.c + leaky_subr.c */ 413*0Sstevel@tonic-gate { "leak", "given a leak ctl, walk other leaks w/ that stacktrace", 414*0Sstevel@tonic-gate leaky_walk_init, leaky_walk_step, leaky_walk_fini }, 415*0Sstevel@tonic-gate { "leakbuf", "given a leak ctl, walk addr of leaks w/ that stacktrace", 416*0Sstevel@tonic-gate leaky_walk_init, leaky_buf_walk_step, leaky_walk_fini }, 417*0Sstevel@tonic-gate #endif 418*0Sstevel@tonic-gate 419*0Sstevel@tonic-gate { NULL } 420*0Sstevel@tonic-gate }; 421*0Sstevel@tonic-gate 422*0Sstevel@tonic-gate static const mdb_modinfo_t modinfo = {MDB_API_VERSION, dcmds, walkers}; 423*0Sstevel@tonic-gate 424*0Sstevel@tonic-gate const mdb_modinfo_t * 425*0Sstevel@tonic-gate _mdb_init(void) 426*0Sstevel@tonic-gate { 427*0Sstevel@tonic-gate mdb_walker_t w = { 428*0Sstevel@tonic-gate "umem_cache", "walk list of umem caches", umem_cache_walk_init, 429*0Sstevel@tonic-gate umem_cache_walk_step, umem_cache_walk_fini 430*0Sstevel@tonic-gate }; 431*0Sstevel@tonic-gate 432*0Sstevel@tonic-gate if (umem_init() != 0) 433*0Sstevel@tonic-gate return (NULL); 434*0Sstevel@tonic-gate 435*0Sstevel@tonic-gate /* 436*0Sstevel@tonic-gate * Load the umem_cache walker manually, and then invoke it to add 437*0Sstevel@tonic-gate * named walks for each cache. This walker needs to be added by 438*0Sstevel@tonic-gate * hand since walkers in the linkage structure cannot be loaded 439*0Sstevel@tonic-gate * until _mdb_init returns the pointer to the linkage structure. 440*0Sstevel@tonic-gate */ 441*0Sstevel@tonic-gate if (mdb_add_walker(&w) == 0) { 442*0Sstevel@tonic-gate (void) mdb_walk("umem_cache", (mdb_walk_cb_t) 443*0Sstevel@tonic-gate umem_init_walkers, NULL); 444*0Sstevel@tonic-gate } else 445*0Sstevel@tonic-gate mdb_warn("failed to add umem_cache walker"); 446*0Sstevel@tonic-gate 447*0Sstevel@tonic-gate return (&modinfo); 448*0Sstevel@tonic-gate } 449*0Sstevel@tonic-gate 450*0Sstevel@tonic-gate void 451*0Sstevel@tonic-gate _mdb_fini(void) 452*0Sstevel@tonic-gate { 453*0Sstevel@tonic-gate #ifndef _KMDB 454*0Sstevel@tonic-gate leaky_cleanup(1); 455*0Sstevel@tonic-gate #endif 456*0Sstevel@tonic-gate } 457