Skip to content

Commit 14e15f1

Browse files
dgchinnerdjwong
authored andcommitted
xfs: push the grant head when the log head moves forward
When the log fills up, we can get into the state where the outstanding items in the CIL being committed and aggregated are larger than the range that the reservation grant head tail pushing will attempt to clean. This can result in the tail pushing range being trimmed back to the the log head (l_last_sync_lsn) and so may not actually move the push target at all. When the iclogs associated with the CIL commit finally land, the log head moves forward, and this removes the restriction on the AIL push target. However, if we already have transactions sleeping on the grant head, and there's nothing in the AIL still to flush from the current push target, then nothing will move the tail of the log and trigger a log reservation wakeup. Hence the there is nothing that will trigger xlog_grant_push_ail() to recalculate the AIL push target and start pushing on the AIL again to write back the metadata objects that pin the tail of the log and hence free up space and allow the transaction reservations to be woken and make progress. Hence we need to push on the grant head when we move the log head forward, as this may be the only trigger we have that can move the AIL push target forwards in this situation. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1 parent 0383f54 commit 14e15f1

1 file changed

Lines changed: 47 additions & 25 deletions

File tree

‎fs/xfs/xfs_log.c‎

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,6 +2650,46 @@ xlog_get_lowest_lsn(
26502650
return lowest_lsn;
26512651
}
26522652

2653+
/*
2654+
* Completion of a iclog IO does not imply that a transaction has completed, as
2655+
* transactions can be large enough to span many iclogs. We cannot change the
2656+
* tail of the log half way through a transaction as this may be the only
2657+
* transaction in the log and moving the tail to point to the middle of it
2658+
* will prevent recovery from finding the start of the transaction. Hence we
2659+
* should only update the last_sync_lsn if this iclog contains transaction
2660+
* completion callbacks on it.
2661+
*
2662+
* We have to do this before we drop the icloglock to ensure we are the only one
2663+
* that can update it.
2664+
*
2665+
* If we are moving the last_sync_lsn forwards, we also need to ensure we kick
2666+
* the reservation grant head pushing. This is due to the fact that the push
2667+
* target is bound by the current last_sync_lsn value. Hence if we have a large
2668+
* amount of log space bound up in this committing transaction then the
2669+
* last_sync_lsn value may be the limiting factor preventing tail pushing from
2670+
* freeing space in the log. Hence once we've updated the last_sync_lsn we
2671+
* should push the AIL to ensure the push target (and hence the grant head) is
2672+
* no longer bound by the old log head location and can move forwards and make
2673+
* progress again.
2674+
*/
2675+
static void
2676+
xlog_state_set_callback(
2677+
struct xlog *log,
2678+
struct xlog_in_core *iclog,
2679+
xfs_lsn_t header_lsn)
2680+
{
2681+
iclog->ic_state = XLOG_STATE_CALLBACK;
2682+
2683+
ASSERT(XFS_LSN_CMP(atomic64_read(&log->l_last_sync_lsn),
2684+
header_lsn) <= 0);
2685+
2686+
if (list_empty_careful(&iclog->ic_callbacks))
2687+
return;
2688+
2689+
atomic64_set(&log->l_last_sync_lsn, header_lsn);
2690+
xlog_grant_push_ail(log, 0);
2691+
}
2692+
26532693
/*
26542694
* Return true if we need to stop processing, false to continue to the next
26552695
* iclog. The caller will need to run callbacks if the iclog is returned in the
@@ -2663,6 +2703,7 @@ xlog_state_iodone_process_iclog(
26632703
bool *ioerror)
26642704
{
26652705
xfs_lsn_t lowest_lsn;
2706+
xfs_lsn_t header_lsn;
26662707

26672708
/* Skip all iclogs in the ACTIVE & DIRTY states */
26682709
if (iclog->ic_state & (XLOG_STATE_ACTIVE | XLOG_STATE_DIRTY))
@@ -2702,34 +2743,15 @@ xlog_state_iodone_process_iclog(
27022743
* callbacks) see the above if.
27032744
*
27042745
* We will do one more check here to see if we have chased our tail
2705-
* around.
2746+
* around. If this is not the lowest lsn iclog, then we will leave it
2747+
* for another completion to process.
27062748
*/
2749+
header_lsn = be64_to_cpu(iclog->ic_header.h_lsn);
27072750
lowest_lsn = xlog_get_lowest_lsn(log);
2708-
if (lowest_lsn &&
2709-
XFS_LSN_CMP(lowest_lsn, be64_to_cpu(iclog->ic_header.h_lsn)) < 0)
2710-
return false; /* Leave this iclog for another thread */
2711-
2712-
iclog->ic_state = XLOG_STATE_CALLBACK;
2713-
2714-
/*
2715-
* Completion of a iclog IO does not imply that a transaction has
2716-
* completed, as transactions can be large enough to span many iclogs.
2717-
* We cannot change the tail of the log half way through a transaction
2718-
* as this may be the only transaction in the log and moving th etail to
2719-
* point to the middle of it will prevent recovery from finding the
2720-
* start of the transaction. Hence we should only update the
2721-
* last_sync_lsn if this iclog contains transaction completion callbacks
2722-
* on it.
2723-
*
2724-
* We have to do this before we drop the icloglock to ensure we are the
2725-
* only one that can update it.
2726-
*/
2727-
ASSERT(XFS_LSN_CMP(atomic64_read(&log->l_last_sync_lsn),
2728-
be64_to_cpu(iclog->ic_header.h_lsn)) <= 0);
2729-
if (!list_empty_careful(&iclog->ic_callbacks))
2730-
atomic64_set(&log->l_last_sync_lsn,
2731-
be64_to_cpu(iclog->ic_header.h_lsn));
2751+
if (lowest_lsn && XFS_LSN_CMP(lowest_lsn, header_lsn) < 0)
2752+
return false;
27322753

2754+
xlog_state_set_callback(log, iclog, header_lsn);
27332755
return false;
27342756

27352757
}

0 commit comments

Comments
 (0)