Skip to contentSkip to conversation

btrfs: fix unnecessary UUID tree rescan on mount

PATCH In review Dave Chen 2 participants 5 messages Apr 2 – Apr 7 Btrfs file system

lore
Share & tools
lore

Dave Chen

author
#0 lore raw

PATCH 1/1 btrfs: fix unnecessary UUID tree rescan on mount

The UUID tree rescan check in open_ctree() compares fs_info->generation with the superblock's uuid_tree_generation. This comparison can produce false positives because fs_info->generation is bumped at transaction start time in join_transaction(), while uuid_tree_generation is only updated at commit time via update_super_roots().

Between the early BTRFS_FS_UPDATE_UUID_TREE_GEN flag check and the late rescan decision, mount operations such as orphan cleanup start transactions without committing them. This advances fs_info->generation past uuid_tree_generation, triggering an unnecessary full UUID tree rescan on every mount that recovers file orphans from an unclean shutdown.

Fix this by using the BTRFS_FS_UPDATE_UUID_TREE_GEN flag directly, which was already set earlier when the generations were known to match, and is not invalidated by subsequent transaction starts.

Fixes 70f80175472 ("Btrfs: check UUID tree during mount if required")
---
 fs/btrfs/disk-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/disk-io.c +1 -1
index 1b0eb246b7147..70357b12508d0 100644
@@ -3674,7 +3674,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
 
 	if (fs_info->uuid_root &&
 	    (btrfs_test_opt(fs_info, RESCAN_UUID_TREE) ||
-	     fs_info->generation != btrfs_super_uuid_tree_generation(disk_super))) {
+	     !test_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags))) {
 		btrfs_info(fs_info, "checking UUID tree");
 		ret = btrfs_check_uuid_tree(fs_info);
 		if (ret) {
Signature · 4 lines
2.43.0


Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Dave Chen

The UUID tree rescan check in open_ctree() compares fs_info->generation with the superblock's uuid_tree_generation. This comparison can produce false positives because fs_info->generation is bumped at transaction start time in join_transaction(), while uuid_tree_generation is only updated at commit time via update_super_roots().

Between the early BTRFS_FS_UPDATE_UUID_TREE_GEN flag check and the late rescan decision, mount operations such as orphan cleanup start transactions without committing them. This advances fs_info->generation past uuid_tree_generation, triggering an unnecessary full UUID tree rescan on every mount that recovers file orphans from an unclean shutdown.

Quoted 5 lines

Fix this by using the BTRFS_FS_UPDATE_UUID_TREE_GEN flag directly, which was already set earlier when the generations were known to match, and is not invalidated by subsequent transaction starts.

Fixes 70f80175472 ("Btrfs: check UUID tree during mount if required")

Normally we only use the Fixes tag for functional bugs and performance regressions that cause usability problems.

How much slowdown did you see because of the unnecessary rescan? For this to make any significant difference we would probably need several thousand subvolumes or snapshots.

The change looks good to me; however, thanks.

Quoted 25 lines
---
 fs/btrfs/disk-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/disk-io.c +1 -2
index 1b0eb246b7147..70357b12508d0 100644
@@ -3674,7 +3674,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
 
        if (fs_info->uuid_root &&
            (btrfs_test_opt(fs_info, RESCAN_UUID_TREE) ||
-            fs_info->generation != btrfs_super_uuid_tree_generation(disk_super))) {
+            !test_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags))) {
                btrfs_info(fs_info, "checking UUID tree");
                ret = btrfs_check_uuid_tree(fs_info);
                if (ret) {
--

2.43.0

Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.

author
#2 lore raw
Quoted 9 lines · Filipe Manana
Quoted 2 lines
Fixes 70f80175472 ("Btrfs: check UUID tree during mount if required")

Normally we only use the Fixes tag for functional bugs and performance regressions that cause usability problems.

How much slowdown did you see because of the unnecessary rescan? For this to make any significant difference we would probably need several thousand subvolumes or snapshots.

You're right, I don't have benchmark numbers from a filesystem with thousands of subvolumes to quantify the impact. I'll drop the Fixes tag and resend a v2 as a correctness improvement.

Quoted 3 lines

The change looks good to me; however, thanks.

Thanks for the review, I'll carry your Reviewed-by tag in v2.

Dave

Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.

author
#3 lore raw

PATCH v2 1/1 btrfs: use BTRFS_FS_UPDATE_UUID_TREE_GEN flag for UUID tree rescan check

In reply to Dave Chen

The UUID tree rescan check in open_ctree() compares fs_info->generation with the superblock's uuid_tree_generation. This comparison is not reliable because fs_info->generation is bumped at transaction start time in join_transaction(), while uuid_tree_generation is only updated at commit time via update_super_roots().

Between the early BTRFS_FS_UPDATE_UUID_TREE_GEN flag check and the late rescan decision, mount operations such as file orphan cleanup from an unclean shutdown start transactions without committing them. This advances fs_info->generation past uuid_tree_generation and produces a false-positive mismatch.

Use the BTRFS_FS_UPDATE_UUID_TREE_GEN flag directly instead. The flag was already set earlier in open_ctree() when the generations were known to match, and accurately represents "UUID tree is up to date" without being affected by subsequent transaction starts.

---
v2:
- Drop Fixes tag, no benchmark numbers to justify it (Filipe)
- Reword subject and commit message as a correctness improvement

 fs/btrfs/disk-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/disk-io.c +1 -1
index 1b0eb246b7147..70357b12508d0 100644
@@ -3674,7 +3674,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
 
 	if (fs_info->uuid_root &&
 	    (btrfs_test_opt(fs_info, RESCAN_UUID_TREE) ||
-	     fs_info->generation != btrfs_super_uuid_tree_generation(disk_super))) {
+	     !test_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags))) {
 		btrfs_info(fs_info, "checking UUID tree");
 		ret = btrfs_check_uuid_tree(fs_info);
 		if (ret) {
Signature · 4 lines
2.43.0


Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.
#4 lore raw

Re: [PATCH v2] btrfs: use BTRFS_FS_UPDATE_UUID_TREE_GEN flag for UUID tree rescan check

Quoted 19 lines · Dave Chen

The UUID tree rescan check in open_ctree() compares fs_info->generation with the superblock's uuid_tree_generation. This comparison is not reliable because fs_info->generation is bumped at transaction start time in join_transaction(), while uuid_tree_generation is only updated at commit time via update_super_roots().

Between the early BTRFS_FS_UPDATE_UUID_TREE_GEN flag check and the late rescan decision, mount operations such as file orphan cleanup from an unclean shutdown start transactions without committing them. This advances fs_info->generation past uuid_tree_generation and produces a false-positive mismatch.

Use the BTRFS_FS_UPDATE_UUID_TREE_GEN flag directly instead. The flag was already set earlier in open_ctree() when the generations were known to match, and accurately represents "UUID tree is up to date" without being affected by subsequent transaction starts.

Quoted 7 lines

---
v2:
- Drop Fixes tag, no benchmark numbers to justify it (Filipe)
- Reword subject and commit message as a correctness improvement

Pushed to the for-next github branch, thanks.

Quoted 22 lines
 fs/btrfs/disk-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/disk-io.c +1 -2
index 1b0eb246b7147..70357b12508d0 100644
@@ -3674,7 +3674,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
 
        if (fs_info->uuid_root &&
            (btrfs_test_opt(fs_info, RESCAN_UUID_TREE) ||
-            fs_info->generation != btrfs_super_uuid_tree_generation(disk_super))) {
+            !test_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags))) {
                btrfs_info(fs_info, "checking UUID tree");
                ret = btrfs_check_uuid_tree(fs_info);
                if (ret) {
--

2.43.0

Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.