mbox series

[v3,0/2] btrfs: reduce div64 calls for __btrfs_map_block() and its variants

Message ID cover.1675681212.git.wqu@suse.com (mailing list archive)
Headers show
Series btrfs: reduce div64 calls for __btrfs_map_block() and its variants | expand

Message

Qu Wenruo Feb. 6, 2023, 11:18 a.m. UTC
Changelog:
v3:
- Move more BTRFS_STRIPE_LEN_SHIFT cleanup to patch 1
- Use const_ilog2() to define BTRFS_STRIPE_LEN_SHIFT
- Introduce BTRFS_STRIPE_LEN_MASK to make offset calculation easier.
- Convert all "u64 stripe_nr" to "u32 stripe_nr"
  Previously there is one in get_raid56_logic_offset() not converted.

v2:
- Fix a linkage error for 32bits platform in block-group.c
  We have a line "stripe_nr = (stripe_nr * num_stripes + i) /
		  sub_stripes."
  In that case, @stripe_nr itself is already u64, thus the division
  is dividing u64 with u32.

  And we can not easily do a forced u32 conversion, as we only have
  ensured @stripe_nr can be contained in u32.
  Even with 10G chunk size in mined, if the RAID10 array has over 26
  devices, then we can overflow U32 and cause problems.

  For now, keeps the old div_u64 call.

Div64 is much slower than 32 bit division, and only get improved in
the most recent CPUs, that's why we have dedicated div64* helpers.

One usage of div64 is in __btrfs_map_block() and its variants, where we
got @stripe_nr as u64, and all later division has to go the div64
helpers.

But the truth is, with our current chunk size limit (10G) and fixed
stripe length (64K), we can have at most 160K stripes in a chunk, which
is small enough for u32 already.

So this patchset would reduce div64 calls by:

- Remove map_lookup::stripe_len first
  So now we don't need to call div64 to calculate @stripe_nr, just a
  simple right shift, then truncate to u32.

  This is a prerequisite for the 2nd patch, without the fixed stripe
  length, we have to rely on div64.

- Reduce the width of various @stripe_nr from u64 to u32

- Use regular division and modulo to do the calculation
  Now we can get rid of the fear that we missed some div64 helpers.


Qu Wenruo (2):
  btrfs: remove map_lookup->stripe_len
  btrfs: reduce div64 calls by limiting the number of stripes of a chunk
    to u32

 fs/btrfs/block-group.c            |  22 +++---
 fs/btrfs/scrub.c                  |  55 +++++++-------
 fs/btrfs/tests/extent-map-tests.c |   1 -
 fs/btrfs/tree-checker.c           |  14 ++++
 fs/btrfs/volumes.c                | 118 +++++++++++++++---------------
 fs/btrfs/volumes.h                |   6 +-
 6 files changed, 116 insertions(+), 100 deletions(-)