* [PATCH] btrfs: extent-tree: Refactor add_pinned_bytes() to add|sub_pinned_bytes()
@ 2019-05-14 23:33 Qu Wenruo
2019-05-15 11:37 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Qu Wenruo @ 2019-05-14 23:33 UTC (permalink / raw)
To: linux-btrfs
Instead of using @sign to determine whether we're adding or subtracting.
Even it only has 3 callers, it's still (and in fact already caused
problem in the past) confusing to use.
Refactor add_pinned_bytes() to add_pinned_bytes() and sub_pinned_bytes()
to explicitly show what we're doing.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
To David,
Would you please fold this patch to "btrfs: extent-tree: Fix a bug that
btrfs is unable to add pinned bytes" in misc-next branch?
Thanks,
Qu
---
fs/btrfs/extent-tree.c | 43 ++++++++++++++++++++++++++----------------
1 file changed, 27 insertions(+), 16 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 1aee51a9f3bf..aa8c5e3247fc 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -756,27 +756,38 @@ static struct btrfs_space_info *__find_space_info(struct btrfs_fs_info *info,
return NULL;
}
-static void add_pinned_bytes(struct btrfs_fs_info *fs_info,
- struct btrfs_ref *ref, int sign)
+static u64 generic_ref_to_space_flags(struct btrfs_ref *ref)
{
- struct btrfs_space_info *space_info;
- s64 num_bytes;
- u64 flags;
-
- ASSERT(sign == 1 || sign == -1);
- num_bytes = sign * ref->len;
if (ref->type == BTRFS_REF_METADATA) {
if (ref->tree_ref.root == BTRFS_CHUNK_TREE_OBJECTID)
- flags = BTRFS_BLOCK_GROUP_SYSTEM;
+ return BTRFS_BLOCK_GROUP_SYSTEM;
else
- flags = BTRFS_BLOCK_GROUP_METADATA;
- } else {
- flags = BTRFS_BLOCK_GROUP_DATA;
+ return BTRFS_BLOCK_GROUP_METADATA;
}
+ return BTRFS_BLOCK_GROUP_DATA;
+}
+
+static void add_pinned_bytes(struct btrfs_fs_info *fs_info,
+ struct btrfs_ref *ref)
+{
+ struct btrfs_space_info *space_info;
+ u64 flags = generic_ref_to_space_flags(ref);
+
+ space_info = __find_space_info(fs_info, flags);
+ ASSERT(space_info);
+ percpu_counter_add_batch(&space_info->total_bytes_pinned, ref->len,
+ BTRFS_TOTAL_BYTES_PINNED_BATCH);
+}
+
+static void sub_pinned_bytes(struct btrfs_fs_info *fs_info,
+ struct btrfs_ref *ref)
+{
+ struct btrfs_space_info *space_info;
+ u64 flags = generic_ref_to_space_flags(ref);
space_info = __find_space_info(fs_info, flags);
ASSERT(space_info);
- percpu_counter_add_batch(&space_info->total_bytes_pinned, num_bytes,
+ percpu_counter_add_batch(&space_info->total_bytes_pinned, -ref->len,
BTRFS_TOTAL_BYTES_PINNED_BATCH);
}
@@ -2065,7 +2076,7 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
btrfs_ref_tree_mod(fs_info, generic_ref);
if (ret == 0 && old_ref_mod < 0 && new_ref_mod >= 0)
- add_pinned_bytes(fs_info, generic_ref, -1);
+ sub_pinned_bytes(fs_info, generic_ref);
return ret;
}
@@ -7191,7 +7202,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
}
out:
if (pin)
- add_pinned_bytes(fs_info, &generic_ref, 1);
+ add_pinned_bytes(fs_info, &generic_ref);
if (last_ref) {
/*
@@ -7239,7 +7250,7 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref)
btrfs_ref_tree_mod(fs_info, ref);
if (ret == 0 && old_ref_mod >= 0 && new_ref_mod < 0)
- add_pinned_bytes(fs_info, ref, 1);
+ add_pinned_bytes(fs_info, ref);
return ret;
}
--
2.21.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs: extent-tree: Refactor add_pinned_bytes() to add|sub_pinned_bytes()
2019-05-14 23:33 [PATCH] btrfs: extent-tree: Refactor add_pinned_bytes() to add|sub_pinned_bytes() Qu Wenruo
@ 2019-05-15 11:37 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2019-05-15 11:37 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Wed, May 15, 2019 at 07:33:48AM +0800, Qu Wenruo wrote:
> Instead of using @sign to determine whether we're adding or subtracting.
> Even it only has 3 callers, it's still (and in fact already caused
> problem in the past) confusing to use.
>
> Refactor add_pinned_bytes() to add_pinned_bytes() and sub_pinned_bytes()
> to explicitly show what we're doing.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> To David,
>
> Would you please fold this patch to "btrfs: extent-tree: Fix a bug that
> btrfs is unable to add pinned bytes" in misc-next branch?
Folding a refactoring patch to a fix is not a good practice, I had a
second thought on that and let's have both patches. The fix will go to
5.2-rc and this cleanup will show up in the devel queue once the fix is
merged.
And the cleanup looks good to me, thanks.
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-05-15 11:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-14 23:33 [PATCH] btrfs: extent-tree: Refactor add_pinned_bytes() to add|sub_pinned_bytes() Qu Wenruo
2019-05-15 11:37 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).