ceph: fix caps revocation stuck
v2 cover ceph: fix caps revocation stuck
From: Xiubo Li <[email protected]>
Just remove the "[1/3] ceph: do not break the loop if CEPH_I_FLUSH is set" patch from V1, which is causing a regression in
https://tracker.ceph.com/issues/63298
Xiubo Li (2):
ceph: always queue a writeback when revoking the Fb caps
ceph: add ceph_cap_unlink_work to fire check caps immediately
fs/ceph/caps.c | 65 +++++++++++++++++++++++++++----------------- fs/ceph/mds_client.c | 34 +++++++++++++++++++++++ fs/ceph/mds_client.h | 4 +++ 3 files changed, 78 insertions(+), 25 deletions(-)
Signature · 1 line
2.39.1
PATCH v2 1/2 ceph: always queue a writeback when revoking the Fb caps
From: Xiubo Li <[email protected]>
In case there is 'Fw' dirty caps and 'CHECK_CAPS_FLUSH' is set we will always ignore queue a writeback. Queue a writeback is very important because it will block kclient flushing the snapcaps to MDS and which will block MDS waiting for revoking the 'Fb' caps.
URL: https://tracker.ceph.com/issues/50223
--- fs/ceph/caps.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-)
fs/ceph/caps.c +24 -24
@@ -2156,6 +2156,30 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags)ceph_cap_string (cap->implemented), ceph_cap_string(revoking)); +/* completed revocation? going down and there are no caps? */ +if (revoking) { +if ((revoking & cap_used) ==0 ) { +doutc (cl,"completed revocation of %s\n" , +ceph_cap_string (cap->implemented & ~cap->issued)); + goto ack; + } + +/* +* If the "i_wrbuffer_ref" was increased by mmap or generic +* cache write just before the ceph_check_caps() is called, +* the Fb capability revoking will fail this time. Then we +* must wait for the BDI's delayed work to flush the dirty +* pages and to release the "i_wrbuffer_ref", which will cost +* at most 5 seconds. That means the MDS needs to wait at +* most 5 seconds to finished the Fb capability's revocation. +* +* Let's queue a writeback for it. +*/ +if (S_ISREG (inode->i_mode) && ci->i_wrbuffer_ref && + (revoking &CEPH_CAP_FILE_BUFFER )) + queue_writeback = true; + } +if (cap == ci->i_auth_cap && (cap->issued &CEPH_CAP_FILE_WR )) {/* request larger max_size from MDS? */
@@ -2183,30 +2207,6 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags) } } -/* completed revocation? going down and there are no caps? */ -if (revoking) { -if ((revoking & cap_used) ==0 ) { -doutc (cl,"completed revocation of %s\n" , -ceph_cap_string (cap->implemented & ~cap->issued)); - goto ack; - } - -/* -* If the "i_wrbuffer_ref" was increased by mmap or generic -* cache write just before the ceph_check_caps() is called, -* the Fb capability revoking will fail this time. Then we -* must wait for the BDI's delayed work to flush the dirty -* pages and to release the "i_wrbuffer_ref", which will cost -* at most 5 seconds. That means the MDS needs to wait at -* most 5 seconds to finished the Fb capability's revocation. -* -* Let's queue a writeback for it. -*/ -if (S_ISREG (inode->i_mode) && ci->i_wrbuffer_ref && - (revoking &CEPH_CAP_FILE_BUFFER )) - queue_writeback = true; - } -/* want more caps from mds? */ if (want & ~cap->mds_wanted) {if (want & ~(cap->mds_wanted | cap->issued))
Signature · 1 line
2.39.1
PATCH v2 2/2 ceph: add ceph_cap_unlink_work to fire check caps immediately
In reply to [email protected]From: Xiubo Li <[email protected]>
When unlinking a file the check caps could be delayed for more than 5 seconds, but in MDS side it maybe waiting for the clients to release caps.
This will add a dedicated work queue and list to help trigger to fire the check caps and dirty buffer flushing immediately.
URL: https://tracker.ceph.com/issues/50223
--- fs/ceph/caps.c | 17 ++++++++++++++++- fs/ceph/mds_client.c | 34 ++++++++++++++++++++++++++++++++++ fs/ceph/mds_client.h | 4 ++++ 3 files changed, 54 insertions(+), 1 deletion(-)
fs/ceph/caps.c +16 -1
@@ -4790,7 +4790,22 @@ int ceph_drop_caps_for_unlink(struct inode *inode)if (__ceph_caps_dirty (ci)) {struct ceph_mds_client *mdsc =ceph_inode_to_fs_client (inode)->mdsc; -__cap_delay_requeue_front (mdsc, ci); + +doutc (mdsc->fsc->client,"%p %llx.%llx\n" , inode, +ceph_vinop (inode)); +spin_lock (&mdsc->cap_unlink_delay_lock); + ci->i_ceph_flags |=CEPH_I_FLUSH ; +if (!list_empty (&ci->i_cap_delay_list)) +list_del_init (&ci->i_cap_delay_list); +list_add_tail (&ci->i_cap_delay_list, + &mdsc->cap_unlink_delay_list); +spin_unlock (&mdsc->cap_unlink_delay_lock); + +/* +* Fire the work immediately, because the MDS maybe +* waiting for caps release. +*/ +schedule_work (&mdsc->cap_unlink_work); } }spin_unlock (&ci->i_ceph_lock);
fs/ceph/mds_client.c +34 -0
@@ -2500,6 +2500,37 @@ void ceph_reclaim_caps_nr(struct ceph_mds_client *mdsc, int nr) } } +static void ceph_cap_unlink_work (struct work_struct *work) +{ +struct ceph_mds_client *mdsc = + container_of(work, struct ceph_mds_client, cap_unlink_work); +struct ceph_client *cl = mdsc->fsc->client; + +doutc (cl,"begin\n" ); +spin_lock (&mdsc->cap_unlink_delay_lock); +while (!list_empty (&mdsc->cap_unlink_delay_list)) { +struct ceph_inode_info *ci; +struct inode *inode; + + ci =list_first_entry (&mdsc->cap_unlink_delay_list, + struct ceph_inode_info, + i_cap_delay_list); +list_del_init (&ci->i_cap_delay_list); + + inode =igrab (&ci->netfs.inode); +if (inode) { +spin_unlock (&mdsc->cap_unlink_delay_lock); +doutc (cl,"on %p %llx.%llx\n" , inode, +ceph_vinop (inode)); +ceph_check_caps (ci,CHECK_CAPS_FLUSH ); +iput (inode); +spin_lock (&mdsc->cap_unlink_delay_lock); + } + } +spin_unlock (&mdsc->cap_unlink_delay_lock); +doutc (cl,"done\n" ); +} +/* * requests */
@@ -5372,6 +5403,8 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)INIT_LIST_HEAD (&mdsc->cap_delay_list);INIT_LIST_HEAD (&mdsc->cap_wait_list);spin_lock_init (&mdsc->cap_delay_lock); +INIT_LIST_HEAD (&mdsc->cap_unlink_delay_list); +spin_lock_init (&mdsc->cap_unlink_delay_lock);INIT_LIST_HEAD (&mdsc->snap_flush_list);spin_lock_init (&mdsc->snap_flush_lock); mdsc->last_cap_flush_tid =1 ;
@@ -5380,6 +5413,7 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)spin_lock_init (&mdsc->cap_dirty_lock);init_waitqueue_head (&mdsc->cap_flushing_wq);INIT_WORK (&mdsc->cap_reclaim_work, ceph_cap_reclaim_work); +INIT_WORK (&mdsc->cap_unlink_work, ceph_cap_unlink_work); err =ceph_metric_init (&mdsc->metric);if (err) goto err_mdsmap;
fs/ceph/mds_client.h +4 -0
@@ -462,6 +462,8 @@ struct ceph_mds_client {unsigned long last_renew_caps;/* last time we renewed our caps */ struct list_head cap_delay_list;/* caps with delayed release */ spinlock_t cap_delay_lock;/* protects cap_delay_list */ +struct list_head cap_unlink_delay_list;/* caps with delayed release for unlink */ +spinlock_t cap_unlink_delay_lock;/* protects cap_unlink_delay_list */ struct list_head snap_flush_list;/* cap_snaps ready to flush */ spinlock_t snap_flush_lock;
@@ -475,6 +477,8 @@ struct ceph_mds_client {struct work_struct cap_reclaim_work;atomic_t cap_reclaim_pending; +struct work_struct cap_unlink_work; +/* * Cap reservations *
Signature · 1 line
2.39.1
Ilya Dryomov
maintainerRe: [PATCH v2 2/2] ceph: add ceph_cap_unlink_work to fire check caps immediately
Quoted 33 lines · On Wed, Oct 25, 2023 at 8:22 AM <[email protected]> wrote:
From: Xiubo Li <[email protected]>
When unlinking a file the check caps could be delayed for more than 5 seconds, but in MDS side it maybe waiting for the clients to release caps.
This will add a dedicated work queue and list to help trigger to fire the check caps and dirty buffer flushing immediately.
URL: https://tracker.ceph.com/issues/50223
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/caps.c | 17 ++++++++++++++++- fs/ceph/mds_client.c | 34 ++++++++++++++++++++++++++++++++++ fs/ceph/mds_client.h | 4 ++++ 3 files changed, 54 insertions(+), 1 deletion(-)fs/ceph/caps.c +6
-1@@ -4790,7 +4790,22 @@ int ceph_drop_caps_for_unlink(struct inode *inode)if (__ceph_caps_dirty (ci)) {struct ceph_mds_client *mdsc =ceph_inode_to_fs_client (inode)->mdsc; -__cap_delay_requeue_front (mdsc, ci); + +doutc (mdsc->fsc->client,"%p %llx.%llx\n" , inode, +ceph_vinop (inode)); +spin_lock (&mdsc->cap_unlink_delay_lock); + ci->i_ceph_flags |=CEPH_I_FLUSH ; +if (!list_empty (&ci->i_cap_delay_list))
fs/ceph/caps.c int ceph_drop_caps_for_unlink(struct inode *inode) · line 4808
Quoted 10 lines
fs/ceph/caps.c +10
-0+list_del_init (&ci->i_cap_delay_list); +list_add_tail (&ci->i_cap_delay_list, + &mdsc->cap_unlink_delay_list); +spin_unlock (&mdsc->cap_unlink_delay_lock); + +/* +* Fire the work immediately, because the MDS maybe +* waiting for caps release. +*/ +schedule_work (&mdsc->cap_unlink_work);
Hi Xiubo,
This schedules a work an a system-wide workqueue, not specific to CephFS. Is there something that ensures that it gets flushed as part of unmount and possibly on other occasions that have to do with individual inodes?
Thanks,
Ilya
Re: [PATCH v2 2/2] ceph: add ceph_cap_unlink_work to fire check caps immediately
Quoted 45 lines · Ilya Dryomov
Quoted 32 lines · On Wed, Oct 25, 2023 at 8:22 AM <[email protected]> wrote:
From: Xiubo Li <[email protected]>
When unlinking a file the check caps could be delayed for more than 5 seconds, but in MDS side it maybe waiting for the clients to release caps.
This will add a dedicated work queue and list to help trigger to fire the check caps and dirty buffer flushing immediately.
URL: https://tracker.ceph.com/issues/50223
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/caps.c | 17 ++++++++++++++++- fs/ceph/mds_client.c | 34 ++++++++++++++++++++++++++++++++++ fs/ceph/mds_client.h | 4 ++++ 3 files changed, 54 insertions(+), 1 deletion(-)fs/ceph/caps.c +6
-1@@ -4790,7 +4790,22 @@ int ceph_drop_caps_for_unlink(struct inode *inode)if (__ceph_caps_dirty (ci)) {struct ceph_mds_client *mdsc =ceph_inode_to_fs_client (inode)->mdsc; -__cap_delay_requeue_front (mdsc, ci); + +doutc (mdsc->fsc->client,"%p %llx.%llx\n" , inode, +ceph_vinop (inode)); +spin_lock (&mdsc->cap_unlink_delay_lock); + ci->i_ceph_flags |=CEPH_I_FLUSH ; +if (!list_empty (&ci->i_cap_delay_list))fs/ceph/caps.c int ceph_drop_caps_for_unlink(struct inode *inode) · line 4808
Quoted 10 lines
fs/ceph/caps.c +10
-0+list_del_init (&ci->i_cap_delay_list); +list_add_tail (&ci->i_cap_delay_list, + &mdsc->cap_unlink_delay_list); +spin_unlock (&mdsc->cap_unlink_delay_lock); + +/* +* Fire the work immediately, because the MDS maybe +* waiting for caps release. +*/ +schedule_work (&mdsc->cap_unlink_work);Hi Xiubo,
Quoted 4 lines
This schedules a work an a system-wide workqueue, not specific to CephFS. Is there something that ensures that it gets flushed as part of unmount and possibly on other occasions that have to do with individual inodes?
Hi Ilya,
There seems no, I didn't find any.
Let me add a dedicated workqueue for this.
Thanks
- Xiubo
Quoted 4 lines
Thanks,
Ilya