]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Use rw_tryupgrade() in dmu_bonus_hold_by_dnode()
authorRichard Yao <richard.yao@alumni.stonybrook.edu>
Thu, 23 Feb 2023 00:33:23 +0000 (19:33 -0500)
committerGitHub <noreply@github.com>
Thu, 23 Feb 2023 00:33:23 +0000 (16:33 -0800)
When dn->dn_bonus == NULL, dmu_bonus_hold_by_dnode() will unlock its
read lock on dn->dn_struct_rwlock and grab a write lock. This can be
micro-optimized by calling rw_tryupgrade().

Linux will not benefit from this since it does not support rwlock
upgrades, but FreeBSD will.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14517

module/zfs/dmu.c

index d6a9f813c2701fa659ac771a3664314858b02302..9b8fc7e49b2dfe447dee148b389afce85fee4aa3 100644 (file)
@@ -357,8 +357,10 @@ int dmu_bonus_hold_by_dnode(dnode_t *dn, const void *tag, dmu_buf_t **dbp,
 
        rw_enter(&dn->dn_struct_rwlock, RW_READER);
        if (dn->dn_bonus == NULL) {
-               rw_exit(&dn->dn_struct_rwlock);
-               rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
+               if (!rw_tryupgrade(&dn->dn_struct_rwlock)) {
+                       rw_exit(&dn->dn_struct_rwlock);
+                       rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
+               }
                if (dn->dn_bonus == NULL)
                        dbuf_create_bonus(dn);
        }