From: David Sterba <dsterba@suse.cz>
To: Yangtao Li <frank.li@vivo.com>
Cc: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] btrfs: use BTRFS_PATH_AUTO_FREE in insert_balance_item()
Date: Wed, 9 Apr 2025 00:47:49 +0200 [thread overview]
Message-ID: <20250408224749.GD13292@twin.jikos.cz> (raw)
In-Reply-To: <20250408122933.121056-1-frank.li@vivo.com>
On Tue, Apr 08, 2025 at 06:29:30AM -0600, Yangtao Li wrote:
> All cleanup paths lead to btrfs_path_free so we can define path with the
> automatic free callback.
>
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> fs/btrfs/volumes.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index c8c21c55be53..a962efaec4ea 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -3730,7 +3730,7 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
> struct btrfs_trans_handle *trans;
> struct btrfs_balance_item *item;
> struct btrfs_disk_balance_args disk_bargs;
> - struct btrfs_path *path;
> + BTRFS_PATH_AUTO_FREE(path);
> struct extent_buffer *leaf;
> struct btrfs_key key;
> int ret, err;
> @@ -3740,10 +3740,8 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
> return -ENOMEM;
>
> trans = btrfs_start_transaction(root, 0);
> - if (IS_ERR(trans)) {
> - btrfs_free_path(path);
> + if (IS_ERR(trans))
> return PTR_ERR(trans);
> - }
>
> key.objectid = BTRFS_BALANCE_OBJECTID;
> key.type = BTRFS_TEMPORARY_ITEM_KEY;
> @@ -3767,7 +3765,6 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
> btrfs_set_balance_sys(leaf, item, &disk_bargs);
> btrfs_set_balance_flags(leaf, item, bctl->flags);
> out:
> - btrfs_free_path(path);
The pattern where btrfs_free_path() is not called at the end and is
followed by other code is probably not worth converting. It would be
possible to replace it by
btrfs_release_path(path);
path = NULL;
that drops the locks and refs from the path but this does not save us
much compared to the straightforward BTRFS_PATH_AUTO_FREE() conversions.
Also release will still keep the object allocated although we don't need
it. As a principle, resources, locks and critical sections should be as
short as possible.
Unfortunatelly I've probably fished all the trivial and almost-trivial
conversions, we don't want 100% use of BTRFS_PATH_AUTO_FREE(), only when
it improves the code.
You may still find cases worth converting, the typical pattern is
btrfs_path_alloc() somewhere near top of the function and
btrfs_free_path() called right before a return.
next prev parent reply other threads:[~2025-04-08 22:48 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-08 12:29 Yangtao Li
2025-04-08 12:29 ` [PATCH 2/4] btrfs: use BTRFS_PATH_AUTO_FREE in del_balance_item() Yangtao Li
2025-04-08 14:47 ` Filipe Manana
2025-04-08 12:29 ` [PATCH 3/4] btrfs: Fix transaction abort during failure in insert_balance_item() Yangtao Li
2025-04-08 14:50 ` Filipe Manana
2025-04-08 12:29 ` [PATCH 4/4] btrfs: Fix transaction abort during failure in del_balance_item() Yangtao Li
2025-04-08 14:53 ` Filipe Manana
2025-04-08 23:04 ` David Sterba
2025-04-09 9:50 ` Filipe Manana
2025-04-08 14:44 ` [PATCH 1/4] btrfs: use BTRFS_PATH_AUTO_FREE in insert_balance_item() Filipe Manana
2025-04-08 17:36 ` Daniel Vacek
2025-04-08 17:40 ` Filipe Manana
2025-04-08 17:47 ` Daniel Vacek
2025-04-08 17:52 ` Filipe Manana
2025-04-08 18:00 ` Daniel Vacek
2025-04-09 12:19 ` 回复: " 李扬韬
2025-04-08 22:47 ` David Sterba [this message]
2025-04-09 9:45 ` Filipe Manana
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250408224749.GD13292@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=frank.li@vivo.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®