From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Hanabishi <i.r.e.c.c.a.k.u.n+kernel.org@gmail.com>,
linux-btrfs@vger.kernel.org
Subject: Re: 'btrfs filesystem defragment' makes files explode in size, especially fallocated ones
Date: Tue, 6 Aug 2024 20:12:06 +0930 [thread overview]
Message-ID: <e72e1aed-4493-4d03-81cd-a88abcda5051@gmx.com> (raw)
In-Reply-To: <62433c69-5d07-4781-bf2f-6558d7e79134@gmail.com>
在 2024/8/6 19:53, Hanabishi 写道:
> On 8/6/24 09:55, Qu Wenruo wrote:
>
>> So either there is something like cgroup involved (which can limits the
>> dirty page cache and trigger write backs), or some other weird
>> behavior/bugs.
>
> Yes, this line reveals something. I do have modified dirty page cache
> values. I tend to keep it on low values.
>
> Now playing around with it - yes, it is seems to be the cause. When I
> tune 'vm.dirty_ratio' and 'vm.dirty_background_ratio' up to higher
> values, the problem becames less prevalent.
>
> Which means lowering them cranks up the problem to extremes. E.g. try
>
> # sysctl -w vm.dirty_bytes=8192
> # sysctl -w vm.dirty_background_ratio=0
>
> With that setup defrag completely obliterates files even with default
> threshold value.
At least I no longer need to live under the fear of new defrag bugs.
This also explains why defrag (even with default values) would trigger
rewrites of extents, because although fiemap is only showing a single
extent, it will be a lot of small extents on the larger pre-allocated range.
Thus btrfs believe it can merge all of them into a larger extent, but VM
settings forces btrfs to write them early, causing extra data COW, and
cause worse fragmentation.
Too low values means kernel will trigger dirty writeback aggressively, I
believe for all extent based file systems (ext4/xfs/btrfs etc), it would
cause a huge waste of metadata, due to the huge amount of small extents.
So yes, that setting is the cause, although it will reduce the memory
used by page cache (it still counts as memory pressure), but the cost is
more fragmented extents and overall worse fs performance and possibly
more wear on NAND based storage.
Thanks,
Qu
next prev parent reply other threads:[~2024-08-06 10:42 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-04 9:20 'btrfs filesystem defragment' makes files explode in size, especially fallocated ones i.r.e.c.c.a.k.u.n+kernel.org
2024-08-04 22:19 ` Qu Wenruo
2024-08-05 18:16 ` Hanabishi
2024-08-05 22:47 ` Qu Wenruo
2024-08-06 7:19 ` Hanabishi
2024-08-06 9:55 ` Qu Wenruo
2024-08-06 10:23 ` Hanabishi
2024-08-06 10:42 ` Qu Wenruo [this message]
2024-08-06 11:05 ` Hanabishi
2024-08-06 11:23 ` Qu Wenruo
2024-08-06 12:08 ` Hanabishi
2024-08-06 22:10 ` Qu Wenruo
2024-08-06 22:42 ` Hanabishi
2024-08-06 22:51 ` Qu Wenruo
2024-08-06 23:04 ` Hanabishi
2024-08-06 12:17 ` Hanabishi
2024-08-06 13:22 ` Hanabishi
2024-08-06 22:18 ` Qu Wenruo
2024-08-06 22:55 ` Hanabishi
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=e72e1aed-4493-4d03-81cd-a88abcda5051@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=i.r.e.c.c.a.k.u.n+kernel.org@gmail.com \
--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