Skip to content

Commit 74f36cf

Browse files
committed
Avoid 64bit division in multilist index functions.
Number of sublists in multilists equal to number of CPUs is typically small even or even power of 2. It makes almost no sense to use full slow 64bit division. Signed-off-by: Alexander Motin <[email protected]> Sponsored-By: iXsystems, Inc.
1 parent f20fb19 commit 74f36cf

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

module/zfs/arc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7454,9 +7454,10 @@ arc_state_multilist_index_func(multilist_t *ml, void *obj)
74547454
* Also, the low order bits of the hash value are thought to be
74557455
* distributed evenly. Otherwise, in the case that the multilist
74567456
* has a power of two number of sublists, each sublists' usage
7457-
* would not be evenly distributed.
7457+
* would not be evenly distributed. In this context full 64bit
7458+
* division would be a waste of time, so limit it to 32 bits.
74587459
*/
7459-
return (buf_hash(hdr->b_spa, &hdr->b_dva, hdr->b_birth) %
7460+
return ((unsigned int)buf_hash(hdr->b_spa, &hdr->b_dva, hdr->b_birth) %
74607461
multilist_get_num_sublists(ml));
74617462
}
74627463

module/zfs/dbuf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,10 @@ dbuf_cache_multilist_index_func(multilist_t *ml, void *obj)
622622
* Also, the low order bits of the hash value are thought to be
623623
* distributed evenly. Otherwise, in the case that the multilist
624624
* has a power of two number of sublists, each sublists' usage
625-
* would not be evenly distributed.
625+
* would not be evenly distributed. In this context full 64bit
626+
* division would be a waste of time, so limit it to 32 bits.
626627
*/
627-
return (dbuf_hash(db->db_objset, db->db.db_object,
628+
return ((unsigned int)dbuf_hash(db->db_objset, db->db.db_object,
628629
db->db_level, db->db_blkid) %
629630
multilist_get_num_sublists(ml));
630631
}

module/zfs/dmu_objset.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,15 @@ static unsigned int
399399
dnode_multilist_index_func(multilist_t *ml, void *obj)
400400
{
401401
dnode_t *dn = obj;
402-
return (dnode_hash(dn->dn_objset, dn->dn_object) %
402+
403+
/*
404+
* The low order bits of the hash value are thought to be
405+
* distributed evenly. Otherwise, in the case that the multilist
406+
* has a power of two number of sublists, each sublists' usage
407+
* would not be evenly distributed. In this context full 64bit
408+
* division would be a waste of time, so limit it to 32 bits.
409+
*/
410+
return ((unsigned int)dnode_hash(dn->dn_objset, dn->dn_object) %
403411
multilist_get_num_sublists(ml));
404412
}
405413

module/zfs/metaslab.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,12 @@ static unsigned int
18741874
metaslab_idx_func(multilist_t *ml, void *arg)
18751875
{
18761876
metaslab_t *msp = arg;
1877-
return (msp->ms_id % multilist_get_num_sublists(ml));
1877+
1878+
/*
1879+
* ms_id values are allocated sequentially, so full 64bit
1880+
* division would be a waste of time, so limit it to 32 bits.
1881+
*/
1882+
return ((unsigned int)msp->ms_id % multilist_get_num_sublists(ml));
18781883
}
18791884

18801885
uint64_t

0 commit comments

Comments
 (0)