From bb21c0aa3b7b1595c81518ca81fb99e4d1bc23bb Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Thu, 15 Oct 2020 05:45:28 +0000 Subject: [PATCH] Add branch prediction to ZFS_ENTER and ZFS_VERIFY_ZP macros They are expected to fail only in corner cases. Reviewed-by: Ryan Moeller Reviewed-by: Brian Behlendorf Reviewed-by: Matt Macy Signed-off-by: Mateusz Guzik Closes #11153 --- include/os/freebsd/zfs/sys/zfs_znode_impl.h | 4 ++-- include/os/linux/zfs/sys/zfs_znode_impl.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/os/freebsd/zfs/sys/zfs_znode_impl.h b/include/os/freebsd/zfs/sys/zfs_znode_impl.h index d87938f097..a791ef6c2b 100644 --- a/include/os/freebsd/zfs/sys/zfs_znode_impl.h +++ b/include/os/freebsd/zfs/sys/zfs_znode_impl.h @@ -123,7 +123,7 @@ extern minor_t zfsdev_minor_alloc(void); #define ZFS_ENTER(zfsvfs) \ { \ rrm_enter_read(&(zfsvfs)->z_teardown_lock, FTAG); \ - if ((zfsvfs)->z_unmounted) { \ + if (__predict_false((zfsvfs)->z_unmounted)) { \ ZFS_EXIT(zfsvfs); \ return (EIO); \ } \ @@ -134,7 +134,7 @@ extern minor_t zfsdev_minor_alloc(void); /* Verifies the znode is valid */ #define ZFS_VERIFY_ZP(zp) \ - if ((zp)->z_sa_hdl == NULL) { \ + if (__predict_false((zp)->z_sa_hdl == NULL)) { \ ZFS_EXIT((zp)->z_zfsvfs); \ return (EIO); \ } \ diff --git a/include/os/linux/zfs/sys/zfs_znode_impl.h b/include/os/linux/zfs/sys/zfs_znode_impl.h index 7321f2740f..5f410e0fc2 100644 --- a/include/os/linux/zfs/sys/zfs_znode_impl.h +++ b/include/os/linux/zfs/sys/zfs_znode_impl.h @@ -80,7 +80,7 @@ extern "C" { #define ZFS_ENTER_ERROR(zfsvfs, error) \ do { \ rrm_enter_read(&(zfsvfs)->z_teardown_lock, FTAG); \ - if ((zfsvfs)->z_unmounted) { \ + if (unlikely((zfsvfs)->z_unmounted)) { \ ZFS_EXIT(zfsvfs); \ return (error); \ } \ @@ -103,7 +103,7 @@ do { \ /* Verifies the znode is valid. */ #define ZFS_VERIFY_ZP_ERROR(zp, error) \ do { \ - if ((zp)->z_sa_hdl == NULL) { \ + if (unlikely((zp)->z_sa_hdl == NULL)) { \ ZFS_EXIT(ZTOZSB(zp)); \ return (error); \ } \