Skip to content

nvme: apple: send every flush to the drive by default; T6040 shares the T8132 quirks - #2989

Draft
Alyx-ML wants to merge 2 commits into
aurora-silicon:mainfrom
Alyx-ML:aurora/nvme-flush-durability
Draft

Alyx-ML wants to merge 2 commits into
aurora-silicon:mainfrom
Alyx-ML:aurora/nvme-flush-durability

Conversation

@Alyx-ML

@Alyx-ML Alyx-ML commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Part of the #2755 split. Draft: it needs numbers I cannot measure (no Mac here).

Summary

-unsigned int flush_interval = 1000;    # flushes inside 1 s are acked before the drive flushes
+static unsigned int flush_interval;    # 0: every flush reaches the drive; still a module parameter
+#define APPLE_NVME_T8132_QUIRKS NVME_QUIRK_BROKEN_FUA   # the J713 result
 t8132: .quirks = APPLE_NVME_T8132_QUIRKS
-t6040: .quirks = NVME_QUIRK_NO_APST
+t6040: .quirks = APPLE_NVME_T8132_QUIRKS | NVME_QUIRK_NO_APST   # the same controller

Evidence

  • A host harness shows that with the old default, 99 of 100 flushes sent 10 jiffies apart were
    acked before reaching the drive, and with the new default none are.
  • Build: passed, Apple build and KUnit.
  • Needed before merging: fio fsync and sync-write numbers, before and after, on one M1, one M2
    and one M3 machine, and an M4 Pro row (an fsynced FUA write across an abrupt reset, and FUA
    write throughput).

Merge Danger

Door: two-way

Blast Radius: storage performance

Slower flushes on M1/M2/M3 and slower FUA writes on M4 Pro, in exchange for fsync() meaning what it
says. flush_interval=1000 restores the old behaviour.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@Alyx-ML checking open drafts today. To come out of draft, this still needs:

  • It conflicts with main. Merge main in or rebase (no force push needed: a merge commit is fine).
  • Then a test run at the final head on a Mac with the hardware it touches, and mark it ready for review.

If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done.

flush_interval defaulted to 1000 ms. Within that window
apple_nvme_queue_rq() completed a REQ_OP_FLUSH at once and sent one
flush to the drive when the window ended. The filesystem was told the
data was durable while it was still in the drive's cache, so a power
loss or a crash in that window lost data that fsync() had reported as
safe. Post-M4 controllers were already exempt; every earlier ANS (the
t8015 and t8103 profiles, which the generic apple,nvme-ans2 compatible
also selects for T600x and T8112) ran with the deferral on.

Make 0 the default, so every flush reaches the drive before it
completes. Keep the parameter for people who accept the risk, and say
in its description that a non-zero value acknowledges flushes before
they reach the drive. Make the variable static: it was a global symbol
named flush_interval.

This trades flush latency for durability on M1, M2 and M3 machines.
The cost has not been measured: fio numbers on M1, M2 and M3 are needed
before this is merged.

Checked with a host harness built from the real
apple_nvme_delayed_flush() text under ASan and UBSan: with the old
default, 99 of 100 flushes sent 10 jiffies apart were completed early;
with the new default none are, and an opt-in interval behaves as before.
Not built as a kernel module here, and not run on hardware.

Signed-off-by: Alyx-ML <[email protected]>
T6040 (M4 Pro) is the T8132 controller with a different register
layout, as the comment above its profile says. T8132 sets
NVME_QUIRK_BROKEN_FUA because writes were lost across a reset on J713
unless they were flushed. T6040 did not set it, so it trusted FUA on the
same controller.

Name the T8132 quirk set once and use it in both profiles, so T6040
follows the J713 result instead of a copied list that can drift. The
block layer then follows each FUA write with a flush on T6040. At worst
this costs one extra flush per FUA write; it cannot lose data that FUA
alone would have kept.

The evidence is the J713 (T8132) result. It has not been repeated on
T6040: an M4 Pro run (an fsynced FUA write across an abrupt reset, and
fio before and after) is needed before this is merged.

Signed-off-by: Alyx-ML <[email protected]>
@Alyx-ML

Alyx-ML commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (3001857). I rebased rather than merged, so the diff
shows only these two commits. The only conflict was the T6040 profile: main added its sleep
fields, and they are kept, with quirks = APPLE_NVME_T8132_QUIRKS | NVME_QUIRK_NO_APST.

The build link in the description is from the old base. My fork's Actions could not run this
time, so the PR's own CI is the build check at this head. It still needs the fio numbers listed
in the description before it can leave draft.

Assisted-by: LLM (Claude:Opus 5.5)

@Alyx-ML
Alyx-ML force-pushed the aurora/nvme-flush-durability branch from 0621648 to 3001857 Compare November 27, 2026 01:14
@satchlj

satchlj commented Nov 30, 2026

Copy link
Copy Markdown
Member

M2 data for this PR: MacBook Air J413 (T8112), internal ANS, main-based kernel. The rows ran with nvme_apple.flush_interval=0 on the command line, which is what this PR makes the default on T8112. They are not the PR head.

Test. A raw 256 MiB window on the internal disk, outside any filesystem, written with O_DIRECT.

  • Each write is a 16 KiB block with a unique sequence token, followed by fsync() on the block device. The device reports a write-back cache with FUA, so fsync() sends a flush.
  • After each fsync() returns, the writer prints an ack over the network to a second machine.
  • About 2 s in, the watchdog resets the SoC while the loop is still writing. The loop keeps going until the reset lands.
  • On the next boot, each block must hold its last acked token or a newer one.
flush_interval Resets Resets that lost acked writes Lost writes per reset write+fsync rate (median, 10 runs)
1000 (current default) 10 2 1938 (acked in the last 68 ms), 7523 (last 397 ms) 31,167/s
0 (this PR) 10 0 0 1,263/s
  • With 1000, the lost writes are always the tail of the acked stream. Those blocks read back their previous contents, so an acked flush did not mean the data was durable.
  • With 0, every acked block read back intact after all 10 resets.
  • The same test with the disk idle for 1 s between the last fsync() and the reset lost nothing in 10 resets with 1000. So the loss window is the grace period, as the code says.

Cost. About 0.8 ms per real flush, roughly 25× fewer fsyncs per second for an fsync-bound loop on this machine. That is what fsync() is supposed to cost.

A filesystem that writes its superblock after a flush it was told completed can be left referencing blocks that never reached the disk. That matches the btrfs damage seen after repeated resets on a T8122 machine. I'd support taking this PR. I haven't run the T6040 quirk change; I have no hardware for it.

@satchlj

satchlj commented Nov 30, 2026

Copy link
Copy Markdown
Member

Row at this PR's head (both commits, unchanged) on the M2 MacBook Air J413, default command line, no nvme_apple parameter. The kernel is main plus our four open T8112 PRs (#3647 #3659 #3595 #3668) plus this PR's two commits. It's now that machine's default. Same test as above: a raw window outside any filesystem, 16 KiB O_DIRECT writes each followed by fsync(), acks sent over the network, and the watchdog reset landing mid-stream.

  • flush_interval reads 0 with no parameter.
  • 10 resets, 0 acked writes lost: every block read back its last acked token.
  • write+fsync rate in line with the flush_interval=0 row above (about 1,300/s).
  • After the series: btrfs scrub of the root is clean, device stats are all zero, 0 failed units, keyboard/trackpad/GPU/Wi-Fi fine.

So the M2 part of the evidence list is done at the PR head. The T6040 quirk change isn't covered; I have no such machine.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants