10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1528Sjwadams * Common Development and Distribution License (the "License"). 6*1528Sjwadams * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*1528Sjwadams * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include "umem.h" 290Sstevel@tonic-gate #include <libproc.h> 300Sstevel@tonic-gate #include <mdb/mdb_modapi.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include "kgrep.h" 330Sstevel@tonic-gate #include "leaky.h" 340Sstevel@tonic-gate #include "misc.h" 350Sstevel@tonic-gate #include "proc_kludges.h" 360Sstevel@tonic-gate 370Sstevel@tonic-gate #include <umem_impl.h> 380Sstevel@tonic-gate #include <sys/vmem_impl_user.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate #include "umem_pagesize.h" 410Sstevel@tonic-gate 420Sstevel@tonic-gate typedef struct datafmt { 430Sstevel@tonic-gate char *hdr1; 440Sstevel@tonic-gate char *hdr2; 450Sstevel@tonic-gate char *dashes; 460Sstevel@tonic-gate char *fmt; 470Sstevel@tonic-gate } datafmt_t; 480Sstevel@tonic-gate 490Sstevel@tonic-gate static datafmt_t umemfmt[] = { 500Sstevel@tonic-gate { "cache ", "name ", 510Sstevel@tonic-gate "-------------------------", "%-25s " }, 520Sstevel@tonic-gate { " buf", " size", "------", "%6u " }, 530Sstevel@tonic-gate { " buf", "in use", "------", "%6u " }, 540Sstevel@tonic-gate { " buf", " total", "------", "%6u " }, 550Sstevel@tonic-gate { " memory", " in use", "---------", "%9u " }, 560Sstevel@tonic-gate { " alloc", " succeed", "---------", "%9u " }, 570Sstevel@tonic-gate { "alloc", " fail", "-----", "%5llu " }, 580Sstevel@tonic-gate { NULL, NULL, NULL, NULL } 590Sstevel@tonic-gate }; 600Sstevel@tonic-gate 610Sstevel@tonic-gate static datafmt_t vmemfmt[] = { 620Sstevel@tonic-gate { "vmem ", "name ", 630Sstevel@tonic-gate "-------------------------", "%-*s " }, 640Sstevel@tonic-gate { " memory", " in use", "---------", "%9llu " }, 650Sstevel@tonic-gate { " memory", " total", "----------", "%10llu " }, 660Sstevel@tonic-gate { " memory", " import", "---------", "%9llu " }, 670Sstevel@tonic-gate { " alloc", " succeed", "---------", "%9llu " }, 680Sstevel@tonic-gate { "alloc", " fail", "-----", "%5llu " }, 690Sstevel@tonic-gate { NULL, NULL, NULL, NULL } 700Sstevel@tonic-gate }; 710Sstevel@tonic-gate 720Sstevel@tonic-gate /*ARGSUSED*/ 730Sstevel@tonic-gate static int 740Sstevel@tonic-gate umastat_cpu_avail(uintptr_t addr, const umem_cpu_cache_t *ccp, int *avail) 750Sstevel@tonic-gate { 760Sstevel@tonic-gate if (ccp->cc_rounds > 0) 770Sstevel@tonic-gate *avail += ccp->cc_rounds; 780Sstevel@tonic-gate if (ccp->cc_prounds > 0) 790Sstevel@tonic-gate *avail += ccp->cc_prounds; 800Sstevel@tonic-gate 810Sstevel@tonic-gate return (WALK_NEXT); 820Sstevel@tonic-gate } 830Sstevel@tonic-gate 840Sstevel@tonic-gate /*ARGSUSED*/ 850Sstevel@tonic-gate static int 860Sstevel@tonic-gate umastat_cpu_alloc(uintptr_t addr, const umem_cpu_cache_t *ccp, int *alloc) 870Sstevel@tonic-gate { 880Sstevel@tonic-gate *alloc += ccp->cc_alloc; 890Sstevel@tonic-gate 900Sstevel@tonic-gate return (WALK_NEXT); 910Sstevel@tonic-gate } 920Sstevel@tonic-gate 930Sstevel@tonic-gate /*ARGSUSED*/ 940Sstevel@tonic-gate static int 950Sstevel@tonic-gate umastat_slab_avail(uintptr_t addr, const umem_slab_t *sp, int *avail) 960Sstevel@tonic-gate { 970Sstevel@tonic-gate *avail += sp->slab_chunks - sp->slab_refcnt; 980Sstevel@tonic-gate 990Sstevel@tonic-gate return (WALK_NEXT); 1000Sstevel@tonic-gate } 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate typedef struct umastat_vmem { 1030Sstevel@tonic-gate uintptr_t kv_addr; 1040Sstevel@tonic-gate struct umastat_vmem *kv_next; 1050Sstevel@tonic-gate int kv_meminuse; 1060Sstevel@tonic-gate int kv_alloc; 1070Sstevel@tonic-gate int kv_fail; 1080Sstevel@tonic-gate } umastat_vmem_t; 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate static int 1110Sstevel@tonic-gate umastat_cache(uintptr_t addr, const umem_cache_t *cp, umastat_vmem_t **kvp) 1120Sstevel@tonic-gate { 1130Sstevel@tonic-gate umastat_vmem_t *kv; 1140Sstevel@tonic-gate datafmt_t *dfp = umemfmt; 1150Sstevel@tonic-gate int magsize; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate int avail, alloc, total; 1180Sstevel@tonic-gate size_t meminuse = (cp->cache_slab_create - cp->cache_slab_destroy) * 1190Sstevel@tonic-gate cp->cache_slabsize; 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate mdb_walk_cb_t cpu_avail = (mdb_walk_cb_t)umastat_cpu_avail; 1220Sstevel@tonic-gate mdb_walk_cb_t cpu_alloc = (mdb_walk_cb_t)umastat_cpu_alloc; 1230Sstevel@tonic-gate mdb_walk_cb_t slab_avail = (mdb_walk_cb_t)umastat_slab_avail; 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate magsize = umem_get_magsize(cp); 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate alloc = cp->cache_slab_alloc + cp->cache_full.ml_alloc; 1280Sstevel@tonic-gate avail = cp->cache_full.ml_total * magsize; 1290Sstevel@tonic-gate total = cp->cache_buftotal; 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate (void) mdb_pwalk("umem_cpu_cache", cpu_alloc, &alloc, addr); 1320Sstevel@tonic-gate (void) mdb_pwalk("umem_cpu_cache", cpu_avail, &avail, addr); 1330Sstevel@tonic-gate (void) mdb_pwalk("umem_slab_partial", slab_avail, &avail, addr); 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate for (kv = *kvp; kv != NULL; kv = kv->kv_next) { 1360Sstevel@tonic-gate if (kv->kv_addr == (uintptr_t)cp->cache_arena) 1370Sstevel@tonic-gate goto out; 1380Sstevel@tonic-gate } 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate kv = mdb_zalloc(sizeof (umastat_vmem_t), UM_SLEEP | UM_GC); 1410Sstevel@tonic-gate kv->kv_next = *kvp; 1420Sstevel@tonic-gate kv->kv_addr = (uintptr_t)cp->cache_arena; 1430Sstevel@tonic-gate *kvp = kv; 1440Sstevel@tonic-gate out: 1450Sstevel@tonic-gate kv->kv_meminuse += meminuse; 1460Sstevel@tonic-gate kv->kv_alloc += alloc; 1470Sstevel@tonic-gate kv->kv_fail += cp->cache_alloc_fail; 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_name); 1500Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_bufsize); 1510Sstevel@tonic-gate mdb_printf((dfp++)->fmt, total - avail); 1520Sstevel@tonic-gate mdb_printf((dfp++)->fmt, total); 1530Sstevel@tonic-gate mdb_printf((dfp++)->fmt, meminuse); 1540Sstevel@tonic-gate mdb_printf((dfp++)->fmt, alloc); 1550Sstevel@tonic-gate mdb_printf((dfp++)->fmt, cp->cache_alloc_fail); 1560Sstevel@tonic-gate mdb_printf("\n"); 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate return (WALK_NEXT); 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate static int 1620Sstevel@tonic-gate umastat_vmem_totals(uintptr_t addr, const vmem_t *v, umastat_vmem_t *kv) 1630Sstevel@tonic-gate { 1640Sstevel@tonic-gate while (kv != NULL && kv->kv_addr != addr) 1650Sstevel@tonic-gate kv = kv->kv_next; 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate if (kv == NULL || kv->kv_alloc == 0) 1680Sstevel@tonic-gate return (WALK_NEXT); 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate mdb_printf("Total [%s]%*s %6s %6s %6s %9u %9u %5u\n", v->vm_name, 1710Sstevel@tonic-gate 17 - strlen(v->vm_name), "", "", "", "", 1720Sstevel@tonic-gate kv->kv_meminuse, kv->kv_alloc, kv->kv_fail); 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate return (WALK_NEXT); 1750Sstevel@tonic-gate } 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate /*ARGSUSED*/ 1780Sstevel@tonic-gate static int 1790Sstevel@tonic-gate umastat_vmem(uintptr_t addr, const vmem_t *v, void *ignored) 1800Sstevel@tonic-gate { 1810Sstevel@tonic-gate datafmt_t *dfp = vmemfmt; 1820Sstevel@tonic-gate uintptr_t paddr; 1830Sstevel@tonic-gate vmem_t parent; 1840Sstevel@tonic-gate int ident = 0; 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate for (paddr = (uintptr_t)v->vm_source; paddr != NULL; ident += 4) { 1870Sstevel@tonic-gate if (mdb_vread(&parent, sizeof (parent), paddr) == -1) { 1880Sstevel@tonic-gate mdb_warn("couldn't trace %p's ancestry", addr); 1890Sstevel@tonic-gate ident = 0; 1900Sstevel@tonic-gate break; 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate paddr = (uintptr_t)parent.vm_source; 1930Sstevel@tonic-gate } 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate mdb_printf("%*s", ident, ""); 1960Sstevel@tonic-gate mdb_printf((dfp++)->fmt, 25 - ident, v->vm_name); 1970Sstevel@tonic-gate mdb_printf((dfp++)->fmt, v->vm_kstat.vk_mem_inuse); 1980Sstevel@tonic-gate mdb_printf((dfp++)->fmt, v->vm_kstat.vk_mem_total); 1990Sstevel@tonic-gate mdb_printf((dfp++)->fmt, v->vm_kstat.vk_mem_import); 2000Sstevel@tonic-gate mdb_printf((dfp++)->fmt, v->vm_kstat.vk_alloc); 2010Sstevel@tonic-gate mdb_printf((dfp++)->fmt, v->vm_kstat.vk_fail); 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate mdb_printf("\n"); 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate return (WALK_NEXT); 2060Sstevel@tonic-gate } 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate /*ARGSUSED*/ 2090Sstevel@tonic-gate int 2100Sstevel@tonic-gate umastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 2110Sstevel@tonic-gate { 2120Sstevel@tonic-gate umastat_vmem_t *kv = NULL; 2130Sstevel@tonic-gate datafmt_t *dfp; 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate if (argc != 0) 2160Sstevel@tonic-gate return (DCMD_USAGE); 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++) 2190Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr1); 2200Sstevel@tonic-gate mdb_printf("\n"); 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++) 2230Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr2); 2240Sstevel@tonic-gate mdb_printf("\n"); 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++) 2270Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 2280Sstevel@tonic-gate mdb_printf("\n"); 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate if (mdb_walk("umem_cache", (mdb_walk_cb_t)umastat_cache, &kv) == -1) { 2310Sstevel@tonic-gate mdb_warn("can't walk 'umem_cache'"); 2320Sstevel@tonic-gate return (DCMD_ERR); 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++) 2360Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 2370Sstevel@tonic-gate mdb_printf("\n"); 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate if (mdb_walk("vmem", (mdb_walk_cb_t)umastat_vmem_totals, kv) == -1) { 2400Sstevel@tonic-gate mdb_warn("can't walk 'vmem'"); 2410Sstevel@tonic-gate return (DCMD_ERR); 2420Sstevel@tonic-gate } 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate for (dfp = umemfmt; dfp->hdr1 != NULL; dfp++) 2450Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 2460Sstevel@tonic-gate mdb_printf("\n"); 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate mdb_printf("\n"); 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 2510Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr1); 2520Sstevel@tonic-gate mdb_printf("\n"); 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 2550Sstevel@tonic-gate mdb_printf("%s ", dfp->hdr2); 2560Sstevel@tonic-gate mdb_printf("\n"); 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 2590Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 2600Sstevel@tonic-gate mdb_printf("\n"); 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate if (mdb_walk("vmem", (mdb_walk_cb_t)umastat_vmem, NULL) == -1) { 2630Sstevel@tonic-gate mdb_warn("can't walk 'vmem'"); 2640Sstevel@tonic-gate return (DCMD_ERR); 2650Sstevel@tonic-gate } 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate for (dfp = vmemfmt; dfp->hdr1 != NULL; dfp++) 2680Sstevel@tonic-gate mdb_printf("%s ", dfp->dashes); 2690Sstevel@tonic-gate mdb_printf("\n"); 2700Sstevel@tonic-gate return (DCMD_OK); 2710Sstevel@tonic-gate } 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate /* 2740Sstevel@tonic-gate * kmdb doesn't use libproc, and thus doesn't have any prmap_t's to walk. 2750Sstevel@tonic-gate * We have other ways to grep kmdb's address range. 2760Sstevel@tonic-gate */ 2770Sstevel@tonic-gate #ifndef _KMDB 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate typedef struct ugrep_walk_data { 2800Sstevel@tonic-gate kgrep_cb_func *ug_cb; 2810Sstevel@tonic-gate void *ug_cbdata; 2820Sstevel@tonic-gate } ugrep_walk_data_t; 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate /*ARGSUSED*/ 2850Sstevel@tonic-gate int 2860Sstevel@tonic-gate ugrep_mapping_cb(uintptr_t addr, const void *prm_arg, void *data) 2870Sstevel@tonic-gate { 2880Sstevel@tonic-gate ugrep_walk_data_t *ug = data; 2890Sstevel@tonic-gate const prmap_t *prm = prm_arg; 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate return (ug->ug_cb(prm->pr_vaddr, prm->pr_vaddr + prm->pr_size, 2920Sstevel@tonic-gate ug->ug_cbdata)); 2930Sstevel@tonic-gate } 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate int 2960Sstevel@tonic-gate kgrep_subr(kgrep_cb_func *cb, void *cbdata) 2970Sstevel@tonic-gate { 2980Sstevel@tonic-gate ugrep_walk_data_t ug; 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate prockludge_add_walkers(); 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate ug.ug_cb = cb; 3030Sstevel@tonic-gate ug.ug_cbdata = cbdata; 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate if (mdb_walk(KLUDGE_MAPWALK_NAME, ugrep_mapping_cb, &ug) == -1) { 3060Sstevel@tonic-gate mdb_warn("Unable to walk "KLUDGE_MAPWALK_NAME); 3070Sstevel@tonic-gate return (DCMD_ERR); 3080Sstevel@tonic-gate } 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate prockludge_remove_walkers(); 3110Sstevel@tonic-gate return (DCMD_OK); 3120Sstevel@tonic-gate } 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate size_t 3150Sstevel@tonic-gate kgrep_subr_pagesize(void) 3160Sstevel@tonic-gate { 3170Sstevel@tonic-gate return (PAGESIZE); 3180Sstevel@tonic-gate } 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate #endif /* !_KMDB */ 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate /* from libumem.c */ 3250Sstevel@tonic-gate { "umastat", NULL, "umem allocator stats", umastat }, 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate /* from misc.c */ 3280Sstevel@tonic-gate { "umem_debug", NULL, "toggle umem dcmd/walk debugging", umem_debug}, 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate /* from umem.c */ 3310Sstevel@tonic-gate { "umem_status", NULL, "Print umem status and message buffer", 3320Sstevel@tonic-gate umem_status }, 3330Sstevel@tonic-gate { "allocdby", ":", "given a thread, print its allocated buffers", 3340Sstevel@tonic-gate allocdby }, 3350Sstevel@tonic-gate { "bufctl", ":[-vh] [-a addr] [-c caller] [-e earliest] [-l latest] " 3360Sstevel@tonic-gate "[-t thd]", "print or filter a bufctl", bufctl, bufctl_help }, 3370Sstevel@tonic-gate { "bufctl_audit", ":", "print a bufctl_audit", bufctl_audit }, 3380Sstevel@tonic-gate { "freedby", ":", "given a thread, print its freed buffers", freedby }, 3390Sstevel@tonic-gate { "umalog", "[ fail | slab ]", 3400Sstevel@tonic-gate "display umem transaction log and stack traces", umalog }, 3410Sstevel@tonic-gate { "umausers", "[-ef] [cache ...]", "display current medium and large " 3420Sstevel@tonic-gate "users of the umem allocator", umausers }, 3430Sstevel@tonic-gate { "umem_cache", "?", "print a umem cache", umem_cache }, 3440Sstevel@tonic-gate { "umem_log", "?", "dump umem transaction log", umem_log }, 345*1528Sjwadams { "umem_malloc_dist", "[-dg] [-b maxbins] [-B minbinsize]", 346*1528Sjwadams "report distribution of outstanding malloc()s", 347*1528Sjwadams umem_malloc_dist, umem_malloc_dist_help }, 348*1528Sjwadams { "umem_malloc_info", "?[-dg] [-b maxbins] [-B minbinsize]", 349*1528Sjwadams "report information about malloc()s by cache", 350*1528Sjwadams umem_malloc_info, umem_malloc_info_help }, 3510Sstevel@tonic-gate { "umem_verify", "?", "check integrity of umem-managed memory", 3520Sstevel@tonic-gate umem_verify }, 3530Sstevel@tonic-gate { "vmem", "?", "print a vmem_t", vmem }, 3540Sstevel@tonic-gate { "vmem_seg", ":[-sv] [-c caller] [-e earliest] [-l latest] " 3550Sstevel@tonic-gate "[-m minsize] [-M maxsize] [-t thread] [-T type]", 3560Sstevel@tonic-gate "print or filter a vmem_seg", vmem_seg, vmem_seg_help }, 3570Sstevel@tonic-gate { "whatis", ":[-abv]", "given an address, return information", whatis }, 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate #ifndef _KMDB 3600Sstevel@tonic-gate /* from ../genunix/kgrep.c + libumem.c */ 3610Sstevel@tonic-gate { "ugrep", KGREP_USAGE, "search user address space for a pointer", 3620Sstevel@tonic-gate kgrep }, 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate /* from ../genunix/leaky.c + leaky_subr.c */ 3650Sstevel@tonic-gate { "findleaks", FINDLEAKS_USAGE, "search for potential memory leaks", 3660Sstevel@tonic-gate findleaks, findleaks_help }, 3670Sstevel@tonic-gate #endif 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate { NULL } 3700Sstevel@tonic-gate }; 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate /* from umem.c */ 3750Sstevel@tonic-gate { "allocdby", "given a thread, walk its allocated bufctls", 3760Sstevel@tonic-gate allocdby_walk_init, allocdby_walk_step, allocdby_walk_fini }, 3770Sstevel@tonic-gate { "bufctl", "walk a umem cache's bufctls", 3780Sstevel@tonic-gate bufctl_walk_init, umem_walk_step, umem_walk_fini }, 3790Sstevel@tonic-gate { "bufctl_history", "walk the available history of a bufctl", 3800Sstevel@tonic-gate bufctl_history_walk_init, bufctl_history_walk_step, 3810Sstevel@tonic-gate bufctl_history_walk_fini }, 3820Sstevel@tonic-gate { "freectl", "walk a umem cache's free bufctls", 3830Sstevel@tonic-gate freectl_walk_init, umem_walk_step, umem_walk_fini }, 3840Sstevel@tonic-gate { "freedby", "given a thread, walk its freed bufctls", 3850Sstevel@tonic-gate freedby_walk_init, allocdby_walk_step, allocdby_walk_fini }, 3860Sstevel@tonic-gate { "freemem", "walk a umem cache's free memory", 3870Sstevel@tonic-gate freemem_walk_init, umem_walk_step, umem_walk_fini }, 3880Sstevel@tonic-gate { "umem", "walk a umem cache", 3890Sstevel@tonic-gate umem_walk_init, umem_walk_step, umem_walk_fini }, 3900Sstevel@tonic-gate { "umem_cpu", "walk the umem CPU structures", 3910Sstevel@tonic-gate umem_cpu_walk_init, umem_cpu_walk_step, umem_cpu_walk_fini }, 3920Sstevel@tonic-gate { "umem_cpu_cache", "given a umem cache, walk its per-CPU caches", 3930Sstevel@tonic-gate umem_cpu_cache_walk_init, umem_cpu_cache_walk_step, NULL }, 3940Sstevel@tonic-gate { "umem_hash", "given a umem cache, walk its allocated hash table", 3950Sstevel@tonic-gate umem_hash_walk_init, umem_hash_walk_step, umem_hash_walk_fini }, 3960Sstevel@tonic-gate { "umem_log", "walk the umem transaction log", 3970Sstevel@tonic-gate umem_log_walk_init, umem_log_walk_step, umem_log_walk_fini }, 3980Sstevel@tonic-gate { "umem_slab", "given a umem cache, walk its slabs", 3990Sstevel@tonic-gate umem_slab_walk_init, umem_slab_walk_step, NULL }, 4000Sstevel@tonic-gate { "umem_slab_partial", 4010Sstevel@tonic-gate "given a umem cache, walk its partially allocated slabs (min 1)", 4020Sstevel@tonic-gate umem_slab_walk_partial_init, umem_slab_walk_step, NULL }, 4030Sstevel@tonic-gate { "vmem", "walk vmem structures in pre-fix, depth-first order", 4040Sstevel@tonic-gate vmem_walk_init, vmem_walk_step, vmem_walk_fini }, 4050Sstevel@tonic-gate { "vmem_alloc", "given a vmem_t, walk its allocated vmem_segs", 4060Sstevel@tonic-gate vmem_alloc_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 4070Sstevel@tonic-gate { "vmem_free", "given a vmem_t, walk its free vmem_segs", 4080Sstevel@tonic-gate vmem_free_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 4090Sstevel@tonic-gate { "vmem_postfix", "walk vmem structures in post-fix, depth-first order", 4100Sstevel@tonic-gate vmem_walk_init, vmem_postfix_walk_step, vmem_walk_fini }, 4110Sstevel@tonic-gate { "vmem_seg", "given a vmem_t, walk all of its vmem_segs", 4120Sstevel@tonic-gate vmem_seg_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 4130Sstevel@tonic-gate { "vmem_span", "given a vmem_t, walk its spanning vmem_segs", 4140Sstevel@tonic-gate vmem_span_walk_init, vmem_seg_walk_step, vmem_seg_walk_fini }, 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate #ifndef _KMDB 4170Sstevel@tonic-gate /* from ../genunix/leaky.c + leaky_subr.c */ 4180Sstevel@tonic-gate { "leak", "given a leak ctl, walk other leaks w/ that stacktrace", 4190Sstevel@tonic-gate leaky_walk_init, leaky_walk_step, leaky_walk_fini }, 4200Sstevel@tonic-gate { "leakbuf", "given a leak ctl, walk addr of leaks w/ that stacktrace", 4210Sstevel@tonic-gate leaky_walk_init, leaky_buf_walk_step, leaky_walk_fini }, 4220Sstevel@tonic-gate #endif 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate { NULL } 4250Sstevel@tonic-gate }; 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate static const mdb_modinfo_t modinfo = {MDB_API_VERSION, dcmds, walkers}; 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate const mdb_modinfo_t * 4300Sstevel@tonic-gate _mdb_init(void) 4310Sstevel@tonic-gate { 4320Sstevel@tonic-gate if (umem_init() != 0) 4330Sstevel@tonic-gate return (NULL); 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate return (&modinfo); 4360Sstevel@tonic-gate } 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate void 4390Sstevel@tonic-gate _mdb_fini(void) 4400Sstevel@tonic-gate { 4410Sstevel@tonic-gate #ifndef _KMDB 4420Sstevel@tonic-gate leaky_cleanup(1); 4430Sstevel@tonic-gate #endif 4440Sstevel@tonic-gate } 445