Skip to content

Commit ad252c6

Browse files
tingchangadam900710
authored andcommitted
btrfs: preallocate extent changeset before acquiring extent_io_tree lock
In btrfs_clear_extent_bit_changeset(), the extent changeset ulist may need to allocate new nodes. Currently, this can happen while holding the extent_io_tree->lock spinlock. Although ulist_prealloc() uses GFP_NOFS to avoid deadlock with filesystem reclaim, it's better to preallocate before acquiring the spinlock to: 1. Avoid potential allocation failures while holding the lock 2. Be consistent with set_extent_bit() which already preallocates both extent state and changeset before the spinlock 3. Reduce lock contention by not doing allocations under the lock Preallocate the changeset ulist node before acquiring the spinlock, mirroring the pattern used for extent state preallocation. Signed-off-by: Ting-Chang Hou <tchou@synology.com> Reviewed-by: Qu Wenruo <wqu@suse.com>
1 parent 662114b commit ad252c6

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

fs/btrfs/extent-io-tree.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ int btrfs_clear_extent_bit_changeset(struct extent_io_tree *tree, u64 start, u64
663663
*/
664664
prealloc = alloc_extent_state(mask);
665665
}
666+
/* Preallocate the extent changeset ulist node before acquiring spinlock. */
667+
if (changeset)
668+
extent_changeset_prealloc(changeset, mask);
666669

667670
spin_lock(&tree->lock);
668671
if (cached_state) {

0 commit comments

Comments
 (0)