]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: defer agfl block frees when dfops is available
authorBrian Foster <bfoster@redhat.com>
Thu, 28 Jun 2018 20:11:55 +0000 (15:11 -0500)
committerEric Sandeen <sandeen@redhat.com>
Thu, 28 Jun 2018 20:11:55 +0000 (15:11 -0500)
Source kernel commit: f8f2835a9cf300079835e1adb1d90f85033be04c

The AGFL fixup code executes before every block allocation/free and
rectifies the AGFL based on the current, dynamic allocation
requirements of the fs. The AGFL must hold a minimum number of
blocks to satisfy a worst case split of the free space btrees caused
by the impending allocation operation. The AGFL is also updated to
maintain the implicit requirement for a minimum number of free slots
to satisfy a worst case join of the free space btrees.

Since the AGFL caches individual blocks, AGFL reduction typically
involves multiple, single block frees. We've had reports of
transaction overrun problems during certain workloads that boil down
to AGFL reduction freeing multiple blocks and consuming more space
in the log than was reserved for the transaction.

Since the objective of freeing AGFL blocks is to ensure free AGFL
free slots are available for the upcoming allocation, one way to
address this problem is to release surplus blocks from the AGFL
immediately but defer the free of those blocks (similar to how
file-mapped blocks are unmapped from the file in one transaction and
freed via a deferred operation) until the transaction is rolled.
This turns AGFL reduction into an operation with predictable log
reservation consumption.

Add the capability to defer AGFL block frees when a deferred ops
list is available to the AGFL fixup code. Add a dfops pointer to the
transaction to carry dfops through various contexts to the allocator
context. Deferring AGFL frees is  conditional behavior based on
whether the transaction pointer is populated. The long term
objective is to reuse the transaction pointer to clean up all
unrelated callchains that pass dfops on the stack along with a
transaction and in doing so, consistently defer AGFL blocks from the
allocator.

A bit of customization is required to handle deferred completion
processing because AGFL blocks are accounted against a per-ag
reservation pool and AGFL blocks are not inserted into the extent
busy list when freed (they are inserted when used and released back
to the AGFL). Reuse the majority of the existing deferred extent
free infrastructure and customize it appropriately to handle AGFL
blocks.

Note that this patch only adds infrastructure. It does not change
behavior because no callers have been updated to pass ->t_agfl_dfops
into the allocation code.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
include/xfs_trace.h
include/xfs_trans.h
libxfs/xfs_alloc.c
libxfs/xfs_defer.h

index becb2c5db46cbefd423398d075cad4d5c60f0f1c..7b9eb6ff4c92a8c13db8d47169292b4871fb2631 100644 (file)
@@ -19,7 +19,7 @@
 #define __TRACE_H__
 
 #define trace_xfs_agfl_reset(a,b,c,d)          ((void) 0)
-
+#define trace_xfs_agfl_free_defer(a,b,c,d,e)   ((void) 0)
 #define trace_xfs_alloc_exact_done(a)          ((void) 0)
 #define trace_xfs_alloc_exact_notfound(a)      ((void) 0)
 #define trace_xfs_alloc_exact_error(a)         ((void) 0)
index d76a3240133717cf6ef650e855ab1335608bb852..2a7d1edcbd8b7f7cd4f8d194fbd5be8ba7ac606a 100644 (file)
@@ -81,6 +81,8 @@ typedef struct xfs_trans {
        long            t_fdblocks_delta;       /* superblock fdblocks chg */
        long            t_frextents_delta;      /* superblock freextents chg */
        struct list_head        t_items;        /* first log item desc chunk */
+       struct xfs_defer_ops    *t_agfl_dfops;  /* optional agfl fixup dfops */
+
 } xfs_trans_t;
 
 void   xfs_trans_init(struct xfs_mount *);
index 79f94fbdbf9d392ff469b4955cdf518f05092e4f..b2108c3422854dca3fab28fa4821ea963d7aea3d 100644 (file)
@@ -35,6 +35,9 @@
 #include "xfs_trace.h"
 #include "xfs_trans.h"
 #include "xfs_ag_resv.h"
+#include "xfs_bmap.h"
+
+extern kmem_zone_t     *xfs_bmap_free_item_zone;
 
 struct workqueue_struct *xfs_alloc_wq;
 
@@ -2167,6 +2170,40 @@ xfs_agfl_reset(
        pag->pagf_agflreset = false;
 }
 
+/*
+ * Defer an AGFL block free. This is effectively equivalent to
+ * xfs_bmap_add_free() with some special handling particular to AGFL blocks.
+ *
+ * Deferring AGFL frees helps prevent log reservation overruns due to too many
+ * allocation operations in a transaction. AGFL frees are prone to this problem
+ * because for one they are always freed one at a time. Further, an immediate
+ * AGFL block free can cause a btree join and require another block free before
+ * the real allocation can proceed. Deferring the free disconnects freeing up
+ * the AGFL slot from freeing the block.
+ */
+STATIC void
+xfs_defer_agfl_block(
+       struct xfs_mount                *mp,
+       struct xfs_defer_ops            *dfops,
+       xfs_agnumber_t                  agno,
+       xfs_fsblock_t                   agbno,
+       struct xfs_owner_info           *oinfo)
+{
+       struct xfs_extent_free_item     *new;           /* new element */
+
+       ASSERT(xfs_bmap_free_item_zone != NULL);
+       ASSERT(oinfo != NULL);
+
+       new = kmem_zone_alloc(xfs_bmap_free_item_zone, KM_SLEEP);
+       new->xefi_startblock = XFS_AGB_TO_FSB(mp, agno, agbno);
+       new->xefi_blockcount = 1;
+       new->xefi_oinfo = *oinfo;
+
+       trace_xfs_agfl_free_defer(mp, agno, 0, agbno, 1);
+
+       xfs_defer_add(dfops, XFS_DEFER_OPS_TYPE_AGFL_FREE, &new->xefi_list);
+}
+
 /*
  * Decide whether to use this allocation group for this allocation.
  * If so, fix up the btree freelist's size.
@@ -2271,10 +2308,16 @@ xfs_alloc_fix_freelist(
                if (error)
                        goto out_agbp_relse;
 
-               error = xfs_free_agfl_block(tp, args->agno, bno, agbp,
-                                           &targs.oinfo);
-               if (error)
-                       goto out_agbp_relse;
+               /* defer agfl frees if dfops is provided */
+               if (tp->t_agfl_dfops) {
+                       xfs_defer_agfl_block(mp, tp->t_agfl_dfops, args->agno,
+                                            bno, &targs.oinfo);
+               } else {
+                       error = xfs_free_agfl_block(tp, args->agno, bno, agbp,
+                                                   &targs.oinfo);
+                       if (error)
+                               goto out_agbp_relse;
+               }
        }
 
        targs.tp = tp;
index 045beacdd37d81c9e01e0ab46ab2bbcbbb581fbb..e70725ba1f5f794d2b262084e44ac3f80680c7b5 100644 (file)
@@ -55,6 +55,7 @@ enum xfs_defer_ops_type {
        XFS_DEFER_OPS_TYPE_REFCOUNT,
        XFS_DEFER_OPS_TYPE_RMAP,
        XFS_DEFER_OPS_TYPE_FREE,
+       XFS_DEFER_OPS_TYPE_AGFL_FREE,
        XFS_DEFER_OPS_TYPE_MAX,
 };