aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2021-06-29 12:59:14 +0000
committerGitHub <noreply@github.com>2021-06-29 12:59:14 +0000
commit5b7053a9a5a624603843a07ac0b360af64839e72 (patch)
tree14f35686ae48cd8b876fc1a0741993e0a5c324d1
parentf20fb199e60722abc052b6034bddb6b83d870c99 (diff)
downloadsrc-5b7053a9a5a624603843a07ac0b360af64839e72.tar.gz
src-5b7053a9a5a624603843a07ac0b360af64839e72.zip
Avoid 64bit division in multilist index functions
The number of sublists in a multilist is relatively small. We dont need 64 bits to calculate an index. 32 bits is sufficient and makes the code more efficient. Reviewed-by: Matthew Ahrens <mahrens@delphix.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Mark Maybee <mark.maybee@delphix.com> Signed-off-by: Alexander Motin <mav@FreeBSD.org> Sponsored-By: iXsystems, Inc. Closes #12288
-rw-r--r--module/zfs/arc.c5
-rw-r--r--module/zfs/dbuf.c5
-rw-r--r--module/zfs/dmu_objset.c10
-rw-r--r--module/zfs/metaslab.c7
4 files changed, 21 insertions, 6 deletions
diff --git a/module/zfs/arc.c b/module/zfs/arc.c
index 04d275dd80f4..3484fff3b4d4 100644
--- a/module/zfs/arc.c
+++ b/module/zfs/arc.c
@@ -7454,9 +7454,10 @@ arc_state_multilist_index_func(multilist_t *ml, void *obj)
* Also, the low order bits of the hash value are thought to be
* distributed evenly. Otherwise, in the case that the multilist
* has a power of two number of sublists, each sublists' usage
- * would not be evenly distributed.
+ * would not be evenly distributed. In this context full 64bit
+ * division would be a waste of time, so limit it to 32 bits.
*/
- return (buf_hash(hdr->b_spa, &hdr->b_dva, hdr->b_birth) %
+ return ((unsigned int)buf_hash(hdr->b_spa, &hdr->b_dva, hdr->b_birth) %
multilist_get_num_sublists(ml));
}
diff --git a/module/zfs/dbuf.c b/module/zfs/dbuf.c
index f9bcd9313f0a..9ce091b80dcb 100644
--- a/module/zfs/dbuf.c
+++ b/module/zfs/dbuf.c
@@ -622,9 +622,10 @@ dbuf_cache_multilist_index_func(multilist_t *ml, void *obj)
* Also, the low order bits of the hash value are thought to be
* distributed evenly. Otherwise, in the case that the multilist
* has a power of two number of sublists, each sublists' usage
- * would not be evenly distributed.
+ * would not be evenly distributed. In this context full 64bit
+ * division would be a waste of time, so limit it to 32 bits.
*/
- return (dbuf_hash(db->db_objset, db->db.db_object,
+ return ((unsigned int)dbuf_hash(db->db_objset, db->db.db_object,
db->db_level, db->db_blkid) %
multilist_get_num_sublists(ml));
}
diff --git a/module/zfs/dmu_objset.c b/module/zfs/dmu_objset.c
index 22deee7f3dc9..af107fb8ad63 100644
--- a/module/zfs/dmu_objset.c
+++ b/module/zfs/dmu_objset.c
@@ -399,7 +399,15 @@ static unsigned int
dnode_multilist_index_func(multilist_t *ml, void *obj)
{
dnode_t *dn = obj;
- return (dnode_hash(dn->dn_objset, dn->dn_object) %
+
+ /*
+ * The low order bits of the hash value are thought to be
+ * distributed evenly. Otherwise, in the case that the multilist
+ * has a power of two number of sublists, each sublists' usage
+ * would not be evenly distributed. In this context full 64bit
+ * division would be a waste of time, so limit it to 32 bits.
+ */
+ return ((unsigned int)dnode_hash(dn->dn_objset, dn->dn_object) %
multilist_get_num_sublists(ml));
}
diff --git a/module/zfs/metaslab.c b/module/zfs/metaslab.c
index 92f51806ace5..23f3e2989ae7 100644
--- a/module/zfs/metaslab.c
+++ b/module/zfs/metaslab.c
@@ -1874,7 +1874,12 @@ static unsigned int
metaslab_idx_func(multilist_t *ml, void *arg)
{
metaslab_t *msp = arg;
- return (msp->ms_id % multilist_get_num_sublists(ml));
+
+ /*
+ * ms_id values are allocated sequentially, so full 64bit
+ * division would be a waste of time, so limit it to 32 bits.
+ */
+ return ((unsigned int)msp->ms_id % multilist_get_num_sublists(ml));
}
uint64_t