Commit c7bc6319c59cc791743cf1b6e98f86be69444495

Authored by Filipe Manana
Committed by Chris Mason
1 parent 7e33fd993a

Btrfs: avoid premature -ENOMEM in clear_extent_bit()

We try to allocate an extent state structure before acquiring the extent
state tree's spinlock as we might need a new one later and therefore avoid
doing later an atomic allocation while holding the tree's spinlock. However
we returned -ENOMEM if that initial non-atomic allocation failed, which is
a bit excessive since we might end up not needing the pre-allocated extent
state at all - for the case where the tree doesn't have any extent states
that cover the input range and cover too any other range. Therefore don't
return -ENOMEM if that pre-allocation fails.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>

Showing 1 changed file with 7 additions and 2 deletions Side-by-side Diff

fs/btrfs/extent_io.c
... ... @@ -595,9 +595,14 @@
595 595 clear = 1;
596 596 again:
597 597 if (!prealloc && (mask & __GFP_WAIT)) {
  598 + /*
  599 + * Don't care for allocation failure here because we might end
  600 + * up not needing the pre-allocated extent state at all, which
  601 + * is the case if we only have in the tree extent states that
  602 + * cover our input range and don't cover too any other range.
  603 + * If we end up needing a new extent state we allocate it later.
  604 + */
598 605 prealloc = alloc_extent_state(mask);
599   - if (!prealloc)
600   - return -ENOMEM;
601 606 }
602 607  
603 608 spin_lock(&tree->lock);