• Filipe Manana's avatar
    btrfs: avoid allocating and running pointless delayed extent operations · eba1469f
    Filipe Manana authored
    We always allocate a delayed extent op structure when allocating a tree
    block (except for log trees), but most of the time we don't need it as
    we only need to set the BTRFS_BLOCK_FLAG_FULL_BACKREF if we're dealing
    with a relocation tree and we only need to set the key of a tree block
    in a btrfs_tree_block_info structure if we are not using skinny metadata
    (feature enabled by default since btrfs-progs 3.18 and available as of
    kernel 3.10).
    
    In these cases, where we don't need neither to update flags nor to set
    the key, we only use the delayed extent op structure to set the tree
    block's level. This is a waste of memory and besides that, the memory
    allocation can fail and can add additional latency.
    
    Instead of using a delayed extent op structure to store the level of
    the tree block, use the delayed ref head to store it. This doesn't
    change the size of neither structure and helps us avoid allocating
    delayed extent ops structures when using the skinny metadata feature
    and there's no relocation going on. This also gets rid of a BUG_ON().
    
    For example, for a fs_mark run, with 5 iterations, 8 threads and 100K
    files per iteration, before this patch there were 118109 allocations
    of delayed extent op structures and after it there were none.
    Reviewed-by: default avatarBoris Burkov <boris@bur.io>
    Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    eba1469f
extent-tree.c 180 KB