From patchwork Tue Dec 31 23:43:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13924052 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 039C413FD72 for ; Tue, 31 Dec 2024 23:43:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735688598; cv=none; b=kbKmAvTHXiwGGf7yctEUJqtK6YUwpIXJSLuzFXUO6DxC4eFNHNX6pyvAbAz7RhNnGnviyk8McNa+2wvPB4vpn9ObRVjUryiaWz5Nlu2kd6kuqXCBSTTe//UBqMfn6HpQ6ByrA0gdKQ1BbhgkWRtqERoN7ic2voCOmeuXgpHf6Sc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735688598; c=relaxed/simple; bh=XejIJj64lmGfHNYlrTNwSmR6+tSN/MpROhk+ivINfIg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y1ZMaCT44elDP2tNM5IUWTN6q3Ohtszzs9VMbetCHiEEtmMeVUzW1lRk0qi0U0Jb0mDIJ63mUK2Zu/4hQjBjRsB1lf11SH26fxXDnsqtBB9ALr6lN+41jaHMg+lq9CzN46db/BqUAiSuj65uxndBgVpgGLo/dGbJf16jtmjd9so= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mFQU3PUQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mFQU3PUQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73338C4CED2; Tue, 31 Dec 2024 23:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735688597; bh=XejIJj64lmGfHNYlrTNwSmR6+tSN/MpROhk+ivINfIg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=mFQU3PUQA3yn6zfbxNhqIO8IqcjkJRwmIZTe+koOTrs7vbjExpGLO2BXX3Dsd7+l7 JVWRSsZOJiiCDy/KeQltvr/CHpDO22e4zOGlj2geMvPN8MQsv1YhRf5YzI+B3hxcT0 uMPfXAPUtWO6gkE1S4IO7mJwte9jw1M/6NvyumnIl+7WEo93/P7iOvOR1d+Y02PZdD S/mTF0XF7B+gKamWL6Me0ZPq+o5BvFfmv0TAB4S25LnWovsGxKaWw0SW808Qq6Cl2q jKyuLaJ1bB20gC6+q1Z1U3h8QZvnFbX2SG/kEloyIc8F4Aje4fvRJ/faoS+GjA5w5x 02Dh+qEbTnODA== Date: Tue, 31 Dec 2024 15:43:17 -0800 Subject: [PATCH 1/5] xfs: track deferred ops statistics From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173568777023.2709441.15844314401526725196.stgit@frogsfrogsfrogs> In-Reply-To: <173568777001.2709441.13781927144429990672.stgit@frogsfrogsfrogs> References: <173568777001.2709441.13781927144429990672.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Track some basic statistics on how hard we're pushing the defer ops. Signed-off-by: "Darrick J. Wong" --- include/xfs_trans.h | 4 ++++ libxfs/xfs_defer.c | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/xfs_trans.h b/include/xfs_trans.h index 248064019a0ab5..64d73c36851b75 100644 --- a/include/xfs_trans.h +++ b/include/xfs_trans.h @@ -82,6 +82,10 @@ typedef struct xfs_trans { long t_frextents_delta;/* superblock freextents chg*/ struct list_head t_items; /* log item descriptors */ struct list_head t_dfops; /* deferred operations */ + + unsigned int t_dfops_nr; + unsigned int t_dfops_nr_max; + unsigned int t_dfops_finished; } xfs_trans_t; void xfs_trans_init(struct xfs_mount *); diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 8f6708c0f3bfcd..7e6167949f6509 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -611,6 +611,8 @@ xfs_defer_finish_one( /* Done with the dfp, free it. */ list_del(&dfp->dfp_list); kmem_cache_free(xfs_defer_pending_cache, dfp); + tp->t_dfops_nr--; + tp->t_dfops_finished++; out: if (ops->finish_cleanup) ops->finish_cleanup(tp, state, error); @@ -673,6 +675,9 @@ xfs_defer_finish_noroll( list_splice_init(&(*tp)->t_dfops, &dop_pending); + (*tp)->t_dfops_nr_max = max((*tp)->t_dfops_nr, + (*tp)->t_dfops_nr_max); + if (has_intents < 0) { error = has_intents; goto out_shutdown; @@ -714,6 +719,7 @@ xfs_defer_finish_noroll( xfs_force_shutdown((*tp)->t_mountp, SHUTDOWN_CORRUPT_INCORE); trace_xfs_defer_finish_error(*tp, error); xfs_defer_cancel_list((*tp)->t_mountp, &dop_pending); + (*tp)->t_dfops_nr = 0; xfs_defer_cancel(*tp); return error; } @@ -761,6 +767,7 @@ xfs_defer_cancel( trace_xfs_defer_cancel(tp, _RET_IP_); xfs_defer_trans_abort(tp, &tp->t_dfops); xfs_defer_cancel_list(mp, &tp->t_dfops); + tp->t_dfops_nr = 0; } /* @@ -846,8 +853,10 @@ xfs_defer_add( } dfp = xfs_defer_find_last(tp, ops); - if (!dfp || !xfs_defer_can_append(dfp, ops)) + if (!dfp || !xfs_defer_can_append(dfp, ops)) { dfp = xfs_defer_alloc(&tp->t_dfops, ops); + tp->t_dfops_nr++; + } xfs_defer_add_item(dfp, li); trace_xfs_defer_add_item(tp->t_mountp, dfp, li); @@ -872,6 +881,7 @@ xfs_defer_add_barrier( return; xfs_defer_alloc(&tp->t_dfops, &xfs_barrier_defer_type); + tp->t_dfops_nr++; trace_xfs_defer_add_item(tp->t_mountp, dfp, NULL); } @@ -932,6 +942,12 @@ xfs_defer_move( struct xfs_trans *stp) { list_splice_init(&stp->t_dfops, &dtp->t_dfops); + dtp->t_dfops_nr += stp->t_dfops_nr; + dtp->t_dfops_nr_max = stp->t_dfops_nr_max; + dtp->t_dfops_finished = stp->t_dfops_finished; + stp->t_dfops_nr = 0; + stp->t_dfops_nr_max = 0; + stp->t_dfops_finished = 0; /* * Low free space mode was historically controlled by a dfops field. From patchwork Tue Dec 31 23:43:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13924053 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CB9513FD72 for ; Tue, 31 Dec 2024 23:43:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735688613; cv=none; b=syaudtGFNw4dHgAbWc8Y85zo1gv0iiWzLJo7g8RLP0TYZ60ScXKpdcpRs/wo/FfP/WsZXWvpZmpHIQmCpN+BBOeuGiyavTKTWNPToLE8xqf6WnhbFBbSE7ly+ra580IRxx32mxnIehVRmyxKvc4tkAxBHSDNd3QGNkmQ2O79MOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735688613; c=relaxed/simple; bh=hRBhGZXBw6ENH358xigtdzny6luPA/hZ87gprRKUYUU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tifoSDgl5X8a1qpZG854kZ7xD751oYM+6LUA1dLMs+5ePuR78DC8mPLAB7thuUx5Mb40p9beo1yPB+3OMoQ5jAU7Gx7S4BawmNp7YBhQM2SUNGD5Ev74365Kz6dci93GVfpiAJ4A/JsKoM+1p+YxECUGK/DQE/AVHgmzZSEdEm4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LYpUB0Ko; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LYpUB0Ko" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10676C4CED2; Tue, 31 Dec 2024 23:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735688613; bh=hRBhGZXBw6ENH358xigtdzny6luPA/hZ87gprRKUYUU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LYpUB0KoWJC7o90gnxaWHKXSsXcV1oHU7MZNloAOdxZotH9hregMY+LBZH9dHMT50 wp79bdzQmslcz58brvLKVquYrDGcp9IzhbXvr59zNfLDkGY5n70UjeY5cGI11v3lnw 1owGpWodJuHdFsqcl3QvyTjzAQ7itrKaWvNB7oo4mikrKDI1fFHZJ6z40sDLQyjIqi z1UQjW3QkbQPwcYw8HSUvjAE439rqarwb02FBm2xrastVpSAu1h3FA0Z3GXDASdXPT u+HyFhAL6ZMdhkjiB2veVRfmjA5phnLH9WpX+gKTfKd2le0iEIPjDGUDGr5MQY/V6g GVINTW7bV4G9g== Date: Tue, 31 Dec 2024 15:43:32 -0800 Subject: [PATCH 2/5] xfs: create a noalloc mode for allocation groups From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173568777039.2709441.5588361008382501280.stgit@frogsfrogsfrogs> In-Reply-To: <173568777001.2709441.13781927144429990672.stgit@frogsfrogsfrogs> References: <173568777001.2709441.13781927144429990672.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Create a new noalloc state for the per-AG structure that will disable block allocation in this AG. We accomplish this by subtracting from fdblocks all the free blocks in this AG, hiding those blocks from the allocator, and preventing freed blocks from updating fdblocks until we're ready to lift noalloc mode. Note that we reduce the free block count of the filesystem so that we can prevent transactions from entering the allocator looking for "free" space that we've turned off incore. Signed-off-by: "Darrick J. Wong" --- include/xfs_trace.h | 2 ++ libxfs/xfs_ag.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_ag.h | 8 +++++++ libxfs/xfs_ag_resv.c | 28 +++++++++++++++++++++-- 4 files changed, 95 insertions(+), 3 deletions(-) diff --git a/include/xfs_trace.h b/include/xfs_trace.h index 30166c11dd597b..7778366c5e3319 100644 --- a/include/xfs_trace.h +++ b/include/xfs_trace.h @@ -13,6 +13,8 @@ #define trace_xfbtree_trans_cancel_buf(...) ((void) 0) #define trace_xfbtree_trans_commit_buf(...) ((void) 0) +#define trace_xfs_ag_clear_noalloc(a) ((void) 0) +#define trace_xfs_ag_set_noalloc(a) ((void) 0) #define trace_xfs_agfl_reset(a,b,c,d) ((void) 0) #define trace_xfs_agfl_free_defer(...) ((void) 0) #define trace_xfs_alloc_cur_check(...) ((void) 0) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 095b581a116180..462d16347cadb9 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -974,3 +974,63 @@ xfs_ag_get_geometry( xfs_buf_relse(agi_bp); return error; } + +/* How many blocks does this AG contribute to fdblocks? */ +xfs_extlen_t +xfs_ag_fdblocks( + struct xfs_perag *pag) +{ + xfs_extlen_t ret; + + ASSERT(xfs_perag_initialised_agf(pag)); + + ret = pag->pagf_freeblks + pag->pagf_flcount + pag->pagf_btreeblks; + ret -= pag->pag_meta_resv.ar_reserved; + ret -= pag->pag_rmapbt_resv.ar_orig_reserved; + return ret; +} + +/* + * Hide all the free space in this AG. Caller must hold both the AGI and the + * AGF buffers or have otherwise prevented concurrent access. + */ +int +xfs_ag_set_noalloc( + struct xfs_perag *pag) +{ + struct xfs_mount *mp = pag_mount(pag); + int error; + + ASSERT(xfs_perag_initialised_agf(pag)); + ASSERT(xfs_perag_initialised_agi(pag)); + + if (xfs_perag_prohibits_alloc(pag)) + return 0; + + error = xfs_dec_fdblocks(mp, xfs_ag_fdblocks(pag), false); + if (error) + return error; + + trace_xfs_ag_set_noalloc(pag); + set_bit(XFS_AGSTATE_NOALLOC, &pag->pag_opstate); + return 0; +} + +/* + * Unhide all the free space in this AG. Caller must hold both the AGI and + * the AGF buffers or have otherwise prevented concurrent access. + */ +void +xfs_ag_clear_noalloc( + struct xfs_perag *pag) +{ + struct xfs_mount *mp = pag_mount(pag); + + if (!xfs_perag_prohibits_alloc(pag)) + return; + + xfs_add_fdblocks(mp, xfs_ag_fdblocks(pag)); + + trace_xfs_ag_clear_noalloc(pag); + clear_bit(XFS_AGSTATE_NOALLOC, &pag->pag_opstate); +} diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 1f24cfa2732172..e8fae59206d929 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -120,6 +120,7 @@ static inline xfs_agnumber_t pag_agno(const struct xfs_perag *pag) #define XFS_AGSTATE_PREFERS_METADATA 2 #define XFS_AGSTATE_ALLOWS_INODES 3 #define XFS_AGSTATE_AGFL_NEEDS_RESET 4 +#define XFS_AGSTATE_NOALLOC 5 #define __XFS_AG_OPSTATE(name, NAME) \ static inline bool xfs_perag_ ## name (struct xfs_perag *pag) \ @@ -132,6 +133,7 @@ __XFS_AG_OPSTATE(initialised_agi, AGI_INIT) __XFS_AG_OPSTATE(prefers_metadata, PREFERS_METADATA) __XFS_AG_OPSTATE(allows_inodes, ALLOWS_INODES) __XFS_AG_OPSTATE(agfl_needs_reset, AGFL_NEEDS_RESET) +__XFS_AG_OPSTATE(prohibits_alloc, NOALLOC) int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t orig_agcount, xfs_agnumber_t new_agcount, xfs_rfsblock_t dcount, @@ -164,6 +166,7 @@ xfs_perag_put( xfs_group_put(pag_group(pag)); } + /* Active AG references */ static inline struct xfs_perag * xfs_perag_grab( @@ -208,6 +211,11 @@ xfs_perag_next( return xfs_perag_next_from(mp, pag, 0); } +/* Enable or disable allocation from an AG */ +xfs_extlen_t xfs_ag_fdblocks(struct xfs_perag *pag); +int xfs_ag_set_noalloc(struct xfs_perag *pag); +void xfs_ag_clear_noalloc(struct xfs_perag *pag); + /* * Per-ag geometry infomation and validation */ diff --git a/libxfs/xfs_ag_resv.c b/libxfs/xfs_ag_resv.c index 83cac20331fd34..e811a6807e12ea 100644 --- a/libxfs/xfs_ag_resv.c +++ b/libxfs/xfs_ag_resv.c @@ -20,6 +20,7 @@ #include "xfs_ialloc_btree.h" #include "xfs_ag.h" #include "xfs_ag_resv.h" +#include "xfs_ag.h" /* * Per-AG Block Reservations @@ -73,6 +74,13 @@ xfs_ag_resv_critical( xfs_extlen_t avail; xfs_extlen_t orig; + /* + * Pretend we're critically low on reservations in this AG to scare + * everyone else away. + */ + if (xfs_perag_prohibits_alloc(pag)) + return true; + switch (type) { case XFS_AG_RESV_METADATA: avail = pag->pagf_freeblks - pag->pag_rmapbt_resv.ar_reserved; @@ -115,7 +123,12 @@ xfs_ag_resv_needed( break; case XFS_AG_RESV_METAFILE: case XFS_AG_RESV_NONE: - /* empty */ + /* + * In noalloc mode, we pretend that all the free blocks in this + * AG have been allocated. Make this AG look full. + */ + if (xfs_perag_prohibits_alloc(pag)) + len += xfs_ag_fdblocks(pag); break; default: ASSERT(0); @@ -343,6 +356,8 @@ xfs_ag_resv_alloc_extent( xfs_extlen_t len; uint field; + ASSERT(type != XFS_AG_RESV_NONE || !xfs_perag_prohibits_alloc(pag)); + trace_xfs_ag_resv_alloc_extent(pag, type, args->len); switch (type) { @@ -400,7 +415,14 @@ xfs_ag_resv_free_extent( ASSERT(0); fallthrough; case XFS_AG_RESV_NONE: - xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, (int64_t)len); + /* + * Normally we put freed blocks back into fdblocks. In noalloc + * mode, however, we pretend that there are no fdblocks in the + * AG, so don't put them back. + */ + if (!xfs_perag_prohibits_alloc(pag)) + xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, + (int64_t)len); fallthrough; case XFS_AG_RESV_IGNORE: return; @@ -413,6 +435,6 @@ xfs_ag_resv_free_extent( /* Freeing into the reserved pool only requires on-disk update... */ xfs_trans_mod_sb(tp, XFS_TRANS_SB_RES_FDBLOCKS, len); /* ...but freeing beyond that requires in-core and on-disk update. */ - if (len > leftover) + if (len > leftover && !xfs_perag_prohibits_alloc(pag)) xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, len - leftover); } From patchwork Tue Dec 31 23:43:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13924054 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19D9B1B0414 for ; Tue, 31 Dec 2024 23:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735688629; cv=none; b=hVF1vkQrifoNiP3Vor36P6mZXLgs45tG//eze4xH4EzUstVjnE72uUgJfcSN5Otl4Aaac6cHSPe3L/33AktD8YYlOjoB7nV3sQT/J2o5WUyk22YeP8U5XtdgRxF3FBiuSC2HgcHoCYo2R78RGUKiIW1MlfNQzUigW5zGMlKlyMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735688629; c=relaxed/simple; bh=T+R0DUVU6aRc3tSIpZJ+ojcFn5JJ6Xtu2UgxoZ9j92Q=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ecMD32+HRXfDuDrtYEUE6VlMLAlMhdeva1j5V4zmlN3UcFlU/VTAwH+7YDA/vm8KCfiyP7xBxiHV75Gt7JVfhjB3V2U+MZgUbWWSyzsYdv1vqRjNzjN17O9829VnLFGxIRt3VX/CdPzMsLgyW7ka1Hl4wBN+11/kXw8wOqt5eVc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gDEdVmPF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gDEdVmPF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5923C4CED2; Tue, 31 Dec 2024 23:43:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735688628; bh=T+R0DUVU6aRc3tSIpZJ+ojcFn5JJ6Xtu2UgxoZ9j92Q=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=gDEdVmPFY1HmS/lT8Nm9fzB0bDK+tCtG3xYWM21GwcxfQLmvb6ol2Yvlzj+ssPp46 eXA3VQPyVrfZARmXon2dbtKgzIGbFbsS14vr6NM4dUc1BK1SrGIAeYBP7lIo7WY/Qg giuOkEblBuyNmPjV6U29yCSCpmbrWTyNb62SYcNMHhRIh5SjzcyqrixcMaCPmj+LKZ OKy0vswKfNsICWp4p+z19iUKeDA+H+ibpoBTOORZ0Jme/Nb+Q+fzOFNeMp83QMKk/m MInrIqZPzoR2uKj9Dvoq2vGf7jXR874wc3FFF15+u5UCMgt6gOe3J7TNs5nqLi4aVK wzWZY/FZiaIJw== Date: Tue, 31 Dec 2024 15:43:48 -0800 Subject: [PATCH 3/5] xfs: enable userspace to hide an AG from allocation From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173568777054.2709441.1315096884845974561.stgit@frogsfrogsfrogs> In-Reply-To: <173568777001.2709441.13781927144429990672.stgit@frogsfrogsfrogs> References: <173568777001.2709441.13781927144429990672.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Add an administrative interface so that userspace can hide an allocation group from block allocation. Signed-off-by: "Darrick J. Wong" --- libxfs/xfs_ag.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_fs.h | 5 +++++ 2 files changed, 59 insertions(+) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 462d16347cadb9..b3e21e0d26a36c 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -930,6 +930,54 @@ xfs_ag_extend_space( return 0; } +/* Compute the AG geometry flags. */ +static inline uint32_t +xfs_ag_calc_geoflags( + struct xfs_perag *pag) +{ + uint32_t ret = 0; + + if (xfs_perag_prohibits_alloc(pag)) + ret |= XFS_AG_FLAG_NOALLOC; + + return ret; +} + +/* + * Compare the current AG geometry flags against the flags in the AG geometry + * structure and update the AG state to reflect any changes, then update the + * struct to reflect the current status. + */ +static inline int +xfs_ag_update_geoflags( + struct xfs_perag *pag, + struct xfs_ag_geometry *ageo, + uint32_t new_flags) +{ + uint32_t old_flags = xfs_ag_calc_geoflags(pag); + int error; + + if (!(new_flags & XFS_AG_FLAG_UPDATE)) { + ageo->ag_flags = old_flags; + return 0; + } + + if ((old_flags & XFS_AG_FLAG_NOALLOC) && + !(new_flags & XFS_AG_FLAG_NOALLOC)) { + xfs_ag_clear_noalloc(pag); + } + + if (!(old_flags & XFS_AG_FLAG_NOALLOC) && + (new_flags & XFS_AG_FLAG_NOALLOC)) { + error = xfs_ag_set_noalloc(pag); + if (error) + return error; + } + + ageo->ag_flags = xfs_ag_calc_geoflags(pag); + return 0; +} + /* Retrieve AG geometry. */ int xfs_ag_get_geometry( @@ -941,6 +989,7 @@ xfs_ag_get_geometry( struct xfs_agi *agi; struct xfs_agf *agf; unsigned int freeblks; + uint32_t inflags = ageo->ag_flags; int error; /* Lock the AG headers. */ @@ -951,6 +1000,10 @@ xfs_ag_get_geometry( if (error) goto out_agi; + error = xfs_ag_update_geoflags(pag, ageo, inflags); + if (error) + goto out; + /* Fill out form. */ memset(ageo, 0, sizeof(*ageo)); ageo->ag_number = pag_agno(pag); @@ -968,6 +1021,7 @@ xfs_ag_get_geometry( ageo->ag_freeblks = freeblks; xfs_ag_geom_health(pag, ageo); +out: /* Release resources. */ xfs_buf_relse(agf_bp); out_agi: diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index 12463ba766da05..b391bf9de93dbf 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -307,6 +307,11 @@ struct xfs_ag_geometry { #define XFS_AG_GEOM_SICK_REFCNTBT (1 << 9) /* reference counts */ #define XFS_AG_GEOM_SICK_INODES (1 << 10) /* bad inodes were seen */ +#define XFS_AG_FLAG_UPDATE (1 << 0) /* update flags */ +#define XFS_AG_FLAG_NOALLOC (1 << 1) /* do not allocate from this AG */ +#define XFS_AG_FLAG_ALL (XFS_AG_FLAG_UPDATE | \ + XFS_AG_FLAG_NOALLOC) + /* * Structures for XFS_IOC_FSGROWFSDATA, XFS_IOC_FSGROWFSLOG & XFS_IOC_FSGROWFSRT */ From patchwork Tue Dec 31 23:44:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13924055 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67B5913FD72 for ; Tue, 31 Dec 2024 23:44:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735688644; cv=none; b=VtuoJXxRvwXwh9wMtE28kzpIF7vFuckE5qf/fkJRoQ265jQ6Pf2wdPAhuJYiUA8nba4k40kFUiNL46ZuxRQVyUg0JfIKWOdBELt9BtQqX41I4UuGoTXxztrkg/pgYEetGHD4fIpxkmObqLUUlw9YmeBYzeQdKUB5UrZgpXpgqxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735688644; c=relaxed/simple; bh=N10oYL9CHBMX/3gL38XLVgTO9sabR72S9fmCSrVaZnM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BZlIqFl+GBM3xf1vCjmy+DdeWvdiL36swZ7OXHKJGWMRxzVFWEW0oVSOULuCdoxxlFRTGbgztCs5P6vba57lN8QW+CXy1iB9l/qkyvK5rEGLNxIiuARaPmX2DfJ/ivwc5vkos1IYsbgZ5Tg/oiyyW05AgPZEeXSvx6eWhTve2JI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lxWGxsE1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lxWGxsE1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FA3FC4CED2; Tue, 31 Dec 2024 23:44:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735688644; bh=N10oYL9CHBMX/3gL38XLVgTO9sabR72S9fmCSrVaZnM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lxWGxsE1MTQ9LTeVsSn79G190SfuHXPyP2cZeYKWoFpbecqjTtvbZeiNzQeaaeEzJ ywg3pEqzhuopwUU9FAxF6s9rEJr/zVA+kimWjdcA/+5OuRxfAu2nzl/aYwGTzlvBLW dQjKHKCjj2k0baZiHeu8f0g8qjKsamDufG4LJt+ju86mA27Nd4N1L7r2vn0PrZQkUR PPE1kkBShx0JCv3yArtfxbWngiQndF7g0wsDq9krRqFvKPZDXdP/UlZXSn49WgCeUJ kf4gOB7TrAlpaWWONy3hPoTSFxs0FkHaXNX/J5s/KCcnVKst43qdbqH6GndK9GtQoc Dd91XpXqcPUqQ== Date: Tue, 31 Dec 2024 15:44:03 -0800 Subject: [PATCH 4/5] xfs: apply noalloc mode to inode allocations too From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173568777070.2709441.10513728780460673933.stgit@frogsfrogsfrogs> In-Reply-To: <173568777001.2709441.13781927144429990672.stgit@frogsfrogsfrogs> References: <173568777001.2709441.13781927144429990672.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Don't allow inode allocations from this group if it's marked noalloc. Signed-off-by: "Darrick J. Wong" --- libxfs/xfs_ialloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index b401299ad933f7..a086fb30b227a0 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -1102,6 +1102,7 @@ xfs_dialloc_ag_inobt( ASSERT(xfs_perag_initialised_agi(pag)); ASSERT(xfs_perag_allows_inodes(pag)); + ASSERT(!xfs_perag_prohibits_alloc(pag)); ASSERT(pag->pagi_freecount > 0); restart_pagno: @@ -1730,6 +1731,8 @@ xfs_dialloc_good_ag( return false; if (!xfs_perag_allows_inodes(pag)) return false; + if (xfs_perag_prohibits_alloc(pag)) + return false; if (!xfs_perag_initialised_agi(pag)) { error = xfs_ialloc_read_agi(pag, tp, 0, NULL); From patchwork Tue Dec 31 23:44:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13924056 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C13813FD72 for ; Tue, 31 Dec 2024 23:44:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735688660; cv=none; b=pVvCXX1Ej9hB53AiuAAiP3MkvIB1fzk5lqoKHbRk+9VLGDF9Q/Dr0zZS60JU0rgsMsWgpjVl/QQatZz/AUDIWYje1Pbg1+ZhN6//bSOfFlbtE13HJBXkoX4Rf6HruHL/0tcXVcMvOT0z0fN94pN0IlY4hGucS+HRAEGk2tdFc0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735688660; c=relaxed/simple; bh=lIdImL701tgru6YrzkI7F4ckUkV6qrDcRaxbXhrBQMw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k9aIREPGDdpc59zckYiHq6ukKVcON0dpMyDomjk665dFcoEUswxQa4DQ2KDeK7YswpL22/XDYMsdmnQOPQ2vqbnFvFxr1rcJPKFzSSE+FCQpEWjiwndrqHh9nRaLQEXRmkhib5UoxeMq80IcnAZCmxKk3XCXNrqj+eDmwWbaupg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OapAINpU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OapAINpU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6695C4CED2; Tue, 31 Dec 2024 23:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735688659; bh=lIdImL701tgru6YrzkI7F4ckUkV6qrDcRaxbXhrBQMw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OapAINpUiWw5C4Dt+WFyfoICJXwFlIjr9QbfVLk1jtok9TNa3Bc62dhOiJJFgDGoW KFlJK2h6+pejSX2Y4V3ZZXF7hlDsIVEWbctV1t6c7f8oXocUbu0lf/Am8AKq8YW4ek i23kRaQEtCtgbucEa3FaD8Iv9iu1RHC9yQjHt0Gy9BpTAtY/mmM7+skEY4PvgCiVSu g1UwN44kXOw+0iXLzFFt8RvttftU4rZSN1ritjbI1P+DblubuHGHnXPybETqpuh/lL xJfhIscYRqRvbFgYHIodK26JbOcYCCyAnMZMc2DALXwgK2iyRAwUtz/LA22AW20v2m bxeLg/D//XgJg== Date: Tue, 31 Dec 2024 15:44:19 -0800 Subject: [PATCH 5/5] xfs_io: enhance the aginfo command to control the noalloc flag From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <173568777085.2709441.14866795327136765077.stgit@frogsfrogsfrogs> In-Reply-To: <173568777001.2709441.13781927144429990672.stgit@frogsfrogsfrogs> References: <173568777001.2709441.13781927144429990672.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Augment the aginfo command to be able to set and clear the noalloc state for an AG. Signed-off-by: "Darrick J. Wong" --- io/aginfo.c | 45 ++++++++++++++++++++++++++++++++++++++++----- man/man8/xfs_io.8 | 6 +++++- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/io/aginfo.c b/io/aginfo.c index f81986f0df4df3..0320a98b12f981 100644 --- a/io/aginfo.c +++ b/io/aginfo.c @@ -19,9 +19,11 @@ static cmdinfo_t rginfo_cmd; static int report_aginfo( struct xfs_fd *xfd, - xfs_agnumber_t agno) + xfs_agnumber_t agno, + int oflag) { struct xfs_ag_geometry ageo = { 0 }; + bool update = false; int ret; ret = -xfrog_ag_geometry(xfd->fd, agno, &ageo); @@ -30,6 +32,26 @@ report_aginfo( return 1; } + switch (oflag) { + case 0: + ageo.ag_flags |= XFS_AG_FLAG_UPDATE; + ageo.ag_flags &= ~XFS_AG_FLAG_NOALLOC; + update = true; + break; + case 1: + ageo.ag_flags |= (XFS_AG_FLAG_UPDATE | XFS_AG_FLAG_NOALLOC); + update = true; + break; + } + + if (update) { + ret = -xfrog_ag_geometry(xfd->fd, agno, &ageo); + if (ret) { + xfrog_perror(ret, "aginfo update"); + return 1; + } + } + printf(_("AG: %u\n"), ageo.ag_number); printf(_("Blocks: %u\n"), ageo.ag_length); printf(_("Free Blocks: %u\n"), ageo.ag_freeblks); @@ -51,6 +73,7 @@ aginfo_f( struct xfs_fd xfd = XFS_FD_INIT(file->fd); unsigned long long x; xfs_agnumber_t agno = NULLAGNUMBER; + int oflag = -1; int c; int ret = 0; @@ -61,7 +84,7 @@ aginfo_f( return 1; } - while ((c = getopt(argc, argv, "a:")) != EOF) { + while ((c = getopt(argc, argv, "a:o:")) != EOF) { switch (c) { case 'a': errno = 0; @@ -74,16 +97,27 @@ aginfo_f( } agno = x; break; + case 'o': + errno = 0; + x = strtoll(optarg, NULL, 10); + if (!errno && x != 0 && x != 1) + errno = ERANGE; + if (errno) { + perror("aginfo"); + return 1; + } + oflag = x; + break; default: return command_usage(&aginfo_cmd); } } if (agno != NULLAGNUMBER) { - ret = report_aginfo(&xfd, agno); + ret = report_aginfo(&xfd, agno, oflag); } else { for (agno = 0; !ret && agno < xfd.fsgeom.agcount; agno++) { - ret = report_aginfo(&xfd, agno); + ret = report_aginfo(&xfd, agno, oflag); } } @@ -98,6 +132,7 @@ aginfo_help(void) "Report allocation group geometry.\n" "\n" " -a agno -- Report on the given allocation group.\n" +" -o state -- Change the NOALLOC state for this allocation group.\n" "\n")); } @@ -107,7 +142,7 @@ static cmdinfo_t aginfo_cmd = { .cfunc = aginfo_f, .argmin = 0, .argmax = -1, - .args = "[-a agno]", + .args = "[-a agno] [-o state]", .flags = CMD_NOMAP_OK, .help = aginfo_help, }; diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index 59d5ddc54dcc66..a42ab61a0de422 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -1243,7 +1243,7 @@ .SH MEMORY MAPPED I/O COMMANDS .SH FILESYSTEM COMMANDS .TP -.BI "aginfo [ \-a " agno " ]" +.BI "aginfo [ \-a " agno " ] [ \-o " nr " ]" Show information about or update the state of allocation groups. .RE .RS 1.0i @@ -1251,6 +1251,10 @@ .SH FILESYSTEM COMMANDS .TP .BI \-a Act only on a specific allocation group. +.TP +.BI \-o +If 0, clear the NOALLOC flag. +If 1, set the NOALLOC flag. .PD .RE