Analsys and tentativ fix below:
blktrace for before the commit:
259,0 1 2 0.000002543 2394 G D 0 + 8388607 [mkfs.xfs]
259,0 1 3 0.000008230 2394 I D 0 + 8388607 [mkfs.xfs]
259,0 1 4 0.000031090 207 D D 0 + 8388607 [kworker/1:1H]
259,0 1 5 0.000044869 2394 Q D 8388607 + 8388607 [mkfs.xfs]
259,0 1 6 0.000045992 2394 G D 8388607 + 8388607 [mkfs.xfs]
259,0 1 7 0.000049559 2394 I D 8388607 + 8388607 [mkfs.xfs]
259,0 1 8 0.000061551 207 D D 8388607 + 8388607 [kworker/1:1H]
.. and so on.
blktrace with the commit:
259,0 2 1 0.000000000 1228 Q D 0 + 4194304 [mkfs.xfs]
259,0 2 2 0.000002543 1228 G D 0 + 4194304 [mkfs.xfs]
259,0 2 3 0.000010080 1228 I D 0 + 4194304 [mkfs.xfs]
259,0 2 4 0.000082187 267 D D 0 + 4194304 [kworker/2:1H]
259,0 2 5 0.000224869 1228 Q D 4194304 + 4194304 [mkfs.xfs]
259,0 2 6 0.000225835 1228 G D 4194304 + 4194304 [mkfs.xfs]
259,0 2 7 0.000229457 1228 I D 4194304 + 4194304 [mkfs.xfs]
259,0 2 8 0.000238507 267 D D 4194304 + 4194304 [kworker/2:1H]
So discards are smaller, but better aligned. Now if I tweak a single
line in blk-lib.c to be able to use all of bi_size I get the old I/O
pattern back and everything works fine again: