Skip to content

Commit a07776a

Browse files
Dave ChinnerChandan Babu R
authored andcommitted
xfs: ensure log tail is always up to date
Whenever we write an iclog, we call xlog_assign_tail_lsn() to update the current tail before we write it into the iclog header. This means we have to take the AIL lock on every iclog write just to check if the tail of the log has moved. This doesn't avoid races with log tail updates - the log tail could move immediately after we assign the tail to the iclog header and hence by the time the iclog reaches stable storage the tail LSN has moved forward in memory. Hence the log tail LSN in the iclog header is really just a point in time snapshot of the current state of the AIL. With this in mind, if we simply update the in memory log->l_tail_lsn every time it changes in the AIL, there is no need to update the in memory value when we are writing it into an iclog - it will already be up-to-date in memory and checking the AIL again will not change this. Hence xlog_state_release_iclog() does not need to check the AIL to update the tail lsn and can just sample it directly without needing to take the AIL lock. Signed-off-by: Dave Chinner <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent b50b4c4 commit a07776a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

fs/xfs/xfs_log.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@ xlog_state_release_iclog(
530530
struct xlog_in_core *iclog,
531531
struct xlog_ticket *ticket)
532532
{
533-
xfs_lsn_t tail_lsn;
534533
bool last_ref;
535534

536535
lockdep_assert_held(&log->l_icloglock);
@@ -545,8 +544,8 @@ xlog_state_release_iclog(
545544
if ((iclog->ic_state == XLOG_STATE_WANT_SYNC ||
546545
(iclog->ic_flags & XLOG_ICL_NEED_FUA)) &&
547546
!iclog->ic_header.h_tail_lsn) {
548-
tail_lsn = xlog_assign_tail_lsn(log->l_mp);
549-
iclog->ic_header.h_tail_lsn = cpu_to_be64(tail_lsn);
547+
iclog->ic_header.h_tail_lsn =
548+
cpu_to_be64(atomic64_read(&log->l_tail_lsn));
550549
}
551550

552551
last_ref = atomic_dec_and_test(&iclog->ic_refcnt);

fs/xfs/xfs_trans_ail.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,13 @@ xfs_ail_push_all_sync(
720720
finish_wait(&ailp->ail_empty, &wait);
721721
}
722722

723+
/*
724+
* Callers should pass the original tail lsn so that we can detect if the tail
725+
* has moved as a result of the operation that was performed. If the caller
726+
* needs to force a tail LSN update, it should pass NULLCOMMITLSN to bypass the
727+
* "did the tail LSN change?" checks. If the caller wants to avoid a tail update
728+
* (e.g. it knows the tail did not change) it should pass an @old_lsn of 0.
729+
*/
723730
void
724731
xfs_ail_update_finish(
725732
struct xfs_ail *ailp,
@@ -804,10 +811,16 @@ xfs_trans_ail_update_bulk(
804811

805812
/*
806813
* If this is the first insert, wake up the push daemon so it can
807-
* actively scan for items to push.
814+
* actively scan for items to push. We also need to do a log tail
815+
* LSN update to ensure that it is correctly tracked by the log, so
816+
* set the tail_lsn to NULLCOMMITLSN so that xfs_ail_update_finish()
817+
* will see that the tail lsn has changed and will update the tail
818+
* appropriately.
808819
*/
809-
if (!mlip)
820+
if (!mlip) {
810821
wake_up_process(ailp->ail_task);
822+
tail_lsn = NULLCOMMITLSN;
823+
}
811824

812825
xfs_ail_update_finish(ailp, tail_lsn);
813826
}

0 commit comments

Comments
 (0)