Skip to content

RFC fs/iomap/xfs: generation-based DIO range draining

Vitali Lovich linux-xfs 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest6 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6fs: implement range-based generation-coordinated DIO drainingDocumentation/filesystems/locking.rst Documentation/filesystems/vfs.rst fs/inode.c +3 more+334 -330 replies
2/6iomap: support generation accounting and caller-registered DIOfs/ext4/file.c fs/iomap/direct-io.c fs/xfs/xfs_file.c +1 more+67 -290 replies
3/6fs: add KUnit coverage for generation-based DIO drainingfs/Kconfig fs/Makefile fs/inode.c +2 more+425 -00 replies
4/6xfs: add range-drain state and latch-based DIO admissionfs/xfs/xfs_file.c fs/xfs/xfs_icache.c fs/xfs/xfs_inode.h +1 more+149 -110 replies
5/6xfs: use range-based DIO draining for aligned hole punchesfs/xfs/xfs_bmap_util.c fs/xfs/xfs_file.c fs/xfs/xfs_inode.c+105 -20 replies
6/6xfs: use range-based DIO draining for post-EOF zeroingfs/xfs/xfs_file.c+94 -150 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 v1 0/6] fs/iomap/xfs: generation-based DIO range draining

The core problem this patch series tries to address is how to keep read IOPS up and read latency down in the face of concurrent (but non-overlapping) hole punching or writes past the EOF with gaps.

Previous ideas have explored the idea of using range tracking for operations. The downside is that it has a small but measurable overhead for IOPs throughput, increased CPU usage, and more memory usage. Range tracking also enables more concurrency of certain write operations of unrelated ranges.

The core idea of this patch series is instead to ignore trying to support hole punches of unrelated regions. Instead, hole punching (and writes past the end with gaps) remain exclusive of each other and update a read-optimized data structure to contain the range they're operating on. Reads then check against this range on submission to know if they need to defer themselves against a pending hole punch. This flips the problem and side-steps the need for interval tracking, resulting in no overhead for pure-read scenarios.

As the data at the end shows, this patch series solves a good chunk of the read IOPs and latency performance under concurrent hole punches while showing no impact on pure read workloads. There remain two additional sources of contention that show up; the exclusive metadata lock (extent mapping + modified timestamps when not using lazytime) and the ili_lock which is unnecessarily checked for reads. I have prototyped optimizing the extent metadata mapping and it shows read IOPs and read latency approach the uncontended case even with a large number of concurrent hole punches. It also significantly improves the "reduced" hole punching performance the numbers below show (I explain below why it's a phantom reduction and not a bug in the patch set). Fixing the ili_lock contention on top of this should largely eliminate the remaining contention bottleneck between readers and hole punching.

I'll also note that even in the uncontended read cases, this performs slightly better in pure reads and, combined with the metadata mapping contention improvement, results in a ~2-6% speedup for read-only workloads; this patchset by itself is more modest for pure read workload wins.

The specific mechanism this patch series implements is:
* Introduces a new draining lock that hole punching and writes past end need to acquire. This ensures that concurrent hole punching, as currently, can only happen one at a time. This restriction is not lifted by this patchset.
* Once the lock is acquired, the drainer updates a seqcount_latch_t protected exclusion range and reading counter with the number of currently outstanding DIOs acts as the natural barrier. We use a single bit generation counter to dilineate DIO cohorts that may have not observed the installed latch and those that definitely did. The former on completion will notice the writer is waiting for draining and they count off and know when to wake the writer that the OPs it's waiting to drain have completed.
* The read path checks the seqcount_latch_t state cheaply and safely so that it knows upon start which drain generation it's part of and which range to potentially check on. Conflicting rights take the slow path and will wait for the already started draining - the head of line blocking that occurs here is no different than the current status quo, except only overlapping reads are impacted.

The i_dio_counter acts as the barrier mechanism for the latch snapshot protocol. This upgrades the relaxed increment of the counter on registration into fully ordered. While I confirmed this has no observable impact on pure read workloads, I don't have access to a weakly ordered machine with huge concurrency to confirm it doesn't have an impact on less concurrency. The SeqCst consistency in this patch set could be optimized to use Acquire/Release instead, but I decided to be a bit more conservative here.

Patches 1-3 add VFS accounting, iomap ownership, documentation, a focused LKMM litmus test, and KUnit coverage. Patches 4-6 integrate admission and the two consumers in XFS. The ext4 change only adapts the iomap helper signature.

KUnit, two CPUs: 5 passed, 0 failed, 0 skipped LKMM, herd7 7.58: Forbidden outcome Never
XFS debug + lockdep fstests: 16 passed, 0 failed, 0 skipped

Performance measurements gathered as requested in:
https://lore.kernel.org/linux-xfs/atF7xJlbck-xA1G3@dread/T/#m203f6ae3899e7061afc847a45f72abd9d257dfef

Workload is number of concurrent readers + writers. Hole punches column is the workers attempting to hit 1000/s and the effective number actually reached. All IOPs are hitting the same inode. Read IOPs are in millions and P99.9 is in milliseconds.

kernel | readers/workers | punches/s | read IOPS | read P99.9 (ms)
----------+-----------------+-----------+-----------+----------------

baseline  |       1/0       |      0.00 |   592,088 |           0.214
latch     |       1/0       |      0.00 |   584,266 |           0.189
baseline  |       1/1       |    989.44 |   400,052 |           0.758
latch     |       1/1       |    790.79 |   522,255 |           0.436
baseline  |       1/8       |    879.33 |    32,103 |           5.603
latch     |       1/8       |    768.11 |   261,712 |           1.221
baseline  |       1/32      |    998.67 |    15,721 |          16.318
latch     |       1/32      |    704.56 |   256,991 |           1.237
baseline  |       1/64      |    999.81 |    25,364 |          12.517
latch     |       1/64      |    711.11 |   256,288 |           1.221
----------+-----------------+-----------+-----------+----------------
baseline  |       8/0       |      0.00 | 2,159,746 |           0.416
latch     |       8/0       |      0.00 | 2,142,864 |           0.387
baseline  |       8/1       |    300.72 |   715,545 |           2.867
latch     |       8/1       |    131.08 | 1,302,691 |           4.047
baseline  |       8/8       |    744.09 |   185,504 |           6.193
latch     |       8/8       |    204.85 |   594,782 |           4.014
baseline  |       8/32      |    999.41 |    66,411 |          15.663
latch     |       8/32      |    205.75 |   594,228 |           4.014
baseline  |       8/64      |    940.88 |    22,154 |          43.778
latch     |       8/64      |    203.97 |   593,788 |           4.014
----------+-----------------+-----------+-----------+----------------
baseline  |      32/0       |      0.00 | 2,467,761 |           1.221
latch     |      32/0       |      0.00 | 2,497,401 |           0.913
baseline  |      32/1       |    129.01 |   653,812 |           6.914
latch     |      32/1       |     65.50 | 1,112,291 |           6.783
baseline  |      32/8       |    507.07 |   347,173 |          10.289
latch     |      32/8       |     89.23 |   750,753 |           9.765
baseline  |      32/32      |    617.12 |   112,667 |          25.559
latch     |      32/32      |     88.54 |   751,453 |           9.765
baseline  |      32/64      |    821.00 |    70,012 |          42.205
latch     |      32/64      |     88.81 |   750,884 |           9.765
----------+-----------------+-----------+-----------+----------------
baseline  |      64/0       |      0.00 | 2,511,819 |           1.761
latch     |      64/0       |      0.00 | 2,520,544 |           1.761
latch+fix |      64/0       |      0.00 | 2,682,546 |           2.245
baseline  |      64/1       |     65.46 |   677,507 |          13.042
latch     |      64/1       |     39.78 | 1,036,213 |          10.682
latch+fix |      64/1       |    690.05 | 2,619,882 |           2.277
baseline  |      64/8       |    326.80 |   383,964 |          18.481
latch     |      64/8       |     48.12 |   801,694 |          18.481
latch+fix |      64/8       |    539.84 | 2,506,797 |           3.785
baseline  |      64/32      |    472.71 |   142,776 |          39.059
latch     |      64/32      |     48.04 |   800,569 |          18.481
latch+fix |      64/32      |    526.69 | 2,505,012 |           3.785
baseline  |      64/64      |    659.57 |    86,426 |          63.701
latch     |      64/64      |     47.92 |   800,364 |          18.481
latch+fix |      64/64      |    541.89 | 2,508,080 |           3.752
----------+-----------------+-----------+-----------+----------------
baseline  |     128/0       |      0.00 | 2,703,411 |           3.195
latch     |     128/0       |      0.00 | 2,738,430 |           3.129
latch+fix |     128/0       |      0.00 | 2,780,706 |           3.097
baseline  |     128/1       |     35.24 |   698,842 |          25.035
latch     |     128/1       |     21.83 | 1,003,072 |          18.743
latch+fix |     128/1       |    349.77 | 2,612,422 |          47.972
baseline  |     128/8       |    233.86 |   525,114 |          25.559
latch     |     128/8       |     26.26 |   857,379 |          33.817
latch+fix |     128/8       |    324.93 | 2,549,251 |          52.167
baseline  |     128/32      |    468.56 |   279,933 |          42.729
latch     |     128/32      |     26.04 |   855,151 |          34.341
latch+fix |     128/32      |    396.54 | 2,557,483 |           5.341
baseline  |     128/64      |    500.56 |   140,166 |          80.216
latch     |     128/64      |     26.13 |   853,051 |          34.341
latch+fix |     128/64      |    363.48 | 2,561,624 |          35.914

As I call out above, punch throughput seems to crash / not scale as well as it does today. This isn't some bug in the patch set. Instead, what happens is that the increased read IOPs that don't block on the I/O lock causes more contention on the metadata lock and in this case the writer loses. If you kept read IOPs artificially lower at the throughput we could manage before, then hole punch IOPs would rise. So this patch set on its own could result in regression of hole punch IOPs performance in the face of a lot of concurrent readers on the same inode. This is only intended as a temporary state of affairs though. Once this approach is approved, I'll present how the metadata extent mapping contention could be lifted. When that is done, hole punching performance under concurrent read IOPs largely restores, read IOPs are almost identical with and without hole punching, and read P99.9 latency is similarly reduced further to the uncontended read case. Perf profiles and tracing point to the ili_lock contention as the final area to cut this gap further.

Tradeoffs this patch series introduces:
* xfs inode struct grows by 1 cache line because there's no padding available to absorb the pointer we add. The callbacks used in the FS layer ensure only filesystems opting into this new codepath pay for that pointer.
* Hole punch throughput can suffer under heavier concurrent read contention that is now possible. This is fixable.

Vitali Lovich (6):
fs: implement range-based generation-coordinated DIO draining
iomap: support generation accounting and caller-registered DIO
fs: add KUnit coverage for generation-based DIO draining
xfs: add range-drain state and latch-based DIO admission
xfs: use range-based DIO draining for aligned hole punches
xfs: use range-based DIO draining for post-EOF zeroing

 Documentation/filesystems/locking.rst         |  89 ++--
 Documentation/filesystems/vfs.rst             |  41 ++
 fs/Kconfig                                    |  13 +
 fs/Makefile                                   |   1 +
 fs/ext4/file.c                                |   2 +-
 fs/inode.c                                    | 120 +++++-
 fs/iomap/direct-io.c                          |  36 +-
 fs/tests/dio_drain_kunit.c                    | 393 ++++++++++++++++++
 fs/xfs/xfs_bmap_util.c                        |   9 +-
 fs/xfs/xfs_file.c                             | 343 +++++++++++++--
 fs/xfs/xfs_icache.c                           |   2 +
 fs/xfs/xfs_inode.c                            |  10 +
 fs/xfs/xfs_inode.h                            |   1 +
 fs/xfs/xfs_iops.c                             |   9 +
 fs/xfs/xfs_reflink.h                          |   2 +-
 include/linux/fs.h                            |  97 ++++-
 include/linux/iomap.h                         |  56 ++-
 .../litmus-tests/DIO-register-first.litmus    |  36 ++
 18 files changed, 1172 insertions(+), 88 deletions(-)
 create mode 100644 fs/tests/dio_drain_kunit.c
 create mode 100644 tools/memory-model/litmus-tests/DIO-register-first.litmus

base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053

Signature · 1 line
2.56.0