Skip to content

RFC btrfs: dynamic and periodic block_group reclaim

Boris Burkov linux-btrfs oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest6 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6btrfs: report reclaim count in sysfsfs/btrfs/block-group.c fs/btrfs/space-info.h fs/btrfs/sysfs.c+11 -00 replies
2/6btrfs: store fs_info on space_infofs/btrfs/space-info.c fs/btrfs/space-info.h+2 -00 replies
3/6btrfs: dynamic block_group reclaim thresholdfs/btrfs/block-group.c fs/btrfs/space-info.c fs/btrfs/space-info.h +1 more+134 -90 replies
4/6btrfs: periodic block_group reclaimfs/btrfs/block-group.c fs/btrfs/block-group.h fs/btrfs/space-info.c +2 more+95 -00 replies
5/6btrfs: urgent periodic reclaim passfs/btrfs/space-info.c+34 -10 replies
6/6btrfs: prevent pathological periodic reclaim loopsfs/btrfs/block-group.c fs/btrfs/space-info.c fs/btrfs/space-info.h+14 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/6] btrfs: dynamic and periodic block_group reclaim

Btrfs's block_group allocator suffers from a well known problem, that it is capable of eagerly allocating too much space to either data or metadata (most often data, absent bugs) and then later be unable to allocate more space for the other, when needed. When data starves metadata, this can extra painfully result in read only filesystems that need careful manual balancing to fix.

This can be worked around by:
- enabling automatic reclaim
- periodically running balance

Neither of these enjoy widespread use, as far as I know, though the former is used at scale at Meta with good results.

This patch set expands on automatic reclaim, adding the ability to set a dynamic reclaim threshold that appropriately scales with the global file system allocation conditions as well as periodic reclaim which runs that reclaim sweep in the cleaner thread. Together, I believe they constitute a robust and general automatic reclaim system that should avoid unfortunate read only filesystems in all but extreme conditions, where space is running quite low anyway and failure is more reasonable.

I ran it on three workloads (described in detail on the dynamic reclaim patch) but they are:
1. bounce allocations around X% full.
2. fill up all the way and introduce full fragmentation.
3. write in a fragmented way until the filesystem is just about full. script can be found here:
https://github.com/boryas/scripts/tree/main/fio/reclaim

The important results can be seen here (full results explorable at bur.io/dyn-rec/)

bounce at 30%, much higher relocations with a fixed threshold:
https://bur.io/dyn-rec/bounce-30/relocs.png

hard 30% fragmentation, dynamic actually reclaims, relocs not crazy:
https://bur.io/dyn-rec/strict_frag-30/unalloc_bytes.png
https://bur.io/dyn-rec/strict_frag-30/relocs.png

fill it all the way up, not crazy churn, but saving a buffer:
https://bur.io/dyn-rec/last_gig/unalloc_bytes.png
https://bur.io/dyn-rec/last_gig/relocs.png
https://bur.io/dyn-rec/last_gig/thresh.png

Boris Burkov (6):
btrfs: report reclaim count in sysfs
btrfs: store fs_info on space_info
btrfs: dynamic block_group reclaim threshold
btrfs: periodic block_group reclaim
btrfs: urgent periodic reclaim pass
btrfs: prevent pathological periodic reclaim loops

 fs/btrfs/block-group.c |  26 ++++---
 fs/btrfs/block-group.h |   1 +
 fs/btrfs/space-info.c  | 165 +++++++++++++++++++++++++++++++++++++++++
 fs/btrfs/space-info.h  |  28 +++++++
 fs/btrfs/sysfs.c       |  79 +++++++++++++++++++-
 5 files changed, 289 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0