btrfs: use shifts for sectorsize and nodesize

Convert more multiplications of sectorsize or nodesize to use the
shifts. The remaining cases are multiplications by constants that
compiler can optimize by itself, and in tests.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba
2026-05-27 13:16:52 +02:00
committed by Johannes Thumshirn
parent 532085d00e
commit 422ccdfe22
5 changed files with 7 additions and 7 deletions

View File

@@ -281,7 +281,7 @@ static void btrfs_calculate_inode_block_rsv_size(struct btrfs_fs_info *fs_info,
*
* This is overestimating in most cases.
*/
qgroup_rsv_size = (u64)outstanding_extents * fs_info->nodesize;
qgroup_rsv_size = ((u64)outstanding_extents << fs_info->nodesize_bits);
spin_lock(&block_rsv->lock);
block_rsv->size = reserve_size;
@@ -311,7 +311,7 @@ static void calc_inode_reservations(struct btrfs_inode *inode,
* for an inode update.
*/
*meta_reserve += inode_update;
*qgroup_reserve = nr_extents * fs_info->nodesize;
*qgroup_reserve = (nr_extents << fs_info->nodesize_bits);
}
int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes,

View File

@@ -563,7 +563,7 @@ static bool btree_dirty_folio(struct address_space *mapping,
continue;
}
spin_unlock_irqrestore(&subpage->lock, flags);
cur = page_start + cur_bit * fs_info->sectorsize;
cur = page_start + (cur_bit << fs_info->sectorsize_bits);
eb = find_extent_buffer(fs_info, cur);
ASSERT(eb);

View File

@@ -1309,7 +1309,7 @@ int btrfs_insert_data_csums(struct btrfs_trans_handle *trans,
index += ins_size;
ins_size /= csum_size;
total_bytes += ins_size * fs_info->sectorsize;
total_bytes += (ins_size << fs_info->sectorsize_bits);
if (total_bytes < sums->len) {
btrfs_release_path(path);

View File

@@ -1574,7 +1574,7 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
* and * 2 since we have two trees to COW.
*/
reserve_level = max_t(int, 1, btrfs_root_level(root_item));
min_reserved = fs_info->nodesize * reserve_level * 2;
min_reserved = (reserve_level << fs_info->nodesize_bits) * 2;
memset(&next_key, 0, sizeof(next_key));
while (1) {
@@ -2572,7 +2572,7 @@ static int relocate_cowonly_block(struct btrfs_trans_handle *trans,
nr_levels = max(btrfs_header_level(root->node) - block->level, 0) + 1;
num_bytes = fs_info->nodesize * nr_levels;
num_bytes = (nr_levels << fs_info->nodesize_bits);
ret = refill_metadata_space(trans, rc, num_bytes);
if (ret) {
btrfs_put_root(root);

View File

@@ -631,7 +631,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
* the appropriate flushing if need be.
*/
if (num_items && root != fs_info->chunk_root) {
qgroup_reserved = num_items * fs_info->nodesize;
qgroup_reserved = (num_items << fs_info->nodesize_bits);
/*
* Use prealloc for now, as there might be a currently running
* transaction that could free this reserved space prematurely