diff mbox series

[1/8] btrfs: do not shorten unpin len for caching block groups

Message ID 1e88615a596a6d811954832a744d105f94e42645.1603460665.git.josef@toxicpanda.com
State New, archived
Headers show
Series Block group caching fixes | expand

Commit Message

Josef Bacik Oct. 23, 2020, 1:58 p.m. UTC
While fixing up our ->last_byte_to_unpin locking I noticed that we will
shorten len based on ->last_byte_to_unpin if we're caching when we're
adding back the free space.  This is correct for the free space, as we
cannot unpin more than ->last_byte_to_unpin, however we use len to
adjust the ->bytes_pinned counters and such, which need to track the
actual pinned usage.  This could result in
WARN_ON(space_info->bytes_pinned) triggering at unmount time.  Fix this
by using a local variable for the amount to add to free space cache, and
leave len untouched in this case.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/extent-tree.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Filipe Manana Nov. 4, 2020, 1:38 p.m. UTC | #1
On Fri, Oct 23, 2020 at 7:16 PM Josef Bacik <josef@toxicpanda.com> wrote:
>
> While fixing up our ->last_byte_to_unpin locking I noticed that we will
> shorten len based on ->last_byte_to_unpin if we're caching when we're
> adding back the free space.  This is correct for the free space, as we
> cannot unpin more than ->last_byte_to_unpin, however we use len to
> adjust the ->bytes_pinned counters and such, which need to track the
> actual pinned usage.  This could result in
> WARN_ON(space_info->bytes_pinned) triggering at unmount time.  Fix this
> by using a local variable for the amount to add to free space cache, and
> leave len untouched in this case.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Filipe Manana <fdmanana@suse.com>

Looks good, thanks.

> ---
>  fs/btrfs/extent-tree.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 5fd60b13f4f8..a98f484a2fc1 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -2816,10 +2816,10 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info,
>                 len = cache->start + cache->length - start;
>                 len = min(len, end + 1 - start);
>
> -               if (start < cache->last_byte_to_unpin) {
> -                       len = min(len, cache->last_byte_to_unpin - start);
> -                       if (return_free_space)
> -                               btrfs_add_free_space(cache, start, len);
> +               if (start < cache->last_byte_to_unpin && return_free_space) {
> +                       u64 add_len = min(len,
> +                                         cache->last_byte_to_unpin - start);
> +                       btrfs_add_free_space(cache, start, add_len);
>                 }
>
>                 start += len;
> --
> 2.26.2
>
diff mbox series

Patch

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 5fd60b13f4f8..a98f484a2fc1 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2816,10 +2816,10 @@  static int unpin_extent_range(struct btrfs_fs_info *fs_info,
 		len = cache->start + cache->length - start;
 		len = min(len, end + 1 - start);
 
-		if (start < cache->last_byte_to_unpin) {
-			len = min(len, cache->last_byte_to_unpin - start);
-			if (return_free_space)
-				btrfs_add_free_space(cache, start, len);
+		if (start < cache->last_byte_to_unpin && return_free_space) {
+			u64 add_len = min(len,
+					  cache->last_byte_to_unpin - start);
+			btrfs_add_free_space(cache, start, add_len);
 		}
 
 		start += len;