Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Anand Suveer Jain <asj@kernel.org>
To: fdmanana@kernel.org, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/6] btrfs: defrag: use a single list for each loop in defrag_one_range()
Date: Fri, 26 Jun 2026 07:02:17 +0800	[thread overview]
Message-ID: <3a52eadb-002d-4982-8580-8b83a45c69fb@kernel.org> (raw)
In-Reply-To: <20e1226097db10e92c2059cb5ce51205348362a7.1782321584.git.fdmanana@suse.com>

On 26/6/26 03:20, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> There's no need to have one list for each loop to defrag each subrange and
> then another one to free each subrange (struct defrag_target_range).
> We can do it in a single loop, freeing each subrange after defragging,
> plus no need to delete each subrange from the list since we immediately
> free it.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> ---
>  fs/btrfs/defrag.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c
> index 0697b285e05f..ad1d04d8f165 100644
> --- a/fs/btrfs/defrag.c
> +++ b/fs/btrfs/defrag.c
> @@ -1234,16 +1234,12 @@ static int defrag_one_range(struct btrfs_inode *inode, u64 start, u32 len,
>  	if (ret < 0)
>  		goto unlock_extent;
>  
> -	list_for_each_entry(entry, &target_list, list) {
> +	list_for_each_entry_safe(entry, tmp, &target_list, list) {
>  		defrag_one_locked_target(inode, entry, folios, nr_pages, &cached_state);
>  		if (entry->start > last_defrag_end)
>  			btrfs_delalloc_release_space(inode, data_reserved, last_defrag_end,
>  						     entry->start - last_defrag_end, true);
>  		last_defrag_end = entry->start + entry->len;
> -	}
> -
> -	list_for_each_entry_safe(entry, tmp, &target_list, list) {
> -		list_del_init(&entry->list);
>  		kfree(entry);
>  	}
>  unlock_extent:


LGTM.

Reviewed-by: Anand Jain <asj@kernel.org>



  reply	other threads:[~2026-06-25 23:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25 19:20 [PATCH 0/6] btrfs: defrag/autodefrag fixes and cleanups fdmanana
2026-06-25 19:20 ` [PATCH 1/6] btrfs: defrag: fix deadlock between defrag and delalloc space reservation fdmanana
2026-06-25 19:20 ` [PATCH 2/6] btrfs: fix pending delayed iputs when using autodefrag fdmanana
2026-06-25 19:20 ` [PATCH 3/6] btrfs: defrag: use a single list for each loop in defrag_one_range() fdmanana
2026-06-25 23:02   ` Anand Suveer Jain [this message]
2026-06-25 19:20 ` [PATCH 4/6] btrfs: defrag: use auto kfree in defrag_one_range() for folios array fdmanana
2026-06-25 19:20 ` [PATCH 5/6] btrfs: defrag: use simple list_del() in defrag_collect_targets() fdmanana
2026-06-25 23:10   ` Anand Suveer Jain
2026-06-25 19:20 ` [PATCH 6/6] btrfs: defrag: remove pointless list_del_init() in defrag_one_cluster() fdmanana
2026-06-25 23:03   ` Anand Suveer Jain
2026-06-25 23:00 ` [PATCH 0/6] btrfs: defrag/autodefrag fixes and cleanups Qu Wenruo

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=3a52eadb-002d-4982-8580-8b83a45c69fb@kernel.org \
    --to=asj@kernel.org \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@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