]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: track log space pinned by the AIL
authorDave Chinner <dchinner@redhat.com>
Thu, 20 Jun 2024 07:21:25 +0000 (09:21 +0200)
committerChandan Babu R <chandanbabu@kernel.org>
Thu, 4 Jul 2024 07:16:46 +0000 (12:46 +0530)
Currently we track space used in the log by grant heads.
These store the reserved space as a physical log location and
combine both space reserved for future use with space already used in
the log in a single variable. The amount of space consumed in the
log is then calculated as the  distance between the log tail and
the grant head.

The problem with tracking the grant head as a physical location
comes from the fact that it tracks both log cycle count and offset
into the log in bytes in a single 64 bit variable. because the cycle
count on disk is a 32 bit number, this also limits the offset into
the log to 32 bits. ANd because that is in bytes, we are limited to
being able to track only 2GB of log space in the grant head.

Hence to support larger physical logs, we need to track used space
differently in the grant head. We no longer use the grant head for
guiding AIL pushing, so the only thing it is now used for is
determining if we've run out of reservation space via the
calculation in xlog_space_left().

What we really need to do is move the grant heads away from tracking
physical space in the log. The issue here is that space consumed in
the log is not directly tracked by the current mechanism - the
space consumed in the log by grant head reservations gets returned
to the free pool by the tail of the log moving forward. i.e. the
space isn't directly tracked or calculated, but the used grant space
gets "freed" as the physical limits of the log are updated without
actually needing to update the grant heads.

Hence to move away from implicit, zero-update log space tracking we
need to explicitly track the amount of physical space the log
actually consumes separately to the in-memory reservations for
operations that will be committed to the journal. Luckily, we
already track the information we need to calculate this in the AIL
itself.

That is, the space currently consumed by the journal is the maximum
LSN that the AIL has seen minus the current log tail. As we update
both of these items dynamically as the head and tail of the log
moves, we always know exactly how much space the journal consumes.

This means that we also know exactly how much space the currently
active reservations require, and exactly how much free space we have
remaining for new reservations to be made. Most importantly, we know
what these spaces are indepedently of the physical locations of
the head and tail of the log.

Hence by separating out the physical space consumed by the journal,
we can now track reservations in the grant heads purely as a byte
count, and the log can be considered full when the tail space +
reservation space exceeds the size of the log. This means we can use
the full 64 bits of grant head space for reservation space,
completely removing the 32 bit byte count limitation on log size
that they impose.

Hence the first step in this conversion is to track and update the
"log tail space" every time the AIL tail or maximum seen LSN
changes.

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>
fs/xfs/xfs_log_cil.c
fs/xfs/xfs_log_priv.h
fs/xfs/xfs_trans_ail.c

index 482955f1fa1f9f5c5cd2663854f8a81c4fcc41b5..92ccac7f905448d1b0e3645432e6e7a6b5980fcb 100644 (file)
@@ -772,14 +772,17 @@ xlog_cil_ail_insert(
         * always be the same (as iclogs can contain multiple commit records) or
         * higher LSN than the current head. We do this before insertion of the
         * items so that log space checks during insertion will reflect the
-        * space that this checkpoint has already consumed.
+        * space that this checkpoint has already consumed.  We call
+        * xfs_ail_update_finish() so that tail space and space-based wakeups
+        * will be recalculated appropriately.
         */
        ASSERT(XFS_LSN_CMP(ctx->commit_lsn, ailp->ail_head_lsn) >= 0 ||
                        aborted);
        spin_lock(&ailp->ail_lock);
-       ailp->ail_head_lsn = ctx->commit_lsn;
        xfs_trans_ail_cursor_last(ailp, &cur, ctx->start_lsn);
-       spin_unlock(&ailp->ail_lock);
+       ailp->ail_head_lsn = ctx->commit_lsn;
+       /* xfs_ail_update_finish() drops the ail_lock */
+       xfs_ail_update_finish(ailp, NULLCOMMITLSN);
 
        /* unpin all the log items */
        list_for_each_entry(lv, &ctx->lv_chain, lv_list) {
index 4b8ef926044599cd25a7792520bdbe7c34e69475..2896745989795d89f0261e5756ffc6da6c9412d4 100644 (file)
@@ -440,6 +440,7 @@ struct xlog {
 
        struct xlog_grant_head  l_reserve_head;
        struct xlog_grant_head  l_write_head;
+       uint64_t                l_tail_space;
 
        struct xfs_kobj         l_kobj;
 
index 5f03f82c46838e79948099b8f191c4fcc3e70d56..6a106a05fae01795d62ae1a70c4fe5d08e91d0e9 100644 (file)
@@ -736,6 +736,8 @@ __xfs_ail_assign_tail_lsn(
        if (!tail_lsn)
                tail_lsn = ailp->ail_head_lsn;
 
+       WRITE_ONCE(log->l_tail_space,
+                       xlog_lsn_sub(log, ailp->ail_head_lsn, tail_lsn));
        trace_xfs_log_assign_tail_lsn(log, tail_lsn);
        atomic64_set(&log->l_tail_lsn, tail_lsn);
 }
@@ -743,9 +745,10 @@ __xfs_ail_assign_tail_lsn(
 /*
  * 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.
+ * needs to force a tail space 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(