Print this page
patch nuke-the-dbuf-hash


 483                 (void) mdb_snprintf(objectname, sizeof (objectname), "%llx",
 484                     (u_longlong_t)db.db.db_object);
 485 
 486         if (db.db_blkid == DMU_BONUS_BLKID)
 487                 (void) strcpy(blkidname, "bonus");
 488         else
 489                 (void) mdb_snprintf(blkidname, sizeof (blkidname), "%llx",
 490                     (u_longlong_t)db.db_blkid);
 491 
 492         if (objset_name(db.db_objset, path)) {
 493                 return (DCMD_ERR);
 494         }
 495 
 496         mdb_printf("%p %8s %1u %9s %2llu %s\n", addr,
 497             objectname, (int)db.db_level, blkidname,
 498             db.db_holds.rc_count, path);
 499 
 500         return (DCMD_OK);
 501 }
 502 
 503 /* ARGSUSED */
 504 static int
 505 dbuf_stats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
 506 {
 507 #define HISTOSZ 32
 508         uintptr_t dbp;
 509         dmu_buf_impl_t db;
 510         dbuf_hash_table_t ht;
 511         uint64_t bucket, ndbufs;
 512         uint64_t histo[HISTOSZ];
 513         uint64_t histo2[HISTOSZ];
 514         int i, maxidx;
 515 
 516         if (mdb_readvar(&ht, "dbuf_hash_table") == -1) {
 517                 mdb_warn("failed to read 'dbuf_hash_table'");
 518                 return (DCMD_ERR);
 519         }
 520 
 521         for (i = 0; i < HISTOSZ; i++) {
 522                 histo[i] = 0;
 523                 histo2[i] = 0;
 524         }
 525 
 526         ndbufs = 0;
 527         for (bucket = 0; bucket < ht.hash_table_mask+1; bucket++) {
 528                 int len;
 529 
 530                 if (mdb_vread(&dbp, sizeof (void *),
 531                     (uintptr_t)(ht.hash_table+bucket)) == -1) {
 532                         mdb_warn("failed to read hash bucket %u at %p",
 533                             bucket, ht.hash_table+bucket);
 534                         return (DCMD_ERR);
 535                 }
 536 
 537                 len = 0;
 538                 while (dbp != 0) {
 539                         if (mdb_vread(&db, sizeof (dmu_buf_impl_t),
 540                             dbp) == -1) {
 541                                 mdb_warn("failed to read dbuf at %p", dbp);
 542                                 return (DCMD_ERR);
 543                         }
 544                         dbp = (uintptr_t)db.db_hash_next;
 545                         for (i = MIN(len, HISTOSZ - 1); i >= 0; i--)
 546                                 histo2[i]++;
 547                         len++;
 548                         ndbufs++;
 549                 }
 550 
 551                 if (len >= HISTOSZ)
 552                         len = HISTOSZ-1;
 553                 histo[len]++;
 554         }
 555 
 556         mdb_printf("hash table has %llu buckets, %llu dbufs "
 557             "(avg %llu buckets/dbuf)\n",
 558             ht.hash_table_mask+1, ndbufs,
 559             (ht.hash_table_mask+1)/ndbufs);
 560 
 561         mdb_printf("\n");
 562         maxidx = 0;
 563         for (i = 0; i < HISTOSZ; i++)
 564                 if (histo[i] > 0)
 565                         maxidx = i;
 566         mdb_printf("hash chain length   number of buckets\n");
 567         for (i = 0; i <= maxidx; i++)
 568                 mdb_printf("%u                  %llu\n", i, histo[i]);
 569 
 570         mdb_printf("\n");
 571         maxidx = 0;
 572         for (i = 0; i < HISTOSZ; i++)
 573                 if (histo2[i] > 0)
 574                         maxidx = i;
 575         mdb_printf("hash chain depth    number of dbufs\n");
 576         for (i = 0; i <= maxidx; i++)
 577                 mdb_printf("%u or more          %llu    %llu%%\n",
 578                     i, histo2[i], histo2[i]*100/ndbufs);
 579 
 580 
 581         return (DCMD_OK);
 582 }
 583 
 584 #define CHAIN_END 0xffff
 585 /*
 586  * ::zap_leaf [-v]
 587  *
 588  * Print a zap_leaf_phys_t, assumed to be 16k
 589  */
 590 /* ARGSUSED */
 591 static int
 592 zap_leaf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
 593 {
 594         char buf[16*1024];
 595         int verbose = B_FALSE;
 596         int four = B_FALSE;
 597         zap_leaf_t l;
 598         zap_leaf_phys_t *zlp = (void *)buf;
 599         int i;
 600 
 601         if (mdb_getopts(argc, argv,
 602             'v', MDB_OPT_SETBITS, TRUE, &verbose,
 603             '4', MDB_OPT_SETBITS, TRUE, &four,


3253          * "::walk thread | ::tsd -v <rrw_key>", but there is no support
3254          * for programmatic consumption of dcmds, so this would be
3255          * difficult, potentially requiring reimplementing ::tsd (both
3256          * user and kernel versions) in this MDB module.
3257          */
3258 
3259         return (DCMD_OK);
3260 }
3261 
3262 /*
3263  * MDB module linkage information:
3264  *
3265  * We declare a list of structures describing our dcmds, and a function
3266  * named _mdb_init to return a pointer to our module information.
3267  */
3268 
3269 static const mdb_dcmd_t dcmds[] = {
3270         { "arc", "[-bkmg]", "print ARC variables", arc_print },
3271         { "blkptr", ":", "print blkptr_t", blkptr },
3272         { "dbuf", ":", "print dmu_buf_impl_t", dbuf },
3273         { "dbuf_stats", ":", "dbuf stats", dbuf_stats },
3274         { "dbufs",
3275             "\t[-O objset_t*] [-n objset_name | \"mos\"] "
3276             "[-o object | \"mdn\"] \n"
3277             "\t[-l level] [-b blkid | \"bonus\"]",
3278             "find dmu_buf_impl_t's that match specified criteria", dbufs },
3279         { "abuf_find", "dva_word[0] dva_word[1]",
3280             "find arc_buf_hdr_t of a specified DVA",
3281             abuf_find },
3282         { "spa", "?[-cevmMh]\n"
3283             "\t-c display spa config\n"
3284             "\t-e display vdev statistics\n"
3285             "\t-v display vdev information\n"
3286             "\t-m display metaslab statistics\n"
3287             "\t-M display metaslab group statistics\n"
3288             "\t-h display histogram (requires -m or -M)\n",
3289             "spa_t summary", spa_print },
3290         { "spa_config", ":", "print spa_t configuration", spa_print_config },
3291         { "spa_space", ":[-b]", "print spa_t on-disk space usage", spa_space },
3292         { "spa_vdevs", ":[-emMh]\n"
3293             "\t-e display vdev statistics\n"




 483                 (void) mdb_snprintf(objectname, sizeof (objectname), "%llx",
 484                     (u_longlong_t)db.db.db_object);
 485 
 486         if (db.db_blkid == DMU_BONUS_BLKID)
 487                 (void) strcpy(blkidname, "bonus");
 488         else
 489                 (void) mdb_snprintf(blkidname, sizeof (blkidname), "%llx",
 490                     (u_longlong_t)db.db_blkid);
 491 
 492         if (objset_name(db.db_objset, path)) {
 493                 return (DCMD_ERR);
 494         }
 495 
 496         mdb_printf("%p %8s %1u %9s %2llu %s\n", addr,
 497             objectname, (int)db.db_level, blkidname,
 498             db.db_holds.rc_count, path);
 499 
 500         return (DCMD_OK);
 501 }
 502 

















































































 503 #define CHAIN_END 0xffff
 504 /*
 505  * ::zap_leaf [-v]
 506  *
 507  * Print a zap_leaf_phys_t, assumed to be 16k
 508  */
 509 /* ARGSUSED */
 510 static int
 511 zap_leaf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
 512 {
 513         char buf[16*1024];
 514         int verbose = B_FALSE;
 515         int four = B_FALSE;
 516         zap_leaf_t l;
 517         zap_leaf_phys_t *zlp = (void *)buf;
 518         int i;
 519 
 520         if (mdb_getopts(argc, argv,
 521             'v', MDB_OPT_SETBITS, TRUE, &verbose,
 522             '4', MDB_OPT_SETBITS, TRUE, &four,


3172          * "::walk thread | ::tsd -v <rrw_key>", but there is no support
3173          * for programmatic consumption of dcmds, so this would be
3174          * difficult, potentially requiring reimplementing ::tsd (both
3175          * user and kernel versions) in this MDB module.
3176          */
3177 
3178         return (DCMD_OK);
3179 }
3180 
3181 /*
3182  * MDB module linkage information:
3183  *
3184  * We declare a list of structures describing our dcmds, and a function
3185  * named _mdb_init to return a pointer to our module information.
3186  */
3187 
3188 static const mdb_dcmd_t dcmds[] = {
3189         { "arc", "[-bkmg]", "print ARC variables", arc_print },
3190         { "blkptr", ":", "print blkptr_t", blkptr },
3191         { "dbuf", ":", "print dmu_buf_impl_t", dbuf },

3192         { "dbufs",
3193             "\t[-O objset_t*] [-n objset_name | \"mos\"] "
3194             "[-o object | \"mdn\"] \n"
3195             "\t[-l level] [-b blkid | \"bonus\"]",
3196             "find dmu_buf_impl_t's that match specified criteria", dbufs },
3197         { "abuf_find", "dva_word[0] dva_word[1]",
3198             "find arc_buf_hdr_t of a specified DVA",
3199             abuf_find },
3200         { "spa", "?[-cevmMh]\n"
3201             "\t-c display spa config\n"
3202             "\t-e display vdev statistics\n"
3203             "\t-v display vdev information\n"
3204             "\t-m display metaslab statistics\n"
3205             "\t-M display metaslab group statistics\n"
3206             "\t-h display histogram (requires -m or -M)\n",
3207             "spa_t summary", spa_print },
3208         { "spa_config", ":", "print spa_t configuration", spa_print_config },
3209         { "spa_space", ":[-b]", "print spa_t on-disk space usage", spa_space },
3210         { "spa_vdevs", ":[-emMh]\n"
3211             "\t-e display vdev statistics\n"