summaryrefslogtreecommitdiff
path: root/fs/xfs/xfs_trans_ail.c
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2024-06-20 09:21:22 +0200
committerChandan Babu R <chandanbabu@kernel.org>2024-07-04 12:46:46 +0530
commita07776ab814d432190a902c2c3fac867c4e76934 (patch)
tree5e9e3efeb7d06edc6a4ba703a0f0fafe4a5e3743 /fs/xfs/xfs_trans_ail.c
parentb50b4c49d8d79af05ac3bb3587f58589713139cc (diff)
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 <dchinner@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Diffstat (limited to 'fs/xfs/xfs_trans_ail.c')
-rw-r--r--fs/xfs/xfs_trans_ail.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/fs/xfs/xfs_trans_ail.c b/fs/xfs/xfs_trans_ail.c
index 26d4d9b3e357..7d6ccd21aae2 100644
--- a/fs/xfs/xfs_trans_ail.c
+++ b/fs/xfs/xfs_trans_ail.c
@@ -720,6 +720,13 @@ xfs_ail_push_all_sync(
finish_wait(&ailp->ail_empty, &wait);
}
+/*
+ * Callers should pass the original tail lsn so that we can detect if the tail
+ * has moved as a result of the operation that was performed. If the caller
+ * needs to force a tail LSN update, it should pass NULLCOMMITLSN to bypass the
+ * "did the tail LSN change?" checks. If the caller wants to avoid a tail update
+ * (e.g. it knows the tail did not change) it should pass an @old_lsn of 0.
+ */
void
xfs_ail_update_finish(
struct xfs_ail *ailp,
@@ -804,10 +811,16 @@ xfs_trans_ail_update_bulk(
/*
* If this is the first insert, wake up the push daemon so it can
- * actively scan for items to push.
+ * actively scan for items to push. We also need to do a log tail
+ * LSN update to ensure that it is correctly tracked by the log, so
+ * set the tail_lsn to NULLCOMMITLSN so that xfs_ail_update_finish()
+ * will see that the tail lsn has changed and will update the tail
+ * appropriately.
*/
- if (!mlip)
+ if (!mlip) {
wake_up_process(ailp->ail_task);
+ tail_lsn = NULLCOMMITLSN;
+ }
xfs_ail_update_finish(ailp, tail_lsn);
}