Skip to content

Commit

Permalink
Btrfs: if we have a lot of pinned space, commit the transaction
Browse files Browse the repository at this point in the history
Mitch kept hitting a panic because he was getting ENOSPC.  One of my previous
patches makes it so we are much better at not allocating new metadata chunks.
Unfortunately coupled with the overcommit patch this works us into a bit of a
problem if we are removing a bunch of space and end up chewing up all of our
space with pinned extents.  We can allocate chunks fine and overflow is ok, but
the only way to reclaim this space is to commit the transaction.  So if we go to
overcommit, first check and see how much pinned space we have.  If we have more
than 80% of the free space chewed up with pinned extents, just commit the
transaction, this will free up enough space for our reservation and we won't
have this problem anymore.  With this patch Mitch's test doesn't blow up
anymore.  Thanks,

Reported-and-tested-by: Mitch Harder <mitch.harder@sabayonlinux.org>
Signed-off-by: Josef Bacik <josef@redhat.com>
  • Loading branch information
Josef Bacik committed Oct 19, 2011
1 parent 36ba022 commit 7e355b8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -3510,6 +3510,20 @@ static int reserve_metadata_bytes(struct btrfs_root *root,
u64 profile = btrfs_get_alloc_profile(root, 0);
u64 avail;

/*
* If we have a lot of space that's pinned, don't bother doing
* the overcommit dance yet and just commit the transaction.
*/
avail = (space_info->total_bytes - space_info->bytes_used) * 8;
do_div(avail, 10);
if (space_info->bytes_pinned >= avail && flush && !trans &&
!committed) {
space_info->flush = 1;
flushing = true;
spin_unlock(&space_info->lock);
goto commit;
}

spin_lock(&root->fs_info->free_chunk_lock);
avail = root->fs_info->free_chunk_space;

Expand Down Expand Up @@ -3581,6 +3595,7 @@ static int reserve_metadata_bytes(struct btrfs_root *root,
if (trans)
goto out;

commit:
ret = -ENOSPC;
if (committed)
goto out;
Expand Down

0 comments on commit 7e355b8

Please sign in to comment.