From 231a37c4c0fdc96d412946b584ebff553e734484 Mon Sep 17 00:00:00 2001 From: George Amanakis Date: Tue, 7 Mar 2023 01:13:05 +0100 Subject: [PATCH] Optimize the is_l2cacheable functions by placing the most common use case (no special vdevs) first and avoid allocating new variables. Reviewed-by: Alexander Motin Reviewed-by: Brian Behlendorf Signed-off-by: George Amanakis Closes #14494 Closes #14563 --- module/zfs/dbuf.c | 56 ++++++++++++++++++++--------------------- module/zfs/dmu_objset.c | 26 +++++++++---------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/module/zfs/dbuf.c b/module/zfs/dbuf.c index 91e95771b3..a59aa78f3c 100644 --- a/module/zfs/dbuf.c +++ b/module/zfs/dbuf.c @@ -602,58 +602,58 @@ dbuf_is_metadata(dmu_buf_impl_t *db) boolean_t dbuf_is_l2cacheable(dmu_buf_impl_t *db) { - vdev_t *vd = NULL; - zfs_cache_type_t cache = db->db_objset->os_secondary_cache; - blkptr_t *bp = db->db_blkptr; + if (db->db_objset->os_secondary_cache == ZFS_CACHE_ALL || + (db->db_objset->os_secondary_cache == + ZFS_CACHE_METADATA && dbuf_is_metadata(db))) { + if (l2arc_exclude_special == 0) + return (B_TRUE); - if (bp != NULL && !BP_IS_HOLE(bp)) { + blkptr_t *bp = db->db_blkptr; + if (bp == NULL || BP_IS_HOLE(bp)) + return (B_FALSE); uint64_t vdev = DVA_GET_VDEV(bp->blk_dva); vdev_t *rvd = db->db_objset->os_spa->spa_root_vdev; + vdev_t *vd = NULL; if (vdev < rvd->vdev_children) vd = rvd->vdev_child[vdev]; - if (cache == ZFS_CACHE_ALL || - (dbuf_is_metadata(db) && cache == ZFS_CACHE_METADATA)) { - if (vd == NULL) - return (B_TRUE); + if (vd == NULL) + return (B_TRUE); - if ((vd->vdev_alloc_bias != VDEV_BIAS_SPECIAL && - vd->vdev_alloc_bias != VDEV_BIAS_DEDUP) || - l2arc_exclude_special == 0) - return (B_TRUE); - } + if (vd->vdev_alloc_bias != VDEV_BIAS_SPECIAL && + vd->vdev_alloc_bias != VDEV_BIAS_DEDUP) + return (B_TRUE); } - return (B_FALSE); } static inline boolean_t dnode_level_is_l2cacheable(blkptr_t *bp, dnode_t *dn, int64_t level) { - vdev_t *vd = NULL; - zfs_cache_type_t cache = dn->dn_objset->os_secondary_cache; + if (dn->dn_objset->os_secondary_cache == ZFS_CACHE_ALL || + (dn->dn_objset->os_secondary_cache == ZFS_CACHE_METADATA && + (level > 0 || + DMU_OT_IS_METADATA(dn->dn_handle->dnh_dnode->dn_type)))) { + if (l2arc_exclude_special == 0) + return (B_TRUE); - if (bp != NULL && !BP_IS_HOLE(bp)) { + if (bp == NULL || BP_IS_HOLE(bp)) + return (B_FALSE); uint64_t vdev = DVA_GET_VDEV(bp->blk_dva); vdev_t *rvd = dn->dn_objset->os_spa->spa_root_vdev; + vdev_t *vd = NULL; if (vdev < rvd->vdev_children) vd = rvd->vdev_child[vdev]; - if (cache == ZFS_CACHE_ALL || ((level > 0 || - DMU_OT_IS_METADATA(dn->dn_handle->dnh_dnode->dn_type)) && - cache == ZFS_CACHE_METADATA)) { - if (vd == NULL) - return (B_TRUE); + if (vd == NULL) + return (B_TRUE); - if ((vd->vdev_alloc_bias != VDEV_BIAS_SPECIAL && - vd->vdev_alloc_bias != VDEV_BIAS_DEDUP) || - l2arc_exclude_special == 0) - return (B_TRUE); - } + if (vd->vdev_alloc_bias != VDEV_BIAS_SPECIAL && + vd->vdev_alloc_bias != VDEV_BIAS_DEDUP) + return (B_TRUE); } - return (B_FALSE); } diff --git a/module/zfs/dmu_objset.c b/module/zfs/dmu_objset.c index 345803e42f..adff615a6f 100644 --- a/module/zfs/dmu_objset.c +++ b/module/zfs/dmu_objset.c @@ -419,28 +419,28 @@ dnode_multilist_index_func(multilist_t *ml, void *obj) static inline boolean_t dmu_os_is_l2cacheable(objset_t *os) { - vdev_t *vd = NULL; - zfs_cache_type_t cache = os->os_secondary_cache; - blkptr_t *bp = os->os_rootbp; + if (os->os_secondary_cache == ZFS_CACHE_ALL || + os->os_secondary_cache == ZFS_CACHE_METADATA) { + if (l2arc_exclude_special == 0) + return (B_TRUE); - if (bp != NULL && !BP_IS_HOLE(bp)) { + blkptr_t *bp = os->os_rootbp; + if (bp == NULL || BP_IS_HOLE(bp)) + return (B_FALSE); uint64_t vdev = DVA_GET_VDEV(bp->blk_dva); vdev_t *rvd = os->os_spa->spa_root_vdev; + vdev_t *vd = NULL; if (vdev < rvd->vdev_children) vd = rvd->vdev_child[vdev]; - if (cache == ZFS_CACHE_ALL || cache == ZFS_CACHE_METADATA) { - if (vd == NULL) - return (B_TRUE); + if (vd == NULL) + return (B_TRUE); - if ((vd->vdev_alloc_bias != VDEV_BIAS_SPECIAL && - vd->vdev_alloc_bias != VDEV_BIAS_DEDUP) || - l2arc_exclude_special == 0) - return (B_TRUE); - } + if (vd->vdev_alloc_bias != VDEV_BIAS_SPECIAL && + vd->vdev_alloc_bias != VDEV_BIAS_DEDUP) + return (B_TRUE); } - return (B_FALSE); }