Commit 7cac6094 authored by Yuto Ohnuki's avatar Yuto Ohnuki Committed by Carlos Maiolino
Browse files

xfs: refactor xfsaild_push loop into helper



Factor the loop body of xfsaild_push() into a separate
xfsaild_process_logitem() helper to improve readability.

This is a pure code movement with no functional change.

Signed-off-by: default avatarYuto Ohnuki <ytohnuki@amazon.com>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarCarlos Maiolino <cem@kernel.org>
parent 394d70b8
Loading
Loading
Loading
Loading
+69 −58
Original line number Diff line number Diff line
@@ -464,60 +464,18 @@ xfs_ail_calc_push_target(
	return target_lsn;
}

static long
xfsaild_push(
	struct xfs_ail		*ailp)
static void
xfsaild_process_logitem(
	struct xfs_ail		*ailp,
	struct xfs_log_item	*lip,
	int			*stuck,
	int			*flushing)
{
	struct xfs_mount	*mp = ailp->ail_log->l_mp;
	struct xfs_ail_cursor	cur;
	struct xfs_log_item	*lip;
	xfs_lsn_t		lsn;
	long			tout;
	int			stuck = 0;
	int			flushing = 0;
	int			count = 0;

	/*
	 * If we encountered pinned items or did not finish writing out all
	 * buffers the last time we ran, force a background CIL push to get the
	 * items unpinned in the near future. We do not wait on the CIL push as
	 * that could stall us for seconds if there is enough background IO
	 * load. Stalling for that long when the tail of the log is pinned and
	 * needs flushing will hard stop the transaction subsystem when log
	 * space runs out.
	 */
	if (ailp->ail_log_flush && ailp->ail_last_pushed_lsn == 0 &&
	    (!list_empty_careful(&ailp->ail_buf_list) ||
	     xfs_ail_min_lsn(ailp))) {
		ailp->ail_log_flush = 0;

		XFS_STATS_INC(mp, xs_push_ail_flush);
		xlog_cil_flush(ailp->ail_log);
	}

	spin_lock(&ailp->ail_lock);
	WRITE_ONCE(ailp->ail_target, xfs_ail_calc_push_target(ailp));
	if (ailp->ail_target == NULLCOMMITLSN)
		goto out_done;

	/* we're done if the AIL is empty or our push has reached the end */
	lip = xfs_trans_ail_cursor_first(ailp, &cur, ailp->ail_last_pushed_lsn);
	if (!lip)
		goto out_done_cursor;

	XFS_STATS_INC(mp, xs_push_ail);

	ASSERT(ailp->ail_target != NULLCOMMITLSN);

	lsn = lip->li_lsn;
	while ((XFS_LSN_CMP(lip->li_lsn, ailp->ail_target) <= 0)) {
		int		lock_result;
	uint			type = lip->li_type;
	unsigned long		flags = lip->li_flags;
	xfs_lsn_t		item_lsn = lip->li_lsn;

		if (test_bit(XFS_LI_FLUSHING, &lip->li_flags))
			goto next_item;
	int			lock_result;

	/*
	 * Note that iop_push may unlock and reacquire the AIL lock. We
@@ -551,7 +509,7 @@ xfsaild_push(
		XFS_STATS_INC(mp, xs_push_ail_flushing);
		trace_xfs_ail_flushing(ailp, type, flags, item_lsn);

			flushing++;
		(*flushing)++;
		ailp->ail_last_pushed_lsn = item_lsn;
		break;

@@ -559,20 +517,73 @@ xfsaild_push(
		XFS_STATS_INC(mp, xs_push_ail_pinned);
		trace_xfs_ail_pinned(ailp, type, flags, item_lsn);

			stuck++;
		(*stuck)++;
		ailp->ail_log_flush++;
		break;
	case XFS_ITEM_LOCKED:
		XFS_STATS_INC(mp, xs_push_ail_locked);
		trace_xfs_ail_locked(ailp, type, flags, item_lsn);

			stuck++;
		(*stuck)++;
		break;
	default:
		ASSERT(0);
		break;
	}
}

static long
xfsaild_push(
	struct xfs_ail		*ailp)
{
	struct xfs_mount	*mp = ailp->ail_log->l_mp;
	struct xfs_ail_cursor	cur;
	struct xfs_log_item	*lip;
	xfs_lsn_t		lsn;
	long			tout;
	int			stuck = 0;
	int			flushing = 0;
	int			count = 0;

	/*
	 * If we encountered pinned items or did not finish writing out all
	 * buffers the last time we ran, force a background CIL push to get the
	 * items unpinned in the near future. We do not wait on the CIL push as
	 * that could stall us for seconds if there is enough background IO
	 * load. Stalling for that long when the tail of the log is pinned and
	 * needs flushing will hard stop the transaction subsystem when log
	 * space runs out.
	 */
	if (ailp->ail_log_flush && ailp->ail_last_pushed_lsn == 0 &&
	    (!list_empty_careful(&ailp->ail_buf_list) ||
	     xfs_ail_min_lsn(ailp))) {
		ailp->ail_log_flush = 0;

		XFS_STATS_INC(mp, xs_push_ail_flush);
		xlog_cil_flush(ailp->ail_log);
	}

	spin_lock(&ailp->ail_lock);
	WRITE_ONCE(ailp->ail_target, xfs_ail_calc_push_target(ailp));
	if (ailp->ail_target == NULLCOMMITLSN)
		goto out_done;

	/* we're done if the AIL is empty or our push has reached the end */
	lip = xfs_trans_ail_cursor_first(ailp, &cur, ailp->ail_last_pushed_lsn);
	if (!lip)
		goto out_done_cursor;

	XFS_STATS_INC(mp, xs_push_ail);

	ASSERT(ailp->ail_target != NULLCOMMITLSN);

	lsn = lip->li_lsn;
	while ((XFS_LSN_CMP(lip->li_lsn, ailp->ail_target) <= 0)) {

		if (test_bit(XFS_LI_FLUSHING, &lip->li_flags))
			goto next_item;

		xfsaild_process_logitem(ailp, lip, &stuck, &flushing);
		count++;

		/*