• Filipe Manana's avatar
    btrfs: allow to run delayed refs by bytes to be released instead of count · 8a526c44
    Filipe Manana authored
    When running delayed references, through btrfs_run_delayed_refs(), we can
    specify how many to run, run all existing delayed references and keep
    running delayed references while we can find any. This is controlled with
    the value of the 'count' argument, where a value of 0 means to run all
    delayed references that exist by the time btrfs_run_delayed_refs() is
    called, (unsigned long)-1 means to keep running delayed references while
    we are able find any, and any other value to run that exact number of
    delayed references.
    
    Typically a specific value other than 0 or -1 is used when flushing space
    to try to release a certain amount of bytes for a ticket. In this case
    we just simply calculate how many delayed reference heads correspond to a
    specific amount of bytes, with calc_delayed_refs_nr(). However that only
    takes into account the space reserved for the reference heads themselves,
    and does not account for the space reserved for deleting checksums from
    the csum tree (see add_delayed_ref_head() and update_existing_head_ref())
    in case we are going to delete a data extent. This means we may end up
    running more delayed references than necessary in case we process delayed
    references for deleting a data extent.
    
    So change the logic of btrfs_run_delayed_refs() to take a bytes argument
    to specify how many bytes of delayed references to run/release, using the
    special values of 0 to mean all existing delayed references and U64_MAX
    (or (u64)-1) to keep running delayed references while we can find any.
    
    This prevents running more delayed references than necessary, when we have
    delayed references for deleting data extents, but also makes the upcoming
    changes/patches simpler and it's preparatory work for them.
    Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
    Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    8a526c44
extent-tree.h 4.93 KB