All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: cem@kernel.org
To: linux-xfs@vger.kernel.org
Cc: djwong@kernel.org, hch@lst.de
Subject: [PATCH 15/67] xfs: don't append work items to logged xfs_defer_pending objects
Date: Mon, 22 Apr 2024 18:25:37 +0200	[thread overview]
Message-ID: <20240422163832.858420-17-cem@kernel.org> (raw)
In-Reply-To: <20240422163832.858420-2-cem@kernel.org>

From: "Darrick J. Wong" <djwong@kernel.org>

Source kernel commit: 6b126139401a2284402d7c38fe3168d5a26da41d

When someone tries to add a deferred work item to xfs_defer_add, it will
try to attach the work item to the most recently added xfs_defer_pending
object attached to the transaction.  However, it doesn't check if the
pending object has a log intent item attached to it.  This is incorrect
behavior because we cannot add more work to an object that has already
been committed to the ondisk log.

Therefore, change the behavior not to append to pending items with a non
null dfp_intent.  In practice this has not been an issue because the
only way xfs_defer_add gets called after log intent items have been
the @dop_pending isolation in xfs_defer_finish_noroll protects the
pending items that have already been logged.

However, the next patch will add the ability to pause a deferred extent
free object during online btree rebuilding, and any new extfree work
items need to have their own pending event.

While we're at it, hoist the predicate to its own static inline function
for readability.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
---
 libxfs/xfs_defer.c | 61 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 48 insertions(+), 13 deletions(-)

diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c
index 722ff6a77..200d1b300 100644
--- a/libxfs/xfs_defer.c
+++ b/libxfs/xfs_defer.c
@@ -689,6 +689,51 @@ xfs_defer_cancel(
 	xfs_defer_cancel_list(mp, &tp->t_dfops);
 }
 
+/*
+ * Return the last pending work item attached to this transaction if it matches
+ * the deferred op type.
+ */
+static inline struct xfs_defer_pending *
+xfs_defer_find_last(
+	struct xfs_trans		*tp,
+	enum xfs_defer_ops_type		type,
+	const struct xfs_defer_op_type	*ops)
+{
+	struct xfs_defer_pending	*dfp = NULL;
+
+	/* No dfops at all? */
+	if (list_empty(&tp->t_dfops))
+		return NULL;
+
+	dfp = list_last_entry(&tp->t_dfops, struct xfs_defer_pending,
+			dfp_list);
+
+	/* Wrong type? */
+	if (dfp->dfp_type != type)
+		return NULL;
+	return dfp;
+}
+
+/*
+ * Decide if we can add a deferred work item to the last dfops item attached
+ * to the transaction.
+ */
+static inline bool
+xfs_defer_can_append(
+	struct xfs_defer_pending	*dfp,
+	const struct xfs_defer_op_type	*ops)
+{
+	/* Already logged? */
+	if (dfp->dfp_intent)
+		return false;
+
+	/* Already full? */
+	if (ops->max_items && dfp->dfp_count >= ops->max_items)
+		return false;
+
+	return true;
+}
+
 /* Add an item for later deferred processing. */
 void
 xfs_defer_add(
@@ -702,19 +747,9 @@ xfs_defer_add(
 	ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
 	BUILD_BUG_ON(ARRAY_SIZE(defer_op_types) != XFS_DEFER_OPS_TYPE_MAX);
 
-	/*
-	 * Add the item to a pending item at the end of the intake list.
-	 * If the last pending item has the same type, reuse it.  Else,
-	 * create a new pending item at the end of the intake list.
-	 */
-	if (!list_empty(&tp->t_dfops)) {
-		dfp = list_last_entry(&tp->t_dfops,
-				struct xfs_defer_pending, dfp_list);
-		if (dfp->dfp_type != type ||
-		    (ops->max_items && dfp->dfp_count >= ops->max_items))
-			dfp = NULL;
-	}
-	if (!dfp) {
+	dfp = xfs_defer_find_last(tp, type, ops);
+	if (!dfp || !xfs_defer_can_append(dfp, ops)) {
+		/* Create a new pending item at the end of the intake list. */
 		dfp = kmem_cache_zalloc(xfs_defer_pending_cache,
 				GFP_NOFS | __GFP_NOFAIL);
 		dfp->dfp_type = type;
-- 
2.44.0


  parent reply	other threads:[~2024-04-22 16:39 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-22 16:25 [PATCH 00/67] libxfs: Sync to Linux 6.8 cem
2024-04-22 16:25 ` [PATCH 01/67] xfs: use xfs_defer_pending objects to recover intent items cem
2024-04-22 16:25 ` [PATCH 02/67] xfs: recreate work items when recovering " cem
2024-04-22 16:25 ` [PATCH 03/67] xfs: use xfs_defer_finish_one to finish recovered work items cem
2024-04-22 16:25 ` [PATCH 04/67] xfs: move ->iop_recover to xfs_defer_op_type cem
2024-04-22 16:25 ` [PATCH 05/67] xfs: hoist intent done flag setting to ->finish_item callsite cem
2024-04-22 16:25 ` [PATCH 06/67] xfs: hoist ->create_intent boilerplate to its callsite cem
2024-04-22 16:25 ` [PATCH 07/67] xfs: use xfs_defer_create_done for the relogging operation cem
2024-04-22 16:25 ` [PATCH 08/67] xfs: clean out XFS_LI_DIRTY setting boilerplate from ->iop_relog cem
2024-04-22 16:25 ` [PATCH 09/67] xfs: hoist xfs_trans_add_item calls to defer ops functions cem
2024-04-22 16:25 ` [PATCH 10/67] xfs: move ->iop_relog to struct xfs_defer_op_type cem
2024-04-22 16:25 ` [PATCH 11/67] xfs: make rextslog computation consistent with mkfs cem
2024-04-22 16:25 ` [PATCH 12/67] xfs: fix 32-bit truncation in xfs_compute_rextslog cem
2024-04-22 16:25 ` [PATCH 13/67] xfs: don't allow overly small or large realtime volumes cem
2024-04-22 16:25 ` [PATCH 14/67] xfs: elide ->create_done calls for unlogged deferred work cem
2024-04-22 16:25 ` cem [this message]
2024-04-22 16:25 ` [PATCH 16/67] xfs: allow pausing of pending deferred work items cem
2024-04-22 16:25 ` [PATCH 17/67] xfs: remove __xfs_free_extent_later cem
2024-04-22 16:25 ` [PATCH 18/67] xfs: automatic freeing of freshly allocated unwritten space cem
2024-04-22 16:25 ` [PATCH 19/67] xfs: remove unused fields from struct xbtree_ifakeroot cem
2024-04-22 16:25 ` [PATCH 20/67] xfs: force small EFIs for reaping btree extents cem
2024-04-22 16:25 ` [PATCH 21/67] xfs: ensure logflagsp is initialized in xfs_bmap_del_extent_real cem
2024-04-22 16:25 ` [PATCH 22/67] xfs: update dir3 leaf block metadata after swap cem
2024-04-22 16:25 ` [PATCH 23/67] xfs: extract xfs_da_buf_copy() helper function cem
2024-04-22 16:25 ` [PATCH 24/67] xfs: move xfs_ondisk.h to libxfs/ cem
2024-04-22 16:25 ` [PATCH 25/67] xfs: consolidate the xfs_attr_defer_* helpers cem
2024-04-22 16:25 ` [PATCH 26/67] xfs: store an ops pointer in struct xfs_defer_pending cem
2024-04-22 16:25 ` [PATCH 27/67] xfs: pass the defer ops instead of type to xfs_defer_start_recovery cem
2024-04-22 16:25 ` [PATCH 28/67] xfs: pass the defer ops directly to xfs_defer_add cem
2024-04-22 16:25 ` [PATCH 29/67] xfs: force all buffers to be written during btree bulk load cem
2024-04-22 16:25 ` [PATCH 30/67] xfs: set XBF_DONE on newly formatted btree block that are ready for writing cem
2024-04-22 16:25 ` [PATCH 31/67] xfs: read leaf blocks when computing keys for bulkloading into node blocks cem
2024-04-22 16:25 ` [PATCH 32/67] xfs: move btree bulkload record initialization to ->get_record implementations cem
2024-04-22 16:25 ` [PATCH 33/67] xfs: constrain dirty buffers while formatting a staged btree cem
2024-04-22 16:25 ` [PATCH 34/67] xfs: repair free space btrees cem
2024-04-22 16:25 ` [PATCH 35/67] xfs: repair inode btrees cem
2024-04-22 16:25 ` [PATCH 36/67] xfs: repair refcount btrees cem
2024-04-22 16:25 ` [PATCH 37/67] xfs: dont cast to char * for XFS_DFORK_*PTR macros cem
2024-04-22 16:26 ` [PATCH 38/67] xfs: set inode sick state flags when we zap either ondisk fork cem
2024-04-22 16:26 ` [PATCH 39/67] xfs: zap broken inode forks cem
2024-04-22 16:26 ` [PATCH 40/67] xfs: repair inode fork block mapping data structures cem
2024-04-22 16:26 ` [PATCH 41/67] xfs: create a ranged query function for refcount btrees cem
2024-04-22 16:26 ` [PATCH 42/67] xfs: create a new inode fork block unmap helper cem
2024-04-22 16:26 ` [PATCH 43/67] xfs: improve dquot iteration for scrub cem
2024-04-22 16:26 ` [PATCH 44/67] xfs: add lock protection when remove perag from radix tree cem
2024-04-22 16:26 ` [PATCH 45/67] xfs: fix perag leak when growfs fails cem
2024-04-22 16:26 ` [PATCH 46/67] xfs: remove the xfs_alloc_arg argument to xfs_bmap_btalloc_accounting cem
2024-04-22 16:26 ` [PATCH 47/67] xfs: also use xfs_bmap_btalloc_accounting for RT allocations cem
2024-04-22 16:26 ` [PATCH 48/67] xfs: return -ENOSPC from xfs_rtallocate_* cem
2024-04-22 16:26 ` [PATCH 49/67] xfs: indicate if xfs_bmap_adjacent changed ap->blkno cem
2024-04-22 16:26 ` [PATCH 50/67] xfs: move xfs_rtget_summary to xfs_rtbitmap.c cem
2024-04-22 16:26 ` [PATCH 51/67] xfs: split xfs_rtmodify_summary_int cem
2024-04-22 16:26 ` [PATCH 52/67] xfs: remove rt-wrappers from xfs_format.h cem
2024-04-22 16:26 ` [PATCH 53/67] xfs: remove XFS_RTMIN/XFS_RTMAX cem
2024-04-22 16:26 ` [PATCH 54/67] xfs: make if_data a void pointer cem
2024-04-22 16:26 ` [PATCH 55/67] xfs: return if_data from xfs_idata_realloc cem
2024-04-22 16:26 ` [PATCH 56/67] xfs: move the xfs_attr_sf_lookup tracepoint cem
2024-04-22 16:26 ` [PATCH 57/67] xfs: simplify xfs_attr_sf_findname cem
2024-04-22 16:26 ` [PATCH 58/67] xfs: remove xfs_attr_shortform_lookup cem
2024-04-22 16:26 ` [PATCH 59/67] xfs: use xfs_attr_sf_findname in xfs_attr_shortform_getvalue cem
2024-04-22 16:26 ` [PATCH 60/67] xfs: remove struct xfs_attr_shortform cem
2024-04-22 16:26 ` [PATCH 61/67] xfs: remove xfs_attr_sf_hdr_t cem
2024-04-22 16:26 ` [PATCH 62/67] xfs: turn the XFS_DA_OP_REPLACE checks in xfs_attr_shortform_addname into asserts cem
2024-04-22 16:26 ` [PATCH 63/67] xfs: fix a use after free in xfs_defer_finish_recovery cem
2024-04-22 16:26 ` [PATCH 64/67] xfs: use the op name in trace_xlog_intent_recovery_failed cem
2024-04-22 16:26 ` [PATCH 65/67] xfs: fix backwards logic in xfs_bmap_alloc_account cem
2024-04-22 16:26 ` [PATCH 66/67] xfs: reset XFS_ATTR_INCOMPLETE filter on node removal cem
2024-04-22 16:26 ` [PATCH 67/67] xfs: remove conditional building of rt geometry validator functions cem
  -- strict thread matches above, loose matches on Subject: below --
2024-04-17 21:16 [PATCHSET 04/11] libxfs: sync with 6.8 Darrick J. Wong
2024-04-17 21:25 ` [PATCH 15/67] xfs: don't append work items to logged xfs_defer_pending objects Darrick J. Wong
2024-03-26  2:55 [PATCHSET 02/18] libxfs: sync with 6.8 Darrick J. Wong
2024-03-26  3:06 ` [PATCH 15/67] xfs: don't append work items to logged xfs_defer_pending objects Darrick J. Wong
2024-03-13  1:47 [PATCHSET 02/10] libxfs: sync with 6.8 Darrick J. Wong
2024-03-13  1:56 ` [PATCH 15/67] xfs: don't append work items to logged xfs_defer_pending objects Darrick J. Wong

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=20240422163832.858420-17-cem@kernel.org \
    --to=cem@kernel.org \
    --cc=djwong@kernel.org \
    --cc=hch@lst.de \
    --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.