btrfs: preallocate extent changeset before acquiring extent_io_tree lock
PATCH 1/1 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.
--- fs/btrfs/extent-io-tree.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/extent-io-tree.c +3 -0
@@ -663,6 +663,9 @@ int btrfs_clear_extent_bit_changeset(struct extent_io_tree *tree, u64 start, u64*/ prealloc =alloc_extent_state (mask); } +/* Preallocate the extent changeset ulist node before acquiring spinlock. */ +if (changeset) +extent_changeset_prealloc (changeset, mask);spin_lock (&tree->lock);if (cached_state) {
Signature · 4 lines
2.34.1 Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.
Quoted 6 lines · tchou
In
btrfs_clear_extent_bit_changeset(), the extent changeset ulist may need to allocate new nodes. Currently, this can happen while holding theextent_io_tree->lockspinlock. Althoughulist_prealloc()usesGFP_NOFSto avoid deadlock with filesystem reclaim, it's better to preallocate before acquiring the spinlock to:
Quoted 7 lines
1. Avoid potential allocation failures while holding the lock
2. Be consistent withset_extent_bit()which already preallocates both extent state and changeset before the spinlock
3. Reduce lock contention by not doing allocations under the lockPreallocate the changeset ulist node before acquiring the spinlock, mirroring the pattern used for extent state preallocation.
Missing the SoB line.
Otherwise looks good to me.
Thanks,
Qu
Quoted 18 lines
--- fs/btrfs/extent-io-tree.c | 3 +++ 1 file changed, 3 insertions(+)fs/btrfs/extent-io-tree.c +3
-0@@ -663,6 +663,9 @@ int btrfs_clear_extent_bit_changeset(struct extent_io_tree *tree, u64 start, u64*/ prealloc =alloc_extent_state (mask); } +/* Preallocate the extent changeset ulist node before acquiring spinlock. */ +if (changeset) +extent_changeset_prealloc (changeset, mask);spin_lock (&tree->lock);if (cached_state) {