Skip to content

btrfs: further cleanup on dirty_cowonly_roots and switch_commits

Qu Wenruo linux-btrfs 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 4 repliesIn review
  2. v12 patches 0 repliesSuperseded

Changes in v2 from the cover letter

- Add a patch to release qgroup swapped blocks during btrfs_put_root() This is addressing a real but rare memory leak.

- Replace the btrfs_extent_io_tree_release() with an ASSERT() As cowonly roots should never have dirty_log_pages populated. That is only utilized by log trees, and log trees are already poperly cleaned up in btrfs_drop_all_logs()

- Remove the btrfs_qgroup_clean_swapped_blocks() call in btrfs_free_fs_roots()
As we have a dedicated cleanup during btrfs_put_root(), no need to do it inside btrfs_free_fs_roots()

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3btrfs: always remove quota_root from dirty_cowonly_rootsfs/btrfs/qgroup.c+6 -42 replies
2/3btrfs: cleanup qgroup swapped blocks at root releasefs/btrfs/disk-io.c+1 -01 reply
3/3btrfs: cleanup dirty_cowonly_roots during btrfs_free_fs_roots()fs/btrfs/disk-io.c+19 -01 reply

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchFilipe Manana
1/3R-b
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/3] btrfs: further cleanup on dirty_cowonly_roots and switch_commits

[CHANGELOG]
v2:
- Add a patch to release qgroup swapped blocks during btrfs_put_root() This is addressing a real but rare memory leak.

- Replace the btrfs_extent_io_tree_release() with an ASSERT() As cowonly roots should never have dirty_log_pages populated. That is only utilized by log trees, and log trees are already poperly cleaned up in btrfs_drop_all_logs()

- Remove the btrfs_qgroup_clean_swapped_blocks() call in btrfs_free_fs_roots()
As we have a dedicated cleanup during btrfs_put_root(), no need to do it inside btrfs_free_fs_roots()

Sashiko mentioned that dirty_cowonly_roots can still be non-empty if a transaction aborts during commit_cowonly_roots().

However it should not cause any problem, as after a transaction is aborted, no one will ever touch dirty_cowonly_roots.
So even if it has some dangling pointers, as long as no one is reading it, it's completely fine.

Furthermore, dirty_cowonly_roots contains roots that are not subvolume nor log trees, thus they should not have swapped qgroup blocks nor dirty_log_pages. This means no memory leak from those two members either.

But we're still depending on such quirky behavior, and it's only going to cause more false alerts from various LLMs, e.g. Sashiko is already reporting problems on this.

This series address all those minor problems by:

- Remove quota_root from dirty_cowonly_roots during btrfs_quota_disable()
This prepares for the final patch as we're adding a reader for dirty_cowonly_roots during unmount.

- Cleanup qgroup swapped blocks during btrfs_put_root() This is to address a real possible memory leak, that some dirty subvolumes can have qgroup swapped blocks, and that can leak memory if not properly handled.

- Cleanup dirty_cowonly_roots during btrfs_free_fs_roots() This to remove the quirky dirty_cowonly_roots handling, and relies on explicit removal during unmount.

Also add a new ASSERT() to make sure that roots linked into dirty_cowonly_roots() has no dirty_log_pages.

*** BLURB HERE ***

Qu Wenruo (3):
btrfs: always remove quota_root from dirty_cowonly_roots
btrfs: cleanup qgroup swapped blocks at root release
btrfs: cleanup dirty_cowonly_roots during btrfs_free_fs_roots()

 fs/btrfs/disk-io.c | 20 ++++++++++++++++++++
 fs/btrfs/qgroup.c  | 10 ++++++----
 2 files changed, 26 insertions(+), 4 deletions(-)
Signature · 1 line
2.56.0