Re: [PATCH] ceph: only check the caps of a clean file early after its last close
From: Xiubo Li
Date: Thu Dec 03 2026 - 02:08:45 EST
Hi Alex,
Thanks for the review.
On Wed, Dec 02, 2026 at 12:00:22PM +0000, Alex Markuze wrote:
> If data writeback finishes shortly after the last close, the completion
> check can run while the recently used write caps are still wanted. The
> new guard has already skipped the idle check. A second client opening
> before the wanted interval expires can leave the MDS in MIX beyond the
> time the old idle check would have run.
You are right, I could reproduce it on a vstart cluster: write 4 KiB,
close, then sync() at once. Without this patch the client gives Fw
back about 10s after the close, with it only after 65s, when
caps_wanted_delay_max is up. A second client opening the file in that
window makes the MDS revoke them, and the new client has only Frw for
20-30ms, until the first one has given them up.
v2 will queue the file at its last close again, dirty or not, and skip
it in check_delayed_caps_list() only if it is still under writeback by
then. A file whose writeback completed in the meantime gets the idle
check as before (Fw given back 6-10s after the close in the same test),
and one still under writeback is left to the check at writeback
completion, which flushes and gives the caps back in one message. The
caps messages and journal events per file stay where this version has
them.
> In MIX, a non-lazy MAP_SHARED fault can dirty a folio with Fw but without
> Fb. A third client can then complete a write to a different part of the
> same folio, and the mapped client's later whole-folio writeback can
> overwrite that write. This is possible without this patch too; skipping
> the idle check can extend the window.
Confirmed as well, and on the base too: client B maps the file and
stores to bytes 0-15, client C does a pwrite() to bytes 2048-2063 and
fsync(), then B's writeback of the whole folio overwrites C's bytes,
5 out of 5 runs. The same test with pwrite() on B instead of the store
loses nothing. With v2 the patch no longer extends the window.
I also tried to fix it, two ways:
- Have the mapped client wait for Fb in ceph_page_mkwrite() when it has
no lazy I/O, and drop pages it cached without Fc once Fc comes back.
That closes the window, but a store through the mapping then blocks
for as long as any other client has the file open, even read-only,
and two clients storing to a shared mapping of the same file wait for
each other until one of them is killed.
- Keep a copy of the folio at ceph_page_mkwrite() and write back only
the bytes that differ from it. That misses a store of a value the
stale copy already holds, after another client changed that byte:
the other client's byte wins.
Neither is good enough yet. Since this is not caused by this patch,
let's discuss and fix it separately.
> The CephFS POSIX documentation describes a cache-coherency limitation
> when a file is mapped on multiple hosts. Does that limitation also cover
> this case, with one mapped host and a separate ordinary writer whose
> completed, disjoint write can later be overwritten?
Not as it is written, I think. It says the mapping host's cached page
is not invalidated when another host writes, which reads as "the mapped
host may see stale data". Here the stale page is written back, so the
other client's completed write is lost, and the writer does not need to
map the file at all. It has the same cause, but the effect is worse
than what the text describes. At the least the documentation should
say so; I can send a patch for posix.rst if we agree that is the
behaviour we keep for now.
Thanks,
Xiubo
On Wed, 2 Dec 2026 at 13:00, Alex Markuze <amarkuze@xxxxxxxxxx> wrote:
>
> Hi Xiubo,
>
> If data writeback finishes shortly after the last close, the completion
> check can run while the recently used write caps are still wanted. The
> new guard has already skipped the idle check. A second client opening
> before the wanted interval expires can leave the MDS in MIX beyond the
> time the old idle check would have run.
>
> In MIX, a non-lazy MAP_SHARED fault can dirty a folio with Fw but without
> Fb. A third client can then complete a write to a different part of the
> same folio, and the mapped client's later whole-folio writeback can
> overwrite that write. This is possible without this patch too; skipping
> the idle check can extend the window.
>
> The CephFS POSIX documentation describes a cache-coherency limitation
> when a file is mapped on multiple hosts. Does that limitation also cover
> this case, with one mapped host and a separate ordinary writer whose
> completed, disjoint write can later be overwritten?
>
> Thanks,
> Alex