Skip to content

Commit 8191d82

Browse files
Dave ChinnerDarrick J. Wong
authored andcommitted
xfs: avoid unnecessary waits in xfs_log_force_lsn()
Before waiting on a iclog in xfs_log_force_lsn(), we don't check to see if the iclog has already been completed and the contents on stable storage. We check for completed iclogs in xfs_log_force(), so we should do the same thing for xfs_log_force_lsn(). This fixed some random up-to-30s pauses seen in unmounting filesystems in some tests. A log force ends up waiting on completed iclog, and that doesn't then get flushed (and hence the log force get completed) until the background log worker issues a log force that flushes the iclog in question. Then the unmount unblocks and continues. Signed-off-by: Dave Chinner <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 2bf1ec0 commit 8191d82

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

fs/xfs/xfs_log.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3143,6 +3143,35 @@ xlog_state_switch_iclogs(
31433143
log->l_iclog = iclog->ic_next;
31443144
}
31453145

3146+
/*
3147+
* Force the iclog to disk and check if the iclog has been completed before
3148+
* xlog_force_iclog() returns. This can happen on synchronous (e.g.
3149+
* pmem) or fast async storage because we drop the icloglock to issue the IO.
3150+
* If completion has already occurred, tell the caller so that it can avoid an
3151+
* unnecessary wait on the iclog.
3152+
*/
3153+
static int
3154+
xlog_force_and_check_iclog(
3155+
struct xlog_in_core *iclog,
3156+
bool *completed)
3157+
{
3158+
xfs_lsn_t lsn = be64_to_cpu(iclog->ic_header.h_lsn);
3159+
int error;
3160+
3161+
*completed = false;
3162+
error = xlog_force_iclog(iclog);
3163+
if (error)
3164+
return error;
3165+
3166+
/*
3167+
* If the iclog has already been completed and reused the header LSN
3168+
* will have been rewritten by completion
3169+
*/
3170+
if (be64_to_cpu(iclog->ic_header.h_lsn) != lsn)
3171+
*completed = true;
3172+
return 0;
3173+
}
3174+
31463175
/*
31473176
* Write out all data in the in-core log as of this exact moment in time.
31483177
*
@@ -3177,7 +3206,6 @@ xfs_log_force(
31773206
{
31783207
struct xlog *log = mp->m_log;
31793208
struct xlog_in_core *iclog;
3180-
xfs_lsn_t lsn;
31813209

31823210
XFS_STATS_INC(mp, xs_log_force);
31833211
trace_xfs_log_force(mp, 0, _RET_IP_);
@@ -3206,11 +3234,12 @@ xfs_log_force(
32063234
} else if (iclog->ic_state == XLOG_STATE_ACTIVE) {
32073235
if (atomic_read(&iclog->ic_refcnt) == 0) {
32083236
/* We have exclusive access to this iclog. */
3209-
lsn = be64_to_cpu(iclog->ic_header.h_lsn);
3210-
if (xlog_force_iclog(iclog))
3237+
bool completed;
3238+
3239+
if (xlog_force_and_check_iclog(iclog, &completed))
32113240
goto out_error;
32123241

3213-
if (be64_to_cpu(iclog->ic_header.h_lsn) != lsn)
3242+
if (completed)
32143243
goto out_unlock;
32153244
} else {
32163245
/*
@@ -3250,6 +3279,7 @@ xlog_force_lsn(
32503279
bool already_slept)
32513280
{
32523281
struct xlog_in_core *iclog;
3282+
bool completed;
32533283

32543284
spin_lock(&log->l_icloglock);
32553285
iclog = log->l_iclog;
@@ -3287,10 +3317,12 @@ xlog_force_lsn(
32873317
&log->l_icloglock);
32883318
return -EAGAIN;
32893319
}
3290-
if (xlog_force_iclog(iclog))
3320+
if (xlog_force_and_check_iclog(iclog, &completed))
32913321
goto out_error;
32923322
if (log_flushed)
32933323
*log_flushed = 1;
3324+
if (completed)
3325+
goto out_unlock;
32943326
break;
32953327
case XLOG_STATE_WANT_SYNC:
32963328
/*

0 commit comments

Comments
 (0)