All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH 5/8] xfs: track log space pinned by the AIL
Date: Fri,  8 Jul 2022 11:55:55 +1000	[thread overview]
Message-ID: <20220708015558.1134330-6-david@fromorbit.com> (raw)
In-Reply-To: <20220708015558.1134330-1-david@fromorbit.com>

From: Dave Chinner <dchinner@redhat.com>

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>
---
 fs/xfs/xfs_log_priv.h    | 1 +
 fs/xfs/xfs_log_recover.c | 2 ++
 fs/xfs/xfs_trans_ail.c   | 8 ++++++--
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/xfs/xfs_log_priv.h b/fs/xfs/xfs_log_priv.h
index 5f4358f18224..8a005cb08a02 100644
--- a/fs/xfs/xfs_log_priv.h
+++ b/fs/xfs/xfs_log_priv.h
@@ -435,6 +435,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;
 
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index b8e25da876d8..ba2d591a1437 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -1213,6 +1213,8 @@ xlog_set_state(
 		log->l_curr_cycle++;
 	atomic64_set(&log->l_tail_lsn, be64_to_cpu(rhead->h_tail_lsn));
 	log->l_ailp->ail_max_seen_lsn = be64_to_cpu(rhead->h_lsn);
+	WRITE_ONCE(log->l_tail_space, atomic64_read(&log->l_tail_lsn) -
+						log->l_ailp->ail_max_seen_lsn);
 	xlog_assign_grant_head(&log->l_reserve_head.grant, log->l_curr_cycle,
 					BBTOB(log->l_curr_block));
 	xlog_assign_grant_head(&log->l_write_head.grant, log->l_curr_cycle,
diff --git a/fs/xfs/xfs_trans_ail.c b/fs/xfs/xfs_trans_ail.c
index f0741c42130a..fd4aa9c4e914 100644
--- a/fs/xfs/xfs_trans_ail.c
+++ b/fs/xfs/xfs_trans_ail.c
@@ -728,6 +728,8 @@ xfs_ail_update_tail_lsn(
 	if (!tail_lsn)
 		tail_lsn = ailp->ail_max_seen_lsn;
 
+	WRITE_ONCE(log->l_tail_space,
+			xlog_lsn_sub(log, ailp->ail_max_seen_lsn, tail_lsn));
 	trace_xfs_log_assign_tail_lsn(log, tail_lsn);
 	atomic64_set(&log->l_tail_lsn, tail_lsn);
 }
@@ -735,7 +737,7 @@ xfs_ail_update_tail_lsn(
 /*
  * Callers should pass the 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
+ * needs to force a tail space update, it should pass NULLCOMMITLSN to bypass the
  * "did the tail LSN change?" checks.
  */
 void
@@ -822,8 +824,10 @@ xfs_trans_ail_update_bulk(
 	 * If this is the highest LSN we've seen in the AIL, update the tracking
 	 * so that we know what to set the tail to when the AIL is next emptied.
 	 */
-	if (XFS_LSN_CMP(lsn, ailp->ail_max_seen_lsn) > 0)
+	if (XFS_LSN_CMP(lsn, ailp->ail_max_seen_lsn) > 0) {
 		ailp->ail_max_seen_lsn = lsn;
+		tail_lsn = NULLCOMMITLSN;
+	}
 
 	/*
 	 * If this is the first insert, wake up the push daemon so it can
-- 
2.36.1


  parent reply	other threads:[~2022-07-08  1:56 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-08  1:55 [RFC] [PATCH 0/8] xfs: byte-base grant head reservation tracking Dave Chinner
2022-07-08  1:55 ` [PATCH 1/8] xfs: AIL doesn't need manual pushing Dave Chinner
2022-07-08  7:23   ` kernel test robot
2022-07-11  6:02   ` Christoph Hellwig
2022-07-11 23:40     ` Dave Chinner
2022-07-08  1:55 ` [PATCH 2/8] xfs: AIL targets log space, not grant space Dave Chinner
2022-07-11  6:04   ` Christoph Hellwig
2022-07-08  1:55 ` [PATCH 3/8] xfs: ensure log tail is always up to date Dave Chinner
2022-07-11  6:07   ` Christoph Hellwig
2022-07-11 23:42     ` Dave Chinner
2022-07-08  1:55 ` [PATCH 4/8] xfs: l_last_sync_lsn is really tracking AIL state Dave Chinner
2022-07-11  6:42   ` Christoph Hellwig
2022-07-11 23:47     ` Dave Chinner
2022-07-20  1:18   ` Dave Chinner
2022-07-08  1:55 ` Dave Chinner [this message]
2022-07-11  6:54   ` [PATCH 5/8] xfs: track log space pinned by the AIL Christoph Hellwig
2022-07-11 23:53     ` Dave Chinner
2022-07-08  1:55 ` [PATCH 6/8] xfs: pass the full grant head to accounting functions Dave Chinner
2022-07-08  1:55 ` [PATCH 7/8] xfs: move and xfs_trans_committed_bulk Dave Chinner
2022-07-08  7:54   ` kernel test robot
2022-07-08  9:15   ` kernel test robot
2022-07-11  6:12   ` Christoph Hellwig
2022-07-11 23:54     ` Dave Chinner
2022-07-08  1:55 ` [PATCH 8/8] xfs: grant heads track byte counts, not LSNs Dave Chinner
2022-07-11  6:59   ` Christoph Hellwig
2022-07-11 23:59     ` Dave Chinner
2022-07-12  8:28   ` [xfs] 65cf4eb83e: xfstests.xfs.011.fail kernel test robot
2022-07-12  8:28     ` kernel test robot
2022-07-12 22:24     ` Dave Chinner
2022-07-12 22:24       ` Dave Chinner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220708015558.1134330-6-david@fromorbit.com \
    --to=david@fromorbit.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.