public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Gerhard Wiesinger <lists@wiesinger.com>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>, linux-btrfs@vger.kernel.org
Subject: Re: BTRFS doesn't compress on the fly
Date: Sun, 3 Dec 2023 09:24:10 +0100	[thread overview]
Message-ID: <a9fafe9c-27c8-4465-aafa-a4af6987c031@wiesinger.com> (raw)
In-Reply-To: <6ae85272-3967-417e-bc9a-e2141a4c688a@gmx.com>

On 02.12.2023 22:56, Qu Wenruo wrote:
>>
>>>
>>> How can I find something about preallocation out?
>>
>> Above compsize is already showing there is some preallocated space.
>>
>> Thus I'm wondering if the preallocation is the cause.
>>
>> As should_nocow() would also check the PREALLOC inode flag, and tries
>> NOCOW path first (then falls to COW if needed)
>
> Yep, I just reproduced it, for any INODE with PREALLOC flag (aka, the
> file has some preallocated range), even we're writing into the range
> that needs COW anyway (e.g. new writes which would enlarge the file),
> the compression would not work anyway.
>
>  # mkfs.btrfs test.img
>  # mount test.img -o compress-force=zstd /mnt/btrfs
>  # fallocate -l 128k /mnt/btrfs/file1
>  # xfs_io -f -c "pwrite 128k 128k" /mnt/btrfs/file1
>  # xfs_io -f -c "pwrite 128k 128k" /mnt/btrfs/file2
>  # sync
>
> Since file1 has 128K preallocated range, thus the inode has PREALLOC
> flag, and would lead to no compression:
>
>     item 6 key (257 INODE_ITEM 0) itemoff 15811 itemsize 160
>         generation 8 transid 8 size 262144 nbytes 262144
>         block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0
>         sequence 33 flags 0x10(PREALLOC) <<<<
>     item 7 key (257 INODE_REF 256) itemoff 15796 itemsize 15
>         index 2 namelen 5 name: file1
>     item 8 key (257 EXTENT_DATA 0) itemoff 15743 itemsize 53
>         generation 8 type 2 (prealloc)
>         prealloc data disk byte 13631488 nr 131072
>         prealloc data offset 0 nr 131072
>     item 9 key (257 EXTENT_DATA 131072) itemoff 15690 itemsize 53
>         generation 8 type 1 (regular)
>         extent data disk byte 13762560 nr 131072
>         extent data offset 0 nr 131072 ram 131072
>         extent compression 0 (none) <<<
>
> Meanwhile for the other file, which has no prealloc, would go regular
> compression path.
>
>     item 10 key (258 INODE_ITEM 0) itemoff 15530 itemsize 160
>         generation 8 transid 8 size 262144 nbytes 131072
>         block group 0 mode 100600 links 1 uid 0 gid 0 rdev 0
>         sequence 32 flags 0x0(none)
>     item 11 key (258 INODE_REF 256) itemoff 15515 itemsize 15
>         index 3 namelen 5 name: file2
>     item 12 key (258 EXTENT_DATA 131072) itemoff 15462 itemsize 53
>         generation 8 type 1 (regular)
>         extent data disk byte 13893632 nr 4096
>         extent data offset 0 nr 131072 ram 131072
>         extent compression 3 (zstd)
>
> To me, this looks a bug, and the reason is exactly what I explained 
> before.
>
> The worst thing is, as long as the inode has PREALLOC flag, even if all
> preallocated extents are used, it would prevent compression from
> happening, forever for that inode.
>
> Let me try to fix the fallback to COW path to include compression.


Thank you for reproducting it. Think we nailed it down.

Is there a way to get the output of the file of the chunks/items?

Thnx.

Ciao,

Gerhard


  reply	other threads:[~2023-12-03  8:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-30 11:21 BTRFS doesn't compress on the fly Gerhard Wiesinger
2023-11-30 20:53 ` Qu Wenruo
2023-12-02 12:02   ` Gerhard Wiesinger
2023-12-02 20:07     ` Qu Wenruo
2023-12-02 21:56       ` Qu Wenruo
2023-12-03  8:24         ` Gerhard Wiesinger [this message]
2023-12-03  9:11           ` Qu Wenruo
2023-12-03  9:45             ` Gerhard Wiesinger
2023-12-03 10:19               ` Qu Wenruo
2023-12-22  5:58                 ` Gerhard Wiesinger
2023-12-22  6:13                   ` Qu Wenruo
2024-08-11  9:39                     ` Gerhard Wiesinger

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=a9fafe9c-27c8-4465-aafa-a4af6987c031@wiesinger.com \
    --to=lists@wiesinger.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