From patchwork Wed Dec 27 13:38:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13508392 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 7C640389 for ; Mon, 1 Jan 2024 00:38:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hGh3sdw8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C6DAC433C8; Mon, 1 Jan 2024 00:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704069505; bh=vi8EwOohvCKe6L/UMonB9ipugdMGiXeWnn0W1zVWJVI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hGh3sdw8n967E6kei0fKrrH4QQJ51CNJfVM3EobVn6zqZUD3GxLI+4kBUihffMDTN 4hSoDR8yIREYsbEAQBO6rGKTWtM0jFaS5u/o/FfomLdttoPHaChAyJHeClTM2V0/VJ pXsdQez1vif5kUmptksercHgSYZIZFKHkTBczVSJpeDXJUhBdXBPsGj317Vf+Fx6Gj wP5lb0Y4QSaPifmHidAQFTanCJURet0R3Ate1p7Xy1gbx18pMgTyb7EaXiUm8yhYJt OUDjHyJtWwmQf+uqobRWyU+KF2l/E06avTNvPnr0mnitVv0FvBK5zRs+p/Yn0ZuMSs vJZY5Z12I3LBA== Date: Sun, 31 Dec 2023 16:38:24 +9900 Subject: [PATCH 1/5] xfs: track deferred ops statistics From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170405019577.1820520.10283388638932874687.stgit@frogsfrogsfrogs> In-Reply-To: <170405019560.1820520.7145960948523376788.stgit@frogsfrogsfrogs> References: <170405019560.1820520.7145960948523376788.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 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 | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/xfs_trans.h b/include/xfs_trans.h index 630bc85ce37..4b4c26b5561 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 4a1139913b9..2e32939024d 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; } /* @@ -824,6 +831,7 @@ xfs_defer_alloc( dfp->dfp_ops = ops; INIT_LIST_HEAD(&dfp->dfp_work); list_add_tail(&dfp->dfp_list, &tp->t_dfops); + tp->t_dfops_nr++; return dfp; } @@ -936,6 +944,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 Wed Dec 27 13:38:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13508393 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 65FAD644 for ; Mon, 1 Jan 2024 00:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BL8vClBC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA809C433C8; Mon, 1 Jan 2024 00:38:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704069521; bh=jihn1geNjr6lGaZfG3pTeajVaUq/oPfdL1IVICbsbTY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=BL8vClBCEXOTzjOVD2mg7zRGIig+1RYetp/u53PC9IykUIcdJCEYMdOsIHJRcLh2q K5aZJjg3om1G/Ppbhh9T85cR9+/Kqj43O0SYIwJduINM5gtm20Dvgsa/zERCQoYHxK ClRgq08i9R1CTzolWyJ7ctTpSI1Zci/IyQKAND14qkOk9VTjlC94BGRe27BM9Zy8dn KcoIfh2dM0N47LjWUWCn4VjbT/EMTL4pMkEH4VIqFvcBFS8svjFEm8DJyTCQujVFlq eXTXlFOaJgD2bLt3jaeNx7uIoMqCBJJIQLkCGrbGoBkT5JR/2F2b8oLP9li/1/jE7g zFx1/kS9mMPZg== Date: Sun, 31 Dec 2023 16:38:40 +9900 Subject: [PATCH 2/5] xfs: create a noalloc mode for allocation groups From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170405019590.1820520.6157557397044115302.stgit@frogsfrogsfrogs> In-Reply-To: <170405019560.1820520.7145960948523376788.stgit@frogsfrogsfrogs> References: <170405019560.1820520.7145960948523376788.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 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 a6ae0ca13b6..c8368227705 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_free_defer(...) ((void) 0) #define trace_xfs_agfl_reset(a,b,c,d) ((void) 0) #define trace_xfs_alloc_cur_check(a,b,c,d,e,f) ((void) 0) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index ac6b0090825..c639e8e07d7 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -1117,3 +1117,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->pag_mount; + int error; + + ASSERT(xfs_perag_initialised_agf(pag)); + ASSERT(xfs_perag_initialised_agi(pag)); + + if (xfs_perag_prohibits_alloc(pag)) + return 0; + + error = xfs_mod_fdblocks(mp, -(int64_t)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->pag_mount; + + if (!xfs_perag_prohibits_alloc(pag)) + return; + + xfs_mod_fdblocks(mp, xfs_ag_fdblocks(pag), false); + + 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 79017fcd3df..c21cc30ebc7 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -131,6 +131,7 @@ struct xfs_perag { #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) \ @@ -143,6 +144,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 agcount, xfs_rfsblock_t dcount, xfs_agnumber_t *maxagi); @@ -156,12 +158,18 @@ struct xfs_perag *xfs_perag_get_tag(struct xfs_mount *mp, xfs_agnumber_t agno, struct xfs_perag *xfs_perag_hold(struct xfs_perag *pag); void xfs_perag_put(struct xfs_perag *pag); + /* Active AG references */ struct xfs_perag *xfs_perag_grab(struct xfs_mount *, xfs_agnumber_t); struct xfs_perag *xfs_perag_grab_tag(struct xfs_mount *, xfs_agnumber_t, int tag); void xfs_perag_rele(struct xfs_perag *pag); +/* 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 5963ff5602b..ddb679bc4ae 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 @@ -72,6 +73,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; @@ -114,7 +122,12 @@ xfs_ag_resv_needed( break; case XFS_AG_RESV_IMETA: 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 Wed Dec 27 13:38:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13508394 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 226C37EF for ; Mon, 1 Jan 2024 00:38:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="C/PgQ9Jk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98A73C433C7; Mon, 1 Jan 2024 00:38:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704069536; bh=sRu7lxnEjcAk7fTqGL8LwMYVhy92nBbxnWn/ApW9fDk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=C/PgQ9JkveZqRBN6vfb9JCqLmGv/XA4zbfRxrlvjtAymQc/XElSTF8gwch+P6mVXJ jOggCUWcvRFTLMei+5rmtj7/KOQYwYH0KfCRBKin2cuHbIDh/1jbEjikrzhzfAdYoT tgkO2JLaNkxRy1iA5s5KVevTluYdoFtDWsJnD+BrlHP6AN8IFSMXoAsdeYht7sSQAC 0CqcA/h5UxZ1nkw+jIu18K6GkYRYzgBhlFCr5nRfDtoiitnB3yjXf69hKJCHU8YD+z 4MIij7U7ZEEZDLOFZ29dqrfeLzGITMNN+QDpnGedTpeQCcMBJnqVec+mWqE55hWGE4 +rA+ocRwj6Vsg== Date: Sun, 31 Dec 2023 16:38:56 +9900 Subject: [PATCH 3/5] xfs: enable userspace to hide an AG from allocation From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170405019603.1820520.5253949405191543987.stgit@frogsfrogsfrogs> In-Reply-To: <170405019560.1820520.7145960948523376788.stgit@frogsfrogsfrogs> References: <170405019560.1820520.7145960948523376788.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 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 c639e8e07d7..abc0a9d89c5 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -1073,6 +1073,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( @@ -1084,6 +1132,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. */ @@ -1094,6 +1143,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->pag_agno; @@ -1111,6 +1164,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 4159e96d01a..96688f9301e 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -305,6 +305,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 Wed Dec 27 13:39:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13508395 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 6C3CA7F9 for ; Mon, 1 Jan 2024 00:39:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b9PA6IXW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38FCBC433C7; Mon, 1 Jan 2024 00:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704069552; bh=b27XyqnqjDR9oRR9vFpOLESXgkhid9oSYE+uiZU0CiM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=b9PA6IXW3wTvL56ZYt9BojJ2Z4SAj1QM9Um7QWlRYivJ16dKBEVNzFy69MMJwlkVh rmuEglds7RhFL3DncEcM/O9c83KK2NslnYq+WDdeAGp52T1AVu+JZIVNyDlXCNX8jl UIok900GJDiGKPsF1oUL3OanLSe+ec24YN5yU5lLiXzMkX6wHT8FjRGLOicaIuW+uv FANk2Xhv7Xyd8Xu8UZaeEIDgylIrIKbyRBMSAn6wNCcE3RXvQ/S1s2IFtCno0v5gIp IpTV70tDZ0t0C5xrv6yyCKET2sbysj2nb5S+gbVEFYH2j8is6f58DKyYxXfHgb/RUQ bNVZyH/+4NFZA== Date: Sun, 31 Dec 2023 16:39:11 +9900 Subject: [PATCH 4/5] xfs: apply noalloc mode to inode allocations too From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170405019617.1820520.17125148444200392717.stgit@frogsfrogsfrogs> In-Reply-To: <170405019560.1820520.7145960948523376788.stgit@frogsfrogsfrogs> References: <170405019560.1820520.7145960948523376788.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 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 935f8127c0e..09e494f4089 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -1059,6 +1059,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: @@ -1687,6 +1688,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, NULL); From patchwork Wed Dec 27 13:39:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13508396 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 75F457ED for ; Mon, 1 Jan 2024 00:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cpdgGozP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF37FC433C8; Mon, 1 Jan 2024 00:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704069568; bh=gHrb4zg1fpl6CCmmysDDvtRCYlmOt0cpHSnh9+JvRiw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=cpdgGozPEYp/XMb67jRMw21Buij3WaCHspyE14zN28Mz3QxS51rGx4QcqwWBL9PTT rmtTUTsBd0rqQ5rC/MyZjagKIp0fATZrP0v0hmvOsrzLxdqzH2vfsHmsZT5w1+3d2r Qi8GiV3FRnloDw+Kz5/16ZQ6WQPtUjiTTMRF3aK96ka1EMNLCozZ/GMHrVXqBEf5Pm vpKNIhSXL4ZP3bWVQ+aIaj43FLLWcv2lZazt+Njy0oSm3HYqAvIi0RBjqiRHnY+2nH 6lN5VyChReh4hkOxIINvBFpXGAailNjiUHPJdmdYcmQjMgt2g8tww+oxBMuqCZo9Cs qcmpuTv9q/LOw== Date: Sun, 31 Dec 2023 16:39:27 +9900 Subject: [PATCH 5/5] xfs_io: enhance the aginfo command to control the noalloc flag From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170405019630.1820520.15020176051154391607.stgit@frogsfrogsfrogs> In-Reply-To: <170405019560.1820520.7145960948523376788.stgit@frogsfrogsfrogs> References: <170405019560.1820520.7145960948523376788.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 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 43e0e9c21b8..8345d25c559 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 f94de0ce40f..4ae47555ae3 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -1240,7 +1240,7 @@ for the current memory mapping. .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 @@ -1248,6 +1248,10 @@ Show information about or update the state of allocation groups. .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