ceph: add 'lazyio' mount option to kclient
Subsystems (2)
PATCH v4 1/1 ceph: add 'lazyio' mount option to kclient
Add a 'lazyio' mount option to the kernel Ceph client that enables LazyIO globally for all regular file opens on a mount. This is the kclient equivalent of the 'client_force_lazyio=true' config option in the ceph-fuse userspace client.
When 'lazyio' is specified, CEPH_FILE_MODE_LAZY is automatically added to every regular file's fmode at open time in ceph_open() and ceph_atomic_open(), causing the I/O paths to request CEPH_CAP_FILE_LAZYIO from the MDS. This permits buffered I/O via the page cache even when multiple clients have the file open for write — beneficial for HPC workloads that can tolerate relaxed cache coherency.
The mount option is exposed as 'lazyio' / 'nolazyio' via the VFS fsparam_flag_no mechanism and supports remount.
---
The following is a test report:
=== LazyIO Multi-Client Read Test ===
(B writes → MDS revokes CACHE from A; lazyio keeps LAZYIO → buffered reads)
nolazyio: 200 MB in 0.63s -> 319.8 MB/s
lazyio : 200 MB in 0.24s -> 840.3 MB/s
=== IO500 tool ior test: ===
nolazyio lazyio
Write: 74.49 MB/s -> 185.24 MB/s
---
Changed in V4:
- Base the CACHE/BUFFER -> LAZYIO used-cap substitution on implemented, not issued, so ceph_check_caps() holds the revoke ACK until writeback and invalidation complete; also queue writeback when revoking LAZYIO with dirty buffers.
- In try_get_cap_refs(), let LAZYIO substitute for missing CACHE/BUFFER for callers that request LAZYIO, without dropping issued CACHE/BUFFER refs when LAZYIO is unavailable.
- In handle_cap_grant(), invalidate on CACHE-then-LAZYIO revoke sequences and flush dirty data before ACKing when LAZYIO was covering it.
- In ceph_page_mkwrite(), wait for BUFFER/LAZYIO to be (re)granted before dirtying the folio instead of proceeding with WR alone.
- Request LAZYIO from the netfs read path (ceph_init_request) and ceph_renew_caps().
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- Rework try_get_cap_refs() so a missing LAZYIO never makes a want unsatisfiable and silently drops CACHE/BUFFER refs (degrading to sync I/O).
- Add ceph_adjust_caps_used_for_lazyio() and report LAZYIO in used caps to the MDS when it stands in for CACHE/BUFFER.
- In handle_cap_grant(), flush dirty data before acking an LAZYIO revoke, and invalidate when either CACHE or LAZYIO is revoked and neither remains.
- Define CEPH_O_LAZY as 00020000 (matching src/include/ceph_fs.h) and send it in the open request flags.
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Move LAZYIO fmode addition from ceph_init_file_info() to ceph_open() before ceph_caps_for_mode(), so the MDS sees LAZYIO in the wanted caps at open time. Also cover ceph_atomic_open() for the writer path.
- Add ceph_adjust_caps_used_for_lazyio() to substitute LAZYIO for CACHE/BUFFER in used caps reported to MDS when those caps are not issued.
- Gate try_get_cap_refs() LAZYIO substitution on want & CEPH_CAP_FILE_LAZYIO so a non-lazy fd cannot have its consistency guarantees weakened by a lazy fd on the same inode.
- Separate revocation handling in handle_cap_grant(): BUFFER revocation always triggers writeback; LAZYIO revocation triggers writeback only when dirty data is held (i_wrbuffer_ref/i_wb_ref); clean cached pages fall through to the existing invalidation path.
- Add LAZYIO to ceph_init_request() so readahead works for lazy fds.
- Fix fmode propagation: use fmode instead of req->r_fmode in ceph_open() MDS path, and set req->r_fmode |= CEPH_FILE_MODE_LAZY for both ceph_open() and ceph_atomic_open().
- Remove dead #ifdef O_LAZY blocks in ceph_flags_to_mode() and ceph_renew_caps().
- Link to v1: https://patch.msgid.link/[email protected]
To: Ilya Dryomov <[email protected]>
To: Alex Markuze <[email protected]>
To: Viacheslav Dubeyko <[email protected]>
Cc: [email protected]
Cc: [email protected]
--- fs/ceph/addr.c | 52 +++++++++++++++++++ fs/ceph/caps.c | 116 +++++++++++++++++++++++++++++++++++++++---- fs/ceph/file.c | 33 ++++++++++-- fs/ceph/super.c | 15 ++++++ fs/ceph/super.h | 1 + fs/ceph/util.c | 4 -- include/linux/ceph/ceph_fs.h | 1 + 7 files changed, 202 insertions(+), 20 deletions(-)
fs/ceph/addr.c +52 -0
@@ -491,6 +491,10 @@ static int ceph_init_request(struct netfs_io_request *rreq, struct file *file) rreq->netfs_priv = priv;return 0 ; } + +/* If this is a lazy fd, also try to get LAZYIO caps */ +if (fi->fmode &CEPH_FILE_MODE_LAZY ) + want |=CEPH_CAP_FILE_LAZYIO ; }/*
@@ -2055,6 +2059,30 @@ static vm_fault_t ceph_filemap_fault(struct vm_fault *vmf)return ret; } +/* +* Return true if the MDS has issued us a cap that covers buffered +* dirtying: either BUFFER, or LAZYIO (as long as LAZYIO itself is not +* being revoked). This mirrors the conditions under which +* try_get_cap_refs() will hand out a BUFFER or LAZYIO ref. +*/ +static bool ceph_have_dirtyable_caps (struct inode *inode) +{ +struct ceph_inode_info *ci =ceph_inode (inode); +int have, implemented; +bool ret = false; + +spin_lock (&ci->i_ceph_lock); + have =__ceph_caps_issued (ci, &implemented); +if (have &CEPH_CAP_FILE_BUFFER ) { + ret = true; + }else if ((have &CEPH_CAP_FILE_LAZYIO ) && + !((implemented & ~have) &CEPH_CAP_FILE_LAZYIO )) { + ret = true; + } +spin_unlock (&ci->i_ceph_lock); +return ret; +} +static vm_fault_t ceph_page_mkwrite (struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;
@@ -2093,6 +2121,7 @@ static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf)else want =CEPH_CAP_FILE_BUFFER ; +retry_caps: got =0 ; err =ceph_get_caps (vma->vm_file,CEPH_CAP_FILE_WR , want, off + len, &got);if (err <0 )
@@ -2101,6 +2130,29 @@ static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf)doutc (cl,"%llx.%llx %llu~%zd got cap refs on %s\n" ,ceph_vinop (inode), off, len,ceph_cap_string (got)); +/* +* ceph_write_iter() makes the same check and falls back to +* synchronous writes, but a page fault has no such fallback: +* dirtying the folio without BUFFER or LAZYIO would leave dirty +* data uncovered by any issued cap (e.g. while LAZYIO is being +* revoked, or after it has been released). Wait for the MDS to +* (re)grant a covering cap, matching how the exclude gate in +* try_get_cap_refs() blocks buffered writes while BUFFER is +* revoking. +*/ +if ((fi->fmode &CEPH_FILE_MODE_LAZY ) && + (got & (CEPH_CAP_FILE_BUFFER |CEPH_CAP_FILE_LAZYIO )) ==0 ) { +ceph_put_cap_refs (ci, got); + got =0 ; +doutc (cl,"%llx.%llx %llu~%zd waiting for BUFFER or LAZYIO\n" , +ceph_vinop (inode), off, len); + err =wait_event_killable (ci->i_cap_wq, +ceph_have_dirtyable_caps (inode)); +if (err) + goto out_free; + goto retry_caps; + } +/* Update time before taking folio lock */ file_update_time (vma->vm_file);inode_inc_iversion_raw (inode);
fs/ceph/caps.c +105 -11
168 lines not on this page · raw message
fs/ceph/file.c +28 -5
@@ -346,10 +346,6 @@ int ceph_renew_caps(struct inode *inode, int fmode) flags =O_RDONLY ; else if (wanted & CEPH_CAP_FILE_WR) flags =O_WRONLY ; -#ifdef O_LAZY -if (wanted &CEPH_CAP_FILE_LAZYIO ) - flags |=O_LAZY ; -#endif req =prepare_open_request (inode->i_sb, flags,0 );if (IS_ERR (req)) {
@@ -357,6 +353,10 @@ int ceph_renew_caps(struct inode *inode, int fmode) goto out; } +if (wanted &CEPH_CAP_FILE_LAZYIO ) { + req->r_fmode |=CEPH_FILE_MODE_LAZY ; + req->r_args.open.flags |=cpu_to_le32 (CEPH_O_LAZY ); + } req->r_inode = inode;ihold (inode); req->r_num_caps =1 ;
@@ -408,6 +408,19 @@ int ceph_open(struct inode *inode, struct file *file)doutc (cl,"%p %llx.%llx file %p flags %d (%d)\n" , inode,ceph_vinop (inode), file, flags, file->f_flags); fmode =ceph_flags_to_mode (flags); + +/* +* If lazyio mount option is set, enable lazyio for all regular +* files. Skip snapped files: snap caps never include LAZYIO, +* so including it in wanted would force an unnecessary MDS +* round-trip for every open of a snapped file. +*/ +if (S_ISREG (inode->i_mode) && +ceph_snap (inode) ==CEPH_NOSNAP && + (fsc->mount_options->flags &CEPH_MOUNT_OPT_LAZYIO )) { + fmode |=CEPH_FILE_MODE_LAZY ; + } + wanted =ceph_caps_for_mode (fmode);if (fmode &CEPH_FILE_MODE_WR )
@@ -484,13 +497,16 @@ int ceph_open(struct inode *inode, struct file *file) err =PTR_ERR (req); goto out; } + req->r_fmode |= fmode &CEPH_FILE_MODE_LAZY ; +if (fmode &CEPH_FILE_MODE_LAZY ) + req->r_args.open.flags |=cpu_to_le32 (CEPH_O_LAZY ); req->r_inode = inode;ihold (inode); req->r_num_caps =1 ; err =ceph_mdsc_do_request (mdsc,NULL , req);if (!err) - err =ceph_init_file (inode, file, req->r_fmode); + err =ceph_init_file (inode, file, fmode);ceph_mdsc_put_request (req);doutc (cl,"open result=%d on %llx.%llx\n" , err,ceph_vinop (inode)); out:
@@ -834,6 +850,9 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, }else {int fmode =ceph_flags_to_mode (flags); +if (fsc->mount_options->flags &CEPH_MOUNT_OPT_LAZYIO ) + fmode |=CEPH_FILE_MODE_LAZY ; + mask =MAY_READ ;if (fmode &CEPH_FILE_MODE_WR ) mask |=MAY_WRITE ;
@@ -876,6 +895,10 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, err =PTR_ERR (req); goto out_ctx; } +if (fsc->mount_options->flags &CEPH_MOUNT_OPT_LAZYIO ) { + req->r_fmode |=CEPH_FILE_MODE_LAZY ; + req->r_args.open.flags |=cpu_to_le32 (CEPH_O_LAZY ); + } req->r_dentry =dget (dentry); req->r_num_caps =2 ; mask =CEPH_STAT_CAP_INODE |CEPH_CAP_AUTH_SHARED ;
fs/ceph/super.c +15 -0
@@ -177,6 +177,7 @@ enum { Opt_wsync, Opt_pagecache, Opt_sparseread, + Opt_lazyio, }; enum ceph_recover_session_mode {
@@ -203,6 +204,7 @@ static const struct fs_parameter_spec ceph_mount_parameters[] = {fsparam_flag_no ("fsc" , Opt_fscache),// fsc|nofsc fsparam_string ("fsc" , Opt_fscache),// fsc=... fsparam_flag_no ("ino32" , Opt_ino32), +fsparam_flag_no ("lazyio" , Opt_lazyio),fsparam_string ("mds_namespace" , Opt_mds_namespace),fsparam_string ("mon_addr" , Opt_mon_addr), fsparam_flag_no ("poolperm", Opt_poolperm),
@@ -593,6 +595,12 @@ static int ceph_parse_mount_param(struct fs_context *fc,else fsopt->flags |=CEPH_MOUNT_OPT_SPARSEREAD ;break ; +case Opt_lazyio: +if (result.negated) + fsopt->flags &= ~CEPH_MOUNT_OPT_LAZYIO ; +else + fsopt->flags |=CEPH_MOUNT_OPT_LAZYIO ; +break ;case Opt_test_dummy_encryption:#ifdef CONFIG_FS_ENCRYPTION fscrypt_free_dummy_policy (&fsopt->dummy_enc_policy);
@@ -749,6 +757,8 @@ static int ceph_show_options(struct seq_file *m, struct dentry *root)seq_puts (m,",nopagecache" );if (fsopt->flags &CEPH_MOUNT_OPT_SPARSEREAD )seq_puts (m,",sparseread" ); +if (fsopt->flags &CEPH_MOUNT_OPT_LAZYIO ) +seq_puts (m,",lazyio" );fscrypt_show_test_dummy_encryption (m,',' , root->d_sb);
@@ -1410,6 +1420,11 @@ static int ceph_reconfigure_fc(struct fs_context *fc)else ceph_clear_mount_opt (fsc,SPARSEREAD ); +if (fsopt->flags &CEPH_MOUNT_OPT_LAZYIO ) +ceph_set_mount_opt (fsc,LAZYIO ); +else +ceph_clear_mount_opt (fsc,LAZYIO ); +if (strcmp_null (fsc->mount_options->mon_addr, fsopt->mon_addr)) {kfree (fsc->mount_options->mon_addr); fsc->mount_options->mon_addr = fsopt->mon_addr;
fs/ceph/super.h +1 -0
@@ -45,6 +45,7 @@#define CEPH_MOUNT_OPT_ASYNC_DIROPS (1<<15)/* allow async directory ops */ #define CEPH_MOUNT_OPT_NOPAGECACHE (1<<16)/* bypass pagecache altogether */ #define CEPH_MOUNT_OPT_SPARSEREAD (1<<17)/* always do sparse reads */ +#define CEPH_MOUNT_OPT_LAZYIO (1<<18)/* force lazyio for all file opens */ #define CEPH_MOUNT_OPT_DEFAULT \ (CEPH_MOUNT_OPT_DCACHE | \
fs/ceph/util.c +0 -4
@@ -73,10 +73,6 @@ int ceph_flags_to_mode(int flags) mode =CEPH_FILE_MODE_RDWR ;break ; } -#ifdef O_LAZY -if (flags &O_LAZY ) - mode |=CEPH_FILE_MODE_LAZY ; -#endif return mode; }
include/linux/ceph/ceph_fs.h +1 -0
@@ -414,6 +414,7 @@ extern const char *ceph_mds_op_name(int op);#define CEPH_O_CREAT 00000100#define CEPH_O_EXCL 00000200#define CEPH_O_TRUNC 00001000 +#define CEPH_O_LAZY 00020000#define CEPH_O_DIRECTORY 00200000#define CEPH_O_NOFOLLOW 00400000
---
base-commit: 9fc75b71fdd38465c76c6f6a884cdd4ae3c72d90
change-id: 20260625-lazyio-6987f73c557f
Best regards,
Signature · 1 line
Xiubo Li <[email protected]>
Alex Markuze
maintainerHi Xiubo,
Thanks for the update and the extra testing.
NACK for now — please send a v5 for:
1. fs/ceph/caps.c:2354: FLUSH can ACK a LAZYIO revoke while pages are still cached Xiubo, ceph_adjust_caps_used_for_lazyio() is applied in
ceph_check_caps() and handle_cap_grant(), but __prep_cap()
still does cap->implemented &= cap->issued | used with the raw
used set. try_flush_caps() and __kick_flushing_caps() pass __ceph_caps_used() straight in, so used is CACHE/BUFFER from
nrpages / i_wrbuffer_ref, not LAZYIO. Once LAZYIO is gone from
issued, that drops it from implemented and the FLUSH/reconnect
message is an implicit revoke ACK. ceph_fsync() hits this easily:
file_write_and_wait_range() leaves clean cached pages, then
try_flush_caps() runs. After that ACK the MDS can hand CACHE to
another client while we still have the old pages. That is the hole
the v4 implemented comment is trying to close, and it still
exists on the FLUSH path.
Suggested fix: Run used through
ceph_adjust_caps_used_for_lazyio() in try_flush_caps() and __kick_flushing_caps(), or once inside __prep_cap(). While
implemented still has LAZYIO and CACHE/BUFFER are not issued,
report LAZYIO as used so implemented keeps it until writeback and
invalidation finish.
2. fs/ceph/addr.c:1999: Non-lazy mmap can keep using stale page cache after a CACHE->LAZYIO transition The new revoke path keeps the inode page cache when CACHE is
dropped but LAZYIO remains, and the used-cap rewrite then lets that
revoke be ACKed. That is only safe if every opener is lazy. After remount,lazyio, CEPH_IOC_LAZYIO on one fd, or any mix of old
non-lazy and new lazy opens, a non-lazy mapping still faults
through ceph_filemap_fault() with want = CACHE, gets only RD,
then calls filemap_fault() anyway because
!ceph_has_inline_data(). Those retained pages were kept solely
for the lazy fd, so the non-lazy mmap can observe stale data.
try_get_cap_refs() correctly refuses to satisfy a non-lazy
CACHE/BUFFER want with LAZYIO for read_iter/write_iter; mmap
never got that gate.
Suggested fix: Only let LAZYIO cover retained page cache when every
opener on the inode is lazy, or skip/invalidate page-cache faults
for non-lazy fds once CACHE has been revoked.
3. fs/ceph/addr.c:2149: ceph_page_mkwrite() can sleep until killed if caps are gone The new lazy-fd path drops its refs and waits in `wait_event_killable(ci->i_cap_wq,
ceph_have_dirtyable_caps(inode))` when it got WR but neither BUFFER
nor LAZYIO. Session reset wakes i_cap_wq via cap purge, but ceph_have_dirtyable_caps() stays false once the caps are gone, so
the waiter goes back to sleep. ceph_inode_shutdown() does not
make the condition true and does not wake the queue.
try_get_cap_refs() already fails with -ESTALE on shutdown; this
wait sits outside that path, so a writable fault in that window
wedges until SIGKILL.
Suggested fix: Include shutdown/session-loss in the wait condition,
and fail the fault once the inode can no longer regain BUFFER or
LAZYIO.
FLUSH/reconnect still ACKs a LAZYIO revoke while pages remain; non-lazy mmap and mkwrite shutdown wait also need fixes.
Signature · 1 line
Alex Markuze
Hi Alex,
Thanks for the detailed review and for pointing out these issues. You are right, those are good catches.
This also fixes the read performance issue I hit before.
Patches are ready and will respin as v5.
Thanks
- Xiubo
Quoted 64 lines · Alex Markuze
Hi Xiubo,
Thanks for the update and the extra testing.
NACK for now — please send a v5 for:
1.
fs/ceph/caps.c:2354: FLUSH can ACK a LAZYIO revoke while pages are still cached Xiubo,ceph_adjust_caps_used_for_lazyio()is applied in
ceph_check_caps()andhandle_cap_grant(), but__prep_cap()
still doescap->implemented &= cap->issued | usedwith the raw
used set.try_flush_caps()and__kick_flushing_caps()pass__ceph_caps_used()straight in, so used is CACHE/BUFFER from
nrpages/i_wrbuffer_ref, not LAZYIO. Once LAZYIO is gone from
issued, that drops it fromimplementedand the FLUSH/reconnect
message is an implicit revoke ACK.ceph_fsync()hits this easily:
file_write_and_wait_range()leaves clean cached pages, then
try_flush_caps()runs. After that ACK the MDS can hand CACHE to
another client while we still have the old pages. That is the hole
the v4implementedcomment is trying to close, and it still
exists on the FLUSH path.
Suggested fix: Runusedthrough
ceph_adjust_caps_used_for_lazyio()intry_flush_caps()and__kick_flushing_caps(), or once inside__prep_cap(). While
implementedstill has LAZYIO and CACHE/BUFFER are not issued,
report LAZYIO as used soimplementedkeeps it until writeback and
invalidation finish.
2.fs/ceph/addr.c:1999: Non-lazy mmap can keep using stale page cache after aCACHE->LAZYIOtransition The new revoke path keeps the inode page cache when CACHE is
dropped but LAZYIO remains, and the used-cap rewrite then lets that
revoke be ACKed. That is only safe if every opener is lazy. Afterremount,lazyio,CEPH_IOC_LAZYIOon one fd, or any mix of old
non-lazy and new lazy opens, a non-lazy mapping still faults
throughceph_filemap_fault()withwant = CACHE, gets only RD,
then callsfilemap_fault()anyway because
!ceph_has_inline_data(). Those retained pages were kept solely
for the lazy fd, so the non-lazy mmap can observe stale data.
try_get_cap_refs()correctly refuses to satisfy a non-lazy
CACHE/BUFFER want with LAZYIO forread_iter/write_iter; mmap
never got that gate.
Suggested fix: Only let LAZYIO cover retained page cache when every
opener on the inode is lazy, or skip/invalidate page-cache faults
for non-lazy fds once CACHE has been revoked.
3.fs/ceph/addr.c:2149:ceph_page_mkwrite()can sleep until killed if caps are gone The new lazy-fd path drops its refs and waits in `wait_event_killable(ci->i_cap_wq,
ceph_have_dirtyable_caps(inode))` when it got WR but neither BUFFER
nor LAZYIO. Session reset wakesi_cap_wqvia cap purge, butceph_have_dirtyable_caps()stays false once the caps are gone, so
the waiter goes back to sleep.ceph_inode_shutdown()does not
make the condition true and does not wake the queue.
try_get_cap_refs()already fails with-ESTALEon shutdown; this
wait sits outside that path, so a writable fault in that window
wedges until SIGKILL.
Suggested fix: Include shutdown/session-loss in the wait condition,
and fail the fault once the inode can no longer regain BUFFER or
LAZYIO.FLUSH/reconnect still ACKs a LAZYIO revoke while pages remain; non-lazy mmap and mkwrite shutdown wait also need fixes.
--
Alex Markuze
Any chance of getting in as well the opt-out RFE for going synchronous when an OSD / pool crosses NEARFULL?
Quoted 66 lines · Alex Markuze
Hi Xiubo,
Thanks for the update and the extra testing.
NACK for now — please send a v5 for:
1.
fs/ceph/caps.c:2354: FLUSH can ACK a LAZYIO revoke while pages are still cached Xiubo,ceph_adjust_caps_used_for_lazyio()is applied in
ceph_check_caps()andhandle_cap_grant(), but__prep_cap()
still doescap->implemented &= cap->issued | usedwith the raw
used set.try_flush_caps()and__kick_flushing_caps()pass__ceph_caps_used()straight in, so used is CACHE/BUFFER from
nrpages/i_wrbuffer_ref, not LAZYIO. Once LAZYIO is gone from
issued, that drops it fromimplementedand the FLUSH/reconnect
message is an implicit revoke ACK.ceph_fsync()hits this easily:
file_write_and_wait_range()leaves clean cached pages, then
try_flush_caps()runs. After that ACK the MDS can hand CACHE to
another client while we still have the old pages. That is the hole
the v4implementedcomment is trying to close, and it still
exists on the FLUSH path.
Suggested fix: Runusedthrough
ceph_adjust_caps_used_for_lazyio()intry_flush_caps()and__kick_flushing_caps(), or once inside__prep_cap(). While
implementedstill has LAZYIO and CACHE/BUFFER are not issued,
report LAZYIO as used soimplementedkeeps it until writeback and
invalidation finish.
2.fs/ceph/addr.c:1999: Non-lazy mmap can keep using stale page cache after aCACHE->LAZYIOtransition The new revoke path keeps the inode page cache when CACHE is
dropped but LAZYIO remains, and the used-cap rewrite then lets that
revoke be ACKed. That is only safe if every opener is lazy. Afterremount,lazyio,CEPH_IOC_LAZYIOon one fd, or any mix of old
non-lazy and new lazy opens, a non-lazy mapping still faults
throughceph_filemap_fault()withwant = CACHE, gets only RD,
then callsfilemap_fault()anyway because
!ceph_has_inline_data(). Those retained pages were kept solely
for the lazy fd, so the non-lazy mmap can observe stale data.
try_get_cap_refs()correctly refuses to satisfy a non-lazy
CACHE/BUFFER want with LAZYIO forread_iter/write_iter; mmap
never got that gate.
Suggested fix: Only let LAZYIO cover retained page cache when every
opener on the inode is lazy, or skip/invalidate page-cache faults
for non-lazy fds once CACHE has been revoked.
3.fs/ceph/addr.c:2149:ceph_page_mkwrite()can sleep until killed if caps are gone The new lazy-fd path drops its refs and waits in `wait_event_killable(ci->i_cap_wq,
ceph_have_dirtyable_caps(inode))` when it got WR but neither BUFFER
nor LAZYIO. Session reset wakesi_cap_wqvia cap purge, butceph_have_dirtyable_caps()stays false once the caps are gone, so
the waiter goes back to sleep.ceph_inode_shutdown()does not
make the condition true and does not wake the queue.
try_get_cap_refs()already fails with-ESTALEon shutdown; this
wait sits outside that path, so a writable fault in that window
wedges until SIGKILL.
Suggested fix: Include shutdown/session-loss in the wait condition,
and fail the fault once the inode can no longer regain BUFFER or
LAZYIO.FLUSH/reconnect still ACKs a LAZYIO revoke while pages remain; non-lazy mmap and mkwrite shutdown wait also need fixes.
Signature · 1 line
Alex Markuze
Ilya Dryomov
maintainerQuoted 2 lines · Anthony D'Atri
Any chance of getting in as well the opt-out RFE for going synchronous when an OSD / pool crosses NEARFULL?
Hi Anthony,
That is already queued, courtesy of Alex:
https://github.com/ceph/ceph-client/commit/c7a12c20bfba96a76e94d8dfd700b33e92aa8323
Thanks,
Ilya
Quoted 69 lines
Quoted 67 lines · Alex Markuze
Hi Xiubo,
Thanks for the update and the extra testing.
NACK for now — please send a v5 for:
1.
fs/ceph/caps.c:2354: FLUSH can ACK a LAZYIO revoke while pages are still cached Xiubo,ceph_adjust_caps_used_for_lazyio()is applied in
ceph_check_caps()andhandle_cap_grant(), but__prep_cap()
still doescap->implemented &= cap->issued | usedwith the raw
used set.try_flush_caps()and__kick_flushing_caps()pass__ceph_caps_used()straight in, so used is CACHE/BUFFER from
nrpages/i_wrbuffer_ref, not LAZYIO. Once LAZYIO is gone from
issued, that drops it fromimplementedand the FLUSH/reconnect
message is an implicit revoke ACK.ceph_fsync()hits this easily:
file_write_and_wait_range()leaves clean cached pages, then
try_flush_caps()runs. After that ACK the MDS can hand CACHE to
another client while we still have the old pages. That is the hole
the v4implementedcomment is trying to close, and it still
exists on the FLUSH path.
Suggested fix: Runusedthrough
ceph_adjust_caps_used_for_lazyio()intry_flush_caps()and__kick_flushing_caps(), or once inside__prep_cap(). While
implementedstill has LAZYIO and CACHE/BUFFER are not issued,
report LAZYIO as used soimplementedkeeps it until writeback and
invalidation finish.
2.fs/ceph/addr.c:1999: Non-lazy mmap can keep using stale page cache after aCACHE->LAZYIOtransition The new revoke path keeps the inode page cache when CACHE is
dropped but LAZYIO remains, and the used-cap rewrite then lets that
revoke be ACKed. That is only safe if every opener is lazy. Afterremount,lazyio,CEPH_IOC_LAZYIOon one fd, or any mix of old
non-lazy and new lazy opens, a non-lazy mapping still faults
throughceph_filemap_fault()withwant = CACHE, gets only RD,
then callsfilemap_fault()anyway because
!ceph_has_inline_data(). Those retained pages were kept solely
for the lazy fd, so the non-lazy mmap can observe stale data.
try_get_cap_refs()correctly refuses to satisfy a non-lazy
CACHE/BUFFER want with LAZYIO forread_iter/write_iter; mmap
never got that gate.
Suggested fix: Only let LAZYIO cover retained page cache when every
opener on the inode is lazy, or skip/invalidate page-cache faults
for non-lazy fds once CACHE has been revoked.
3.fs/ceph/addr.c:2149:ceph_page_mkwrite()can sleep until killed if caps are gone The new lazy-fd path drops its refs and waits in `wait_event_killable(ci->i_cap_wq,
ceph_have_dirtyable_caps(inode))` when it got WR but neither BUFFER
nor LAZYIO. Session reset wakesi_cap_wqvia cap purge, butceph_have_dirtyable_caps()stays false once the caps are gone, so
the waiter goes back to sleep.ceph_inode_shutdown()does not
make the condition true and does not wake the queue.
try_get_cap_refs()already fails with-ESTALEon shutdown; this
wait sits outside that path, so a writable fault in that window
wedges until SIGKILL.
Suggested fix: Include shutdown/session-loss in the wait condition,
and fail the fault once the inode can no longer regain BUFFER or
LAZYIO.FLUSH/reconnect still ACKs a LAZYIO revoke while pages remain; non-lazy mmap and mkwrite shutdown wait also need fixes.
--
Alex Markuze
Awesome, thanks! We discussed it a few months back but I hadn't seen that it'd been acted upon.
Quoted 85 lines · Ilya Dryomov
Quoted 2 lines · Anthony D'Atri
Any chance of getting in as well the opt-out RFE for going synchronous when an OSD / pool crosses NEARFULL?
Hi Anthony,
That is already queued, courtesy of Alex:
https://github.com/ceph/ceph-client/commit/c7a12c20bfba96a76e94d8dfd700b33e92aa8323
Thanks,
Ilya
Quoted 69 lines
Quoted 67 lines · Alex Markuze
Hi Xiubo,
Thanks for the update and the extra testing.
NACK for now — please send a v5 for:
1.
fs/ceph/caps.c:2354: FLUSH can ACK a LAZYIO revoke while pages are still cached Xiubo,ceph_adjust_caps_used_for_lazyio()is applied in
ceph_check_caps()andhandle_cap_grant(), but__prep_cap()
still doescap->implemented &= cap->issued | usedwith the raw
used set.try_flush_caps()and__kick_flushing_caps()pass__ceph_caps_used()straight in, so used is CACHE/BUFFER from
nrpages/i_wrbuffer_ref, not LAZYIO. Once LAZYIO is gone from
issued, that drops it fromimplementedand the FLUSH/reconnect
message is an implicit revoke ACK.ceph_fsync()hits this easily:
file_write_and_wait_range()leaves clean cached pages, then
try_flush_caps()runs. After that ACK the MDS can hand CACHE to
another client while we still have the old pages. That is the hole
the v4implementedcomment is trying to close, and it still
exists on the FLUSH path.
Suggested fix: Runusedthrough
ceph_adjust_caps_used_for_lazyio()intry_flush_caps()and__kick_flushing_caps(), or once inside__prep_cap(). While
implementedstill has LAZYIO and CACHE/BUFFER are not issued,
report LAZYIO as used soimplementedkeeps it until writeback and
invalidation finish.
2.fs/ceph/addr.c:1999: Non-lazy mmap can keep using stale page cache after aCACHE->LAZYIOtransition The new revoke path keeps the inode page cache when CACHE is
dropped but LAZYIO remains, and the used-cap rewrite then lets that
revoke be ACKed. That is only safe if every opener is lazy. Afterremount,lazyio,CEPH_IOC_LAZYIOon one fd, or any mix of old
non-lazy and new lazy opens, a non-lazy mapping still faults
throughceph_filemap_fault()withwant = CACHE, gets only RD,
then callsfilemap_fault()anyway because
!ceph_has_inline_data(). Those retained pages were kept solely
for the lazy fd, so the non-lazy mmap can observe stale data.
try_get_cap_refs()correctly refuses to satisfy a non-lazy
CACHE/BUFFER want with LAZYIO forread_iter/write_iter; mmap
never got that gate.
Suggested fix: Only let LAZYIO cover retained page cache when every
opener on the inode is lazy, or skip/invalidate page-cache faults
for non-lazy fds once CACHE has been revoked.
3.fs/ceph/addr.c:2149:ceph_page_mkwrite()can sleep until killed if caps are gone The new lazy-fd path drops its refs and waits in `wait_event_killable(ci->i_cap_wq,
ceph_have_dirtyable_caps(inode))` when it got WR but neither BUFFER
nor LAZYIO. Session reset wakesi_cap_wqvia cap purge, butceph_have_dirtyable_caps()stays false once the caps are gone, so
the waiter goes back to sleep.ceph_inode_shutdown()does not
make the condition true and does not wake the queue.
try_get_cap_refs()already fails with-ESTALEon shutdown; this
wait sits outside that path, so a writable fault in that window
wedges until SIGKILL.
Suggested fix: Include shutdown/session-loss in the wait condition,
and fail the fault once the inode can no longer regain BUFFER or
LAZYIO.FLUSH/reconnect still ACKs a LAZYIO revoke while pages remain; non-lazy mmap and mkwrite shutdown wait also need fixes.
--
Alex Markuze