Re: [REGRESSION] ext4: silent data loss when a split at I/O completion gets ENOSPC
From: Zhang Yi
Date: Tue Nov 17 2026 - 22:44:20 EST
On 11/17/2026 10:23 PM, Jose Fernandez (Anthropic) wrote:
> On Tue, Nov 17, 2026 Zhang Yi wrote:
>> I think the solution should be based on Ojaswin's counting approach in
>> [1] or the PENDING_CONVERSION solution we discussed, and then, after
>> extent splitting fails, try to flush the journal and retry.
>
> Thanks for the quick POC. Our agents ran it on [1] rebased on
> 23c62304dde2 with the report's reproducer, in two separate setups (QEMU
> without KVM). None of 72 files lost data in either, against 42 and 53 of
> 72 with [1] alone.
>
> They found two gaps:
>
> - The new branch in ext4_ext_handle_unwritten_extents() skips both
> ext4_update_inode_fsync_trans() calls, so fdatasync() and O_DSYNC can
> return before the commit. On a full filesystem mounted with
> commit=3600, a shutdown test lost the write in all 13 buffered
> fdatasync() and O_DSYNC cases that reach the zeroout. They pass with
> [1] alone and with that call added.
Yes, this is a pre-existing issue introduced by 5f1a1cccebf8 ("ext4:
correct the mapping status if the extent has been zeroed"), but it
healed itself after 5f18f60d56c0 when extent splitting was deferred
until after I/O completion.
Now the current POC brings the splitting before submitting I/O logic
back in the bh buffered I/O path, so the issue has resurfaced. I can
address this issue together in the formal fix patch.
>
> - Direct writes into preallocated files can still get ENOSPC with the
> POC, on a few percent of files in both setups, with no data lost.
>
Could you provide a reproducer? My guess is that high concurrency causes
the blocks freed by my current process to be taken by I/O issued by
other processes, since we can no longer simply fall back to zeroing the
entire extent as before, which was basically always effective.
> The POC tries the zeroout before the commit and retry. Should it be the
> other way around?
I agree that doing zeroout first and then retrying does look a bit odd,
and it is not friendly to large extents. However, since the previous
logic would just do the zeroing directly when space allocation failed
during splitting, the current POC does not break anything.
Besides, Ojaswin plans to refactor this part later and move zeroout into
the fast path, so I suggest we keep it this way for now to reduce the
probability of ENOSPC, and discuss further approaches later.
> And will you take guolingxing's patch ([2] in my report) as well?
Yeah, we should merge this patch as well.
Best Regards,
Yi.