public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Hanabishi <i.r.e.c.c.a.k.u.n+kernel.org@gmail.com>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>, linux-btrfs@vger.kernel.org
Subject: Re: 'btrfs filesystem defragment' makes files explode in size, especially fallocated ones
Date: Tue, 6 Aug 2024 12:08:21 +0000	[thread overview]
Message-ID: <30687f37-32e9-4482-a453-7451ab05277a@gmail.com> (raw)
In-Reply-To: <d089a164-b2e8-4d29-8d96-41b12cbfae42@gmx.com>

On 8/6/24 11:23, Qu Wenruo wrote:

> When defrag happens, it triggers data COW, and screw up everything.

Yeah, making test files in NOCOW mode seems to prevent the issue.

> I'm not sure how high the value you set, but at least please do
> everything with default kernel config, not just crank the settings up.

Up to 50% of 32G RAM machine. More than enough for a 224M file.

Kernel defaults are meaningless anyway, as they are relative to RAM size. Even Linus admitted that: https://lwn.net/Articles/572921/

> And have you tried sync before compsize/fiemap?

Of course. I do sync on every step.

> If we try to lock the defrag range, to ensure them to land in a larger
> extent, I'm 100% sure MM guys won't be happy, it's blocking the most
> common way to reclaim memory.

Hmm, but couldn't Btrfs simply preallocate that space? I copied files much larger in size than the page cache and even entire RAM, they are totally fine as you could guess.
Is moving extents under the hood that different from copying files around?

> IIRC it's already in the document, although not that clear:
> 
>    The value is only advisory and the final size of the extents may
>    differ, depending on the state of the free space and fragmentation or
>    other internal logic.
> 
> To be honest, defrag is not recommended for modern extent based file
> systems already, thus there is no longer a common and good example to
> follow.
> 
> And for COW file systems, along with btrfs' specific bookend behavior,
> it brings a new level of complexity.
> 
> So overall, if you're not sure what the defrag internal logic is, nor
> have a clear problem you want to solve, do not defrag.

Well, I went into this hole for a reason.
I worked with some software piece which writes files sequentally, but in a very primitive POSIX-compliant way. For reference, ~17G file it produced was split into more than 1 million(!) extents. Basically shredding entire file into 16K pieces. Producing a no-joke access performance penalty even on SSD. In fact I only noticed the problem because of horrible disk performance with the file.

And I even tried to write it in NOCOW mode, but it didn't help, fragmentation level was the same. So it has nothing to do with CoW, it's Btrfs itself not really getting intentions of the software.
I'm not sure how it would behave with other filesystems, but for me it doesn't really look as a FS fault anyway.

So I ended up falling back to the old good defragmentation. Discovering the reported issue along the way, becaming a double-trouble for me.


  reply	other threads:[~2024-08-06 12:08 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
2024-08-06 11:05               ` Hanabishi
2024-08-06 11:23                 ` Qu Wenruo
2024-08-06 12:08                   ` Hanabishi [this message]
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=30687f37-32e9-4482-a453-7451ab05277a@gmail.com \
    --to=i.r.e.c.c.a.k.u.n+kernel.org@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.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