From 67894a597f401e091faa79c27a375fcf88ab1c91 Mon Sep 17 00:00:00 2001 From: Matthew Ahrens Date: Tue, 28 Nov 2023 09:20:48 -0800 Subject: [PATCH] unnecessary alloc/free in dsl_scan_visitbp() Clean up code in dsl_scan_visitbp() by removing an unnecessary alloc/free and `goto`. This has the side benefit of reducing CPU usage, which is only really noticeable if we are not doing i/o for the leaf blocks, like when `zfs_no_scrub_io` is set. Reviewed-by: Alexander Motin Reviewed-by: Mark Maybee Reviewed-by: Richard Yao Signed-off-by: Matthew Ahrens Closes #15549 --- module/zfs/dsl_scan.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/module/zfs/dsl_scan.c b/module/zfs/dsl_scan.c index e16128fdff..d04149f560 100644 --- a/module/zfs/dsl_scan.c +++ b/module/zfs/dsl_scan.c @@ -2142,7 +2142,7 @@ dsl_scan_check_resume(dsl_scan_t *scn, const dnode_phys_t *dnp, return (B_FALSE); } -static void dsl_scan_visitbp(blkptr_t *bp, const zbookmark_phys_t *zb, +static void dsl_scan_visitbp(const blkptr_t *bp, const zbookmark_phys_t *zb, dnode_phys_t *dnp, dsl_dataset_t *ds, dsl_scan_t *scn, dmu_objset_type_t ostype, dmu_tx_t *tx); inline __attribute__((always_inline)) static void dsl_scan_visitdnode( @@ -2307,12 +2307,11 @@ dsl_scan_visitdnode(dsl_scan_t *scn, dsl_dataset_t *ds, * first 5; we want them to be useful. */ static void -dsl_scan_visitbp(blkptr_t *bp, const zbookmark_phys_t *zb, +dsl_scan_visitbp(const blkptr_t *bp, const zbookmark_phys_t *zb, dnode_phys_t *dnp, dsl_dataset_t *ds, dsl_scan_t *scn, dmu_objset_type_t ostype, dmu_tx_t *tx) { dsl_pool_t *dp = scn->scn_dp; - blkptr_t *bp_toread = NULL; if (dsl_scan_check_suspend(scn, zb)) return; @@ -2353,11 +2352,8 @@ dsl_scan_visitbp(blkptr_t *bp, const zbookmark_phys_t *zb, return; } - bp_toread = kmem_alloc(sizeof (blkptr_t), KM_SLEEP); - *bp_toread = *bp; - - if (dsl_scan_recurse(scn, ds, ostype, dnp, bp_toread, zb, tx) != 0) - goto out; + if (dsl_scan_recurse(scn, ds, ostype, dnp, bp, zb, tx) != 0) + return; /* * If dsl_scan_ddt() has already visited this block, it will have @@ -2367,7 +2363,7 @@ dsl_scan_visitbp(blkptr_t *bp, const zbookmark_phys_t *zb, if (ddt_class_contains(dp->dp_spa, scn->scn_phys.scn_ddt_class_max, bp)) { scn->scn_ddt_contained_this_txg++; - goto out; + return; } /* @@ -2379,13 +2375,10 @@ dsl_scan_visitbp(blkptr_t *bp, const zbookmark_phys_t *zb, */ if (BP_PHYSICAL_BIRTH(bp) > scn->scn_phys.scn_cur_max_txg) { scn->scn_gt_max_this_txg++; - goto out; + return; } scan_funcs[scn->scn_phys.scn_func](dp, bp, zb); - -out: - kmem_free(bp_toread, sizeof (blkptr_t)); } static void