public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Filipe Manana <fdmanana@kernel.org>, Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org,
	Christoph Anton Mitterer <calestyo@scientia.org>
Subject: Re: [PATCH 1/2] btrfs: defrag: add under utilized extent to defrag target list
Date: Wed, 7 Feb 2024 08:56:24 +1030	[thread overview]
Message-ID: <ffd42e62-b506-40ac-aeb4-c84edf0e5365@gmx.com> (raw)
In-Reply-To: <54a1bb50-7fd2-440f-8563-a82c54bb2179@gmx.com>



On 2024/2/7 07:11, Qu Wenruo wrote:
[...]
>>
>> item 6 key (257 EXTENT_DATA 0) itemoff 15810 itemsize 53
>> generation 7 type 1 (regular)
>> extent data disk byte 1104150528 nr 134217728
>> extent data offset 0 nr 8650752 ram 134217728
>> extent compression 0 (none)
>> item 7 key (257 EXTENT_DATA 8650752) itemoff 15757 itemsize 53
>> generation 8 type 1 (regular)
>> extent data disk byte 1238368256 nr 33292288
>> extent data offset 0 nr 33292288 ram 33292288
>> extent compression 0 (none)
>
> This behavior is unexpected, as we should redirty the whole 40M, but the
> first 8.25M didn't got re-dirtied is a big problem to me.
> Will look into the situation.
>

Got the cause.

The problem is related to a check in the existing code:

	range_len = em->len - (cur - em->start);

	/* Skip too large extent */
	if (range_len >= extent_thresh)
		goto next;

Since the range_len is to the end of the extent, thus at the beginning
8MiB it's always larger than the 32M extent threshold.

But at around 8M, we no longer meet the 32M extent threshold thus begin
to defrag the remaining 32M.

To me, the check itself is not correct, it should go em->len instead.

But on the other hand, that "goto next" would skip our wasted
ratio/bytes checks.

At least with that fixed, we won't make the situation worse though.

I'll submit a fix for it with a test case.

Thanks for exposing the bug,
Qu

  reply	other threads:[~2024-02-06 22:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-05 23:45 [PATCH 0/2] btrfs: defrag: better lone extent handling Qu Wenruo
2024-02-05 23:45 ` [PATCH 1/2] btrfs: defrag: add under utilized extent to defrag target list Qu Wenruo
2024-02-06 16:23   ` Filipe Manana
2024-02-06 20:41     ` Qu Wenruo
2024-02-06 22:26       ` Qu Wenruo [this message]
2024-02-07 12:19       ` Filipe Manana
2024-02-05 23:45 ` [PATCH 2/2] btrfs: defrag: allow fine-tuning on lone extent defrag behavior Qu Wenruo
2024-02-06 17:03   ` Filipe Manana
2024-02-06 20:50     ` Qu Wenruo
2024-02-07 12:27       ` Filipe Manana
2024-02-07 17:40         ` Christoph Anton Mitterer
2024-02-06 20:27 ` [PATCH 0/2] btrfs: defrag: better lone extent handling Christoph Anton Mitterer

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=ffd42e62-b506-40ac-aeb4-c84edf0e5365@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=calestyo@scientia.org \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.com \
    /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