xfs: fix xfsaild races and re-enable idle mode
cover xfs: fix xfsaild races and re-enable idle mode
Hi all,
We reproduced and debugged several hangs in a rhel6.3 kernel that happened to still support xfsaild idle mode. Our short term fix was to disable idle mode as in upstream, but I'd like to fire out a couple potential fixes that allow us to re-enable idle mode, assuming there aren't any other problems I'm not aware of. The details of the bug are at:
https://bugzilla.redhat.com/show_bug.cgi?id=813137
... but I'll try to provide all relevant data in this post. The reproducer is xfstests 273 running in a 100-iteration loop. I have reproduced this hang on upstream kernels quite reliably with commit 670ce93f reverted. The performance enhancement in that commit makes this much harder to reproduce.
With the proposed modifications, I've probably run 5+ 100-loop iterations of test 273 without reproducing a hang. Previously, I was able to reproduce the first hang with 100% reliability and the second hang reproduced 10 minutes or so after starting a second 100-loop test (with the first fix applied).
I still have to run a full xfstests but the changes are small enough that I wanted to send them out before I got too far. Thanks.
Brian Foster (3):
xfs: re-enable xfsaild idle mode
xfs: fix xfsaild hang due to premature idle
xfs: fix xfsaild hang due to lost wake ups
fs/xfs/xfs_trans_ail.c | 8 ++++---- fs/xfs/xfs_trans_priv.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-)
Signature · 6 lines
1.7.7.6 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
RFC PATCH 1/3 xfs: re-enable xfsaild idle mode
Allow the xfsaild kernel thread to sleep when there is no work to do.
--- fs/xfs/xfs_trans_ail.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/xfs/xfs_trans_ail.c +1 -1
@@ -505,7 +505,7 @@ out_done:/* We're past our target or empty, so idle */ ailp->xa_last_pushed_lsn =0 ; - tout =50 ; + tout =0 ; }else if (XFS_LSN_CMP (lsn, target) >=0 ) {/* * We reached the target so wait a bit longer for I/O to
Signature · 6 lines
1.7.7.6 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
RFC PATCH 2/3 xfs: fix xfsaild hang due to premature idle
In reply to Brian FosterRunning xfstests 273 in a loop reproduces an XFS lockup due to xfsaild entering idle mode indefinitely. The following high-level sequence of events leads to the hang:
- xfsaild is running, hits the stuck item threshold and reschedules, setting xa_last_pushed_lsn appropriately.
- xa_threshold is updated.
- xfsaild restarts from the previous xa_last_pushed_lsn, hits the new target and enters idle mode, even though the previously stuck items still populate the ail.
Modify the tout logic to only enter idle mode when the ail is empty. IOW, if we hit the target but did not perform the current scan from the start of the ail, reschedule at least one more time.
--- fs/xfs/xfs_trans_ail.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/xfs/xfs_trans_ail.c +1 -1
@@ -501,7 +501,7 @@ xfsaild_push(/* assume we have more work to do in a short while */ out_done: -if (!count) { +if (!count && !ailp->xa_last_pushed_lsn) {/* We're past our target or empty, so idle */ ailp->xa_last_pushed_lsn =0 ;
Signature · 6 lines
1.7.7.6 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [RFC PATCH 2/3] xfs: fix xfsaild hang due to premature idle
Hey Brian,
Quoted 11 lines · Brian Foster
Running xfstests 273 in a loop reproduces an XFS lockup due to xfsaild entering idle mode indefinitely. The following high-level sequence of events leads to the hang:
- xfsaild is running, hits the stuck item threshold and reschedules, setting
xa_last_pushed_lsnappropriately.
-xa_thresholdis updated.
- xfsaild restarts from the previousxa_last_pushed_lsn, hits the new target and enters idle mode, even though the previously stuck items still populate the ail.
Quoted 5 lines
Modify the tout logic to only enter idle mode when the ail is empty. IOW, if we hit the target but did not perform the current scan from the start of the ail, reschedule at least one more time.
Signed-off-by Brian Foster <[email protected]>
Thanks for the patch. Unfortunately it does not apply cleanly. Care to spin it again?
Regards,
Ben
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [RFC PATCH 2/3] xfs: fix xfsaild hang due to premature idle
Quoted 14 lines · Ben Myers
Hey Brian,
Quoted 11 lines · Brian Foster
Running xfstests 273 in a loop reproduces an XFS lockup due to xfsaild entering idle mode indefinitely. The following high-level sequence of events leads to the hang:
- xfsaild is running, hits the stuck item threshold and reschedules, setting
xa_last_pushed_lsnappropriately.
-xa_thresholdis updated.
- xfsaild restarts from the previousxa_last_pushed_lsn, hits the new target and enters idle mode, even though the previously stuck items still populate the ail.
Quoted 8 lines
Quoted 5 lines
Modify the tout logic to only enter idle mode when the ail is empty. IOW, if we hit the target but did not perform the current scan from the start of the ail, reschedule at least one more time.
Signed-off-by Brian Foster <[email protected]>Thanks for the patch. Unfortunately it does not apply cleanly. Care to spin it again?
Hmm... thought I rebased, but apparently not. Sorry about that, I'll repost...
Brian
Quoted 2 lines
Regards,
Ben
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
RFC PATCH 3/3 xfs: fix xfsaild hang due to lost wake ups
In reply to Brian FosterRunning xfstests 273 in a loop reproduces an XFS lockup due to xfsaild entering idle mode indefinitely. The following high-level sequence of events leads to the hang:
- xfsaild is running with a cached target lsn
- xfs_ail_push() is invoked, updates ailp->xa_target_lsn and invokes wake_up_process(). wake_up_process() returns 0 because xfsaild is already running.
- xfsaild enters idle mode having met its current target.
Once in the described state, xfs_ail_push() is invoked many more times with the already set threshold_lsn, but these calls do not lead to wake_up_process() calls because no further invocations result in moving the threshold_lsn forward. Add a flag to xfs_ail to capture whether an issued wake actually succeeds. If not, continue issuing wakes until we know one has been successful for the current target.
--- fs/xfs/xfs_trans_ail.c | 4 ++-- fs/xfs/xfs_trans_priv.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)
fs/xfs/xfs_trans_ail.c +2 -2
@@ -576,7 +576,7 @@ xfs_ail_push( lip =xfs_ail_min (ailp);if (!lip ||XFS_FORCED_SHUTDOWN (ailp->xa_mount) || -XFS_LSN_CMP (threshold_lsn, ailp->xa_target) <=0 ) + ((XFS_LSN_CMP (threshold_lsn, ailp->xa_target) <=0 ) && !ailp->xa_pending_wake))return ;/*
@@ -587,7 +587,7 @@ xfs_ail_push(xfs_trans_ail_copy_lsn (ailp, &ailp->xa_target, &threshold_lsn);smp_wmb (); -wake_up_process (ailp->xa_task); + ailp->xa_pending_wake = !wake_up_process (ailp->xa_task); }/*
fs/xfs/xfs_trans_priv.h +1 -0
@@ -70,6 +70,7 @@ struct xfs_ail {struct list_head xa_cursors;spinlock_t xa_lock;xfs_lsn_t xa_last_pushed_lsn; +int xa_pending_wake; };/*
Signature · 6 lines
1.7.7.6 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [RFC PATCH 3/3] xfs: fix xfsaild hang due to lost wake ups
Quoted 38 lines · Brian Foster
Running xfstests 273 in a loop reproduces an XFS lockup due to xfsaild entering idle mode indefinitely. The following high-level sequence of events leads to the hang:
- xfsaild is running with a cached target lsn
-xfs_ail_push()is invoked, updatesailp->xa_target_lsnand invokeswake_up_process().wake_up_process()returns 0 because xfsaild is already running.
- xfsaild enters idle mode having met its current target.Once in the described state,
xfs_ail_push()is invoked many more times with the already setthreshold_lsn, but these calls do not lead towake_up_process()calls because no further invocations result in moving thethreshold_lsnforward. Add a flag toxfs_ailto capture whether an issued wake actually succeeds. If not, continue issuing wakes until we know one has been successful for the current target.Signed-off-by Brian Foster <[email protected]>--- fs/xfs/xfs_trans_ail.c | 4 ++-- fs/xfs/xfs_trans_priv.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)fs/xfs/xfs_trans_ail.c +1
-1@@ -576,7 +576,7 @@ xfs_ail_push( lip =xfs_ail_min (ailp);if (!lip ||XFS_FORCED_SHUTDOWN (ailp->xa_mount) || -XFS_LSN_CMP (threshold_lsn, ailp->xa_target) <=0 ) + ((XFS_LSN_CMP (threshold_lsn, ailp->xa_target) <=0 ) && !ailp->xa_pending_wake))return ;/*
fs/xfs/xfs_trans_ail.c xfs_ail_push( · line 590
Quoted 5 lines
fs/xfs/xfs_trans_ail.c +1
-1@@ -587,7 +587,7 @@ xfs_ail_push(xfs_trans_ail_copy_lsn (ailp, &ailp->xa_target, &threshold_lsn);smp_wmb (); -wake_up_process (ailp->xa_task); + ailp->xa_pending_wake = !wake_up_process (ailp->xa_task);
That means xa_pending_wake is true when the aild is already running.
Which means that the above check for !ailp->xa_pending_wake mean that we don't try a wakeup when the aild is not running. Is that what you meant?
As it is, i don't think this is really all that sane - it has no locking, so is going to be racy, and is really just working around problems where the xfsaild goes to sleep without having completed it's work. So if this patch is necessary, it is just papering over a problem in the logic in the xfsaild where it is idling instead of sleeping for a short time and starting again....
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs