From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Gerhard Wiesinger <lists@wiesinger.com>, linux-btrfs@vger.kernel.org
Subject: Re: BTRFS doesn't compress on the fly
Date: Sun, 3 Dec 2023 20:49:51 +1030 [thread overview]
Message-ID: <9f4ad251-7af7-4f02-b388-64dd6c8257ac@gmx.com> (raw)
In-Reply-To: <771df9a9-c7c3-40a7-a426-0126118d3af0@wiesinger.com>
On 2023/12/3 20:15, Gerhard Wiesinger wrote:
> On 03.12.2023 10:11, Qu Wenruo wrote:
>>
>>>
>>> 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?
>>
>> You can always dump the full subvolume (`btrfs ins dump-tree -t
>> <subvolid> <device>`), then try to grep the inode which has PREALLOC
>> alloc (`| grep -C 5 "flags.*PREALLOC"), which would include the inode
>> number, then you can ping down the inodes which has PREALLOC flags and
>> not undergoing compression.
>>
>> I won't be surprised most (if not all) files of postgresql would have
>> that flag.
>
> Looks like only a small part has PREALLOC:
>
> find /var/lib/pgsql -type f | wc -l
> 5569
>
> btrfs inspect-internal dump-tree /dev/mapper/datab | grep -i PREALLOC |
> wc -l
> 95
>
> For reference:
>
> How to find the file at a certain btrfs inode
> https://serverfault.com/questions/746938/how-to-find-the-file-at-a-certain-btrfs-inode
>
> btrfs inspect-internal inode-resolve 13269 /var/lib/pgsql
> /var/lib/pgsql/16/data/base/16400/16419
>
> find /var/lib/pgsql -xdev -inum 13269
> /var/lib/pgsql/16/data/base/16400/16419
>
> # Get files from inodes
>
> btrfs inspect-internal dump-tree /dev/mapper/datab | grep -C 5
> "flags.*PREALLOC" | grep -i INODE | perl -pe 's/.*?\((.*?) .*/$1/' |
> sort | uniq | while read INODE; do echo -n "$INODE: ";btrfs
> inspect-internal inode-resolve ${INODE} /var/lib/pgsql; done
>
> # Number of inodes, count is consistent
>
> btrfs inspect-internal dump-tree /dev/mapper/datab | grep -C 5
> "flags.*PREALLOC" | grep -i INODE | perl -pe 's/.*?\((.*?) .*/$1/' |
> sort | uniq | while read INODE; do echo -n "$INODE: ";btrfs
> inspect-internal inode-resolve ${INODE} /var/lib/pgsql; done | wc -l
>
> 95
>
> All files are in subdirectories: /var/lib/pgsql/16/data/base/
>
> Already an idea for the fix?
We can copy the files (without using reflink) to a temporary location
(better out of btrfs), then copy the temporary copy back to overwrite
all the existing files.
The problem is still inside pgsql, as long as they do preallocation, the
same problem would still happen.
>
> BTW:
>
> if compression is forced, should be then just any "block" be compressed?
There is a long existing problem with compression with preallocation.
One easy example is, if we go compression for the preallocated range,
what we do with the gap (compressed size is always smaller than the real
size).
If we leave the gap, then the read performance can be even worse, as now
we have to read several small extents with gaps between them, vs a large
contig read.
IIRC years ago when I was a btrfs newbie, that's the direction I tried
to go, but never reached upstream.
Thus you can see some of the reason why we do not go compression for
preallocated range.
But I still don't believe we should go as the current behavior.
We should still try to go compression as long as we know the write still
needs COW, thus we should fix it.
Thanks,
Qu
>
> Or, what's the problem of the logic?
>
> Thnx.
>
> Ciao,
>
> Gerhard
>
next prev parent reply other threads:[~2023-12-03 10:20 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
2023-12-03 9:11 ` Qu Wenruo
2023-12-03 9:45 ` Gerhard Wiesinger
2023-12-03 10:19 ` Qu Wenruo [this message]
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=9f4ad251-7af7-4f02-b388-64dd6c8257ac@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=lists@wiesinger.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