Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH 0/5] btrfs: rework data placement on zoned devices
@ 2026-11-26 13:28 Johannes Thumshirn
  2026-11-26 13:28 ` [PATCH 1/5] btrfs: zoned: search for hinted block-group in prepare_allocation_zoned Johannes Thumshirn
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Johannes Thumshirn @ 2026-11-26 13:28 UTC (permalink / raw)
  To: linux-btrfs
  Cc: Damien Le Moal, Christoph Hellwig, Hans Holmberg, Naohiro Aota,
	Josef Bacik, Filipe Manana, David Sterba, Boris Burkov, Qu Wenruo,
	Wilfred Mallawa, Johannes Thumshirn

Rework data placement on zoned devices. Currently zoned BTRFS ignores
the write hint passed to the extent allocator and always picks the first
block-group in the active_bgs list as extent allocation target.

This causes high fragmentation, which then in turn causes high demands
for garbage collection due to the append only nature of zoned block
devices. As the fragmentation is high garbage collection cannot reset
a full zone when one hughe file is overwritten, but has to evacuate data
that is still referenced by other files first, before performing a zone
reset.

Mimic what XFS on zoned realtime devices does for this setup: As long as
we can still allocate new zones from the underlying devices, allocate a
new block-group and place, the new file there. For extent-allocations of
already existing files, remember the last allocation of this inode and
use it as a hint for the extent allocator. If two allocations race for
the same block-group, retry to see if another block-group can be chosen.

Test setup
----------

QEMU VM (virtme-ng), 8 vCPUs, 8 GiB RAM, base btrfs for-next 98768e7ccd0f
with and without the series. Each test runs 3 times per kernel on a
freshly created filesystem (mkfs.btrfs -d single -m single) on a memory
backed zoned null_blk device:

  memory_backed=1 blocksize=4096 size=4096 (MiB) zoned=1 zone_size=64 (MiB)
  zone_nr_conv=0 zone_max_active=12

btrfs uses 10 of the 12 active zones for data. Writes are done with
xfs_io pwrite in 1 MiB blocks, buffered writes are followed by fsync.

Workloads:

- Interleaved appends: 4 files are appended round-robin in 1 MiB steps,
  each step followed by fsync, until every file is 192 MiB (3 zones).
- Parallel writers: 5 writers start at the same time and each write a
  new 128 MiB file (2 zones).
- More writers than active zones: 20 writers start at the same time and
  each write a new 64 MiB file (1 zone).
- Fill to ENOSPC: 8 O_DIRECT writers write until the filesystem is full.
- GC churn: 5 writers create 6 files each (16-96 MiB, 1.5 GiB total).
  Then, in 8 rounds, every writer picks 2 of its files and either deletes
  and re-creates it with a new size, overwrites it completely, or
  overwrites 25% of it in random 1 MiB pieces. The sequence of operations
  is generated from a fixed seed, so both kernels run the same sequence
  (about 5 GiB of writes in total). There is one sync per round instead
  of fsync per write. GC is the regular zoned reclaim with default
  thresholds; the counters are read after reclaim has settled.

Metrics:

- files/zone: number of files with data in a data block-group, averaged
  over all data block-groups used (1.0 = no sharing).
- extents/file: extents per file as reported by FIEMAP.
- GC copied: bytes relocated by zoned reclaim
  (/sys/fs/btrfs/<uuid>/allocation/data/reclaim_bytes).
- zones freed without copying: data block-groups removed without being
  relocated first.

Results (mean of 3 runs)
------------------------

Workload                              files/zone      extents/file
                                      base -> series  base -> series
------------------------------------  --------------  ----------------
Interleaved appends
  buffered                             4.00 -> 1.00     192 -> 3
  O_DIRECT                             4.00 -> 1.00     192 -> 3
5 parallel writers
  buffered                             4.42 -> 1.48      41 -> 6
  O_DIRECT                             5.00 -> 1.00     964 -> 2
20 parallel writers (2x active zones)
  buffered                            16.98 -> 4.47      53 -> 44
  O_DIRECT                            19.60 -> 5.25     503 -> 244
Fill to ENOSPC, O_DIRECT               8.00 -> 2.35    3920 -> 1261

                                      GC copied        zones freed
                                      base -> series   w/o copying
------------------------------------  ---------------  --------------
GC churn, buffered                    261 -> 4 MiB     17 -> 36
GC churn, O_DIRECT                     70 -> 0 MiB     16 -> 35

Further numbers:

- 5 parallel O_DIRECT writers: every file has its own zones in all runs
  (at most 1 file per zone, base: 5).
- 20 parallel writers: above the active zone limit allocations are spread
  round-robin over the active block-groups; at most 6-10 files per zone
  instead of 20.
- Fill to ENOSPC: the filesystem fills to 92% of the device size with and
  without the series.
- GC churn per run: base copies 45-677 MiB (buffered) and 49-100 MiB
  (O_DIRECT), the series 0-12 MiB and 0 MiB. GC write amplification
  ((written + copied) / written) goes from 1.008-1.129 to 1.000-1.002.
- The series doesn't use more data block-groups for the streaming
  workloads; with more writers than active zones it uses 1-4 more
  (24-25 instead of 21-25).

Performance changes (all numbers in MB/s):

Workload                  write                parallel read          single reader
------------------------  -------------------  ---------------------  --------------------
 5 writers, O_DIRECT      1660 -> 1981 (+19%)  10335 -> 11996 (+16%)  4077 -> 5691 (+40%)
20 writers, O_DIRECT      2346 -> 2928 (+25%)  12584 -> 12920  (+3%)  4561 -> 5283 (+16%)
 5 writers, buffered       643 ->  628  (-2%)  13165 -> 13091  (-1%)  5353 -> 5168  (-3%)
20 writers, buffered       842 ->  831  (-1%)  14507 -> 14620  (+1%)  6240 -> 6370  (+2%)


Johannes Thumshirn (5):
  btrfs: zoned: search for hinted block-group in
    prepare_allocation_zoned
  btrfs: zoned: save last allocation as placement hint
  btrfs: zoned: allocate a new block-group per file
  btrfs: zoned: try to fill hinted block-groups
  btrfs: zoned: break concurrent chunk allocation race

 fs/btrfs/btrfs_inode.h       |  2 +
 fs/btrfs/extent-tree.c       | 85 +++++++++++++++++++++++++++++++++---
 fs/btrfs/extent-tree.h       |  8 ++++
 fs/btrfs/inode.c             |  5 +++
 fs/btrfs/ordered-data.c      |  7 ++-
 fs/btrfs/zoned.c             | 31 +++++++++++++
 fs/btrfs/zoned.h             |  7 +++
 include/trace/events/btrfs.h | 33 ++++++++++++++
 8 files changed, 170 insertions(+), 8 deletions(-)

-- 
2.56.1


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

end of thread, other threads:[~2026-11-26 21:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 13:28 [PATCH 0/5] btrfs: rework data placement on zoned devices Johannes Thumshirn
2026-11-26 13:28 ` [PATCH 1/5] btrfs: zoned: search for hinted block-group in prepare_allocation_zoned Johannes Thumshirn
2026-11-26 21:09   ` Damien Le Moal
2026-11-26 13:28 ` [PATCH 2/5] btrfs: zoned: save last allocation as placement hint Johannes Thumshirn
2026-11-26 21:11   ` Damien Le Moal
2026-11-26 13:28 ` [PATCH 3/5] btrfs: zoned: allocate a new block-group per file Johannes Thumshirn
2026-11-26 21:20   ` Damien Le Moal
2026-11-26 13:28 ` [PATCH 4/5] btrfs: zoned: try to fill hinted block-groups Johannes Thumshirn
2026-11-26 21:25   ` Damien Le Moal
2026-11-26 13:28 ` [PATCH 5/5] btrfs: zoned: break concurrent chunk allocation race Johannes Thumshirn
2026-11-26 21:30   ` Damien Le Moal

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