• Qu Wenruo's avatar
    btrfs: skip subtree scan if it's too high to avoid low stall in btrfs_commit_transaction() · 011b46c3
    Qu Wenruo authored
    Btrfs qgroup has a long history of bringing performance penalty in
    btrfs_commit_transaction().
    
    Although we tried our best to migrate such impact, there is still an
    unsolved call site, btrfs_drop_snapshot().
    
    This function will find the highest shared tree block and modify its
    extent ownership to do a subvolume/snapshot dropping.
    
    Such change will affect the whole subtree, and cause tons of qgroup
    dirty extents and stall btrfs_commit_transaction().
    
    To avoid such problem, here we introduce a new sysfs interface,
    /sys/fs/btrfs/<uuid>/qgroups/drop_subptree_threshold, to determine at
    whether and at which level we should skip qgroup accounting for subtree
    dropping.
    
    The default value is BTRFS_MAX_LEVEL, thus every subtree drop will go
    through qgroup accounting, to ensure qgroup numbers are kept as
    consistent as possible.
    
    While for performance sensitive cases, add a way to change the values to
    more reasonable values like 3, to make any subtree, which is at or higher
    than level 3, to mark qgroup inconsistent and skip the accounting.
    
    The cost is obvious, the qgroup number is no longer consistent, but at
    least performance is more reasonable, and users have the control.
    Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    011b46c3
sysfs.c 62.1 KB