• Qu Wenruo's avatar
    btrfs: reduce div64 calls by limiting the number of stripes of a chunk to u32 · 6ded22c1
    Qu Wenruo authored
    There are quite some div64 calls inside btrfs_map_block() and its
    variants.
    
    Such calls are for @stripe_nr, where @stripe_nr is the number of
    stripes before our logical bytenr inside a chunk.
    
    However we can eliminate such div64 calls by just reducing the width of
    @stripe_nr from 64 to 32.
    
    This can be done because our chunk size limit is already 10G, with fixed
    stripe length 64K.
    Thus a U32 is definitely enough to contain the number of stripes.
    
    With such width reduction, we can get rid of slower div64, and extra
    warning for certain 32bit arch.
    
    This patch would do:
    
    - Add a new tree-checker chunk validation on chunk length
      Make sure no chunk can reach 256G, which can also act as a bitflip
      checker.
    
    - Reduce the width from u64 to u32 for @stripe_nr variables
    
    - Replace unnecessary div64 calls with regular modulo and division
      32bit division and modulo are much faster than 64bit operations, and
      we are finally free of the div64 fear at least in those involved
      functions.
    Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    6ded22c1
tree-checker.c 58.3 KB