* [PATCH 1/2] btrfs: only enforce free space tree if v1 cache is required for bs < ps cases
2025-12-18 4:45 [PATCH 0/2] btrfs: minor bs != ps cases fixes for free space tree enforcing Qu Wenruo
@ 2025-12-18 4:45 ` Qu Wenruo
2025-12-18 4:45 ` [PATCH 2/2] btrfs: forcing free space tree for bs > " Qu Wenruo
2025-12-18 9:36 ` [PATCH 0/2] btrfs: minor bs != ps cases fixes for free space tree enforcing Filipe Manana
2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2025-12-18 4:45 UTC (permalink / raw)
To: linux-btrfs
[BUG]
Since the introduction of btrfs bs < ps support, v1 cache is never on
the plan due to its hard coded PAGE_SIZE usage, and the future plan to
properly deprecate it.
However for bs < ps cases, even if 'nospace_cache,clear_cache' mount
option is specified, it's never respected and free space tree is always
enabled:
mkfs.btrfs -f -O ^bgt,fst $dev
mount $dev $mnt -o clear_cache,nospace_cache
umount $mnt
btrfs ins dump-super $dev
...
compat_ro_flags 0x3
( FREE_SPACE_TREE |
FREE_SPACE_TREE_VALID )
...
This means a different behavior compared to bs >= ps cases.
[CAUSE]
The forcing usage of v2 space cache is done inside
btrfs_set_free_space_cache_settings(), however it never checks if we're
even using space cache but always enabling v2 cache.
[FIX]
Instead unconditionally enable v2 cache, only forcing v2 cache if the
old v1 cache is required.
Now v2 space cache can be properly disabled on bs < ps cases:
mkfs.btrfs -f -O ^bgt,fst $dev
mount $dev $mnt -o clear_cache,nospace_cache
umount $mnt
btrfs ins dump-super $dev
...
compat_ro_flags 0x0
...
Fixes: 9f73f1aef98b ("btrfs: force v2 space cache usage for subpage mount")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/super.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index a37b71091014..09c38becf20b 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -736,14 +736,12 @@ bool btrfs_check_options(const struct btrfs_fs_info *info,
*/
void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info)
{
- if (fs_info->sectorsize < PAGE_SIZE) {
+ if (fs_info->sectorsize < PAGE_SIZE && btrfs_test_opt(fs_info, SPACE_CACHE)) {
+ btrfs_info(fs_info,
+ "forcing free space tree for sector size %u with page size %lu",
+ fs_info->sectorsize, PAGE_SIZE);
btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE);
- if (!btrfs_test_opt(fs_info, FREE_SPACE_TREE)) {
- btrfs_info(fs_info,
- "forcing free space tree for sector size %u with page size %lu",
- fs_info->sectorsize, PAGE_SIZE);
- btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE);
- }
+ btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE);
}
/*
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] btrfs: forcing free space tree for bs > ps cases
2025-12-18 4:45 [PATCH 0/2] btrfs: minor bs != ps cases fixes for free space tree enforcing Qu Wenruo
2025-12-18 4:45 ` [PATCH 1/2] btrfs: only enforce free space tree if v1 cache is required for bs < ps cases Qu Wenruo
@ 2025-12-18 4:45 ` Qu Wenruo
2025-12-18 9:36 ` [PATCH 0/2] btrfs: minor bs != ps cases fixes for free space tree enforcing Filipe Manana
2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2025-12-18 4:45 UTC (permalink / raw)
To: linux-btrfs
[BUG]
Currently we only enforcing free space tree for bs < ps cases, but with
the recently added bs > ps support, we lack the free space tree
enforcing, causing explicit v1 cache mount option to fail on bs > ps
cases:
# mount -o space_cache=v1 /dev/test/scratch1 /mnt/btrfs/
mount: /mnt/btrfs: wrong fs type, bad option, bad superblock on /dev/mapper/test-scratch1, missing codepage or helper program, or other error.
dmesg(1) may have more information after failed mount system call.
# dmesg -t | tail -n7
BTRFS: device fsid ac14a6fa-4ec9-449e-aec9-7d1777bfdc06 devid 1 transid 11 /dev/mapper/test-scratch1 (253:3) scanned by mount (2849)
BTRFS info (device dm-3): first mount of filesystem ac14a6fa-4ec9-449e-aec9-7d1777bfdc06
BTRFS info (device dm-3): using crc32c checksum algorithm
BTRFS warning (device dm-3): support for block size 8192 with page size 4096 is experimental, some features may be missing
BTRFS warning (device dm-3): space cache v1 is being deprecated and will be removed in a future release, please use -o space_cache=v2
BTRFS warning (device dm-3): v1 space cache is not supported for page size 4096 with sectorsize 8192
BTRFS error (device dm-3): open_ctree failed: -22
[FIX]
Just enable the same free space tree for bs > ps cases, aligning the
behavior to bs < ps cases.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/super.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 09c38becf20b..0a931555e6dc 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -736,7 +736,7 @@ bool btrfs_check_options(const struct btrfs_fs_info *info,
*/
void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info)
{
- if (fs_info->sectorsize < PAGE_SIZE && btrfs_test_opt(fs_info, SPACE_CACHE)) {
+ if (fs_info->sectorsize != PAGE_SIZE && btrfs_test_opt(fs_info, SPACE_CACHE)) {
btrfs_info(fs_info,
"forcing free space tree for sector size %u with page size %lu",
fs_info->sectorsize, PAGE_SIZE);
--
2.52.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 0/2] btrfs: minor bs != ps cases fixes for free space tree enforcing
2025-12-18 4:45 [PATCH 0/2] btrfs: minor bs != ps cases fixes for free space tree enforcing Qu Wenruo
2025-12-18 4:45 ` [PATCH 1/2] btrfs: only enforce free space tree if v1 cache is required for bs < ps cases Qu Wenruo
2025-12-18 4:45 ` [PATCH 2/2] btrfs: forcing free space tree for bs > " Qu Wenruo
@ 2025-12-18 9:36 ` Filipe Manana
2 siblings, 0 replies; 4+ messages in thread
From: Filipe Manana @ 2025-12-18 9:36 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Thu, Dec 18, 2025 at 4:46 AM Qu Wenruo <wqu@suse.com> wrote:
>
> I'm update btrfs/131 to remove the v1 cache usage since v1 cache is
> already marked deprecated.
>
> With that update, I can run the test on bs < ps and bs > ps cases, the
> formal failed due to the following reason:
>
> - Free space cache is always enforced for bs < ps case
> Even if 'nospace_cache' mount option is provided.
> This is fixed by the first patch
>
> And during tests I also exposed a minor problem for bs > ps cases:
>
> - v1 cache mount is rejected for bs > ps cases
> That's because we lack the automatic free space tree enforcing for
> bs > ps cases.
> This is fixed by the second patch.
>
> Qu Wenruo (2):
> btrfs: only enforce free space tree if v1 cache is required for bs <
> ps cases
> btrfs: forcing free space tree for bs > ps cases
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Looks good, thanks.
>
> fs/btrfs/super.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread