Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH v3 00/17] btrfs: remove the v1 space cache
@ 2026-09-17  3:59 Tal Zussman
  2026-09-17  3:59 ` [PATCH v3 01/17] btrfs: stop enabling the v1 space cache from the on-disk state Tal Zussman
                   ` (16 more replies)
  0 siblings, 17 replies; 20+ messages in thread
From: Tal Zussman @ 2026-09-17  3:59 UTC (permalink / raw)
  To: David Sterba, Chris Mason, Qu Wenruo
  Cc: linux-btrfs, linux-kernel, Tal Zussman

Since commit 545e560a5b0f ("btrfs: disable v1 space cache") the mount
options can't select the v1 space cache anymore, but the code is all
still there, and a filesystem with an old cache and no free space tree
still enabled it from the superblock. Qu suggested removing it rather
than converting its page handling to folios [1].

Patch 1 stops enabling the cache from the on-disk state, so an existing
cache is cleaned up on the next read-write mount, as -o nospace_cache
already did. This is the one user-visible change: the cleanup is now
unconditional, and a read-write mount fails if it fails. There are two
ways to fix this failure:

1. Convert to the free space tree during mount (the recommended
   conversion), but this could fail for the same reason.

2. Run 'btrfs rescue clear-space-cache v1' on an unmounted filesystem.

Patches 2-6 remove the write path, 7 and 8 the load path and
disk_cache_state, and 9 and 10 the SPACE_CACHE flag and the unused half
of the cleanup helper. Patches 11-16 remove the trimming ranges and the
free space inode special cases in the write path, which only the v1
writer used. Patch 17 removes TRANS_JOIN_NOLOCK, which the space cache
was the only user of.

What's left is what's needed to find and delete the cache inodes of an
existing filesystem:

1. lookup_free_space_inode(), btrfs_remove_free_space_inode(), and
   btrfs_cleanup_free_space_cache_v1(), which runs on the first
   read-write mount and zeroes cache_generation in the super block.

2. btrfs_truncate_free_space_cache() and delete_v1_space_cache(), which
   relocation uses to get a cache inode's extents out of a block group.

3. btrfs_is_free_space_inode(), for the evict and inode update paths.

4. The on-disk definitions: cache_generation in the super block,
   BTRFS_FREE_SPACE_OBJECTID, and the free space header and entry
   items.

space_cache and space_cache=v1 still fall back to nospace_cache with a
warning.

This also removes the page-based I/O in the free space code.
btrfs_io_ctl used a struct page array and was one of the last users
of clear_page_dirty_for_io().

Tested with fstests (btrfs and generic quick groups), with and without
the free space tree, with no regressions against the base kernel.
Upgrading from a filesystem with an existing v1 cache written by a 6.8
kernel was also tested. The cache is removed on the first read-write
mount and on remount from read-only, and the resulting filesystem is
clean under btrfs check and still mountable by the old kernel.

Based on for-7.3-rc2.

[1] https://lore.kernel.org/linux-btrfs/e1dd5a75-9a67-4bc6-b8d8-bfff79b5b907@suse.com/

---
Changes in v3:
- Patch 5 (new): Keep the cache_write_mutex locking that serializes
  btrfs_start_dirty_block_groups() with btrfs_remove_block_group(),
  since it also protects the block group item update and not just the
  cache writeout. Rename it to dirty_bgs_update_mutex.
- Patch 8: Drop the "Old style space inode found, converting." branch
  from lookup_free_space_inode(), as it no longer converts anything.
- Link to v2: https://patch.msgid.link/20260913-btrfs-remove-v1-space-cache-v2-0-186767a7e106@columbia.edu

Changes in v2:
- Split the TRANS_JOIN_NOLOCK removal out of the ordered extent patch
  into its own patch at the end of the series, per David
- Add recovery information for a mount failure due to patch 1 to the
  cover letter.
- Link to v1: https://patch.msgid.link/20260907-btrfs-remove-v1-space-cache-v1-0-5f9a5ba352a7@columbia.edu

---
Tal Zussman (17):
      btrfs: stop enabling the v1 space cache from the on-disk state
      btrfs: remove the v1 space cache writeout from the transaction commit
      btrfs: remove the free space cache endio workqueue
      btrfs: remove the v1 space cache write path
      btrfs: rename cache_write_mutex to dirty_bgs_update_mutex
      btrfs: drop the transaction handle from the prealloc helpers
      btrfs: remove the v1 space cache load path
      btrfs: remove btrfs_disk_cache_state
      btrfs: remove the SPACE_CACHE mount option flag
      btrfs: replace btrfs_set_free_space_cache_v1_active() with a cleanup helper
      btrfs: remove the free space cache trimming ranges
      btrfs: remove BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE
      btrfs: remove the free space inode ordered extent special cases
      btrfs: remove the free space inode special cases from the COW paths
      btrfs: stop special-casing free space inodes in the delalloc accounting
      btrfs: stop reading free space inodes from the commit root
      btrfs: remove TRANS_JOIN_NOLOCK

 fs/btrfs/block-group.c      |  491 ++-----------
 fs/btrfs/block-group.h      |   14 -
 fs/btrfs/btrfs_inode.h      |    6 -
 fs/btrfs/delalloc-space.c   |   13 +-
 fs/btrfs/disk-io.c          |   81 +--
 fs/btrfs/file-item.c        |   11 -
 fs/btrfs/free-space-cache.c | 1630 +++++--------------------------------------
 fs/btrfs/free-space-cache.h |   29 +-
 fs/btrfs/fs.h               |    2 -
 fs/btrfs/inode.c            |  149 +---
 fs/btrfs/ordered-data.c     |   27 +-
 fs/btrfs/relocation.c       |    2 +-
 fs/btrfs/space-info.c       |    2 -
 fs/btrfs/space-info.h       |    4 -
 fs/btrfs/super.c            |   48 +-
 fs/btrfs/transaction.c      |   61 +-
 fs/btrfs/transaction.h      |   29 +-
 fs/btrfs/zoned.c            |    9 -
 18 files changed, 273 insertions(+), 2335 deletions(-)
---
base-commit: 09f1294ee2abee7fe1c2d600671498b7642e0fe0
change-id: 20260906-btrfs-remove-v1-space-cache-45cf57c957a2

Best regards,
--  
Tal Zussman <tz2294@columbia.edu>


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2026-09-22  1:43 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17  3:59 [PATCH v3 00/17] btrfs: remove the v1 space cache Tal Zussman
2026-09-17  3:59 ` [PATCH v3 01/17] btrfs: stop enabling the v1 space cache from the on-disk state Tal Zussman
     [not found]   ` <20260917041202.74A691F00893@smtp.kernel.org>
2026-09-18  9:57     ` David Sterba
2026-09-22  1:43       ` Tal Zussman
2026-09-17  3:59 ` [PATCH v3 02/17] btrfs: remove the v1 space cache writeout from the transaction commit Tal Zussman
2026-09-17  3:59 ` [PATCH v3 03/17] btrfs: remove the free space cache endio workqueue Tal Zussman
2026-09-17  4:00 ` [PATCH v3 04/17] btrfs: remove the v1 space cache write path Tal Zussman
2026-09-17  4:00 ` [PATCH v3 05/17] btrfs: rename cache_write_mutex to dirty_bgs_update_mutex Tal Zussman
2026-09-17  4:00 ` [PATCH v3 06/17] btrfs: drop the transaction handle from the prealloc helpers Tal Zussman
2026-09-17  4:00 ` [PATCH v3 07/17] btrfs: remove the v1 space cache load path Tal Zussman
2026-09-17  4:00 ` [PATCH v3 08/17] btrfs: remove btrfs_disk_cache_state Tal Zussman
2026-09-17  4:00 ` [PATCH v3 09/17] btrfs: remove the SPACE_CACHE mount option flag Tal Zussman
2026-09-17  4:00 ` [PATCH v3 10/17] btrfs: replace btrfs_set_free_space_cache_v1_active() with a cleanup helper Tal Zussman
2026-09-17  4:00 ` [PATCH v3 11/17] btrfs: remove the free space cache trimming ranges Tal Zussman
2026-09-17  4:00 ` [PATCH v3 12/17] btrfs: remove BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE Tal Zussman
2026-09-17  4:00 ` [PATCH v3 13/17] btrfs: remove the free space inode ordered extent special cases Tal Zussman
2026-09-17  4:00 ` [PATCH v3 14/17] btrfs: remove the free space inode special cases from the COW paths Tal Zussman
2026-09-17  4:00 ` [PATCH v3 15/17] btrfs: stop special-casing free space inodes in the delalloc accounting Tal Zussman
2026-09-17  4:00 ` [PATCH v3 16/17] btrfs: stop reading free space inodes from the commit root Tal Zussman
2026-09-17  4:00 ` [PATCH v3 17/17] btrfs: remove TRANS_JOIN_NOLOCK Tal Zussman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox