4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
27 /* Portions Copyright 2010 Robert Milkowski */
29 #include <mdb/mdb_ctf.h>
30 #include <sys/zfs_context.h>
31 #include <sys/mdb_modapi.h>
33 #include <sys/dmu_objset.h>
34 #include <sys/dsl_dir.h>
35 #include <sys/dsl_pool.h>
36 #include <sys/metaslab_impl.h>
37 #include <sys/space_map.h>
39 #include <sys/vdev_impl.h>
40 #include <sys/zap_leaf.h>
41 #include <sys/zap_impl.h>
43 #include <sys/zfs_acl.h>
44 #include <sys/sa_impl.h>
45 #include <sys/multilist.h>
48 #define ZFS_OBJ_NAME "zfs"
49 extern int64_t mdb_gethrtime(void);
51 #define ZFS_OBJ_NAME "libzpool.so.1"
54 #define ZFS_STRUCT "struct " ZFS_OBJ_NAME "`"
61 SPA_FLAG_CONFIG
= 1 << 0,
62 SPA_FLAG_VDEVS
= 1 << 1,
63 SPA_FLAG_ERRORS
= 1 << 2,
64 SPA_FLAG_METASLAB_GROUPS
= 1 << 3,
65 SPA_FLAG_METASLABS
= 1 << 4,
66 SPA_FLAG_HISTOGRAMS
= 1 << 5
70 * If any of these flags are set, call spa_vdevs in spa_print
72 #define SPA_FLAG_ALL_VDEV \
73 (SPA_FLAG_VDEVS | SPA_FLAG_ERRORS | SPA_FLAG_METASLAB_GROUPS | \
77 getmember(uintptr_t addr
, const char *type
, mdb_ctf_id_t
*idp
,
78 const char *member
, int len
, void *buf
)
85 if (mdb_ctf_lookup_by_name(type
, &id
) == -1) {
86 mdb_warn("couldn't find type %s", type
);
92 mdb_ctf_type_name(*idp
, name
, sizeof (name
));
95 if (mdb_ctf_offsetof(*idp
, member
, &off
) == -1) {
96 mdb_warn("couldn't find member %s of type %s\n", member
, type
);
100 mdb_warn("member %s of type %s is unsupported bitfield",
106 if (mdb_vread(buf
, len
, addr
+ off
) == -1) {
107 mdb_warn("failed to read %s from %s at %p",
108 member
, type
, addr
+ off
);
111 /* mdb_warn("read %s from %s at %p+%llx\n", member, type, addr, off); */
116 #define GETMEMB(addr, structname, member, dest) \
117 getmember(addr, ZFS_STRUCT structname, NULL, #member, \
118 sizeof (dest), &(dest))
120 #define GETMEMBID(addr, ctfid, member, dest) \
121 getmember(addr, NULL, ctfid, #member, sizeof (dest), &(dest))
124 strisprint(const char *cp
)
133 #define NICENUM_BUFLEN 6
136 snprintfrac(char *buf
, int len
,
137 uint64_t numerator
, uint64_t denom
, int frac_digits
)
142 for (i
= frac_digits
; i
; i
--)
144 whole
= numerator
/ denom
;
145 frac
= mul
* numerator
/ denom
- mul
* whole
;
146 return (mdb_snprintf(buf
, len
, "%u.%0*u", whole
, frac_digits
, frac
));
150 mdb_nicenum(uint64_t num
, char *buf
)
157 n
= (n
+ (1024 / 2)) / 1024; /* Round up or down */
161 u
= &" \0K\0M\0G\0T\0P\0E\0"[index
*2];
164 (void) mdb_snprintf(buf
, NICENUM_BUFLEN
, "%llu",
166 } else if (n
< 10 && (num
& (num
- 1)) != 0) {
167 (void) snprintfrac(buf
, NICENUM_BUFLEN
,
168 num
, 1ULL << 10 * index
, 2);
170 } else if (n
< 100 && (num
& (num
- 1)) != 0) {
171 (void) snprintfrac(buf
, NICENUM_BUFLEN
,
172 num
, 1ULL << 10 * index
, 1);
175 (void) mdb_snprintf(buf
, NICENUM_BUFLEN
, "%llu%s",
183 freelist_walk_init(mdb_walk_state_t
*wsp
)
185 if (wsp
->walk_addr
== (uintptr_t)NULL
) {
186 mdb_warn("must supply starting address\n");
190 wsp
->walk_data
= 0; /* Index into the freelist */
195 freelist_walk_step(mdb_walk_state_t
*wsp
)
198 uintptr_t number
= (uintptr_t)wsp
->walk_data
;
199 char *ddata
[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
200 "INVALID", "INVALID", "INVALID", "INVALID" };
201 int mapshift
= SPA_MINBLOCKSHIFT
;
203 if (mdb_vread(&entry
, sizeof (entry
), wsp
->walk_addr
) == -1) {
204 mdb_warn("failed to read freelist entry %p", wsp
->walk_addr
);
207 wsp
->walk_addr
+= sizeof (entry
);
208 wsp
->walk_data
= (void *)(number
+ 1);
210 if (SM_DEBUG_DECODE(entry
)) {
211 mdb_printf("DEBUG: %3u %10s: txg=%llu pass=%llu\n",
213 ddata
[SM_DEBUG_ACTION_DECODE(entry
)],
214 SM_DEBUG_TXG_DECODE(entry
),
215 SM_DEBUG_SYNCPASS_DECODE(entry
));
217 mdb_printf("Entry: %3u offsets=%08llx-%08llx type=%c "
218 "size=%06llx", number
,
219 SM_OFFSET_DECODE(entry
) << mapshift
,
220 (SM_OFFSET_DECODE(entry
) + SM_RUN_DECODE(entry
)) <<
222 SM_TYPE_DECODE(entry
) == SM_ALLOC
? 'A' : 'F',
223 SM_RUN_DECODE(entry
) << mapshift
);
225 mdb_printf(" (raw=%012llx)\n", entry
);
232 mdb_dsl_dir_name(uintptr_t addr
, char *buf
)
235 static mdb_ctf_id_t dd_id
;
237 char dd_myname
[ZFS_MAX_DATASET_NAME_LEN
];
240 if (mdb_ctf_lookup_by_name(ZFS_STRUCT
"dsl_dir",
242 mdb_warn("couldn't find struct dsl_dir");
247 if (GETMEMBID(addr
, &dd_id
, dd_parent
, dd_parent
) ||
248 GETMEMBID(addr
, &dd_id
, dd_myname
, dd_myname
)) {
253 if (mdb_dsl_dir_name(dd_parent
, buf
))
259 strcat(buf
, dd_myname
);
267 objset_name(uintptr_t addr
, char *buf
)
270 static mdb_ctf_id_t os_id
, ds_id
;
271 uintptr_t os_dsl_dataset
;
272 char ds_snapname
[ZFS_MAX_DATASET_NAME_LEN
];
278 if (mdb_ctf_lookup_by_name(ZFS_STRUCT
"objset",
280 mdb_warn("couldn't find struct objset");
283 if (mdb_ctf_lookup_by_name(ZFS_STRUCT
"dsl_dataset",
285 mdb_warn("couldn't find struct dsl_dataset");
292 if (GETMEMBID(addr
, &os_id
, os_dsl_dataset
, os_dsl_dataset
))
295 if (os_dsl_dataset
== 0) {
300 if (GETMEMBID(os_dsl_dataset
, &ds_id
, ds_snapname
, ds_snapname
) ||
301 GETMEMBID(os_dsl_dataset
, &ds_id
, ds_dir
, ds_dir
)) {
305 if (ds_dir
&& mdb_dsl_dir_name(ds_dir
, buf
))
308 if (ds_snapname
[0]) {
310 strcat(buf
, ds_snapname
);
316 enum_lookup(char *type
, int val
, const char *prefix
, size_t size
, char *out
)
319 size_t len
= strlen(prefix
);
320 mdb_ctf_id_t enum_type
;
322 if (mdb_ctf_lookup_by_name(type
, &enum_type
) != 0) {
323 mdb_warn("Could not find enum for %s", type
);
327 if ((cp
= mdb_ctf_enum_name(enum_type
, val
)) != NULL
) {
328 if (strncmp(cp
, prefix
, len
) == 0)
330 (void) strncpy(out
, cp
, size
);
332 mdb_snprintf(out
, size
, "? (%d)", val
);
339 zfs_params(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
342 * This table can be approximately generated by running:
343 * egrep "^[a-z0-9_]+ [a-z0-9_]+( =.*)?;" *.c | cut -d ' ' -f 2
345 static const char *params
[] = {
346 "arc_reduce_dnlc_percent",
347 "arc_lotsfree_percent",
348 "zfs_dirty_data_max",
349 "zfs_dirty_data_sync",
351 "zfs_delay_min_dirty_percent",
353 "zfs_vdev_max_active",
354 "zfs_vdev_sync_read_min_active",
355 "zfs_vdev_sync_read_max_active",
356 "zfs_vdev_sync_write_min_active",
357 "zfs_vdev_sync_write_max_active",
358 "zfs_vdev_async_read_min_active",
359 "zfs_vdev_async_read_max_active",
360 "zfs_vdev_async_write_min_active",
361 "zfs_vdev_async_write_max_active",
362 "zfs_vdev_scrub_min_active",
363 "zfs_vdev_scrub_max_active",
364 "zfs_vdev_async_write_active_min_dirty_percent",
365 "zfs_vdev_async_write_active_max_dirty_percent",
366 "spa_asize_inflation",
370 "zfs_mdcomp_disable",
371 "zfs_prefetch_disable",
372 "zfetch_max_streams",
373 "zfetch_min_sec_reap",
375 "zfetch_array_rd_sz",
379 "reference_tracking_enable",
381 "spa_max_replication_override",
385 "zfs_vdev_cache_max",
386 "zfs_vdev_cache_size",
387 "zfs_vdev_cache_bshift",
391 "zfs_no_scrub_prefetch",
392 "zfs_vdev_aggregation_limit",
393 "fzap_default_block_shift",
394 "zfs_immediate_write_sz",
395 "zfs_read_chunk_size",
397 "zil_replay_disable",
398 "metaslab_gang_bang",
399 "metaslab_df_alloc_threshold",
400 "metaslab_df_free_pct",
401 "zio_injection_enabled",
402 "zvol_immediate_write_sz",
405 for (int i
= 0; i
< sizeof (params
) / sizeof (params
[0]); i
++) {
408 uint32_t *val32p
= (uint32_t *)&val64
;
410 sz
= mdb_readvar(&val64
, params
[i
]);
412 mdb_printf("%s = 0x%x\n", params
[i
], *val32p
);
413 } else if (sz
== 8) {
414 mdb_printf("%s = 0x%llx\n", params
[i
], val64
);
416 mdb_warn("variable %s not found", params
[i
]);
425 blkptr(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
427 char type
[80], checksum
[80], compress
[80];
428 blkptr_t blk
, *bp
= &blk
;
429 char buf
[BP_SPRINTF_LEN
];
431 if (mdb_vread(&blk
, sizeof (blkptr_t
), addr
) == -1) {
432 mdb_warn("failed to read blkptr_t");
436 if (enum_lookup("enum dmu_object_type", BP_GET_TYPE(bp
), "DMU_OT_",
437 sizeof (type
), type
) == -1 ||
438 enum_lookup("enum zio_checksum", BP_GET_CHECKSUM(bp
),
439 "ZIO_CHECKSUM_", sizeof (checksum
), checksum
) == -1 ||
440 enum_lookup("enum zio_compress", BP_GET_COMPRESS(bp
),
441 "ZIO_COMPRESS_", sizeof (compress
), compress
) == -1) {
442 mdb_warn("Could not find blkptr enumerated types");
446 SNPRINTF_BLKPTR(mdb_snprintf
, '\n', buf
, sizeof (buf
), bp
, type
,
449 mdb_printf("%s\n", buf
);
454 typedef struct mdb_dmu_buf_impl
{
465 } mdb_dmu_buf_impl_t
;
469 dbuf(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
471 mdb_dmu_buf_impl_t db
;
474 char path
[ZFS_MAX_DATASET_NAME_LEN
];
475 int ptr_width
= (int)(sizeof (void *)) * 2;
477 if (DCMD_HDRSPEC(flags
))
478 mdb_printf("%*s %8s %3s %9s %5s %s\n",
479 ptr_width
, "addr", "object", "lvl", "blkid", "holds", "os");
481 if (mdb_ctf_vread(&db
, ZFS_STRUCT
"dmu_buf_impl", "mdb_dmu_buf_impl_t",
485 if (db
.db
.db_object
== DMU_META_DNODE_OBJECT
)
486 (void) strcpy(objectname
, "mdn");
488 (void) mdb_snprintf(objectname
, sizeof (objectname
), "%llx",
489 (u_longlong_t
)db
.db
.db_object
);
491 if (db
.db_blkid
== DMU_BONUS_BLKID
)
492 (void) strcpy(blkidname
, "bonus");
494 (void) mdb_snprintf(blkidname
, sizeof (blkidname
), "%llx",
495 (u_longlong_t
)db
.db_blkid
);
497 if (objset_name(db
.db_objset
, path
)) {
501 mdb_printf("%*p %8s %3u %9s %5llu %s\n", ptr_width
, addr
,
502 objectname
, (int)db
.db_level
, blkidname
,
503 db
.db_holds
.rc_count
, path
);
510 dbuf_stats(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
515 dbuf_hash_table_t ht
;
516 uint64_t bucket
, ndbufs
;
517 uint64_t histo
[HISTOSZ
];
518 uint64_t histo2
[HISTOSZ
];
521 if (mdb_readvar(&ht
, "dbuf_hash_table") == -1) {
522 mdb_warn("failed to read 'dbuf_hash_table'");
526 for (i
= 0; i
< HISTOSZ
; i
++) {
532 for (bucket
= 0; bucket
< ht
.hash_table_mask
+1; bucket
++) {
535 if (mdb_vread(&dbp
, sizeof (void *),
536 (uintptr_t)(ht
.hash_table
+bucket
)) == -1) {
537 mdb_warn("failed to read hash bucket %u at %p",
538 bucket
, ht
.hash_table
+bucket
);
544 if (mdb_vread(&db
, sizeof (dmu_buf_impl_t
),
546 mdb_warn("failed to read dbuf at %p", dbp
);
549 dbp
= (uintptr_t)db
.db_hash_next
;
550 for (i
= MIN(len
, HISTOSZ
- 1); i
>= 0; i
--)
561 mdb_printf("hash table has %llu buckets, %llu dbufs "
562 "(avg %llu buckets/dbuf)\n",
563 ht
.hash_table_mask
+1, ndbufs
,
564 (ht
.hash_table_mask
+1)/ndbufs
);
568 for (i
= 0; i
< HISTOSZ
; i
++)
571 mdb_printf("hash chain length number of buckets\n");
572 for (i
= 0; i
<= maxidx
; i
++)
573 mdb_printf("%u %llu\n", i
, histo
[i
]);
577 for (i
= 0; i
< HISTOSZ
; i
++)
580 mdb_printf("hash chain depth number of dbufs\n");
581 for (i
= 0; i
<= maxidx
; i
++)
582 mdb_printf("%u or more %llu %llu%%\n",
583 i
, histo2
[i
], histo2
[i
]*100/ndbufs
);
589 #define CHAIN_END 0xffff
593 * Print a zap_leaf_phys_t, assumed to be 16k
597 zap_leaf(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
600 int verbose
= B_FALSE
;
604 zap_leaf_phys_t
*zlp
= (void *)buf
;
607 if (mdb_getopts(argc
, argv
,
608 'v', MDB_OPT_SETBITS
, TRUE
, &verbose
,
609 '4', MDB_OPT_SETBITS
, TRUE
, &four
,
613 l_dbuf
.db_data
= zlp
;
615 l
.l_bs
= 14; /* assume 16k blocks */
619 if (!(flags
& DCMD_ADDRSPEC
)) {
623 if (mdb_vread(buf
, sizeof (buf
), addr
) == -1) {
624 mdb_warn("failed to read zap_leaf_phys_t at %p", addr
);
628 if (zlp
->l_hdr
.lh_block_type
!= ZBT_LEAF
||
629 zlp
->l_hdr
.lh_magic
!= ZAP_LEAF_MAGIC
) {
630 mdb_warn("This does not appear to be a zap_leaf_phys_t");
634 mdb_printf("zap_leaf_phys_t at %p:\n", addr
);
635 mdb_printf(" lh_prefix_len = %u\n", zlp
->l_hdr
.lh_prefix_len
);
636 mdb_printf(" lh_prefix = %llx\n", zlp
->l_hdr
.lh_prefix
);
637 mdb_printf(" lh_nentries = %u\n", zlp
->l_hdr
.lh_nentries
);
638 mdb_printf(" lh_nfree = %u\n", zlp
->l_hdr
.lh_nfree
,
639 zlp
->l_hdr
.lh_nfree
* 100 / (ZAP_LEAF_NUMCHUNKS(&l
)));
640 mdb_printf(" lh_freelist = %u\n", zlp
->l_hdr
.lh_freelist
);
641 mdb_printf(" lh_flags = %x (%s)\n", zlp
->l_hdr
.lh_flags
,
642 zlp
->l_hdr
.lh_flags
& ZLF_ENTRIES_CDSORTED
?
643 "ENTRIES_CDSORTED" : "");
646 mdb_printf(" hash table:\n");
647 for (i
= 0; i
< ZAP_LEAF_HASH_NUMENTRIES(&l
); i
++) {
648 if (zlp
->l_hash
[i
] != CHAIN_END
)
649 mdb_printf(" %u: %u\n", i
, zlp
->l_hash
[i
]);
653 mdb_printf(" chunks:\n");
654 for (i
= 0; i
< ZAP_LEAF_NUMCHUNKS(&l
); i
++) {
655 /* LINTED: alignment */
656 zap_leaf_chunk_t
*zlc
= &ZAP_LEAF_CHUNK(&l
, i
);
657 switch (zlc
->l_entry
.le_type
) {
660 mdb_printf(" %u: free; lf_next = %u\n",
661 i
, zlc
->l_free
.lf_next
);
664 case ZAP_CHUNK_ENTRY
:
665 mdb_printf(" %u: entry\n", i
);
667 mdb_printf(" le_next = %u\n",
668 zlc
->l_entry
.le_next
);
670 mdb_printf(" le_name_chunk = %u\n",
671 zlc
->l_entry
.le_name_chunk
);
672 mdb_printf(" le_name_numints = %u\n",
673 zlc
->l_entry
.le_name_numints
);
674 mdb_printf(" le_value_chunk = %u\n",
675 zlc
->l_entry
.le_value_chunk
);
676 mdb_printf(" le_value_intlen = %u\n",
677 zlc
->l_entry
.le_value_intlen
);
678 mdb_printf(" le_value_numints = %u\n",
679 zlc
->l_entry
.le_value_numints
);
680 mdb_printf(" le_cd = %u\n",
682 mdb_printf(" le_hash = %llx\n",
683 zlc
->l_entry
.le_hash
);
685 case ZAP_CHUNK_ARRAY
:
686 mdb_printf(" %u: array", i
);
687 if (strisprint((char *)zlc
->l_array
.la_array
))
688 mdb_printf(" \"%s\"", zlc
->l_array
.la_array
);
693 for (j
= 0; j
< ZAP_LEAF_ARRAY_BYTES
; j
++) {
695 zlc
->l_array
.la_array
[j
]);
699 if (zlc
->l_array
.la_next
!= CHAIN_END
) {
700 mdb_printf(" lf_next = %u\n",
701 zlc
->l_array
.la_next
);
705 mdb_printf(" %u: undefined type %u\n",
706 zlc
->l_entry
.le_type
);
713 typedef struct dbufs_data
{
722 #define DBUFS_UNSET (0xbaddcafedeadbeefULL)
726 dbufs_cb(uintptr_t addr
, const void *unknown
, void *arg
)
728 dbufs_data_t
*data
= arg
;
733 char osname
[ZFS_MAX_DATASET_NAME_LEN
];
735 if (GETMEMBID(addr
, &data
->id
, db_objset
, objset
) ||
736 GETMEMBID(addr
, &data
->id
, db
, db
) ||
737 GETMEMBID(addr
, &data
->id
, db_level
, level
) ||
738 GETMEMBID(addr
, &data
->id
, db_blkid
, blkid
)) {
742 if ((data
->objset
== DBUFS_UNSET
|| data
->objset
== objset
) &&
743 (data
->osname
== NULL
|| (objset_name(objset
, osname
) == 0 &&
744 strcmp(data
->osname
, osname
) == 0)) &&
745 (data
->object
== DBUFS_UNSET
|| data
->object
== db
.db_object
) &&
746 (data
->level
== DBUFS_UNSET
|| data
->level
== level
) &&
747 (data
->blkid
== DBUFS_UNSET
|| data
->blkid
== blkid
)) {
748 mdb_printf("%#lr\n", addr
);
755 dbufs(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
761 data
.objset
= data
.object
= data
.level
= data
.blkid
= DBUFS_UNSET
;
764 if (mdb_getopts(argc
, argv
,
765 'O', MDB_OPT_UINT64
, &data
.objset
,
766 'n', MDB_OPT_STR
, &data
.osname
,
767 'o', MDB_OPT_STR
, &object
,
768 'l', MDB_OPT_UINT64
, &data
.level
,
769 'b', MDB_OPT_STR
, &blkid
) != argc
) {
774 if (strcmp(object
, "mdn") == 0) {
775 data
.object
= DMU_META_DNODE_OBJECT
;
777 data
.object
= mdb_strtoull(object
);
782 if (strcmp(blkid
, "bonus") == 0) {
783 data
.blkid
= DMU_BONUS_BLKID
;
785 data
.blkid
= mdb_strtoull(blkid
);
789 if (mdb_ctf_lookup_by_name(ZFS_STRUCT
"dmu_buf_impl", &data
.id
) == -1) {
790 mdb_warn("couldn't find struct dmu_buf_impl_t");
794 if (mdb_walk("dmu_buf_impl_t", dbufs_cb
, &data
) != 0) {
795 mdb_warn("can't walk dbufs");
802 typedef struct abuf_find_data
{
809 abuf_find_cb(uintptr_t addr
, const void *unknown
, void *arg
)
811 abuf_find_data_t
*data
= arg
;
814 if (GETMEMBID(addr
, &data
->id
, b_dva
, dva
)) {
818 if (dva
.dva_word
[0] == data
->dva
.dva_word
[0] &&
819 dva
.dva_word
[1] == data
->dva
.dva_word
[1]) {
820 mdb_printf("%#lr\n", addr
);
827 abuf_find(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
829 abuf_find_data_t data
;
832 const char *syms
[] = {
842 for (i
= 0; i
< 2; i
++) {
843 switch (argv
[i
].a_type
) {
844 case MDB_TYPE_STRING
:
845 data
.dva
.dva_word
[i
] = mdb_strtoull(argv
[i
].a_un
.a_str
);
847 case MDB_TYPE_IMMEDIATE
:
848 data
.dva
.dva_word
[i
] = argv
[i
].a_un
.a_val
;
855 if (mdb_ctf_lookup_by_name(ZFS_STRUCT
"arc_buf_hdr", &data
.id
) == -1) {
856 mdb_warn("couldn't find struct arc_buf_hdr");
860 for (i
= 0; i
< sizeof (syms
) / sizeof (syms
[0]); i
++) {
861 if (mdb_lookup_by_obj(ZFS_OBJ_NAME
, syms
[i
], &sym
)) {
862 mdb_warn("can't find symbol %s", syms
[i
]);
866 if (mdb_pwalk("list", abuf_find_cb
, &data
, sym
.st_value
) != 0) {
867 mdb_warn("can't walk %s", syms
[i
]);
876 typedef struct dbgmsg_arg
{
877 boolean_t da_verbose
;
878 boolean_t da_address
;
883 dbgmsg_cb(uintptr_t addr
, const void *unknown
, void *arg
)
885 static mdb_ctf_id_t id
;
886 static boolean_t gotid
;
889 dbgmsg_arg_t
*da
= arg
;
894 if (mdb_ctf_lookup_by_name(ZFS_STRUCT
"zfs_dbgmsg", &id
) ==
896 mdb_warn("couldn't find struct zfs_dbgmsg");
900 if (mdb_ctf_offsetof(id
, "zdm_msg", &off
) == -1) {
901 mdb_warn("couldn't find zdm_msg");
908 if (GETMEMBID(addr
, &id
, zdm_timestamp
, timestamp
)) {
912 if (mdb_readstr(buf
, sizeof (buf
), addr
+ off
) == -1) {
913 mdb_warn("failed to read zdm_msg at %p\n", addr
+ off
);
918 mdb_printf("%p ", addr
);
920 mdb_printf("%Y ", timestamp
);
922 mdb_printf("%s\n", buf
);
925 (void) mdb_call_dcmd("whatis", addr
, DCMD_ADDRSPEC
, 0, NULL
);
932 dbgmsg(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
935 dbgmsg_arg_t da
= { 0 };
937 if (mdb_getopts(argc
, argv
,
938 'v', MDB_OPT_SETBITS
, B_TRUE
, &da
.da_verbose
,
939 'a', MDB_OPT_SETBITS
, B_TRUE
, &da
.da_address
,
943 if (mdb_lookup_by_obj(ZFS_OBJ_NAME
, "zfs_dbgmsgs", &sym
)) {
944 mdb_warn("can't find zfs_dbgmsgs");
948 if (mdb_pwalk("list", dbgmsg_cb
, &da
, sym
.st_value
) != 0) {
949 mdb_warn("can't walk zfs_dbgmsgs");
958 arc_print(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
960 kstat_named_t
*stats
;
963 uint_t opt_a
= FALSE
;
964 uint_t opt_b
= FALSE
;
968 static const char *bytestats
[] = {
969 "p", "c", "c_min", "c_max", "size", "duplicate_buffers_size",
970 "arc_meta_used", "arc_meta_limit", "arc_meta_max",
971 "arc_meta_min", "hdr_size", "data_size", "metadata_size",
972 "other_size", "anon_size", "anon_evictable_data",
973 "anon_evictable_metadata", "mru_size", "mru_evictable_data",
974 "mru_evictable_metadata", "mru_ghost_size",
975 "mru_ghost_evictable_data", "mru_ghost_evictable_metadata",
976 "mfu_size", "mfu_evictable_data", "mfu_evictable_metadata",
977 "mfu_ghost_size", "mfu_ghost_evictable_data",
978 "mfu_ghost_evictable_metadata", "evict_l2_cached",
979 "evict_l2_eligible", "evict_l2_ineligible", "l2_read_bytes",
980 "l2_write_bytes", "l2_size", "l2_asize", "l2_hdr_size",
981 "compressed_size", "uncompressed_size", "overhead_size",
985 static const char *extras
[] = {
986 "arc_no_grow", "arc_tempreserve",
990 if (mdb_lookup_by_obj(ZFS_OBJ_NAME
, "arc_stats", &sym
) == -1) {
991 mdb_warn("failed to find 'arc_stats'");
995 stats
= mdb_zalloc(sym
.st_size
, UM_SLEEP
| UM_GC
);
997 if (mdb_vread(stats
, sym
.st_size
, sym
.st_value
) == -1) {
998 mdb_warn("couldn't read 'arc_stats' at %p", sym
.st_value
);
1002 nstats
= sym
.st_size
/ sizeof (kstat_named_t
);
1004 /* NB: -a / opt_a are ignored for backwards compatability */
1005 if (mdb_getopts(argc
, argv
,
1006 'a', MDB_OPT_SETBITS
, TRUE
, &opt_a
,
1007 'b', MDB_OPT_SETBITS
, TRUE
, &opt_b
,
1008 'k', MDB_OPT_SETBITS
, 10, &shift
,
1009 'm', MDB_OPT_SETBITS
, 20, &shift
,
1010 'g', MDB_OPT_SETBITS
, 30, &shift
,
1012 return (DCMD_USAGE
);
1014 if (!opt_b
&& !shift
)
1034 for (i
= 0; i
< nstats
; i
++) {
1036 boolean_t bytes
= B_FALSE
;
1038 for (j
= 0; bytestats
[j
]; j
++) {
1039 if (strcmp(stats
[i
].name
, bytestats
[j
]) == 0) {
1046 mdb_printf("%-25s = %9llu %s\n", stats
[i
].name
,
1047 stats
[i
].value
.ui64
>> shift
, suffix
);
1049 mdb_printf("%-25s = %9llu\n", stats
[i
].name
,
1050 stats
[i
].value
.ui64
);
1054 for (i
= 0; extras
[i
]; i
++) {
1057 if (mdb_lookup_by_obj(ZFS_OBJ_NAME
, extras
[i
], &sym
) == -1) {
1058 mdb_warn("failed to find '%s'", extras
[i
]);
1062 if (sym
.st_size
!= sizeof (uint64_t) &&
1063 sym
.st_size
!= sizeof (uint32_t)) {
1064 mdb_warn("expected scalar for variable '%s'\n",
1069 if (mdb_vread(&buf
, sym
.st_size
, sym
.st_value
) == -1) {
1070 mdb_warn("couldn't read '%s'", extras
[i
]);
1074 mdb_printf("%-25s = ", extras
[i
]);
1076 /* NB: all the 64-bit extras happen to be byte counts */
1077 if (sym
.st_size
== sizeof (uint64_t))
1078 mdb_printf("%9llu %s\n", buf
>> shift
, suffix
);
1080 if (sym
.st_size
== sizeof (uint32_t))
1081 mdb_printf("%9d\n", *((uint32_t *)&buf
));
1086 typedef struct mdb_spa_print
{
1087 pool_state_t spa_state
;
1088 char spa_name
[ZFS_MAX_DATASET_NAME_LEN
];
1089 uintptr_t spa_normal_class
;
1093 const char histo_stars
[] = "****************************************";
1094 const int histo_width
= sizeof (histo_stars
) - 1;
1097 dump_histogram(const uint64_t *histo
, int size
, int offset
)
1100 int minidx
= size
- 1;
1104 for (i
= 0; i
< size
; i
++) {
1107 if (histo
[i
] > 0 && i
> maxidx
)
1109 if (histo
[i
] > 0 && i
< minidx
)
1113 if (max
< histo_width
)
1116 for (i
= minidx
; i
<= maxidx
; i
++) {
1117 mdb_printf("%3u: %6llu %s\n",
1118 i
+ offset
, (u_longlong_t
)histo
[i
],
1119 &histo_stars
[(max
- histo
[i
]) * histo_width
/ max
]);
1123 typedef struct mdb_metaslab_class
{
1124 uint64_t mc_histogram
[RANGE_TREE_HISTOGRAM_SIZE
];
1125 } mdb_metaslab_class_t
;
1128 * spa_class_histogram(uintptr_t class_addr)
1130 * Prints free space histogram for a device class
1132 * Returns DCMD_OK, or DCMD_ERR.
1135 spa_class_histogram(uintptr_t class_addr
)
1137 mdb_metaslab_class_t mc
;
1138 if (mdb_ctf_vread(&mc
, "metaslab_class_t",
1139 "mdb_metaslab_class_t", class_addr
, 0) == -1)
1143 dump_histogram(mc
.mc_histogram
, RANGE_TREE_HISTOGRAM_SIZE
, 0);
1151 * -c Print configuration information as well
1152 * -v Print vdev state
1153 * -e Print vdev error stats
1154 * -m Print vdev metaslab info
1155 * -M print vdev metaslab group info
1156 * -h Print histogram info (must be combined with -m or -M)
1158 * Print a summarized spa_t. When given no arguments, prints out a table of all
1159 * active pools on the system.
1163 spa_print(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1165 const char *statetab
[] = { "ACTIVE", "EXPORTED", "DESTROYED",
1166 "SPARE", "L2CACHE", "UNINIT", "UNAVAIL", "POTENTIAL" };
1170 if (mdb_getopts(argc
, argv
,
1171 'c', MDB_OPT_SETBITS
, SPA_FLAG_CONFIG
, &spa_flags
,
1172 'v', MDB_OPT_SETBITS
, SPA_FLAG_VDEVS
, &spa_flags
,
1173 'e', MDB_OPT_SETBITS
, SPA_FLAG_ERRORS
, &spa_flags
,
1174 'M', MDB_OPT_SETBITS
, SPA_FLAG_METASLAB_GROUPS
, &spa_flags
,
1175 'm', MDB_OPT_SETBITS
, SPA_FLAG_METASLABS
, &spa_flags
,
1176 'h', MDB_OPT_SETBITS
, SPA_FLAG_HISTOGRAMS
, &spa_flags
,
1178 return (DCMD_USAGE
);
1180 if (!(flags
& DCMD_ADDRSPEC
)) {
1181 if (mdb_walk_dcmd("spa", "spa", argc
, argv
) == -1) {
1182 mdb_warn("can't walk spa");
1189 if (flags
& DCMD_PIPE_OUT
) {
1190 mdb_printf("%#lr\n", addr
);
1194 if (DCMD_HDRSPEC(flags
))
1195 mdb_printf("%<u>%-?s %9s %-*s%</u>\n", "ADDR", "STATE",
1196 sizeof (uintptr_t) == 4 ? 60 : 52, "NAME");
1198 mdb_spa_print_t spa
;
1199 if (mdb_ctf_vread(&spa
, "spa_t", "mdb_spa_print_t", addr
, 0) == -1)
1202 if (spa
.spa_state
< 0 || spa
.spa_state
> POOL_STATE_UNAVAIL
)
1205 state
= statetab
[spa
.spa_state
];
1207 mdb_printf("%0?p %9s %s\n", addr
, state
, spa
.spa_name
);
1208 if (spa_flags
& SPA_FLAG_HISTOGRAMS
)
1209 spa_class_histogram(spa
.spa_normal_class
);
1211 if (spa_flags
& SPA_FLAG_CONFIG
) {
1214 if (mdb_call_dcmd("spa_config", addr
, flags
, 0,
1220 if (spa_flags
& SPA_FLAG_ALL_VDEV
) {
1222 char opts
[100] = "-";
1224 (spa_flags
| SPA_FLAG_VDEVS
) == SPA_FLAG_VDEVS
? 0 : 1;
1226 if (spa_flags
& SPA_FLAG_ERRORS
)
1228 if (spa_flags
& SPA_FLAG_METASLABS
)
1230 if (spa_flags
& SPA_FLAG_METASLAB_GROUPS
)
1232 if (spa_flags
& SPA_FLAG_HISTOGRAMS
)
1235 v
.a_type
= MDB_TYPE_STRING
;
1236 v
.a_un
.a_str
= opts
;
1240 if (mdb_call_dcmd("spa_vdevs", addr
, flags
, args
,
1249 typedef struct mdb_spa_config_spa
{
1250 uintptr_t spa_config
;
1251 } mdb_spa_config_spa_t
;
1256 * Given a spa_t, print the configuration information stored in spa_config.
1257 * Since it's just an nvlist, format it as an indented list of name=value pairs.
1258 * We simply read the value of spa_config and pass off to ::nvlist.
1262 spa_print_config(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1264 mdb_spa_config_spa_t spa
;
1266 if (argc
!= 0 || !(flags
& DCMD_ADDRSPEC
))
1267 return (DCMD_USAGE
);
1269 if (mdb_ctf_vread(&spa
, ZFS_STRUCT
"spa", "mdb_spa_config_spa_t",
1273 if (spa
.spa_config
== 0) {
1274 mdb_printf("(none)\n");
1278 return (mdb_call_dcmd("nvlist", spa
.spa_config
, flags
,
1284 typedef struct mdb_range_tree
{
1288 typedef struct mdb_metaslab_group
{
1289 uint64_t mg_fragmentation
;
1290 uint64_t mg_histogram
[RANGE_TREE_HISTOGRAM_SIZE
];
1292 } mdb_metaslab_group_t
;
1294 typedef struct mdb_metaslab
{
1298 int64_t ms_deferspace
;
1299 uint64_t ms_fragmentation
;
1301 uintptr_t ms_alloctree
[TXG_SIZE
];
1302 uintptr_t ms_freeingtree
;
1303 uintptr_t ms_freedtree
;
1308 typedef struct mdb_space_map_phys_t
{
1310 uint64_t smp_histogram
[SPACE_MAP_HISTOGRAM_SIZE
];
1311 } mdb_space_map_phys_t
;
1313 typedef struct mdb_space_map
{
1320 typedef struct mdb_vdev
{
1321 uintptr_t vdev_path
;
1324 uint64_t vdev_ms_count
;
1326 vdev_stat_t vdev_stat
;
1329 typedef struct mdb_vdev_ops
{
1330 char vdev_op_type
[16];
1334 metaslab_stats(uintptr_t addr
, int spa_flags
)
1339 if (mdb_ctf_vread(&vdev
, "vdev_t", "mdb_vdev_t",
1340 (uintptr_t)addr
, 0) == -1) {
1341 mdb_warn("failed to read vdev at %p\n", addr
);
1346 mdb_printf("%<u>%-?s %6s %20s %10s %9s%</u>\n", "ADDR", "ID",
1347 "OFFSET", "FREE", "FRAGMENTATION");
1349 vdev_ms
= mdb_alloc(vdev
.vdev_ms_count
* sizeof (void *),
1351 if (mdb_vread(vdev_ms
, vdev
.vdev_ms_count
* sizeof (void *),
1352 (uintptr_t)vdev
.vdev_ms
) == -1) {
1353 mdb_warn("failed to read vdev_ms at %p\n", vdev
.vdev_ms
);
1357 for (int m
= 0; m
< vdev
.vdev_ms_count
; m
++) {
1359 mdb_space_map_t sm
= { 0 };
1360 char free
[NICENUM_BUFLEN
];
1362 if (mdb_ctf_vread(&ms
, "metaslab_t", "mdb_metaslab_t",
1363 (uintptr_t)vdev_ms
[m
], 0) == -1)
1366 if (ms
.ms_sm
!= (uintptr_t)NULL
&&
1367 mdb_ctf_vread(&sm
, "space_map_t", "mdb_space_map_t",
1371 mdb_nicenum(ms
.ms_size
- sm
.sm_alloc
, free
);
1373 mdb_printf("%0?p %6llu %20llx %10s ", vdev_ms
[m
], ms
.ms_id
,
1375 if (ms
.ms_fragmentation
== ZFS_FRAG_INVALID
)
1376 mdb_printf("%9s\n", "-");
1378 mdb_printf("%9llu%%\n", ms
.ms_fragmentation
);
1380 if ((spa_flags
& SPA_FLAG_HISTOGRAMS
) && ms
.ms_sm
!= 0) {
1381 mdb_space_map_phys_t smp
;
1383 if (sm
.sm_phys
== (uintptr_t)NULL
)
1386 (void) mdb_ctf_vread(&smp
, "space_map_phys_t",
1387 "mdb_space_map_phys_t", sm
.sm_phys
, 0);
1389 dump_histogram(smp
.smp_histogram
,
1390 SPACE_MAP_HISTOGRAM_SIZE
, sm
.sm_shift
);
1398 metaslab_group_stats(uintptr_t addr
, int spa_flags
)
1400 mdb_metaslab_group_t mg
;
1401 if (mdb_ctf_vread(&mg
, "metaslab_group_t", "mdb_metaslab_group_t",
1402 (uintptr_t)addr
, 0) == -1) {
1403 mdb_warn("failed to read vdev_mg at %p\n", addr
);
1408 mdb_printf("%<u>%-?s %15s%</u>\n", "ADDR", "FRAGMENTATION");
1409 if (mg
.mg_fragmentation
== ZFS_FRAG_INVALID
)
1410 mdb_printf("%0?p %15s\n", addr
, "-");
1412 mdb_printf("%0?p %15llu%%\n", addr
, mg
.mg_fragmentation
);
1414 if (spa_flags
& SPA_FLAG_HISTOGRAMS
)
1415 dump_histogram(mg
.mg_histogram
, RANGE_TREE_HISTOGRAM_SIZE
, 0);
1423 * Print out a summarized vdev_t, in the following form:
1425 * ADDR STATE AUX DESC
1426 * fffffffbcde23df0 HEALTHY - /dev/dsk/c0t0d0
1428 * If '-r' is specified, recursively visit all children.
1430 * With '-e', the statistics associated with the vdev are printed as well.
1433 do_print_vdev(uintptr_t addr
, int flags
, int depth
, boolean_t recursive
,
1437 char desc
[MAXNAMELEN
];
1440 const char *state
, *aux
;
1442 if (mdb_vread(&vdev
, sizeof (vdev
), (uintptr_t)addr
) == -1) {
1443 mdb_warn("failed to read vdev_t at %p\n", (uintptr_t)addr
);
1447 if (flags
& DCMD_PIPE_OUT
) {
1448 mdb_printf("%#lr\n", addr
);
1450 if (vdev
.vdev_path
!= NULL
) {
1451 if (mdb_readstr(desc
, sizeof (desc
),
1452 (uintptr_t)vdev
.vdev_path
) == -1) {
1453 mdb_warn("failed to read vdev_path at %p\n",
1457 } else if (vdev
.vdev_ops
!= NULL
) {
1459 if (mdb_vread(&ops
, sizeof (ops
),
1460 (uintptr_t)vdev
.vdev_ops
) == -1) {
1461 mdb_warn("failed to read vdev_ops at %p\n",
1465 (void) strcpy(desc
, ops
.vdev_op_type
);
1467 (void) strcpy(desc
, "<unknown>");
1470 if (depth
== 0 && DCMD_HDRSPEC(flags
))
1471 mdb_printf("%<u>%-?s %-9s %-12s %-*s%</u>\n",
1472 "ADDR", "STATE", "AUX",
1473 sizeof (uintptr_t) == 4 ? 43 : 35,
1476 mdb_printf("%0?p ", addr
);
1478 switch (vdev
.vdev_state
) {
1479 case VDEV_STATE_CLOSED
:
1482 case VDEV_STATE_OFFLINE
:
1485 case VDEV_STATE_CANT_OPEN
:
1486 state
= "CANT_OPEN";
1488 case VDEV_STATE_DEGRADED
:
1491 case VDEV_STATE_HEALTHY
:
1494 case VDEV_STATE_REMOVED
:
1497 case VDEV_STATE_FAULTED
:
1505 switch (vdev
.vdev_stat
.vs_aux
) {
1509 case VDEV_AUX_OPEN_FAILED
:
1510 aux
= "OPEN_FAILED";
1512 case VDEV_AUX_CORRUPT_DATA
:
1513 aux
= "CORRUPT_DATA";
1515 case VDEV_AUX_NO_REPLICAS
:
1516 aux
= "NO_REPLICAS";
1518 case VDEV_AUX_BAD_GUID_SUM
:
1519 aux
= "BAD_GUID_SUM";
1521 case VDEV_AUX_TOO_SMALL
:
1524 case VDEV_AUX_BAD_LABEL
:
1527 case VDEV_AUX_VERSION_NEWER
:
1530 case VDEV_AUX_VERSION_OLDER
:
1533 case VDEV_AUX_UNSUP_FEAT
:
1536 case VDEV_AUX_SPARED
:
1539 case VDEV_AUX_ERR_EXCEEDED
:
1540 aux
= "ERR_EXCEEDED";
1542 case VDEV_AUX_IO_FAILURE
:
1545 case VDEV_AUX_BAD_LOG
:
1548 case VDEV_AUX_EXTERNAL
:
1551 case VDEV_AUX_SPLIT_POOL
:
1559 mdb_printf("%-9s %-12s %*s%s\n", state
, aux
, depth
, "", desc
);
1561 if (spa_flags
& SPA_FLAG_ERRORS
) {
1562 vdev_stat_t
*vs
= &vdev
.vdev_stat
;
1567 mdb_printf("%<u> %12s %12s %12s %12s "
1568 "%12s%</u>\n", "READ", "WRITE", "FREE", "CLAIM",
1571 for (i
= 1; i
< ZIO_TYPES
; i
++)
1572 mdb_printf("%11#llx%s", vs
->vs_ops
[i
],
1573 i
== ZIO_TYPES
- 1 ? "" : " ");
1575 mdb_printf("BYTES ");
1576 for (i
= 1; i
< ZIO_TYPES
; i
++)
1577 mdb_printf("%11#llx%s", vs
->vs_bytes
[i
],
1578 i
== ZIO_TYPES
- 1 ? "" : " ");
1582 mdb_printf("EREAD %10#llx\n", vs
->vs_read_errors
);
1583 mdb_printf("EWRITE %10#llx\n", vs
->vs_write_errors
);
1584 mdb_printf("ECKSUM %10#llx\n",
1585 vs
->vs_checksum_errors
);
1590 if (spa_flags
& SPA_FLAG_METASLAB_GROUPS
&&
1591 vdev
.vdev_mg
!= NULL
) {
1592 metaslab_group_stats((uintptr_t)vdev
.vdev_mg
,
1595 if (spa_flags
& SPA_FLAG_METASLABS
&& vdev
.vdev_ms
!= NULL
) {
1596 metaslab_stats((uintptr_t)addr
, spa_flags
);
1600 children
= vdev
.vdev_children
;
1602 if (children
== 0 || !recursive
)
1605 child
= mdb_alloc(children
* sizeof (void *), UM_SLEEP
| UM_GC
);
1606 if (mdb_vread(child
, children
* sizeof (void *),
1607 (uintptr_t)vdev
.vdev_child
) == -1) {
1608 mdb_warn("failed to read vdev children at %p", vdev
.vdev_child
);
1612 for (c
= 0; c
< children
; c
++) {
1613 if (do_print_vdev(child
[c
], flags
, depth
+ 2, recursive
,
1623 vdev_print(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1626 boolean_t recursive
= B_FALSE
;
1629 if (mdb_getopts(argc
, argv
,
1630 'e', MDB_OPT_SETBITS
, SPA_FLAG_ERRORS
, &spa_flags
,
1631 'm', MDB_OPT_SETBITS
, SPA_FLAG_METASLABS
, &spa_flags
,
1632 'M', MDB_OPT_SETBITS
, SPA_FLAG_METASLAB_GROUPS
, &spa_flags
,
1633 'h', MDB_OPT_SETBITS
, SPA_FLAG_HISTOGRAMS
, &spa_flags
,
1634 'r', MDB_OPT_SETBITS
, TRUE
, &recursive
,
1635 'd', MDB_OPT_UINT64
, &depth
, NULL
) != argc
)
1636 return (DCMD_USAGE
);
1638 if (!(flags
& DCMD_ADDRSPEC
)) {
1639 mdb_warn("no vdev_t address given\n");
1643 return (do_print_vdev(addr
, flags
, (int)depth
, recursive
, spa_flags
));
1646 typedef struct mdb_metaslab_alloc_trace
{
1650 uint64_t mat_weight
;
1651 uint64_t mat_offset
;
1652 uint32_t mat_dva_id
;
1653 } mdb_metaslab_alloc_trace_t
;
1656 metaslab_print_weight(uint64_t weight
)
1660 if (WEIGHT_IS_SPACEBASED(weight
)) {
1662 weight
& ~(METASLAB_ACTIVE_MASK
| METASLAB_WEIGHT_TYPE
),
1665 char size
[NICENUM_BUFLEN
];
1666 mdb_nicenum(1ULL << WEIGHT_GET_INDEX(weight
), size
);
1667 (void) mdb_snprintf(buf
, sizeof (buf
), "%llu x %s",
1668 WEIGHT_GET_COUNT(weight
), size
);
1670 mdb_printf("%11s ", buf
);
1675 metaslab_weight(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1677 uint64_t weight
= 0;
1680 if (argc
== 0 && (flags
& DCMD_ADDRSPEC
)) {
1681 if (mdb_vread(&weight
, sizeof (uint64_t), addr
) == -1) {
1682 mdb_warn("failed to read weight at %p\n", addr
);
1685 } else if (argc
== 1 && !(flags
& DCMD_ADDRSPEC
)) {
1686 weight
= (argv
[0].a_type
== MDB_TYPE_IMMEDIATE
) ?
1687 argv
[0].a_un
.a_val
: mdb_strtoull(argv
[0].a_un
.a_str
);
1689 return (DCMD_USAGE
);
1692 if (DCMD_HDRSPEC(flags
)) {
1693 mdb_printf("%<u>%-6s %9s %9s%</u>\n",
1694 "ACTIVE", "ALGORITHM", "WEIGHT");
1697 if (weight
& METASLAB_WEIGHT_PRIMARY
)
1699 else if (weight
& METASLAB_WEIGHT_SECONDARY
)
1703 mdb_printf("%6c %8s ", active
,
1704 WEIGHT_IS_SPACEBASED(weight
) ? "SPACE" : "SEGMENT");
1705 metaslab_print_weight(weight
);
1713 metaslab_trace(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1715 mdb_metaslab_alloc_trace_t mat
;
1716 mdb_metaslab_group_t mg
= { 0 };
1717 char result_type
[100];
1719 if (mdb_ctf_vread(&mat
, "metaslab_alloc_trace_t",
1720 "mdb_metaslab_alloc_trace_t", addr
, 0) == -1) {
1724 if (!(flags
& DCMD_PIPE_OUT
) && DCMD_HDRSPEC(flags
)) {
1725 mdb_printf("%<u>%6s %6s %8s %11s %18s %18s%</u>\n",
1726 "MSID", "DVA", "ASIZE", "WEIGHT", "RESULT", "VDEV");
1729 if (mat
.mat_msp
!= 0) {
1732 if (mdb_ctf_vread(&ms
, "metaslab_t", "mdb_metaslab_t",
1733 mat
.mat_msp
, 0) == -1) {
1736 mdb_printf("%6llu ", ms
.ms_id
);
1738 mdb_printf("%6s ", "-");
1741 mdb_printf("%6d %8llx ", mat
.mat_dva_id
, mat
.mat_size
);
1743 metaslab_print_weight(mat
.mat_weight
);
1745 if ((int64_t)mat
.mat_offset
< 0) {
1746 if (enum_lookup("enum trace_alloc_type", mat
.mat_offset
,
1747 "TRACE_", sizeof (result_type
), result_type
) == -1) {
1748 mdb_warn("Could not find enum for trace_alloc_type");
1751 mdb_printf("%18s ", result_type
);
1753 mdb_printf("%<b>%18llx%</b> ", mat
.mat_offset
);
1756 if (mat
.mat_mg
!= 0 &&
1757 mdb_ctf_vread(&mg
, "metaslab_group_t", "mdb_metaslab_group_t",
1758 mat
.mat_mg
, 0) == -1) {
1762 if (mg
.mg_vd
!= 0) {
1764 char desc
[MAXNAMELEN
];
1766 if (mdb_ctf_vread(&vdev
, "vdev_t", "mdb_vdev_t",
1767 mg
.mg_vd
, 0) == -1) {
1771 if (vdev
.vdev_path
!= 0) {
1772 char path
[MAXNAMELEN
];
1774 if (mdb_readstr(path
, sizeof (path
),
1775 vdev
.vdev_path
) == -1) {
1776 mdb_warn("failed to read vdev_path at %p\n",
1781 if ((slash
= strrchr(path
, '/')) != NULL
) {
1782 strcpy(desc
, slash
+ 1);
1786 } else if (vdev
.vdev_ops
!= 0) {
1788 if (mdb_ctf_vread(&ops
, "vdev_ops_t", "mdb_vdev_ops_t",
1789 vdev
.vdev_ops
, 0) == -1) {
1790 mdb_warn("failed to read vdev_ops at %p\n",
1794 (void) mdb_snprintf(desc
, sizeof (desc
),
1795 "%s-%llu", ops
.vdev_op_type
, vdev
.vdev_id
);
1797 (void) strcpy(desc
, "<unknown>");
1799 mdb_printf("%18s\n", desc
);
1805 typedef struct metaslab_walk_data
{
1806 uint64_t mw_numvdevs
;
1807 uintptr_t *mw_vdevs
;
1812 } metaslab_walk_data_t
;
1815 metaslab_walk_step(mdb_walk_state_t
*wsp
)
1817 metaslab_walk_data_t
*mw
= wsp
->walk_data
;
1821 if (mw
->mw_curvdev
>= mw
->mw_numvdevs
)
1824 if (mw
->mw_mss
== NULL
) {
1828 ASSERT(mw
->mw_curms
== 0);
1829 ASSERT(mw
->mw_nummss
== 0);
1831 vdevp
= mw
->mw_vdevs
[mw
->mw_curvdev
];
1832 if (GETMEMB(vdevp
, "vdev", vdev_ms
, mssp
) ||
1833 GETMEMB(vdevp
, "vdev", vdev_ms_count
, mw
->mw_nummss
)) {
1837 mw
->mw_mss
= mdb_alloc(mw
->mw_nummss
* sizeof (void*),
1839 if (mdb_vread(mw
->mw_mss
, mw
->mw_nummss
* sizeof (void*),
1841 mdb_warn("failed to read vdev_ms at %p", mssp
);
1846 if (mw
->mw_curms
>= mw
->mw_nummss
) {
1854 msp
= mw
->mw_mss
[mw
->mw_curms
];
1855 if (mdb_vread(&ms
, sizeof (metaslab_t
), msp
) == -1) {
1856 mdb_warn("failed to read metaslab_t at %p", msp
);
1862 return (wsp
->walk_callback(msp
, &ms
, wsp
->walk_cbdata
));
1866 metaslab_walk_init(mdb_walk_state_t
*wsp
)
1868 metaslab_walk_data_t
*mw
;
1869 uintptr_t root_vdevp
;
1872 if (wsp
->walk_addr
== (uintptr_t)NULL
) {
1873 mdb_warn("must supply address of spa_t\n");
1877 mw
= mdb_zalloc(sizeof (metaslab_walk_data_t
), UM_SLEEP
| UM_GC
);
1879 if (GETMEMB(wsp
->walk_addr
, "spa", spa_root_vdev
, root_vdevp
) ||
1880 GETMEMB(root_vdevp
, "vdev", vdev_children
, mw
->mw_numvdevs
) ||
1881 GETMEMB(root_vdevp
, "vdev", vdev_child
, childp
)) {
1885 mw
->mw_vdevs
= mdb_alloc(mw
->mw_numvdevs
* sizeof (void *),
1887 if (mdb_vread(mw
->mw_vdevs
, mw
->mw_numvdevs
* sizeof (void *),
1889 mdb_warn("failed to read root vdev children at %p", childp
);
1893 wsp
->walk_data
= mw
;
1898 typedef struct mdb_spa
{
1899 uintptr_t spa_dsl_pool
;
1900 uintptr_t spa_root_vdev
;
1903 typedef struct mdb_dsl_pool
{
1904 uintptr_t dp_root_dir
;
1907 typedef struct mdb_dsl_dir
{
1909 int64_t dd_space_towrite
[TXG_SIZE
];
1912 typedef struct mdb_dsl_dir_phys
{
1913 uint64_t dd_used_bytes
;
1914 uint64_t dd_compressed_bytes
;
1915 uint64_t dd_uncompressed_bytes
;
1916 } mdb_dsl_dir_phys_t
;
1918 typedef struct space_data
{
1919 uint64_t ms_alloctree
[TXG_SIZE
];
1920 uint64_t ms_freeingtree
;
1921 uint64_t ms_freedtree
;
1923 int64_t ms_deferspace
;
1930 space_cb(uintptr_t addr
, const void *unknown
, void *arg
)
1932 space_data_t
*sd
= arg
;
1934 mdb_range_tree_t rt
;
1935 mdb_space_map_t sm
= { 0 };
1936 mdb_space_map_phys_t smp
= { 0 };
1939 if (mdb_ctf_vread(&ms
, "metaslab_t", "mdb_metaslab_t",
1943 for (i
= 0; i
< TXG_SIZE
; i
++) {
1944 if (mdb_ctf_vread(&rt
, "range_tree_t",
1945 "mdb_range_tree_t", ms
.ms_alloctree
[i
], 0) == -1)
1948 sd
->ms_alloctree
[i
] += rt
.rt_space
;
1952 if (mdb_ctf_vread(&rt
, "range_tree_t",
1953 "mdb_range_tree_t", ms
.ms_freeingtree
, 0) == -1)
1955 sd
->ms_freeingtree
+= rt
.rt_space
;
1957 if (mdb_ctf_vread(&rt
, "range_tree_t",
1958 "mdb_range_tree_t", ms
.ms_freedtree
, 0) == -1)
1960 sd
->ms_freedtree
+= rt
.rt_space
;
1962 if (mdb_ctf_vread(&rt
, "range_tree_t",
1963 "mdb_range_tree_t", ms
.ms_tree
, 0) == -1)
1965 sd
->ms_tree
+= rt
.rt_space
;
1967 if (ms
.ms_sm
!= (uintptr_t)NULL
&&
1968 mdb_ctf_vread(&sm
, "space_map_t",
1969 "mdb_space_map_t", ms
.ms_sm
, 0) == -1)
1972 if (sm
.sm_phys
!= (uintptr_t)NULL
) {
1973 (void) mdb_ctf_vread(&smp
, "space_map_phys_t",
1974 "mdb_space_map_phys_t", sm
.sm_phys
, 0);
1977 sd
->ms_deferspace
+= ms
.ms_deferspace
;
1978 sd
->avail
+= sm
.sm_size
- sm
.sm_alloc
;
1979 sd
->nowavail
+= sm
.sm_size
- smp
.smp_alloc
;
1987 * Given a spa_t, print out it's on-disk space usage and in-core
1988 * estimates of future usage. If -b is given, print space in bytes.
1989 * Otherwise print in megabytes.
1993 spa_space(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1998 mdb_dmu_buf_impl_t db
;
1999 mdb_dsl_dir_phys_t dsp
;
2003 int bytes
= B_FALSE
;
2005 if (mdb_getopts(argc
, argv
, 'b', MDB_OPT_SETBITS
, TRUE
, &bytes
, NULL
) !=
2007 return (DCMD_USAGE
);
2008 if (!(flags
& DCMD_ADDRSPEC
))
2009 return (DCMD_USAGE
);
2016 if (mdb_ctf_vread(&spa
, ZFS_STRUCT
"spa", "mdb_spa_t",
2018 mdb_ctf_vread(&dp
, ZFS_STRUCT
"dsl_pool", "mdb_dsl_pool_t",
2019 spa
.spa_dsl_pool
, 0) == -1 ||
2020 mdb_ctf_vread(&dd
, ZFS_STRUCT
"dsl_dir", "mdb_dsl_dir_t",
2021 dp
.dp_root_dir
, 0) == -1 ||
2022 mdb_ctf_vread(&db
, ZFS_STRUCT
"dmu_buf_impl", "mdb_dmu_buf_impl_t",
2023 dd
.dd_dbuf
, 0) == -1 ||
2024 mdb_ctf_vread(&dsp
, ZFS_STRUCT
"dsl_dir_phys",
2025 "mdb_dsl_dir_phys_t", db
.db
.db_data
, 0) == -1) {
2029 mdb_printf("dd_space_towrite = %llu%s %llu%s %llu%s %llu%s\n",
2030 dd
.dd_space_towrite
[0] >> shift
, suffix
,
2031 dd
.dd_space_towrite
[1] >> shift
, suffix
,
2032 dd
.dd_space_towrite
[2] >> shift
, suffix
,
2033 dd
.dd_space_towrite
[3] >> shift
, suffix
);
2035 mdb_printf("dd_phys.dd_used_bytes = %llu%s\n",
2036 dsp
.dd_used_bytes
>> shift
, suffix
);
2037 mdb_printf("dd_phys.dd_compressed_bytes = %llu%s\n",
2038 dsp
.dd_compressed_bytes
>> shift
, suffix
);
2039 mdb_printf("dd_phys.dd_uncompressed_bytes = %llu%s\n",
2040 dsp
.dd_uncompressed_bytes
>> shift
, suffix
);
2042 bzero(&sd
, sizeof (sd
));
2043 if (mdb_pwalk("metaslab", space_cb
, &sd
, addr
) != 0) {
2044 mdb_warn("can't walk metaslabs");
2048 mdb_printf("ms_allocmap = %llu%s %llu%s %llu%s %llu%s\n",
2049 sd
.ms_alloctree
[0] >> shift
, suffix
,
2050 sd
.ms_alloctree
[1] >> shift
, suffix
,
2051 sd
.ms_alloctree
[2] >> shift
, suffix
,
2052 sd
.ms_alloctree
[3] >> shift
, suffix
);
2053 mdb_printf("ms_freeingtree = %llu%s\n",
2054 sd
.ms_freeingtree
>> shift
, suffix
);
2055 mdb_printf("ms_freedtree = %llu%s\n",
2056 sd
.ms_freedtree
>> shift
, suffix
);
2057 mdb_printf("ms_tree = %llu%s\n", sd
.ms_tree
>> shift
, suffix
);
2058 mdb_printf("ms_deferspace = %llu%s\n",
2059 sd
.ms_deferspace
>> shift
, suffix
);
2060 mdb_printf("last synced avail = %llu%s\n", sd
.avail
>> shift
, suffix
);
2061 mdb_printf("current syncing avail = %llu%s\n",
2062 sd
.nowavail
>> shift
, suffix
);
2067 typedef struct mdb_spa_aux_vdev
{
2069 uintptr_t sav_vdevs
;
2070 } mdb_spa_aux_vdev_t
;
2072 typedef struct mdb_spa_vdevs
{
2073 uintptr_t spa_root_vdev
;
2074 mdb_spa_aux_vdev_t spa_l2cache
;
2075 mdb_spa_aux_vdev_t spa_spares
;
2079 spa_print_aux(mdb_spa_aux_vdev_t
*sav
, uint_t flags
, mdb_arg_t
*v
,
2087 * Iterate over aux vdevs and print those out as well. This is a
2088 * little annoying because we don't have a root vdev to pass to ::vdev.
2089 * Instead, we print a single line and then call it for each child
2092 if (sav
->sav_count
!= 0) {
2093 v
[1].a_type
= MDB_TYPE_STRING
;
2094 v
[1].a_un
.a_str
= "-d";
2095 v
[2].a_type
= MDB_TYPE_IMMEDIATE
;
2096 v
[2].a_un
.a_val
= 2;
2098 len
= sav
->sav_count
* sizeof (uintptr_t);
2099 aux
= mdb_alloc(len
, UM_SLEEP
);
2100 if (mdb_vread(aux
, len
, sav
->sav_vdevs
) == -1) {
2102 mdb_warn("failed to read l2cache vdevs at %p",
2107 mdb_printf("%-?s %-9s %-12s %s\n", "-", "-", "-", name
);
2109 for (i
= 0; i
< sav
->sav_count
; i
++) {
2110 ret
= mdb_call_dcmd("vdev", aux
[i
], flags
, 3, v
);
2111 if (ret
!= DCMD_OK
) {
2126 * -e Include error stats
2127 * -m Include metaslab information
2128 * -M Include metaslab group information
2129 * -h Include histogram information (requires -m or -M)
2131 * Print out a summarized list of vdevs for the given spa_t.
2132 * This is accomplished by invoking "::vdev -re" on the root vdev, as well as
2133 * iterating over the cache devices.
2137 spa_vdevs(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2141 char opts
[100] = "-r";
2144 if (mdb_getopts(argc
, argv
,
2145 'e', MDB_OPT_SETBITS
, SPA_FLAG_ERRORS
, &spa_flags
,
2146 'm', MDB_OPT_SETBITS
, SPA_FLAG_METASLABS
, &spa_flags
,
2147 'M', MDB_OPT_SETBITS
, SPA_FLAG_METASLAB_GROUPS
, &spa_flags
,
2148 'h', MDB_OPT_SETBITS
, SPA_FLAG_HISTOGRAMS
, &spa_flags
,
2150 return (DCMD_USAGE
);
2152 if (!(flags
& DCMD_ADDRSPEC
))
2153 return (DCMD_USAGE
);
2155 mdb_spa_vdevs_t spa
;
2156 if (mdb_ctf_vread(&spa
, "spa_t", "mdb_spa_vdevs_t", addr
, 0) == -1)
2160 * Unitialized spa_t structures can have a NULL root vdev.
2162 if (spa
.spa_root_vdev
== (uintptr_t)NULL
) {
2163 mdb_printf("no associated vdevs\n");
2167 if (spa_flags
& SPA_FLAG_ERRORS
)
2169 if (spa_flags
& SPA_FLAG_METASLABS
)
2171 if (spa_flags
& SPA_FLAG_METASLAB_GROUPS
)
2173 if (spa_flags
& SPA_FLAG_HISTOGRAMS
)
2176 v
[0].a_type
= MDB_TYPE_STRING
;
2177 v
[0].a_un
.a_str
= opts
;
2179 ret
= mdb_call_dcmd("vdev", (uintptr_t)spa
.spa_root_vdev
,
2184 if (spa_print_aux(&spa
.spa_l2cache
, flags
, v
, "cache") != 0 ||
2185 spa_print_aux(&spa
.spa_spares
, flags
, v
, "spares") != 0)
2194 * Print a summary of zio_t and all its children. This is intended to display a
2195 * zio tree, and hence we only pick the most important pieces of information for
2196 * the main summary. More detailed information can always be found by doing a
2197 * '::print zio' on the underlying zio_t. The columns we display are:
2199 * ADDRESS TYPE STAGE WAITER TIME_ELAPSED
2201 * The 'address' column is indented by one space for each depth level as we
2202 * descend down the tree.
2205 #define ZIO_MAXINDENT 7
2206 #define ZIO_MAXWIDTH (sizeof (uintptr_t) * 2 + ZIO_MAXINDENT)
2207 #define ZIO_WALK_SELF 0
2208 #define ZIO_WALK_CHILD 1
2209 #define ZIO_WALK_PARENT 2
2211 typedef struct zio_print_args
{
2212 int zpa_current_depth
;
2219 typedef struct mdb_zio
{
2220 enum zio_type io_type
;
2221 enum zio_stage io_stage
;
2222 uintptr_t io_waiter
;
2226 uintptr_t list_next
;
2232 typedef struct mdb_zio_timestamp
{
2233 hrtime_t io_timestamp
;
2234 } mdb_zio_timestamp_t
;
2236 static int zio_child_cb(uintptr_t addr
, const void *unknown
, void *arg
);
2239 zio_print_cb(uintptr_t addr
, zio_print_args_t
*zpa
)
2241 mdb_ctf_id_t type_enum
, stage_enum
;
2242 int indent
= zpa
->zpa_current_depth
;
2243 const char *type
, *stage
;
2246 mdb_zio_timestamp_t zio_timestamp
= { 0 };
2248 if (mdb_ctf_vread(&zio
, ZFS_STRUCT
"zio", "mdb_zio_t", addr
, 0) == -1)
2250 (void) mdb_ctf_vread(&zio_timestamp
, ZFS_STRUCT
"zio",
2251 "mdb_zio_timestamp_t", addr
, MDB_CTF_VREAD_QUIET
);
2253 if (indent
> ZIO_MAXINDENT
)
2254 indent
= ZIO_MAXINDENT
;
2256 if (mdb_ctf_lookup_by_name("enum zio_type", &type_enum
) == -1 ||
2257 mdb_ctf_lookup_by_name("enum zio_stage", &stage_enum
) == -1) {
2258 mdb_warn("failed to lookup zio enums");
2262 if ((type
= mdb_ctf_enum_name(type_enum
, zio
.io_type
)) != NULL
)
2263 type
+= sizeof ("ZIO_TYPE_") - 1;
2267 if (zio
.io_error
== 0) {
2268 stage
= mdb_ctf_enum_name(stage_enum
, zio
.io_stage
);
2270 stage
+= sizeof ("ZIO_STAGE_") - 1;
2277 if (zpa
->zpa_current_depth
>= zpa
->zpa_min_depth
) {
2278 if (zpa
->zpa_flags
& DCMD_PIPE_OUT
) {
2279 mdb_printf("%?p\n", addr
);
2281 mdb_printf("%*s%-*p %-5s %-16s ", indent
, "",
2282 ZIO_MAXWIDTH
- indent
, addr
, type
, stage
);
2283 if (zio
.io_waiter
!= 0)
2284 mdb_printf("%-16lx ", zio
.io_waiter
);
2286 mdb_printf("%-16s ", "-");
2288 if (zio_timestamp
.io_timestamp
!= 0) {
2289 mdb_printf("%llums", (mdb_gethrtime() -
2290 zio_timestamp
.io_timestamp
) /
2293 mdb_printf("%-12s ", "-");
2296 mdb_printf("%-12s ", "-");
2302 if (zpa
->zpa_current_depth
>= zpa
->zpa_max_depth
)
2305 if (zpa
->zpa_type
== ZIO_WALK_PARENT
)
2306 laddr
= addr
+ mdb_ctf_offsetof_by_name(ZFS_STRUCT
"zio",
2309 laddr
= addr
+ mdb_ctf_offsetof_by_name(ZFS_STRUCT
"zio",
2312 zpa
->zpa_current_depth
++;
2313 if (mdb_pwalk("list", zio_child_cb
, zpa
, laddr
) != 0) {
2314 mdb_warn("failed to walk zio_t children at %p\n", laddr
);
2317 zpa
->zpa_current_depth
--;
2324 zio_child_cb(uintptr_t addr
, const void *unknown
, void *arg
)
2328 zio_print_args_t
*zpa
= arg
;
2330 if (mdb_vread(&zl
, sizeof (zl
), addr
) == -1) {
2331 mdb_warn("failed to read zio_link_t at %p", addr
);
2335 if (zpa
->zpa_type
== ZIO_WALK_PARENT
)
2336 ziop
= (uintptr_t)zl
.zl_parent
;
2338 ziop
= (uintptr_t)zl
.zl_child
;
2340 return (zio_print_cb(ziop
, zpa
));
2345 zio_print(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2347 zio_print_args_t zpa
= { 0 };
2349 if (!(flags
& DCMD_ADDRSPEC
))
2350 return (DCMD_USAGE
);
2352 if (mdb_getopts(argc
, argv
,
2353 'r', MDB_OPT_SETBITS
, INT_MAX
, &zpa
.zpa_max_depth
,
2354 'c', MDB_OPT_SETBITS
, ZIO_WALK_CHILD
, &zpa
.zpa_type
,
2355 'p', MDB_OPT_SETBITS
, ZIO_WALK_PARENT
, &zpa
.zpa_type
,
2357 return (DCMD_USAGE
);
2359 zpa
.zpa_flags
= flags
;
2360 if (zpa
.zpa_max_depth
!= 0) {
2361 if (zpa
.zpa_type
== ZIO_WALK_SELF
)
2362 zpa
.zpa_type
= ZIO_WALK_CHILD
;
2363 } else if (zpa
.zpa_type
!= ZIO_WALK_SELF
) {
2364 zpa
.zpa_min_depth
= 1;
2365 zpa
.zpa_max_depth
= 1;
2368 if (!(flags
& DCMD_PIPE_OUT
) && DCMD_HDRSPEC(flags
)) {
2369 mdb_printf("%<u>%-*s %-5s %-16s %-16s %-12s%</u>\n",
2370 ZIO_MAXWIDTH
, "ADDRESS", "TYPE", "STAGE", "WAITER",
2374 if (zio_print_cb(addr
, &zpa
) != WALK_NEXT
)
2383 * Print a summary of all zio_t structures on the system, or for a particular
2384 * pool. This is equivalent to '::walk zio_root | ::zio'.
2388 zio_state(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2391 * MDB will remember the last address of the pipeline, so if we don't
2392 * zero this we'll end up trying to walk zio structures for a
2393 * non-existent spa_t.
2395 if (!(flags
& DCMD_ADDRSPEC
))
2398 return (mdb_pwalk_dcmd("zio_root", "zio", argc
, argv
, addr
));
2401 typedef struct mdb_multilist
{
2402 uint64_t ml_num_sublists
;
2403 uintptr_t ml_sublists
;
2406 typedef struct multilist_walk_data
{
2408 mdb_multilist_t mwd_ml
;
2409 } multilist_walk_data_t
;
2413 multilist_print_cb(uintptr_t addr
, const void *unknown
, void *arg
)
2415 mdb_printf("%#lr\n", addr
);
2420 multilist_walk_step(mdb_walk_state_t
*wsp
)
2422 multilist_walk_data_t
*mwd
= wsp
->walk_data
;
2424 if (mwd
->mwd_idx
>= mwd
->mwd_ml
.ml_num_sublists
)
2427 wsp
->walk_addr
= mwd
->mwd_ml
.ml_sublists
+
2428 mdb_ctf_sizeof_by_name("multilist_sublist_t") * mwd
->mwd_idx
+
2429 mdb_ctf_offsetof_by_name("multilist_sublist_t", "mls_list");
2431 mdb_pwalk("list", multilist_print_cb
, NULL
, wsp
->walk_addr
);
2438 multilist_walk_init(mdb_walk_state_t
*wsp
)
2440 multilist_walk_data_t
*mwd
;
2442 if (wsp
->walk_addr
== 0) {
2443 mdb_warn("must supply address of multilist_t\n");
2447 mwd
= mdb_zalloc(sizeof (multilist_walk_data_t
), UM_SLEEP
| UM_GC
);
2448 if (mdb_ctf_vread(&mwd
->mwd_ml
, "multilist_t", "mdb_multilist_t",
2449 wsp
->walk_addr
, 0) == -1) {
2453 if (mwd
->mwd_ml
.ml_num_sublists
== 0 ||
2454 mwd
->mwd_ml
.ml_sublists
== 0) {
2455 mdb_warn("invalid or uninitialized multilist at %#lx\n",
2460 wsp
->walk_data
= mwd
;
2464 typedef struct txg_list_walk_data
{
2465 uintptr_t lw_head
[TXG_SIZE
];
2470 } txg_list_walk_data_t
;
2473 txg_list_walk_init_common(mdb_walk_state_t
*wsp
, int txg
, int maxoff
)
2475 txg_list_walk_data_t
*lwd
;
2479 lwd
= mdb_alloc(sizeof (txg_list_walk_data_t
), UM_SLEEP
| UM_GC
);
2480 if (mdb_vread(&list
, sizeof (txg_list_t
), wsp
->walk_addr
) == -1) {
2481 mdb_warn("failed to read txg_list_t at %#lx", wsp
->walk_addr
);
2485 for (i
= 0; i
< TXG_SIZE
; i
++)
2486 lwd
->lw_head
[i
] = (uintptr_t)list
.tl_head
[i
];
2487 lwd
->lw_offset
= list
.tl_offset
;
2488 lwd
->lw_obj
= mdb_alloc(lwd
->lw_offset
+ sizeof (txg_node_t
),
2490 lwd
->lw_txgoff
= txg
;
2491 lwd
->lw_maxoff
= maxoff
;
2493 wsp
->walk_addr
= lwd
->lw_head
[lwd
->lw_txgoff
];
2494 wsp
->walk_data
= lwd
;
2500 txg_list_walk_init(mdb_walk_state_t
*wsp
)
2502 return (txg_list_walk_init_common(wsp
, 0, TXG_SIZE
-1));
2506 txg_list0_walk_init(mdb_walk_state_t
*wsp
)
2508 return (txg_list_walk_init_common(wsp
, 0, 0));
2512 txg_list1_walk_init(mdb_walk_state_t
*wsp
)
2514 return (txg_list_walk_init_common(wsp
, 1, 1));
2518 txg_list2_walk_init(mdb_walk_state_t
*wsp
)
2520 return (txg_list_walk_init_common(wsp
, 2, 2));
2524 txg_list3_walk_init(mdb_walk_state_t
*wsp
)
2526 return (txg_list_walk_init_common(wsp
, 3, 3));
2530 txg_list_walk_step(mdb_walk_state_t
*wsp
)
2532 txg_list_walk_data_t
*lwd
= wsp
->walk_data
;
2537 while (wsp
->walk_addr
== (uintptr_t)NULL
&&
2538 lwd
->lw_txgoff
< lwd
->lw_maxoff
) {
2540 wsp
->walk_addr
= lwd
->lw_head
[lwd
->lw_txgoff
];
2543 if (wsp
->walk_addr
== (uintptr_t)NULL
)
2546 addr
= wsp
->walk_addr
- lwd
->lw_offset
;
2548 if (mdb_vread(lwd
->lw_obj
,
2549 lwd
->lw_offset
+ sizeof (txg_node_t
), addr
) == -1) {
2550 mdb_warn("failed to read list element at %#lx", addr
);
2554 status
= wsp
->walk_callback(addr
, lwd
->lw_obj
, wsp
->walk_cbdata
);
2555 node
= (txg_node_t
*)((uintptr_t)lwd
->lw_obj
+ lwd
->lw_offset
);
2556 wsp
->walk_addr
= (uintptr_t)node
->tn_next
[lwd
->lw_txgoff
];
2564 * Walk all named spa_t structures in the namespace. This is nothing more than
2565 * a layered avl walk.
2568 spa_walk_init(mdb_walk_state_t
*wsp
)
2572 if (wsp
->walk_addr
!= (uintptr_t)NULL
) {
2573 mdb_warn("spa walk only supports global walks\n");
2577 if (mdb_lookup_by_obj(ZFS_OBJ_NAME
, "spa_namespace_avl", &sym
) == -1) {
2578 mdb_warn("failed to find symbol 'spa_namespace_avl'");
2582 wsp
->walk_addr
= (uintptr_t)sym
.st_value
;
2584 if (mdb_layered_walk("avl", wsp
) == -1) {
2585 mdb_warn("failed to walk 'avl'\n");
2593 spa_walk_step(mdb_walk_state_t
*wsp
)
2595 return (wsp
->walk_callback(wsp
->walk_addr
, NULL
, wsp
->walk_cbdata
));
2601 * Walk all active zio_t structures on the system. This is simply a layered
2602 * walk on top of ::walk zio_cache, with the optional ability to limit the
2603 * structures to a particular pool.
2606 zio_walk_init(mdb_walk_state_t
*wsp
)
2608 wsp
->walk_data
= (void *)wsp
->walk_addr
;
2610 if (mdb_layered_walk("zio_cache", wsp
) == -1) {
2611 mdb_warn("failed to walk 'zio_cache'\n");
2619 zio_walk_step(mdb_walk_state_t
*wsp
)
2622 uintptr_t spa
= (uintptr_t)wsp
->walk_data
;
2624 if (mdb_ctf_vread(&zio
, ZFS_STRUCT
"zio", "mdb_zio_t",
2625 wsp
->walk_addr
, 0) == -1)
2628 if (spa
!= 0 && spa
!= zio
.io_spa
)
2631 return (wsp
->walk_callback(wsp
->walk_addr
, &zio
, wsp
->walk_cbdata
));
2635 * [addr]::walk zio_root
2637 * Walk only root zio_t structures, optionally for a particular spa_t.
2640 zio_walk_root_step(mdb_walk_state_t
*wsp
)
2643 uintptr_t spa
= (uintptr_t)wsp
->walk_data
;
2645 if (mdb_ctf_vread(&zio
, ZFS_STRUCT
"zio", "mdb_zio_t",
2646 wsp
->walk_addr
, 0) == -1)
2649 if (spa
!= 0 && spa
!= zio
.io_spa
)
2652 /* If the parent list is not empty, ignore */
2653 if (zio
.io_parent_list
.list_head
.list_next
!=
2655 mdb_ctf_offsetof_by_name(ZFS_STRUCT
"zio", "io_parent_list") +
2656 mdb_ctf_offsetof_by_name("struct list", "list_head"))
2659 return (wsp
->walk_callback(wsp
->walk_addr
, &zio
, wsp
->walk_cbdata
));
2665 * -v print verbose per-level information
2669 zfs_blkstats(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2671 boolean_t verbose
= B_FALSE
;
2672 zfs_all_blkstats_t stats
;
2673 dmu_object_type_t t
;
2676 dmu_object_type_info_t dmu_ot
[DMU_OT_NUMTYPES
+ 10];
2677 /* +10 in case it grew */
2679 if (mdb_readvar(&dmu_ot
, "dmu_ot") == -1) {
2680 mdb_warn("failed to read 'dmu_ot'");
2684 if (mdb_getopts(argc
, argv
,
2685 'v', MDB_OPT_SETBITS
, TRUE
, &verbose
,
2687 return (DCMD_USAGE
);
2689 if (!(flags
& DCMD_ADDRSPEC
))
2690 return (DCMD_USAGE
);
2692 if (GETMEMB(addr
, "spa", spa_dsl_pool
, addr
) ||
2693 GETMEMB(addr
, "dsl_pool", dp_blkstats
, addr
) ||
2694 mdb_vread(&stats
, sizeof (zfs_all_blkstats_t
), addr
) == -1) {
2695 mdb_warn("failed to read data at %p;", addr
);
2696 mdb_printf("maybe no stats? run \"zpool scrub\" first.");
2700 tzb
= &stats
.zab_type
[DN_MAX_LEVELS
][DMU_OT_TOTAL
];
2701 if (tzb
->zb_gangs
!= 0) {
2702 mdb_printf("Ganged blocks: %llu\n",
2703 (longlong_t
)tzb
->zb_gangs
);
2706 ditto
= tzb
->zb_ditto_2_of_2_samevdev
+ tzb
->zb_ditto_2_of_3_samevdev
+
2707 tzb
->zb_ditto_3_of_3_samevdev
;
2709 mdb_printf("Dittoed blocks on same vdev: %llu\n",
2713 mdb_printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
2714 "\t avg\t comp\t%%Total\tType\n");
2716 for (t
= 0; t
<= DMU_OT_TOTAL
; t
++) {
2717 char csize
[NICENUM_BUFLEN
], lsize
[NICENUM_BUFLEN
];
2718 char psize
[NICENUM_BUFLEN
], asize
[NICENUM_BUFLEN
];
2719 char avg
[NICENUM_BUFLEN
];
2720 char comp
[NICENUM_BUFLEN
], pct
[NICENUM_BUFLEN
];
2725 if (t
== DMU_OT_DEFERRED
)
2726 strcpy(typename
, "deferred free");
2727 else if (t
== DMU_OT_OTHER
)
2728 strcpy(typename
, "other");
2729 else if (t
== DMU_OT_TOTAL
)
2730 strcpy(typename
, "Total");
2731 else if (mdb_readstr(typename
, sizeof (typename
),
2732 (uintptr_t)dmu_ot
[t
].ot_name
) == -1) {
2733 mdb_warn("failed to read type name");
2737 if (stats
.zab_type
[DN_MAX_LEVELS
][t
].zb_asize
== 0)
2740 for (l
= -1; l
< DN_MAX_LEVELS
; l
++) {
2741 int level
= (l
== -1 ? DN_MAX_LEVELS
: l
);
2742 zfs_blkstat_t
*zb
= &stats
.zab_type
[level
][t
];
2744 if (zb
->zb_asize
== 0)
2748 * Don't print each level unless requested.
2750 if (!verbose
&& level
!= DN_MAX_LEVELS
)
2754 * If all the space is level 0, don't print the
2755 * level 0 separately.
2757 if (level
== 0 && zb
->zb_asize
==
2758 stats
.zab_type
[DN_MAX_LEVELS
][t
].zb_asize
)
2761 mdb_nicenum(zb
->zb_count
, csize
);
2762 mdb_nicenum(zb
->zb_lsize
, lsize
);
2763 mdb_nicenum(zb
->zb_psize
, psize
);
2764 mdb_nicenum(zb
->zb_asize
, asize
);
2765 mdb_nicenum(zb
->zb_asize
/ zb
->zb_count
, avg
);
2766 (void) snprintfrac(comp
, NICENUM_BUFLEN
,
2767 zb
->zb_lsize
, zb
->zb_psize
, 2);
2768 (void) snprintfrac(pct
, NICENUM_BUFLEN
,
2769 100 * zb
->zb_asize
, tzb
->zb_asize
, 2);
2771 mdb_printf("%6s\t%5s\t%5s\t%5s\t%5s"
2773 csize
, lsize
, psize
, asize
, avg
, comp
, pct
);
2775 if (level
== DN_MAX_LEVELS
)
2776 mdb_printf("%s\n", typename
);
2778 mdb_printf(" L%d %s\n",
2786 typedef struct mdb_reference
{
2787 uintptr_t ref_holder
;
2788 uintptr_t ref_removed
;
2789 uint64_t ref_number
;
2794 reference_cb(uintptr_t addr
, const void *ignored
, void *arg
)
2796 mdb_reference_t ref
;
2797 boolean_t holder_is_str
= B_FALSE
;
2798 char holder_str
[128];
2799 boolean_t removed
= (boolean_t
)arg
;
2801 if (mdb_ctf_vread(&ref
, "reference_t", "mdb_reference_t", addr
,
2805 if (mdb_readstr(holder_str
, sizeof (holder_str
),
2806 ref
.ref_holder
) != -1)
2807 holder_is_str
= strisprint(holder_str
);
2810 mdb_printf("removed ");
2811 mdb_printf("reference ");
2812 if (ref
.ref_number
!= 1)
2813 mdb_printf("with count=%llu ", ref
.ref_number
);
2814 mdb_printf("with tag %lx", ref
.ref_holder
);
2816 mdb_printf(" \"%s\"", holder_str
);
2817 mdb_printf(", held at:\n");
2819 (void) mdb_call_dcmd("whatis", addr
, DCMD_ADDRSPEC
, 0, NULL
);
2822 mdb_printf("removed at:\n");
2823 (void) mdb_call_dcmd("whatis", ref
.ref_removed
,
2824 DCMD_ADDRSPEC
, 0, NULL
);
2832 typedef struct mdb_refcount
{
2836 typedef struct mdb_refcount_removed
{
2837 uint64_t rc_removed_count
;
2838 } mdb_refcount_removed_t
;
2840 typedef struct mdb_refcount_tracked
{
2841 boolean_t rc_tracked
;
2842 } mdb_refcount_tracked_t
;
2846 refcount(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2849 mdb_refcount_removed_t rcr
;
2850 mdb_refcount_tracked_t rct
;
2852 boolean_t released
= B_FALSE
;
2854 if (!(flags
& DCMD_ADDRSPEC
))
2855 return (DCMD_USAGE
);
2857 if (mdb_getopts(argc
, argv
,
2858 'r', MDB_OPT_SETBITS
, B_TRUE
, &released
,
2860 return (DCMD_USAGE
);
2862 if (mdb_ctf_vread(&rc
, "refcount_t", "mdb_refcount_t", addr
,
2866 if (mdb_ctf_vread(&rcr
, "refcount_t", "mdb_refcount_removed_t", addr
,
2867 MDB_CTF_VREAD_QUIET
) == -1) {
2868 mdb_printf("refcount_t at %p has %llu holds (untracked)\n",
2869 addr
, (longlong_t
)rc
.rc_count
);
2873 if (mdb_ctf_vread(&rct
, "refcount_t", "mdb_refcount_tracked_t", addr
,
2874 MDB_CTF_VREAD_QUIET
) == -1) {
2875 /* If this is an old target, it might be tracked. */
2876 rct
.rc_tracked
= B_TRUE
;
2879 mdb_printf("refcount_t at %p has %llu current holds, "
2880 "%llu recently released holds\n",
2881 addr
, (longlong_t
)rc
.rc_count
, (longlong_t
)rcr
.rc_removed_count
);
2883 if (rct
.rc_tracked
&& rc
.rc_count
> 0)
2884 mdb_printf("current holds:\n");
2885 off
= mdb_ctf_offsetof_by_name("refcount_t", "rc_list");
2888 mdb_pwalk("list", reference_cb
, (void*)B_FALSE
, addr
+ off
);
2890 if (released
&& rcr
.rc_removed_count
> 0) {
2891 mdb_printf("released holds:\n");
2893 off
= mdb_ctf_offsetof_by_name("refcount_t", "rc_removed");
2896 mdb_pwalk("list", reference_cb
, (void*)B_TRUE
, addr
+ off
);
2904 sa_attr_table(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2906 sa_attr_table_t
*table
;
2911 if (mdb_vread(&sa_os
, sizeof (sa_os_t
), addr
) == -1) {
2912 mdb_warn("failed to read sa_os at %p", addr
);
2916 table
= mdb_alloc(sizeof (sa_attr_table_t
) * sa_os
.sa_num_attrs
,
2918 name
= mdb_alloc(MAXPATHLEN
, UM_SLEEP
| UM_GC
);
2920 if (mdb_vread(table
, sizeof (sa_attr_table_t
) * sa_os
.sa_num_attrs
,
2921 (uintptr_t)sa_os
.sa_attr_table
) == -1) {
2922 mdb_warn("failed to read sa_os at %p", addr
);
2926 mdb_printf("%<u>%-10s %-10s %-10s %-10s %s%</u>\n",
2927 "ATTR ID", "REGISTERED", "LENGTH", "BSWAP", "NAME");
2928 for (i
= 0; i
!= sa_os
.sa_num_attrs
; i
++) {
2929 mdb_readstr(name
, MAXPATHLEN
, (uintptr_t)table
[i
].sa_name
);
2930 mdb_printf("%5x %8x %8x %8x %-s\n",
2931 (int)table
[i
].sa_attr
, (int)table
[i
].sa_registered
,
2932 (int)table
[i
].sa_length
, table
[i
].sa_byteswap
, name
);
2939 sa_get_off_table(uintptr_t addr
, uint32_t **off_tab
, int attr_count
)
2941 uintptr_t idx_table
;
2943 if (GETMEMB(addr
, "sa_idx_tab", sa_idx_tab
, idx_table
)) {
2944 mdb_printf("can't find offset table in sa_idx_tab\n");
2948 *off_tab
= mdb_alloc(attr_count
* sizeof (uint32_t),
2951 if (mdb_vread(*off_tab
,
2952 attr_count
* sizeof (uint32_t), idx_table
) == -1) {
2953 mdb_warn("failed to attribute offset table %p", idx_table
);
2962 sa_attr_print(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2964 uint32_t *offset_tab
;
2967 uintptr_t attr_addr
;
2968 uintptr_t bonus_tab
, spill_tab
;
2969 uintptr_t db_bonus
, db_spill
;
2970 uintptr_t os
, os_sa
;
2974 return (DCMD_USAGE
);
2976 if (argv
[0].a_type
== MDB_TYPE_STRING
)
2977 attr_id
= mdb_strtoull(argv
[0].a_un
.a_str
);
2979 return (DCMD_USAGE
);
2981 if (GETMEMB(addr
, "sa_handle", sa_bonus_tab
, bonus_tab
) ||
2982 GETMEMB(addr
, "sa_handle", sa_spill_tab
, spill_tab
) ||
2983 GETMEMB(addr
, "sa_handle", sa_os
, os
) ||
2984 GETMEMB(addr
, "sa_handle", sa_bonus
, db_bonus
) ||
2985 GETMEMB(addr
, "sa_handle", sa_spill
, db_spill
)) {
2986 mdb_printf("Can't find necessary information in sa_handle "
2991 if (GETMEMB(os
, "objset", os_sa
, os_sa
)) {
2992 mdb_printf("Can't find os_sa in objset\n");
2996 if (GETMEMB(os_sa
, "sa_os", sa_num_attrs
, attr_count
)) {
2997 mdb_printf("Can't find sa_num_attrs\n");
3001 if (attr_id
> attr_count
) {
3002 mdb_printf("attribute id number is out of range\n");
3007 if (sa_get_off_table(bonus_tab
, &offset_tab
,
3008 attr_count
) == -1) {
3012 if (GETMEMB(db_bonus
, "dmu_buf", db_data
, db_data
)) {
3013 mdb_printf("can't find db_data in bonus dbuf\n");
3018 if (bonus_tab
&& !TOC_ATTR_PRESENT(offset_tab
[attr_id
]) &&
3019 spill_tab
== (uintptr_t)NULL
) {
3020 mdb_printf("Attribute does not exist\n");
3022 } else if (!TOC_ATTR_PRESENT(offset_tab
[attr_id
]) && spill_tab
) {
3023 if (sa_get_off_table(spill_tab
, &offset_tab
,
3024 attr_count
) == -1) {
3027 if (GETMEMB(db_spill
, "dmu_buf", db_data
, db_data
)) {
3028 mdb_printf("can't find db_data in spill dbuf\n");
3031 if (!TOC_ATTR_PRESENT(offset_tab
[attr_id
])) {
3032 mdb_printf("Attribute does not exist\n");
3036 attr_addr
= db_data
+ TOC_OFF(offset_tab
[attr_id
]);
3037 mdb_printf("%p\n", attr_addr
);
3043 zfs_ace_print_common(uintptr_t addr
, uint_t flags
,
3044 uint64_t id
, uint32_t access_mask
, uint16_t ace_flags
,
3045 uint16_t ace_type
, int verbose
)
3047 if (DCMD_HDRSPEC(flags
) && !verbose
)
3048 mdb_printf("%<u>%-?s %-8s %-8s %-8s %s%</u>\n",
3049 "ADDR", "FLAGS", "MASK", "TYPE", "ID");
3052 mdb_printf("%0?p %-8x %-8x %-8x %-llx\n", addr
,
3053 ace_flags
, access_mask
, ace_type
, id
);
3057 switch (ace_flags
& ACE_TYPE_FLAGS
) {
3059 mdb_printf("owner@:");
3061 case (ACE_IDENTIFIER_GROUP
| ACE_GROUP
):
3062 mdb_printf("group@:");
3065 mdb_printf("everyone@:");
3067 case ACE_IDENTIFIER_GROUP
:
3068 mdb_printf("group:%llx:", (u_longlong_t
)id
);
3070 case 0: /* User entry */
3071 mdb_printf("user:%llx:", (u_longlong_t
)id
);
3075 /* print out permission mask */
3076 if (access_mask
& ACE_READ_DATA
)
3080 if (access_mask
& ACE_WRITE_DATA
)
3084 if (access_mask
& ACE_EXECUTE
)
3088 if (access_mask
& ACE_APPEND_DATA
)
3092 if (access_mask
& ACE_DELETE
)
3096 if (access_mask
& ACE_DELETE_CHILD
)
3100 if (access_mask
& ACE_READ_ATTRIBUTES
)
3104 if (access_mask
& ACE_WRITE_ATTRIBUTES
)
3108 if (access_mask
& ACE_READ_NAMED_ATTRS
)
3112 if (access_mask
& ACE_WRITE_NAMED_ATTRS
)
3116 if (access_mask
& ACE_READ_ACL
)
3120 if (access_mask
& ACE_WRITE_ACL
)
3124 if (access_mask
& ACE_WRITE_OWNER
)
3128 if (access_mask
& ACE_SYNCHRONIZE
)
3135 /* Print out inheritance flags */
3136 if (ace_flags
& ACE_FILE_INHERIT_ACE
)
3140 if (ace_flags
& ACE_DIRECTORY_INHERIT_ACE
)
3144 if (ace_flags
& ACE_INHERIT_ONLY_ACE
)
3148 if (ace_flags
& ACE_NO_PROPAGATE_INHERIT_ACE
)
3152 if (ace_flags
& ACE_SUCCESSFUL_ACCESS_ACE_FLAG
)
3156 if (ace_flags
& ACE_FAILED_ACCESS_ACE_FLAG
)
3160 if (ace_flags
& ACE_INHERITED_ACE
)
3166 case ACE_ACCESS_ALLOWED_ACE_TYPE
:
3167 mdb_printf(":allow\n");
3169 case ACE_ACCESS_DENIED_ACE_TYPE
:
3170 mdb_printf(":deny\n");
3172 case ACE_SYSTEM_AUDIT_ACE_TYPE
:
3173 mdb_printf(":audit\n");
3175 case ACE_SYSTEM_ALARM_ACE_TYPE
:
3176 mdb_printf(":alarm\n");
3186 zfs_ace_print(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
3189 int verbose
= FALSE
;
3192 if (!(flags
& DCMD_ADDRSPEC
))
3193 return (DCMD_USAGE
);
3195 if (mdb_getopts(argc
, argv
,
3196 'v', MDB_OPT_SETBITS
, TRUE
, &verbose
, TRUE
, NULL
) != argc
)
3197 return (DCMD_USAGE
);
3199 if (mdb_vread(&zace
, sizeof (zfs_ace_t
), addr
) == -1) {
3200 mdb_warn("failed to read zfs_ace_t");
3204 if ((zace
.z_hdr
.z_flags
& ACE_TYPE_FLAGS
) == 0 ||
3205 (zace
.z_hdr
.z_flags
& ACE_TYPE_FLAGS
) == ACE_IDENTIFIER_GROUP
)
3210 return (zfs_ace_print_common(addr
, flags
, id
, zace
.z_hdr
.z_access_mask
,
3211 zace
.z_hdr
.z_flags
, zace
.z_hdr
.z_type
, verbose
));
3216 zfs_ace0_print(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
3220 int verbose
= FALSE
;
3222 if (!(flags
& DCMD_ADDRSPEC
))
3223 return (DCMD_USAGE
);
3225 if (mdb_getopts(argc
, argv
,
3226 'v', MDB_OPT_SETBITS
, TRUE
, &verbose
, TRUE
, NULL
) != argc
)
3227 return (DCMD_USAGE
);
3229 if (mdb_vread(&ace
, sizeof (ace_t
), addr
) == -1) {
3230 mdb_warn("failed to read ace_t");
3234 if ((ace
.a_flags
& ACE_TYPE_FLAGS
) == 0 ||
3235 (ace
.a_flags
& ACE_TYPE_FLAGS
) == ACE_IDENTIFIER_GROUP
)
3240 return (zfs_ace_print_common(addr
, flags
, id
, ace
.a_access_mask
,
3241 ace
.a_flags
, ace
.a_type
, verbose
));
3244 typedef struct acl_dump_args
{
3246 const mdb_arg_t
*a_argv
;
3253 acl_aces_cb(uintptr_t addr
, const void *unknown
, void *arg
)
3255 acl_dump_args_t
*acl_args
= (acl_dump_args_t
*)arg
;
3257 if (acl_args
->a_version
== 1) {
3258 if (mdb_call_dcmd("zfs_ace", addr
,
3259 DCMD_ADDRSPEC
|acl_args
->a_flags
, acl_args
->a_argc
,
3260 acl_args
->a_argv
) != DCMD_OK
) {
3264 if (mdb_call_dcmd("zfs_ace0", addr
,
3265 DCMD_ADDRSPEC
|acl_args
->a_flags
, acl_args
->a_argc
,
3266 acl_args
->a_argv
) != DCMD_OK
) {
3270 acl_args
->a_flags
= DCMD_LOOP
;
3276 acl_cb(uintptr_t addr
, const void *unknown
, void *arg
)
3278 acl_dump_args_t
*acl_args
= (acl_dump_args_t
*)arg
;
3280 if (acl_args
->a_version
== 1) {
3281 if (mdb_pwalk("zfs_acl_node_aces", acl_aces_cb
,
3283 mdb_warn("can't walk ACEs");
3287 if (mdb_pwalk("zfs_acl_node_aces0", acl_aces_cb
,
3289 mdb_warn("can't walk ACEs");
3298 zfs_acl_dump(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
3301 int verbose
= FALSE
;
3302 acl_dump_args_t acl_args
;
3304 if (!(flags
& DCMD_ADDRSPEC
))
3305 return (DCMD_USAGE
);
3307 if (mdb_getopts(argc
, argv
,
3308 'v', MDB_OPT_SETBITS
, TRUE
, &verbose
, TRUE
, NULL
) != argc
)
3309 return (DCMD_USAGE
);
3311 if (mdb_vread(&zacl
, sizeof (zfs_acl_t
), addr
) == -1) {
3312 mdb_warn("failed to read zfs_acl_t");
3316 acl_args
.a_argc
= argc
;
3317 acl_args
.a_argv
= argv
;
3318 acl_args
.a_version
= zacl
.z_version
;
3319 acl_args
.a_flags
= DCMD_LOOPFIRST
;
3321 if (mdb_pwalk("zfs_acl_node", acl_cb
, &acl_args
, addr
) != 0) {
3322 mdb_warn("can't walk ACL");
3331 zfs_acl_node_walk_init(mdb_walk_state_t
*wsp
)
3333 if (wsp
->walk_addr
== (uintptr_t)NULL
) {
3334 mdb_warn("must supply address of zfs_acl_node_t\n");
3339 mdb_ctf_offsetof_by_name(ZFS_STRUCT
"zfs_acl", "z_acl");
3341 if (mdb_layered_walk("list", wsp
) == -1) {
3342 mdb_warn("failed to walk 'list'\n");
3350 zfs_acl_node_walk_step(mdb_walk_state_t
*wsp
)
3352 zfs_acl_node_t aclnode
;
3354 if (mdb_vread(&aclnode
, sizeof (zfs_acl_node_t
),
3355 wsp
->walk_addr
) == -1) {
3356 mdb_warn("failed to read zfs_acl_node at %p", wsp
->walk_addr
);
3360 return (wsp
->walk_callback(wsp
->walk_addr
, &aclnode
, wsp
->walk_cbdata
));
3363 typedef struct ace_walk_data
{
3369 zfs_aces_walk_init_common(mdb_walk_state_t
*wsp
, int version
,
3370 int ace_count
, uintptr_t ace_data
)
3372 ace_walk_data_t
*ace_walk_data
;
3374 if (wsp
->walk_addr
== (uintptr_t)NULL
) {
3375 mdb_warn("must supply address of zfs_acl_node_t\n");
3379 ace_walk_data
= mdb_alloc(sizeof (ace_walk_data_t
), UM_SLEEP
| UM_GC
);
3381 ace_walk_data
->ace_count
= ace_count
;
3382 ace_walk_data
->ace_version
= version
;
3384 wsp
->walk_addr
= ace_data
;
3385 wsp
->walk_data
= ace_walk_data
;
3391 zfs_acl_node_aces_walk_init_common(mdb_walk_state_t
*wsp
, int version
)
3394 static mdb_ctf_id_t acl_id
;
3396 uintptr_t z_acldata
;
3399 if (mdb_ctf_lookup_by_name("struct zfs_acl_node",
3401 mdb_warn("couldn't find struct zfs_acl_node");
3407 if (GETMEMBID(wsp
->walk_addr
, &acl_id
, z_ace_count
, z_ace_count
)) {
3410 if (GETMEMBID(wsp
->walk_addr
, &acl_id
, z_acldata
, z_acldata
)) {
3414 return (zfs_aces_walk_init_common(wsp
, version
,
3415 z_ace_count
, z_acldata
));
3420 zfs_acl_node_aces_walk_init(mdb_walk_state_t
*wsp
)
3422 return (zfs_acl_node_aces_walk_init_common(wsp
, 1));
3427 zfs_acl_node_aces0_walk_init(mdb_walk_state_t
*wsp
)
3429 return (zfs_acl_node_aces_walk_init_common(wsp
, 0));
3433 zfs_aces_walk_step(mdb_walk_state_t
*wsp
)
3435 ace_walk_data_t
*ace_data
= wsp
->walk_data
;
3443 if (ace_data
->ace_count
== 0)
3446 if (mdb_vread(&zace
, sizeof (zfs_ace_t
), wsp
->walk_addr
) == -1) {
3447 mdb_warn("failed to read zfs_ace_t at %#lx",
3452 switch (ace_data
->ace_version
) {
3454 acep
= (ace_t
*)&zace
;
3455 entry_type
= acep
->a_flags
& ACE_TYPE_FLAGS
;
3456 allow_type
= acep
->a_type
;
3459 entry_type
= zace
.z_hdr
.z_flags
& ACE_TYPE_FLAGS
;
3460 allow_type
= zace
.z_hdr
.z_type
;
3466 ptr
= (uintptr_t)wsp
->walk_addr
;
3467 switch (entry_type
) {
3470 case (ACE_IDENTIFIER_GROUP
| ACE_GROUP
):
3471 ptr
+= ace_data
->ace_version
== 0 ?
3472 sizeof (ace_t
) : sizeof (zfs_ace_hdr_t
);
3474 case ACE_IDENTIFIER_GROUP
:
3476 switch (allow_type
) {
3477 case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE
:
3478 case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE
:
3479 case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE
:
3480 case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE
:
3481 ptr
+= ace_data
->ace_version
== 0 ?
3482 sizeof (ace_t
) : sizeof (zfs_object_ace_t
);
3485 ptr
+= ace_data
->ace_version
== 0 ?
3486 sizeof (ace_t
) : sizeof (zfs_ace_t
);
3491 ace_data
->ace_count
--;
3492 status
= wsp
->walk_callback(wsp
->walk_addr
,
3493 (void *)(uintptr_t)&zace
, wsp
->walk_cbdata
);
3495 wsp
->walk_addr
= ptr
;
3499 typedef struct mdb_zfs_rrwlock
{
3500 uintptr_t rr_writer
;
3501 boolean_t rr_writer_wanted
;
3502 } mdb_zfs_rrwlock_t
;
3504 static uint_t rrw_key
;
3508 rrwlock(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
3510 mdb_zfs_rrwlock_t rrw
;
3513 if (mdb_ctf_readsym(&rrw_key
, "uint_t", "rrw_tsd_key", 0) == -1)
3517 if (mdb_ctf_vread(&rrw
, "rrwlock_t", "mdb_zfs_rrwlock_t", addr
,
3521 if (rrw
.rr_writer
!= 0) {
3522 mdb_printf("write lock held by thread %lx\n", rrw
.rr_writer
);
3526 if (rrw
.rr_writer_wanted
) {
3527 mdb_printf("writer wanted\n");
3530 mdb_printf("anonymous references:\n");
3531 (void) mdb_call_dcmd("refcount", addr
+
3532 mdb_ctf_offsetof_by_name(ZFS_STRUCT
"rrwlock", "rr_anon_rcount"),
3533 DCMD_ADDRSPEC
, 0, NULL
);
3535 mdb_printf("linked references:\n");
3536 (void) mdb_call_dcmd("refcount", addr
+
3537 mdb_ctf_offsetof_by_name(ZFS_STRUCT
"rrwlock", "rr_linked_rcount"),
3538 DCMD_ADDRSPEC
, 0, NULL
);
3541 * XXX This should find references from
3542 * "::walk thread | ::tsd -v <rrw_key>", but there is no support
3543 * for programmatic consumption of dcmds, so this would be
3544 * difficult, potentially requiring reimplementing ::tsd (both
3545 * user and kernel versions) in this MDB module.
3551 typedef struct mdb_arc_buf_hdr_t
{
3558 } mdb_arc_buf_hdr_t
;
3561 ARC_CFLAG_VERBOSE
= 1 << 0,
3562 ARC_CFLAG_ANON
= 1 << 1,
3563 ARC_CFLAG_MRU
= 1 << 2,
3564 ARC_CFLAG_MFU
= 1 << 3,
3565 ARC_CFLAG_BUFS
= 1 << 4,
3568 typedef struct arc_compression_stats_data
{
3569 GElf_Sym anon_sym
; /* ARC_anon symbol */
3570 GElf_Sym mru_sym
; /* ARC_mru symbol */
3571 GElf_Sym mrug_sym
; /* ARC_mru_ghost symbol */
3572 GElf_Sym mfu_sym
; /* ARC_mfu symbol */
3573 GElf_Sym mfug_sym
; /* ARC_mfu_ghost symbol */
3574 GElf_Sym l2c_sym
; /* ARC_l2c_only symbol */
3575 uint64_t *anon_c_hist
; /* histogram of compressed sizes in anon */
3576 uint64_t *anon_u_hist
; /* histogram of uncompressed sizes in anon */
3577 uint64_t *anon_bufs
; /* histogram of buffer counts in anon state */
3578 uint64_t *mru_c_hist
; /* histogram of compressed sizes in mru */
3579 uint64_t *mru_u_hist
; /* histogram of uncompressed sizes in mru */
3580 uint64_t *mru_bufs
; /* histogram of buffer counts in mru */
3581 uint64_t *mfu_c_hist
; /* histogram of compressed sizes in mfu */
3582 uint64_t *mfu_u_hist
; /* histogram of uncompressed sizes in mfu */
3583 uint64_t *mfu_bufs
; /* histogram of buffer counts in mfu */
3584 uint64_t *all_c_hist
; /* histogram of compressed anon + mru + mfu */
3585 uint64_t *all_u_hist
; /* histogram of uncompressed anon + mru + mfu */
3586 uint64_t *all_bufs
; /* histogram of buffer counts in all states */
3587 int arc_cflags
; /* arc compression flags, specified by user */
3588 int hist_nbuckets
; /* number of buckets in each histogram */
3589 } arc_compression_stats_data_t
;
3592 highbit64(uint64_t i
)
3598 if (i
& 0xffffffff00000000ULL
) {
3601 if (i
& 0xffff0000) {
3621 arc_compression_stats_cb(uintptr_t addr
, const void *unknown
, void *arg
)
3623 arc_compression_stats_data_t
*data
= arg
;
3624 mdb_arc_buf_hdr_t hdr
;
3625 int cbucket
, ubucket
, bufcnt
;
3627 if (mdb_ctf_vread(&hdr
, "arc_buf_hdr_t", "mdb_arc_buf_hdr_t",
3633 * Headers in the ghost states, or the l2c_only state don't have
3634 * arc buffers linked off of them. Thus, their compressed size
3635 * is meaningless, so we skip these from the stats.
3637 if (hdr
.b_l1hdr
.b_state
== data
->mrug_sym
.st_value
||
3638 hdr
.b_l1hdr
.b_state
== data
->mfug_sym
.st_value
||
3639 hdr
.b_l1hdr
.b_state
== data
->l2c_sym
.st_value
) {
3644 * The physical size (compressed) and logical size
3645 * (uncompressed) are in units of SPA_MINBLOCKSIZE. By default,
3646 * we use the log2 of this value (rounded down to the nearest
3647 * integer) to determine the bucket to assign this header to.
3648 * Thus, the histogram is logarithmic with respect to the size
3649 * of the header. For example, the following is a mapping of the
3650 * bucket numbers and the range of header sizes they correspond to:
3653 * 1: 512 byte headers
3654 * 2: [1024 - 2048) byte headers
3655 * 3: [2048 - 4096) byte headers
3656 * 4: [4096 - 8192) byte headers
3657 * 5: [8192 - 16394) byte headers
3658 * 6: [16384 - 32768) byte headers
3659 * 7: [32768 - 65536) byte headers
3660 * 8: [65536 - 131072) byte headers
3661 * 9: 131072 byte headers
3663 * If the ARC_CFLAG_VERBOSE flag was specified, we use the
3664 * physical and logical sizes directly. Thus, the histogram will
3665 * no longer be logarithmic; instead it will be linear with
3666 * respect to the size of the header. The following is a mapping
3667 * of the first many bucket numbers and the header size they
3671 * 1: 512 byte headers
3672 * 2: 1024 byte headers
3673 * 3: 1536 byte headers
3674 * 4: 2048 byte headers
3675 * 5: 2560 byte headers
3676 * 6: 3072 byte headers
3678 * And so on. Keep in mind that a range of sizes isn't used in
3679 * the case of linear scale because the headers can only
3680 * increment or decrement in sizes of 512 bytes. So, it's not
3681 * possible for a header to be sized in between whats listed
3684 * Also, the above mapping values were calculated assuming a
3685 * SPA_MINBLOCKSHIFT of 512 bytes and a SPA_MAXBLOCKSIZE of 128K.
3688 if (data
->arc_cflags
& ARC_CFLAG_VERBOSE
) {
3689 cbucket
= hdr
.b_psize
;
3690 ubucket
= hdr
.b_lsize
;
3692 cbucket
= highbit64(hdr
.b_psize
);
3693 ubucket
= highbit64(hdr
.b_lsize
);
3696 bufcnt
= hdr
.b_l1hdr
.b_bufcnt
;
3697 if (bufcnt
>= data
->hist_nbuckets
)
3698 bufcnt
= data
->hist_nbuckets
- 1;
3700 /* Ensure we stay within the bounds of the histogram array */
3701 ASSERT3U(cbucket
, <, data
->hist_nbuckets
);
3702 ASSERT3U(ubucket
, <, data
->hist_nbuckets
);
3704 if (hdr
.b_l1hdr
.b_state
== data
->anon_sym
.st_value
) {
3705 data
->anon_c_hist
[cbucket
]++;
3706 data
->anon_u_hist
[ubucket
]++;
3707 data
->anon_bufs
[bufcnt
]++;
3708 } else if (hdr
.b_l1hdr
.b_state
== data
->mru_sym
.st_value
) {
3709 data
->mru_c_hist
[cbucket
]++;
3710 data
->mru_u_hist
[ubucket
]++;
3711 data
->mru_bufs
[bufcnt
]++;
3712 } else if (hdr
.b_l1hdr
.b_state
== data
->mfu_sym
.st_value
) {
3713 data
->mfu_c_hist
[cbucket
]++;
3714 data
->mfu_u_hist
[ubucket
]++;
3715 data
->mfu_bufs
[bufcnt
]++;
3718 data
->all_c_hist
[cbucket
]++;
3719 data
->all_u_hist
[ubucket
]++;
3720 data
->all_bufs
[bufcnt
]++;
3727 arc_compression_stats(uintptr_t addr
, uint_t flags
, int argc
,
3728 const mdb_arg_t
*argv
)
3730 arc_compression_stats_data_t data
= { 0 };
3731 unsigned int max_shifted
= SPA_MAXBLOCKSIZE
>> SPA_MINBLOCKSHIFT
;
3732 unsigned int hist_size
;
3736 if (mdb_getopts(argc
, argv
,
3737 'v', MDB_OPT_SETBITS
, ARC_CFLAG_VERBOSE
, &data
.arc_cflags
,
3738 'a', MDB_OPT_SETBITS
, ARC_CFLAG_ANON
, &data
.arc_cflags
,
3739 'b', MDB_OPT_SETBITS
, ARC_CFLAG_BUFS
, &data
.arc_cflags
,
3740 'r', MDB_OPT_SETBITS
, ARC_CFLAG_MRU
, &data
.arc_cflags
,
3741 'f', MDB_OPT_SETBITS
, ARC_CFLAG_MFU
, &data
.arc_cflags
) != argc
)
3742 return (DCMD_USAGE
);
3744 if (mdb_lookup_by_obj(ZFS_OBJ_NAME
, "ARC_anon", &data
.anon_sym
) ||
3745 mdb_lookup_by_obj(ZFS_OBJ_NAME
, "ARC_mru", &data
.mru_sym
) ||
3746 mdb_lookup_by_obj(ZFS_OBJ_NAME
, "ARC_mru_ghost", &data
.mrug_sym
) ||
3747 mdb_lookup_by_obj(ZFS_OBJ_NAME
, "ARC_mfu", &data
.mfu_sym
) ||
3748 mdb_lookup_by_obj(ZFS_OBJ_NAME
, "ARC_mfu_ghost", &data
.mfug_sym
) ||
3749 mdb_lookup_by_obj(ZFS_OBJ_NAME
, "ARC_l2c_only", &data
.l2c_sym
)) {
3750 mdb_warn("can't find arc state symbol");
3755 * Determine the maximum expected size for any header, and use
3756 * this to determine the number of buckets needed for each
3757 * histogram. If ARC_CFLAG_VERBOSE is specified, this value is
3758 * used directly; otherwise the log2 of the maximum size is
3759 * used. Thus, if using a log2 scale there's a maximum of 10
3760 * possible buckets, while the linear scale (when using
3761 * ARC_CFLAG_VERBOSE) has a maximum of 257 buckets.
3763 if (data
.arc_cflags
& ARC_CFLAG_VERBOSE
)
3764 data
.hist_nbuckets
= max_shifted
+ 1;
3766 data
.hist_nbuckets
= highbit64(max_shifted
) + 1;
3768 hist_size
= sizeof (uint64_t) * data
.hist_nbuckets
;
3770 data
.anon_c_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3771 data
.anon_u_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3772 data
.anon_bufs
= mdb_zalloc(hist_size
, UM_SLEEP
);
3774 data
.mru_c_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3775 data
.mru_u_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3776 data
.mru_bufs
= mdb_zalloc(hist_size
, UM_SLEEP
);
3778 data
.mfu_c_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3779 data
.mfu_u_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3780 data
.mfu_bufs
= mdb_zalloc(hist_size
, UM_SLEEP
);
3782 data
.all_c_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3783 data
.all_u_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3784 data
.all_bufs
= mdb_zalloc(hist_size
, UM_SLEEP
);
3786 if (mdb_walk("arc_buf_hdr_t_full", arc_compression_stats_cb
,
3788 mdb_warn("can't walk arc_buf_hdr's");
3793 if (data
.arc_cflags
& ARC_CFLAG_VERBOSE
) {
3794 rc
= mdb_snprintf(range
, sizeof (range
),
3795 "[n*%llu, (n+1)*%llu)", SPA_MINBLOCKSIZE
,
3798 rc
= mdb_snprintf(range
, sizeof (range
),
3799 "[2^(n-1)*%llu, 2^n*%llu)", SPA_MINBLOCKSIZE
,
3804 /* snprintf failed, abort the dcmd */
3808 /* snprintf succeeded above, reset return code */
3812 if (data
.arc_cflags
& ARC_CFLAG_ANON
) {
3813 if (data
.arc_cflags
& ARC_CFLAG_BUFS
) {
3814 mdb_printf("Histogram of the number of anon buffers "
3815 "that are associated with an arc hdr.\n");
3816 dump_histogram(data
.anon_bufs
, data
.hist_nbuckets
, 0);
3819 mdb_printf("Histogram of compressed anon buffers.\n"
3820 "Each bucket represents buffers of size: %s.\n", range
);
3821 dump_histogram(data
.anon_c_hist
, data
.hist_nbuckets
, 0);
3824 mdb_printf("Histogram of uncompressed anon buffers.\n"
3825 "Each bucket represents buffers of size: %s.\n", range
);
3826 dump_histogram(data
.anon_u_hist
, data
.hist_nbuckets
, 0);
3830 if (data
.arc_cflags
& ARC_CFLAG_MRU
) {
3831 if (data
.arc_cflags
& ARC_CFLAG_BUFS
) {
3832 mdb_printf("Histogram of the number of mru buffers "
3833 "that are associated with an arc hdr.\n");
3834 dump_histogram(data
.mru_bufs
, data
.hist_nbuckets
, 0);
3837 mdb_printf("Histogram of compressed mru buffers.\n"
3838 "Each bucket represents buffers of size: %s.\n", range
);
3839 dump_histogram(data
.mru_c_hist
, data
.hist_nbuckets
, 0);
3842 mdb_printf("Histogram of uncompressed mru buffers.\n"
3843 "Each bucket represents buffers of size: %s.\n", range
);
3844 dump_histogram(data
.mru_u_hist
, data
.hist_nbuckets
, 0);
3848 if (data
.arc_cflags
& ARC_CFLAG_MFU
) {
3849 if (data
.arc_cflags
& ARC_CFLAG_BUFS
) {
3850 mdb_printf("Histogram of the number of mfu buffers "
3851 "that are associated with an arc hdr.\n");
3852 dump_histogram(data
.mfu_bufs
, data
.hist_nbuckets
, 0);
3856 mdb_printf("Histogram of compressed mfu buffers.\n"
3857 "Each bucket represents buffers of size: %s.\n", range
);
3858 dump_histogram(data
.mfu_c_hist
, data
.hist_nbuckets
, 0);
3861 mdb_printf("Histogram of uncompressed mfu buffers.\n"
3862 "Each bucket represents buffers of size: %s.\n", range
);
3863 dump_histogram(data
.mfu_u_hist
, data
.hist_nbuckets
, 0);
3867 if (data
.arc_cflags
& ARC_CFLAG_BUFS
) {
3868 mdb_printf("Histogram of all buffers that "
3869 "are associated with an arc hdr.\n");
3870 dump_histogram(data
.all_bufs
, data
.hist_nbuckets
, 0);
3874 mdb_printf("Histogram of all compressed buffers.\n"
3875 "Each bucket represents buffers of size: %s.\n", range
);
3876 dump_histogram(data
.all_c_hist
, data
.hist_nbuckets
, 0);
3879 mdb_printf("Histogram of all uncompressed buffers.\n"
3880 "Each bucket represents buffers of size: %s.\n", range
);
3881 dump_histogram(data
.all_u_hist
, data
.hist_nbuckets
, 0);
3884 mdb_free(data
.anon_c_hist
, hist_size
);
3885 mdb_free(data
.anon_u_hist
, hist_size
);
3886 mdb_free(data
.anon_bufs
, hist_size
);
3888 mdb_free(data
.mru_c_hist
, hist_size
);
3889 mdb_free(data
.mru_u_hist
, hist_size
);
3890 mdb_free(data
.mru_bufs
, hist_size
);
3892 mdb_free(data
.mfu_c_hist
, hist_size
);
3893 mdb_free(data
.mfu_u_hist
, hist_size
);
3894 mdb_free(data
.mfu_bufs
, hist_size
);
3896 mdb_free(data
.all_c_hist
, hist_size
);
3897 mdb_free(data
.all_u_hist
, hist_size
);
3898 mdb_free(data
.all_bufs
, hist_size
);
3904 * MDB module linkage information:
3906 * We declare a list of structures describing our dcmds, and a function
3907 * named _mdb_init to return a pointer to our module information.
3910 static const mdb_dcmd_t dcmds
[] = {
3911 { "arc", "[-bkmg]", "print ARC variables", arc_print
},
3912 { "blkptr", ":", "print blkptr_t", blkptr
},
3913 { "dbuf", ":", "print dmu_buf_impl_t", dbuf
},
3914 { "dbuf_stats", ":", "dbuf stats", dbuf_stats
},
3916 "\t[-O objset_t*] [-n objset_name | \"mos\"] "
3917 "[-o object | \"mdn\"] \n"
3918 "\t[-l level] [-b blkid | \"bonus\"]",
3919 "find dmu_buf_impl_t's that match specified criteria", dbufs
},
3920 { "abuf_find", "dva_word[0] dva_word[1]",
3921 "find arc_buf_hdr_t of a specified DVA",
3923 { "spa", "?[-cevmMh]\n"
3924 "\t-c display spa config\n"
3925 "\t-e display vdev statistics\n"
3926 "\t-v display vdev information\n"
3927 "\t-m display metaslab statistics\n"
3928 "\t-M display metaslab group statistics\n"
3929 "\t-h display histogram (requires -m or -M)\n",
3930 "spa_t summary", spa_print
},
3931 { "spa_config", ":", "print spa_t configuration", spa_print_config
},
3932 { "spa_space", ":[-b]", "print spa_t on-disk space usage", spa_space
},
3933 { "spa_vdevs", ":[-emMh]\n"
3934 "\t-e display vdev statistics\n"
3935 "\t-m dispaly metaslab statistics\n"
3936 "\t-M display metaslab group statistic\n"
3937 "\t-h display histogram (requires -m or -M)\n",
3938 "given a spa_t, print vdev summary", spa_vdevs
},
3939 { "vdev", ":[-remMh]\n"
3940 "\t-r display recursively\n"
3941 "\t-e display statistics\n"
3942 "\t-m display metaslab statistics (top level vdev only)\n"
3943 "\t-M display metaslab group statistics (top level vdev only)\n"
3944 "\t-h display histogram (requires -m or -M)\n",
3945 "vdev_t summary", vdev_print
},
3946 { "zio", ":[-cpr]\n"
3947 "\t-c display children\n"
3948 "\t-p display parents\n"
3949 "\t-r display recursively",
3950 "zio_t summary", zio_print
},
3951 { "zio_state", "?", "print out all zio_t structures on system or "
3952 "for a particular pool", zio_state
},
3953 { "zfs_blkstats", ":[-v]",
3954 "given a spa_t, print block type stats from last scrub",
3956 { "zfs_params", "", "print zfs tunable parameters", zfs_params
},
3957 { "refcount", ":[-r]\n"
3958 "\t-r display recently removed references",
3959 "print refcount_t holders", refcount
},
3960 { "zap_leaf", "", "print zap_leaf_phys_t", zap_leaf
},
3961 { "zfs_aces", ":[-v]", "print all ACEs from a zfs_acl_t",
3963 { "zfs_ace", ":[-v]", "print zfs_ace", zfs_ace_print
},
3964 { "zfs_ace0", ":[-v]", "print zfs_ace0", zfs_ace0_print
},
3965 { "sa_attr_table", ":", "print SA attribute table from sa_os_t",
3967 { "sa_attr", ": attr_id",
3968 "print SA attribute address when given sa_handle_t", sa_attr_print
},
3969 { "zfs_dbgmsg", ":[-va]",
3970 "print zfs debug log", dbgmsg
},
3972 "print rrwlock_t, including readers", rrwlock
},
3973 { "metaslab_weight", "weight",
3974 "print metaslab weight", metaslab_weight
},
3975 { "metaslab_trace", ":",
3976 "print metaslab allocation trace records", metaslab_trace
},
3977 { "arc_compression_stats", ":[-vabrf]\n"
3978 "\t-v verbose, display a linearly scaled histogram\n"
3979 "\t-a display ARC_anon state statistics individually\n"
3980 "\t-r display ARC_mru state statistics individually\n"
3981 "\t-f display ARC_mfu state statistics individually\n"
3982 "\t-b display histogram of buffer counts\n",
3983 "print a histogram of compressed arc buffer sizes",
3984 arc_compression_stats
},
3988 static const mdb_walker_t walkers
[] = {
3989 { "zms_freelist", "walk ZFS metaslab freelist",
3990 freelist_walk_init
, freelist_walk_step
, NULL
},
3991 { "txg_list", "given any txg_list_t *, walk all entries in all txgs",
3992 txg_list_walk_init
, txg_list_walk_step
, NULL
},
3993 { "txg_list0", "given any txg_list_t *, walk all entries in txg 0",
3994 txg_list0_walk_init
, txg_list_walk_step
, NULL
},
3995 { "txg_list1", "given any txg_list_t *, walk all entries in txg 1",
3996 txg_list1_walk_init
, txg_list_walk_step
, NULL
},
3997 { "txg_list2", "given any txg_list_t *, walk all entries in txg 2",
3998 txg_list2_walk_init
, txg_list_walk_step
, NULL
},
3999 { "txg_list3", "given any txg_list_t *, walk all entries in txg 3",
4000 txg_list3_walk_init
, txg_list_walk_step
, NULL
},
4001 { "zio", "walk all zio structures, optionally for a particular spa_t",
4002 zio_walk_init
, zio_walk_step
, NULL
},
4004 "walk all root zio_t structures, optionally for a particular spa_t",
4005 zio_walk_init
, zio_walk_root_step
, NULL
},
4006 { "spa", "walk all spa_t entries in the namespace",
4007 spa_walk_init
, spa_walk_step
, NULL
},
4008 { "metaslab", "given a spa_t *, walk all metaslab_t structures",
4009 metaslab_walk_init
, metaslab_walk_step
, NULL
},
4010 { "multilist", "given a multilist_t *, walk all list_t structures",
4011 multilist_walk_init
, multilist_walk_step
, NULL
},
4012 { "zfs_acl_node", "given a zfs_acl_t, walk all zfs_acl_nodes",
4013 zfs_acl_node_walk_init
, zfs_acl_node_walk_step
, NULL
},
4014 { "zfs_acl_node_aces", "given a zfs_acl_node_t, walk all ACEs",
4015 zfs_acl_node_aces_walk_init
, zfs_aces_walk_step
, NULL
},
4016 { "zfs_acl_node_aces0",
4017 "given a zfs_acl_node_t, walk all ACEs as ace_t",
4018 zfs_acl_node_aces0_walk_init
, zfs_aces_walk_step
, NULL
},
4022 static const mdb_modinfo_t modinfo
= {
4023 MDB_API_VERSION
, dcmds
, walkers
4026 const mdb_modinfo_t
*