From patchwork Thu Jan 20 00:23:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717964 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72D6BC433F5 for ; Thu, 20 Jan 2022 00:23:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345210AbiATAXT (ORCPT ); Wed, 19 Jan 2022 19:23:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345209AbiATAXT (ORCPT ); Wed, 19 Jan 2022 19:23:19 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2056CC061574 for ; Wed, 19 Jan 2022 16:23:19 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B43BF61515 for ; Thu, 20 Jan 2022 00:23:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1821AC004E1; Thu, 20 Jan 2022 00:23:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638198; bh=PpgI70vMegCa+NwOgwSrH+l+Eqz7j5stHqIbVxxZXxs=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=VhbbQR9tL4HaAQuzQWCESfHKzNcKC0GgRIU7BLbmb2MHS5v2+uR+y6GKUnYuLOQ9k yzzLtmIE0BKcnvonZEHbyKhQFrK7pivK0AFdiQpIrQssphc7AKcaNwNQFz5HClWRcB xkLulcSp3krsEWXaN9XwgNpch4n9uAW59RmQik7uevy5GXxpO/4pEcqGc8M00RFHVj 6VQ+T3bwzjF31tjc0ddTNcgaOil1DLsgndW1PLHcGXpEcDRr+FqMsEZeqDx5OJjrCN REylzQjUayWTXDCSHCkmSUlvrPZrwPihuQ3vtzuLfvXhg2W2ykx1wTTIt9NN35hSJb X/2dvgaOSY7DA== Subject: [PATCH 01/48] xfs: formalize the process of holding onto resources across a defer roll From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Allison Henderson , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:23:17 -0800 Message-ID: <164263819776.865554.18114406966594175432.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: c5db9f937b2971c78d6c6bbaa61a6450efa8b845 Transaction users are allowed to flag up to two buffers and two inodes for ownership preservation across a deferred transaction roll. Hoist the variables and code responsible for this out of xfs_defer_trans_roll so that we can use it for the defer capture mechanism. Signed-off-by: Darrick J. Wong Reviewed-by: Allison Henderson Signed-off-by: Darrick J. Wong --- include/xfs_trans.h | 3 -- libxfs/xfs_defer.c | 85 ++++++++++++++++++++++++++++++++------------------- libxfs/xfs_defer.h | 24 ++++++++++++++ 3 files changed, 78 insertions(+), 34 deletions(-) diff --git a/include/xfs_trans.h b/include/xfs_trans.h index 2c55bb85..690759ec 100644 --- a/include/xfs_trans.h +++ b/include/xfs_trans.h @@ -58,9 +58,6 @@ typedef struct xfs_qoff_logitem { xfs_qoff_logformat_t qql_format; /* logged structure */ } xfs_qoff_logitem_t; -#define XFS_DEFER_OPS_NR_INODES 2 /* join up to two inodes */ -#define XFS_DEFER_OPS_NR_BUFS 2 /* join up to two buffers */ - typedef struct xfs_trans { unsigned int t_log_res; /* amt of log space resvd */ unsigned int t_log_count; /* count for perm log res */ diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 1fdf6c72..35f51f87 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -228,23 +228,20 @@ xfs_defer_trans_abort( } } -/* Roll a transaction so we can do some deferred op processing. */ -STATIC int -xfs_defer_trans_roll( - struct xfs_trans **tpp) +/* + * Capture resources that the caller said not to release ("held") when the + * transaction commits. Caller is responsible for zero-initializing @dres. + */ +static int +xfs_defer_save_resources( + struct xfs_defer_resources *dres, + struct xfs_trans *tp) { - struct xfs_trans *tp = *tpp; struct xfs_buf_log_item *bli; struct xfs_inode_log_item *ili; struct xfs_log_item *lip; - struct xfs_buf *bplist[XFS_DEFER_OPS_NR_BUFS]; - struct xfs_inode *iplist[XFS_DEFER_OPS_NR_INODES]; - unsigned int ordered = 0; /* bitmap */ - int bpcount = 0, ipcount = 0; - int i; - int error; - BUILD_BUG_ON(NBBY * sizeof(ordered) < XFS_DEFER_OPS_NR_BUFS); + BUILD_BUG_ON(NBBY * sizeof(dres->dr_ordered) < XFS_DEFER_OPS_NR_BUFS); list_for_each_entry(lip, &tp->t_items, li_trans) { switch (lip->li_type) { @@ -252,28 +249,29 @@ xfs_defer_trans_roll( bli = container_of(lip, struct xfs_buf_log_item, bli_item); if (bli->bli_flags & XFS_BLI_HOLD) { - if (bpcount >= XFS_DEFER_OPS_NR_BUFS) { + if (dres->dr_bufs >= XFS_DEFER_OPS_NR_BUFS) { ASSERT(0); return -EFSCORRUPTED; } if (bli->bli_flags & XFS_BLI_ORDERED) - ordered |= (1U << bpcount); + dres->dr_ordered |= + (1U << dres->dr_bufs); else xfs_trans_dirty_buf(tp, bli->bli_buf); - bplist[bpcount++] = bli->bli_buf; + dres->dr_bp[dres->dr_bufs++] = bli->bli_buf; } break; case XFS_LI_INODE: ili = container_of(lip, struct xfs_inode_log_item, ili_item); if (ili->ili_lock_flags == 0) { - if (ipcount >= XFS_DEFER_OPS_NR_INODES) { + if (dres->dr_inos >= XFS_DEFER_OPS_NR_INODES) { ASSERT(0); return -EFSCORRUPTED; } xfs_trans_log_inode(tp, ili->ili_inode, XFS_ILOG_CORE); - iplist[ipcount++] = ili->ili_inode; + dres->dr_ip[dres->dr_inos++] = ili->ili_inode; } break; default: @@ -281,7 +279,43 @@ xfs_defer_trans_roll( } } - trace_xfs_defer_trans_roll(tp, _RET_IP_); + return 0; +} + +/* Attach the held resources to the transaction. */ +static void +xfs_defer_restore_resources( + struct xfs_trans *tp, + struct xfs_defer_resources *dres) +{ + unsigned short i; + + /* Rejoin the joined inodes. */ + for (i = 0; i < dres->dr_inos; i++) + xfs_trans_ijoin(tp, dres->dr_ip[i], 0); + + /* Rejoin the buffers and dirty them so the log moves forward. */ + for (i = 0; i < dres->dr_bufs; i++) { + xfs_trans_bjoin(tp, dres->dr_bp[i]); + if (dres->dr_ordered & (1U << i)) + xfs_trans_ordered_buf(tp, dres->dr_bp[i]); + xfs_trans_bhold(tp, dres->dr_bp[i]); + } +} + +/* Roll a transaction so we can do some deferred op processing. */ +STATIC int +xfs_defer_trans_roll( + struct xfs_trans **tpp) +{ + struct xfs_defer_resources dres = { }; + int error; + + error = xfs_defer_save_resources(&dres, *tpp); + if (error) + return error; + + trace_xfs_defer_trans_roll(*tpp, _RET_IP_); /* * Roll the transaction. Rolling always given a new transaction (even @@ -291,22 +325,11 @@ xfs_defer_trans_roll( * happened. */ error = xfs_trans_roll(tpp); - tp = *tpp; - /* Rejoin the joined inodes. */ - for (i = 0; i < ipcount; i++) - xfs_trans_ijoin(tp, iplist[i], 0); - - /* Rejoin the buffers and dirty them so the log moves forward. */ - for (i = 0; i < bpcount; i++) { - xfs_trans_bjoin(tp, bplist[i]); - if (ordered & (1U << i)) - xfs_trans_ordered_buf(tp, bplist[i]); - xfs_trans_bhold(tp, bplist[i]); - } + xfs_defer_restore_resources(*tpp, &dres); if (error) - trace_xfs_defer_trans_roll_error(tp, error); + trace_xfs_defer_trans_roll_error(*tpp, error); return error; } diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index 05472f71..e095abb9 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -64,6 +64,30 @@ extern const struct xfs_defer_op_type xfs_rmap_update_defer_type; extern const struct xfs_defer_op_type xfs_extent_free_defer_type; extern const struct xfs_defer_op_type xfs_agfl_free_defer_type; +/* + * Deferred operation item relogging limits. + */ +#define XFS_DEFER_OPS_NR_INODES 2 /* join up to two inodes */ +#define XFS_DEFER_OPS_NR_BUFS 2 /* join up to two buffers */ + +/* Resources that must be held across a transaction roll. */ +struct xfs_defer_resources { + /* held buffers */ + struct xfs_buf *dr_bp[XFS_DEFER_OPS_NR_BUFS]; + + /* inodes with no unlock flags */ + struct xfs_inode *dr_ip[XFS_DEFER_OPS_NR_INODES]; + + /* number of held buffers */ + unsigned short dr_bufs; + + /* bitmap of ordered buffers */ + unsigned short dr_ordered; + + /* number of held inodes */ + unsigned short dr_inos; +}; + /* * This structure enables a dfops user to detach the chain of deferred * operations from a transaction so that they can be continued later. From patchwork Thu Jan 20 00:23:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717965 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81BB7C433EF for ; Thu, 20 Jan 2022 00:23:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345209AbiATAXZ (ORCPT ); Wed, 19 Jan 2022 19:23:25 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:59928 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240495AbiATAXY (ORCPT ); Wed, 19 Jan 2022 19:23:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 38D9661515 for ; Thu, 20 Jan 2022 00:23:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B7F4C004E1; Thu, 20 Jan 2022 00:23:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638203; bh=/kpl9NPpfxagooowStok9BODKRRebKbb/MA65iSv4mE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=hzDnUyddUWAk3tOpCE8Thp7kleqF66654sxSNcn4efMQPjI7zvOLs8widbcZDoHlG f4eKA+0b08zz1aZZnEvCsCAnphG3Ux1SNsg5n8Te+mAPxwjAMCnHxg5iKVKvX3Fjdv nSElrq8p8d9EIMbTZR2O2xyItdz9oyGdsVsh52DI0MEI6FF3NPVC9MALAv1RYx+zce gkVoteutLX7PvqjhuQg1M6oJDEK4Q8TeIkdQK+WWWNuqEV2TAHnSXS7dnAJc6QdZKY WWy5UG1kXxc4xDy0bEUTtqqRezOf8pnVNkdnxyj8G4RM+Mh0ub5oRAIHJXl8FUKHE7 jkNeqvIFhzFbQ== Subject: [PATCH 02/48] xfs: port the defer ops capture and continue to resource capture From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Allison Henderson , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:23:23 -0800 Message-ID: <164263820326.865554.8930683632348589030.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 512edfac85d243ed6a5a5f42f513ebb7c2d32863 When log recovery tries to recover a transaction that had log intent items attached to it, it has to save certain parts of the transaction state (reservation, dfops chain, inodes with no automatic unlock) so that it can finish single-stepping the recovered transactions before finishing the chains. This is done with the xfs_defer_ops_capture and xfs_defer_ops_continue functions. Right now they open-code this functionality, so let's port this to the formalized resource capture structure that we introduced in the previous patch. This enables us to hold up to two inodes and two buffers during log recovery, the same way we do for regular runtime. With this patch applied, we'll be ready to support atomic extent swap which holds two inodes; and logged xattrs which holds one inode and one xattr leaf buffer. Signed-off-by: Darrick J. Wong Reviewed-by: Allison Henderson Signed-off-by: Darrick J. Wong --- libxfs/libxfs_priv.h | 2 + libxfs/xfs_defer.c | 86 ++++++++++++++++++++++++++++++++++++++------------ libxfs/xfs_defer.h | 14 +++----- 3 files changed, 73 insertions(+), 29 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index b94ff41e..466865f7 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -468,6 +468,8 @@ void __xfs_buf_mark_corrupt(struct xfs_buf *bp, xfs_failaddr_t fa); __mode = __mode; /* no set-but-unused warning */ \ }) +#define xfs_lock_two_inodes(ip1, mode1, ip2, mode2) ((void) 0) + /* space allocation */ #define XFS_EXTENT_BUSY_DISCARDED 0x01 /* undergoing a discard op. */ #define XFS_EXTENT_BUSY_SKIP_DISCARD 0x02 /* do not discard */ diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 35f51f87..40d49abc 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -646,10 +646,11 @@ xfs_defer_move( */ static struct xfs_defer_capture * xfs_defer_ops_capture( - struct xfs_trans *tp, - struct xfs_inode *capture_ip) + struct xfs_trans *tp) { struct xfs_defer_capture *dfc; + unsigned short i; + int error; if (list_empty(&tp->t_dfops)) return NULL; @@ -673,27 +674,48 @@ xfs_defer_ops_capture( /* Preserve the log reservation size. */ dfc->dfc_logres = tp->t_log_res; + error = xfs_defer_save_resources(&dfc->dfc_held, tp); + if (error) { + /* + * Resource capture should never fail, but if it does, we + * still have to shut down the log and release things + * properly. + */ + xfs_force_shutdown(tp->t_mountp, SHUTDOWN_CORRUPT_INCORE); + } + /* - * Grab an extra reference to this inode and attach it to the capture - * structure. + * Grab extra references to the inodes and buffers because callers are + * expected to release their held references after we commit the + * transaction. */ - if (capture_ip) { - ihold(VFS_I(capture_ip)); - dfc->dfc_capture_ip = capture_ip; + for (i = 0; i < dfc->dfc_held.dr_inos; i++) { + ASSERT(xfs_isilocked(dfc->dfc_held.dr_ip[i], XFS_ILOCK_EXCL)); + ihold(VFS_I(dfc->dfc_held.dr_ip[i])); } + for (i = 0; i < dfc->dfc_held.dr_bufs; i++) + xfs_buf_hold(dfc->dfc_held.dr_bp[i]); + return dfc; } /* Release all resources that we used to capture deferred ops. */ void -xfs_defer_ops_release( +xfs_defer_ops_capture_free( struct xfs_mount *mp, struct xfs_defer_capture *dfc) { + unsigned short i; + xfs_defer_cancel_list(mp, &dfc->dfc_dfops); - if (dfc->dfc_capture_ip) - xfs_irele(dfc->dfc_capture_ip); + + for (i = 0; i < dfc->dfc_held.dr_bufs; i++) + xfs_buf_relse(dfc->dfc_held.dr_bp[i]); + + for (i = 0; i < dfc->dfc_held.dr_inos; i++) + xfs_irele(dfc->dfc_held.dr_ip[i]); + kmem_free(dfc); } @@ -708,24 +730,21 @@ xfs_defer_ops_release( int xfs_defer_ops_capture_and_commit( struct xfs_trans *tp, - struct xfs_inode *capture_ip, struct list_head *capture_list) { struct xfs_mount *mp = tp->t_mountp; struct xfs_defer_capture *dfc; int error; - ASSERT(!capture_ip || xfs_isilocked(capture_ip, XFS_ILOCK_EXCL)); - /* If we don't capture anything, commit transaction and exit. */ - dfc = xfs_defer_ops_capture(tp, capture_ip); + dfc = xfs_defer_ops_capture(tp); if (!dfc) return xfs_trans_commit(tp); /* Commit the transaction and add the capture structure to the list. */ error = xfs_trans_commit(tp); if (error) { - xfs_defer_ops_release(mp, dfc); + xfs_defer_ops_capture_free(mp, dfc); return error; } @@ -743,17 +762,19 @@ void xfs_defer_ops_continue( struct xfs_defer_capture *dfc, struct xfs_trans *tp, - struct xfs_inode **captured_ipp) + struct xfs_defer_resources *dres) { ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); ASSERT(!(tp->t_flags & XFS_TRANS_DIRTY)); /* Lock and join the captured inode to the new transaction. */ - if (dfc->dfc_capture_ip) { - xfs_ilock(dfc->dfc_capture_ip, XFS_ILOCK_EXCL); - xfs_trans_ijoin(tp, dfc->dfc_capture_ip, 0); - } - *captured_ipp = dfc->dfc_capture_ip; + if (dfc->dfc_held.dr_inos == 2) + xfs_lock_two_inodes(dfc->dfc_held.dr_ip[0], XFS_ILOCK_EXCL, + dfc->dfc_held.dr_ip[1], XFS_ILOCK_EXCL); + else if (dfc->dfc_held.dr_inos == 1) + xfs_ilock(dfc->dfc_held.dr_ip[0], XFS_ILOCK_EXCL); + xfs_defer_restore_resources(tp, &dfc->dfc_held); + memcpy(dres, &dfc->dfc_held, sizeof(struct xfs_defer_resources)); /* Move captured dfops chain and state to the transaction. */ list_splice_init(&dfc->dfc_dfops, &tp->t_dfops); @@ -761,3 +782,26 @@ xfs_defer_ops_continue( kmem_free(dfc); } + +/* Release the resources captured and continued during recovery. */ +void +xfs_defer_resources_rele( + struct xfs_defer_resources *dres) +{ + unsigned short i; + + for (i = 0; i < dres->dr_inos; i++) { + xfs_iunlock(dres->dr_ip[i], XFS_ILOCK_EXCL); + xfs_irele(dres->dr_ip[i]); + dres->dr_ip[i] = NULL; + } + + for (i = 0; i < dres->dr_bufs; i++) { + xfs_buf_relse(dres->dr_bp[i]); + dres->dr_bp[i] = NULL; + } + + dres->dr_inos = 0; + dres->dr_bufs = 0; + dres->dr_ordered = 0; +} diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index e095abb9..7952695c 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -107,11 +107,7 @@ struct xfs_defer_capture { /* Log reservation saved from the transaction. */ unsigned int dfc_logres; - /* - * An inode reference that must be maintained to complete the deferred - * work. - */ - struct xfs_inode *dfc_capture_ip; + struct xfs_defer_resources dfc_held; }; /* @@ -119,9 +115,11 @@ struct xfs_defer_capture { * This doesn't normally happen except log recovery. */ int xfs_defer_ops_capture_and_commit(struct xfs_trans *tp, - struct xfs_inode *capture_ip, struct list_head *capture_list); + struct list_head *capture_list); void xfs_defer_ops_continue(struct xfs_defer_capture *d, struct xfs_trans *tp, - struct xfs_inode **captured_ipp); -void xfs_defer_ops_release(struct xfs_mount *mp, struct xfs_defer_capture *d); + struct xfs_defer_resources *dres); +void xfs_defer_ops_capture_free(struct xfs_mount *mp, + struct xfs_defer_capture *d); +void xfs_defer_resources_rele(struct xfs_defer_resources *dres); #endif /* __XFS_DEFER_H__ */ From patchwork Thu Jan 20 00:23:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717966 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2D82C433EF for ; Thu, 20 Jan 2022 00:23:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345215AbiATAXb (ORCPT ); Wed, 19 Jan 2022 19:23:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240495AbiATAXa (ORCPT ); Wed, 19 Jan 2022 19:23:30 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23A13C061574 for ; Wed, 19 Jan 2022 16:23:30 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B5A1C61514 for ; Thu, 20 Jan 2022 00:23:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16945C004E1; Thu, 20 Jan 2022 00:23:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638209; bh=iEd9kYxT1igOTx1FOnzb7ge5fNNhRZ0TYyRg8rBkMk4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=mKyDJ2Oy+To+uIA1mPR36w0TPaYSl+GXCBVxnOViDgEgbsyml1g0a+JRUCVoXKTte IUeQmmcKY/N9rXPzPPLACekjKQaMdeSIrVZmntQ1eXT5Eu/fuiWngJujwhg6+Blyof 9MaJpGX8NoKeFvh/50uEphNlzZ/FreaC70t4GanbStbiiYkpXRiFFR9Zz5XOui0DRb 9Q45JkUaoe9yWiLyzw3338TFs6YCwh6QrtnXdC2aJu6x1kykw45f0UlNPterkjwX7g JSB8+HgDRk4wzYF7kH3TVDbK3D5BQjAhhBwdjGQneWAA9gno5ZZF96G08K9q5/pnxJ xeBsyxihrg3MA== Subject: [PATCH 03/48] xfs: fix maxlevels comparisons in the btree staging code From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , Christoph Hellwig , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:23:28 -0800 Message-ID: <164263820879.865554.17642172548604235658.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 78e8ec83a404d63dcc86b251f42e4ee8aff27465 The btree geometry computation function has an off-by-one error in that it does not allow maximally tall btrees (nlevels == XFS_BTREE_MAXLEVELS). This can result in repairs failing unnecessarily on very fragmented filesystems. Subsequent patches to remove MAXLEVELS usage in favor of the per-btree type computations will make this a much more likely occurrence. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Reviewed-by: Christoph Hellwig Signed-off-by: Darrick J. Wong --- libxfs/xfs_btree_staging.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_btree_staging.c b/libxfs/xfs_btree_staging.c index 146d2475..daf99797 100644 --- a/libxfs/xfs_btree_staging.c +++ b/libxfs/xfs_btree_staging.c @@ -662,7 +662,7 @@ xfs_btree_bload_compute_geometry( xfs_btree_bload_ensure_slack(cur, &bbl->node_slack, 1); bbl->nr_records = nr_this_level = nr_records; - for (cur->bc_nlevels = 1; cur->bc_nlevels < XFS_BTREE_MAXLEVELS;) { + for (cur->bc_nlevels = 1; cur->bc_nlevels <= XFS_BTREE_MAXLEVELS;) { uint64_t level_blocks; uint64_t dontcare64; unsigned int level = cur->bc_nlevels - 1; @@ -724,7 +724,7 @@ xfs_btree_bload_compute_geometry( nr_this_level = level_blocks; } - if (cur->bc_nlevels == XFS_BTREE_MAXLEVELS) + if (cur->bc_nlevels > XFS_BTREE_MAXLEVELS) return -EOVERFLOW; bbl->btree_height = cur->bc_nlevels; From patchwork Thu Jan 20 00:23:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717967 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC354C433EF for ; Thu, 20 Jan 2022 00:23:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240495AbiATAXh (ORCPT ); Wed, 19 Jan 2022 19:23:37 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:47660 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237314AbiATAXh (ORCPT ); Wed, 19 Jan 2022 19:23:37 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CE90EB81A7D for ; Thu, 20 Jan 2022 00:23:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 912F8C004E1; Thu, 20 Jan 2022 00:23:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638214; bh=1VJL6Qt9tdetVFKgZavDhxVHk8y9F1zS2tKAe3tIoaM=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=XDn1vmW0ODX8Fc1Y3309mnh6Jjb7Q2Fa7gLhxZ3Bufj12JS9QoTRLvDLWthISiJXT FaqWYXzC98Ue+U1Q1xrdTY5A7bgpAHX0V3zX98C2xhPandtpYPwihW4R/bZyfemrRB at5bdWI4kdKp0voiYIB9F0CCYyBwGzyAHTYmIwGqQ7xGqgRYdk1AOlZ8QeFps4/j7h wqrEMLfOWx1lz+iCL76yZGKNrqoau9vDo8a/fINLWHgrhhsfwh0Bs4Y3eIpCzEkU5l uscfm7yWWZ24KyJENN0Y4vWZ6HPIzwxIUARDG2K27seKNtVQ8mtvWuPRpXYjhTnFEf RODhd8RzXd61Q== Subject: [PATCH 04/48] xfs: remove xfs_btree_cur_t typedef From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , Christoph Hellwig , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:23:34 -0800 Message-ID: <164263821427.865554.9319767410440989753.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: ae127f087dc22b6e37edc870079abf0721a6aed0 Get rid of this old typedef before we start changing other things. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Reviewed-by: Christoph Hellwig Signed-off-by: Darrick J. Wong --- libxfs/xfs_alloc.c | 12 ++++++------ libxfs/xfs_bmap.c | 12 ++++++------ libxfs/xfs_btree.c | 12 ++++++------ libxfs/xfs_btree.h | 12 ++++++------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index c60aeb63..fe050d8e 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -422,8 +422,8 @@ xfs_alloc_fix_len( */ STATIC int /* error code */ xfs_alloc_fixup_trees( - xfs_btree_cur_t *cnt_cur, /* cursor for by-size btree */ - xfs_btree_cur_t *bno_cur, /* cursor for by-block btree */ + struct xfs_btree_cur *cnt_cur, /* cursor for by-size btree */ + struct xfs_btree_cur *bno_cur, /* cursor for by-block btree */ xfs_agblock_t fbno, /* starting block of free extent */ xfs_extlen_t flen, /* length of free extent */ xfs_agblock_t rbno, /* starting block of returned extent */ @@ -1196,8 +1196,8 @@ xfs_alloc_ag_vextent_exact( xfs_alloc_arg_t *args) /* allocation argument structure */ { struct xfs_agf __maybe_unused *agf = args->agbp->b_addr; - xfs_btree_cur_t *bno_cur;/* by block-number btree cursor */ - xfs_btree_cur_t *cnt_cur;/* by count btree cursor */ + struct xfs_btree_cur *bno_cur;/* by block-number btree cursor */ + struct xfs_btree_cur *cnt_cur;/* by count btree cursor */ int error; xfs_agblock_t fbno; /* start block of found extent */ xfs_extlen_t flen; /* length of found extent */ @@ -1654,8 +1654,8 @@ xfs_alloc_ag_vextent_size( xfs_alloc_arg_t *args) /* allocation argument structure */ { struct xfs_agf *agf = args->agbp->b_addr; - xfs_btree_cur_t *bno_cur; /* cursor for bno btree */ - xfs_btree_cur_t *cnt_cur; /* cursor for cnt btree */ + struct xfs_btree_cur *bno_cur; /* cursor for bno btree */ + struct xfs_btree_cur *cnt_cur; /* cursor for cnt btree */ int error; /* error result */ xfs_agblock_t fbno; /* start of found freespace */ xfs_extlen_t flen; /* length of found freespace */ diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index d5ccce1f..371aedc2 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -309,7 +309,7 @@ xfs_check_block( */ STATIC void xfs_bmap_check_leaf_extents( - xfs_btree_cur_t *cur, /* btree cursor or null */ + struct xfs_btree_cur *cur, /* btree cursor or null */ xfs_inode_t *ip, /* incore inode pointer */ int whichfork) /* data or attr fork */ { @@ -918,7 +918,7 @@ xfs_bmap_add_attrfork_btree( int *flags) /* inode logging flags */ { struct xfs_btree_block *block = ip->i_df.if_broot; - xfs_btree_cur_t *cur; /* btree cursor */ + struct xfs_btree_cur *cur; /* btree cursor */ int error; /* error return value */ xfs_mount_t *mp; /* file system mount struct */ int stat; /* newroot status */ @@ -961,7 +961,7 @@ xfs_bmap_add_attrfork_extents( struct xfs_inode *ip, /* incore inode pointer */ int *flags) /* inode logging flags */ { - xfs_btree_cur_t *cur; /* bmap btree cursor */ + struct xfs_btree_cur *cur; /* bmap btree cursor */ int error; /* error return value */ if (ip->i_df.if_nextents * sizeof(struct xfs_bmbt_rec) <= @@ -1981,11 +1981,11 @@ xfs_bmap_add_extent_unwritten_real( xfs_inode_t *ip, /* incore inode pointer */ int whichfork, struct xfs_iext_cursor *icur, - xfs_btree_cur_t **curp, /* if *curp is null, not a btree */ + struct xfs_btree_cur **curp, /* if *curp is null, not a btree */ xfs_bmbt_irec_t *new, /* new data to add to file extents */ int *logflagsp) /* inode logging flags */ { - xfs_btree_cur_t *cur; /* btree cursor */ + struct xfs_btree_cur *cur; /* btree cursor */ int error; /* error return value */ int i; /* temp state */ struct xfs_ifork *ifp; /* inode fork pointer */ @@ -5038,7 +5038,7 @@ xfs_bmap_del_extent_real( xfs_inode_t *ip, /* incore inode pointer */ xfs_trans_t *tp, /* current transaction pointer */ struct xfs_iext_cursor *icur, - xfs_btree_cur_t *cur, /* if null, not a btree */ + struct xfs_btree_cur *cur, /* if null, not a btree */ xfs_bmbt_irec_t *del, /* data to remove from extents */ int *logflagsp, /* inode logging flags */ int whichfork, /* data or attr fork */ diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 3d9d0dcc..7097abde 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -385,14 +385,14 @@ xfs_btree_del_cursor( */ int /* error */ xfs_btree_dup_cursor( - xfs_btree_cur_t *cur, /* input cursor */ - xfs_btree_cur_t **ncur) /* output cursor */ + struct xfs_btree_cur *cur, /* input cursor */ + struct xfs_btree_cur **ncur) /* output cursor */ { struct xfs_buf *bp; /* btree block's buffer pointer */ int error; /* error return value */ int i; /* level number of btree block */ xfs_mount_t *mp; /* mount structure for filesystem */ - xfs_btree_cur_t *new; /* new cursor value */ + struct xfs_btree_cur *new; /* new cursor value */ xfs_trans_t *tp; /* transaction pointer, can be NULL */ tp = cur->bc_tp; @@ -688,7 +688,7 @@ xfs_btree_get_block( */ STATIC int /* success=1, failure=0 */ xfs_btree_firstrec( - xfs_btree_cur_t *cur, /* btree cursor */ + struct xfs_btree_cur *cur, /* btree cursor */ int level) /* level to change */ { struct xfs_btree_block *block; /* generic btree block pointer */ @@ -718,7 +718,7 @@ xfs_btree_firstrec( */ STATIC int /* success=1, failure=0 */ xfs_btree_lastrec( - xfs_btree_cur_t *cur, /* btree cursor */ + struct xfs_btree_cur *cur, /* btree cursor */ int level) /* level to change */ { struct xfs_btree_block *block; /* generic btree block pointer */ @@ -982,7 +982,7 @@ xfs_btree_readahead_ptr( */ STATIC void xfs_btree_setbuf( - xfs_btree_cur_t *cur, /* btree cursor */ + struct xfs_btree_cur *cur, /* btree cursor */ int lev, /* level in btree */ struct xfs_buf *bp) /* new buffer to set */ { diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index 4eaf8517..513ade4a 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -216,7 +216,7 @@ struct xfs_btree_cur_ino { * Btree cursor structure. * This collects all information needed by the btree code in one place. */ -typedef struct xfs_btree_cur +struct xfs_btree_cur { struct xfs_trans *bc_tp; /* transaction we're in, if any */ struct xfs_mount *bc_mp; /* file system mount struct */ @@ -243,7 +243,7 @@ typedef struct xfs_btree_cur struct xfs_btree_cur_ag bc_ag; struct xfs_btree_cur_ino bc_ino; }; -} xfs_btree_cur_t; +}; /* cursor flags */ #define XFS_BTREE_LONG_PTRS (1<<0) /* pointers are 64bits long */ @@ -309,7 +309,7 @@ xfs_btree_check_sptr( */ void xfs_btree_del_cursor( - xfs_btree_cur_t *cur, /* btree cursor */ + struct xfs_btree_cur *cur, /* btree cursor */ int error); /* del because of error */ /* @@ -318,8 +318,8 @@ xfs_btree_del_cursor( */ int /* error */ xfs_btree_dup_cursor( - xfs_btree_cur_t *cur, /* input cursor */ - xfs_btree_cur_t **ncur);/* output cursor */ + struct xfs_btree_cur *cur, /* input cursor */ + struct xfs_btree_cur **ncur);/* output cursor */ /* * Compute first and last byte offsets for the fields given. @@ -527,7 +527,7 @@ struct xfs_ifork *xfs_btree_ifork_ptr(struct xfs_btree_cur *cur); /* Does this cursor point to the last block in the given level? */ static inline bool xfs_btree_islastblock( - xfs_btree_cur_t *cur, + struct xfs_btree_cur *cur, int level) { struct xfs_btree_block *block; From patchwork Thu Jan 20 00:23:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717968 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC130C433F5 for ; Thu, 20 Jan 2022 00:23:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240445AbiATAXl (ORCPT ); Wed, 19 Jan 2022 19:23:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237314AbiATAXl (ORCPT ); Wed, 19 Jan 2022 19:23:41 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A6F5C061574 for ; Wed, 19 Jan 2022 16:23:41 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AC95561514 for ; Thu, 20 Jan 2022 00:23:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18143C004E1; Thu, 20 Jan 2022 00:23:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638220; bh=X/vEeiKdGLizcL6jAwlWsAFcrcSZpQpEOvIUbsI09Us=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Zwq6FqxKhAfN2LlcDeMhX+bSoxZHrGmI9VCgU7AmW/DXVa9PMEKVSz25W22a1l9Gb sWQMUvCrVzPTrDyNX8ywwTj7HvcUhosZQLbWOg4tJ19t1DKf+3iWZ15EceOUVj+O5A seGa4txvN3d9U0bJMg2eQkswYMkjS+nsoBvUKoKJ1hJhWDFMPGU4VqxMemVPVaf0CT sa0bM1RI/8ezJOs1wV+jnuzvJ3NxQr/eVhrsAHzyBZjQYeYGMhVDBJyAheO8kEbnwl e+m+msYEBmIP8lJLWXouSFIOx8zZ3nPBQPZIZBF06/O5YZAZYLmJFf7JzkC0g6QNiy K0BzzjSclIACw== Subject: [PATCH 05/48] xfs: check that bc_nlevels never overflows From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , Christoph Hellwig , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:23:39 -0800 Message-ID: <164263821980.865554.4911263848271071817.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 4c175af2ccd3e0d618b2af941e656fabc453c4af Warn if we ever bump nlevels higher than the allowed maximum cursor height. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Reviewed-by: Christoph Hellwig Signed-off-by: Darrick J. Wong --- libxfs/xfs_btree.c | 2 ++ libxfs/xfs_btree_staging.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 7097abde..426ab7f8 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -2934,6 +2934,7 @@ xfs_btree_new_iroot( be16_add_cpu(&block->bb_level, 1); xfs_btree_set_numrecs(block, 1); cur->bc_nlevels++; + ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); cur->bc_ptrs[level + 1] = 1; kp = xfs_btree_key_addr(cur, 1, block); @@ -3097,6 +3098,7 @@ xfs_btree_new_root( xfs_btree_setbuf(cur, cur->bc_nlevels, nbp); cur->bc_ptrs[cur->bc_nlevels] = nptr; cur->bc_nlevels++; + ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); *stat = 1; return 0; error0: diff --git a/libxfs/xfs_btree_staging.c b/libxfs/xfs_btree_staging.c index daf99797..aa3d49cf 100644 --- a/libxfs/xfs_btree_staging.c +++ b/libxfs/xfs_btree_staging.c @@ -703,6 +703,7 @@ xfs_btree_bload_compute_geometry( * block-based btree level. */ cur->bc_nlevels++; + ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); xfs_btree_bload_level_geometry(cur, bbl, level, nr_this_level, &avg_per_block, &level_blocks, &dontcare64); @@ -718,6 +719,7 @@ xfs_btree_bload_compute_geometry( /* Otherwise, we need another level of btree. */ cur->bc_nlevels++; + ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); } nr_blocks += level_blocks; From patchwork Thu Jan 20 00:23:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E295AC433F5 for ; Thu, 20 Jan 2022 00:23:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240584AbiATAXt (ORCPT ); Wed, 19 Jan 2022 19:23:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237314AbiATAXt (ORCPT ); Wed, 19 Jan 2022 19:23:49 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D902C061574 for ; Wed, 19 Jan 2022 16:23:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E726FB81911 for ; Thu, 20 Jan 2022 00:23:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9521DC004E1; Thu, 20 Jan 2022 00:23:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638225; bh=u4qrgJpKWL6t1TOgzSRQabEIHdoucYAk1ORnYtJeor4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=mX9xp8nCGddg/T7J6veD4BF3uqltJRMGZMRNHR742oZv8Ue3g+tWTcpM6lxEN4o1V J4+x5TXKVfugXVCC0xC5uuQUctEVadPlSPFZjnvobQv++39kyy5XiG7J68UE/bLXIi P520VZnYCV6XFmvuCkZbSTULuMAKOUGQYUb5qciK79b84pehctmJf+vU2T+1wftrF6 6HwxrqZz7t4OaP7hXcE5vwW+dV1X6SBoD7fNCfnFeERfc12TWrLuGRxvIJVuMi+x6v ro+NJoUsSs76X/MCmfft1Rsd+y6O9CY5L2+Ay8qg/xraDieuephU/RnhdpW4C02U4T L3/RGYga6Txrg== Subject: [PATCH 06/48] xfs: remove the xfs_dinode_t typedef From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:23:45 -0800 Message-ID: <164263822527.865554.11247552485969553312.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Christoph Hellwig Source kernel commit: de38db7239c4bd2f37ebfcb8a5f22b4e8e657737 Remove the few leftover instances of the xfs_dinode_t typedef. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- db/bmap.c | 4 ++-- db/bmroot.c | 18 +++++++++--------- db/check.c | 30 +++++++++++++++-------------- db/field.c | 4 ++-- db/frag.c | 18 +++++++++--------- db/inode.c | 46 +++++++++++++++++++++++---------------------- db/metadump.c | 20 ++++++++++---------- estimate/xfs_estimate.c | 2 +- libxfs/util.c | 2 +- libxfs/xfs_format.h | 4 ++-- libxfs/xfs_inode_buf.c | 6 +++--- libxfs/xfs_inode_fork.c | 16 ++++++++-------- repair/attr_repair.c | 6 +++--- repair/attr_repair.h | 2 +- repair/da_util.h | 2 +- repair/dino_chunks.c | 4 ++-- repair/dinode.c | 48 ++++++++++++++++++++++++----------------------- repair/dinode.h | 6 +++--- repair/dir2.c | 14 +++++++------- repair/dir2.h | 2 +- repair/incore.h | 2 +- repair/prefetch.c | 6 +++--- repair/rt.c | 4 ++-- repair/rt.h | 2 +- 24 files changed, 134 insertions(+), 134 deletions(-) diff --git a/db/bmap.c b/db/bmap.c index fdc70e95..43300456 100644 --- a/db/bmap.c +++ b/db/bmap.c @@ -38,7 +38,7 @@ bmap( struct xfs_btree_block *block; xfs_fsblock_t bno; xfs_fileoff_t curoffset; - xfs_dinode_t *dip; + struct xfs_dinode *dip; xfs_fileoff_t eoffset; xfs_bmbt_rec_t *ep; enum xfs_dinode_fmt fmt; @@ -129,7 +129,7 @@ bmap_f( int c; xfs_fileoff_t co, cosave; int dfork = 0; - xfs_dinode_t *dip; + struct xfs_dinode *dip; xfs_fileoff_t eo; xfs_filblks_t len; int nex; diff --git a/db/bmroot.c b/db/bmroot.c index f859ac3c..488727ba 100644 --- a/db/bmroot.c +++ b/db/bmroot.c @@ -61,7 +61,7 @@ bmroota_key_count( { xfs_bmdr_block_t *block; #ifdef DEBUG - xfs_dinode_t *dip = obj; + struct xfs_dinode *dip = obj; #endif ASSERT(bitoffs(startoff) == 0); @@ -80,7 +80,7 @@ bmroota_key_offset( { xfs_bmdr_block_t *block; #ifdef DEBUG - xfs_dinode_t *dip = obj; + struct xfs_dinode *dip = obj; #endif xfs_bmdr_key_t *kp; @@ -100,7 +100,7 @@ bmroota_ptr_count( { xfs_bmdr_block_t *block; #ifdef DEBUG - xfs_dinode_t *dip = obj; + struct xfs_dinode *dip = obj; #endif ASSERT(bitoffs(startoff) == 0); @@ -118,7 +118,7 @@ bmroota_ptr_offset( int idx) { xfs_bmdr_block_t *block; - xfs_dinode_t *dip; + struct xfs_dinode *dip; xfs_bmdr_ptr_t *pp; ASSERT(bitoffs(startoff) == 0); @@ -138,7 +138,7 @@ bmroota_size( int startoff, int idx) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; #ifdef DEBUG xfs_bmdr_block_t *block; #endif @@ -161,7 +161,7 @@ bmrootd_key_count( { xfs_bmdr_block_t *block; #ifdef DEBUG - xfs_dinode_t *dip = obj; + struct xfs_dinode *dip = obj; #endif ASSERT(bitoffs(startoff) == 0); @@ -196,7 +196,7 @@ bmrootd_ptr_count( { xfs_bmdr_block_t *block; #ifdef DEBUG - xfs_dinode_t *dip = obj; + struct xfs_dinode *dip = obj; #endif ASSERT(bitoffs(startoff) == 0); @@ -215,7 +215,7 @@ bmrootd_ptr_offset( { xfs_bmdr_block_t *block; xfs_bmdr_ptr_t *pp; - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); @@ -233,7 +233,7 @@ bmrootd_size( int startoff, int idx) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); diff --git a/db/check.c b/db/check.c index 368f80c0..496a4da3 100644 --- a/db/check.c +++ b/db/check.c @@ -276,7 +276,7 @@ static void process_bmbt_reclist(xfs_bmbt_rec_t *rp, int numrecs, dbm_t type, inodata_t *id, xfs_rfsblock_t *tot, blkmap_t **blkmapp); -static void process_btinode(inodata_t *id, xfs_dinode_t *dip, +static void process_btinode(inodata_t *id, struct xfs_dinode *dip, dbm_t type, xfs_rfsblock_t *totd, xfs_rfsblock_t *toti, xfs_extnum_t *nex, blkmap_t **blkmapp, int whichfork); @@ -287,18 +287,18 @@ static xfs_ino_t process_data_dir_v2(int *dot, int *dotdot, static xfs_dir2_data_free_t *process_data_dir_v2_freefind( struct xfs_dir2_data_hdr *data, struct xfs_dir2_data_unused *dup); -static void process_dir(xfs_dinode_t *dip, blkmap_t *blkmap, +static void process_dir(struct xfs_dinode *dip, blkmap_t *blkmap, inodata_t *id); -static int process_dir_v2(xfs_dinode_t *dip, blkmap_t *blkmap, +static int process_dir_v2(struct xfs_dinode *dip, blkmap_t *blkmap, int *dot, int *dotdot, inodata_t *id, xfs_ino_t *parent); -static void process_exinode(inodata_t *id, xfs_dinode_t *dip, +static void process_exinode(inodata_t *id, struct xfs_dinode *dip, dbm_t type, xfs_rfsblock_t *totd, xfs_rfsblock_t *toti, xfs_extnum_t *nex, blkmap_t **blkmapp, int whichfork); static void process_inode(xfs_agf_t *agf, xfs_agino_t agino, - xfs_dinode_t *dip, int isfree); -static void process_lclinode(inodata_t *id, xfs_dinode_t *dip, + struct xfs_dinode *dip, int isfree); +static void process_lclinode(inodata_t *id, struct xfs_dinode *dip, dbm_t type, xfs_rfsblock_t *totd, xfs_rfsblock_t *toti, xfs_extnum_t *nex, blkmap_t **blkmapp, int whichfork); @@ -315,7 +315,7 @@ static void process_quota(qtype_t qtype, inodata_t *id, blkmap_t *blkmap); static void process_rtbitmap(blkmap_t *blkmap); static void process_rtsummary(blkmap_t *blkmap); -static xfs_ino_t process_sf_dir_v2(xfs_dinode_t *dip, int *dot, +static xfs_ino_t process_sf_dir_v2(struct xfs_dinode *dip, int *dot, int *dotdot, inodata_t *id); static void quota_add(xfs_dqid_t *p, xfs_dqid_t *g, xfs_dqid_t *u, int dq, xfs_qcnt_t bc, xfs_qcnt_t ic, @@ -2272,7 +2272,7 @@ process_bmbt_reclist( static void process_btinode( inodata_t *id, - xfs_dinode_t *dip, + struct xfs_dinode *dip, dbm_t type, xfs_rfsblock_t *totd, xfs_rfsblock_t *toti, @@ -2626,7 +2626,7 @@ process_data_dir_v2_freefind( static void process_dir( - xfs_dinode_t *dip, + struct xfs_dinode *dip, blkmap_t *blkmap, inodata_t *id) { @@ -2665,7 +2665,7 @@ process_dir( static int process_dir_v2( - xfs_dinode_t *dip, + struct xfs_dinode *dip, blkmap_t *blkmap, int *dot, int *dotdot, @@ -2702,7 +2702,7 @@ process_dir_v2( static void process_exinode( inodata_t *id, - xfs_dinode_t *dip, + struct xfs_dinode *dip, dbm_t type, xfs_rfsblock_t *totd, xfs_rfsblock_t *toti, @@ -2729,7 +2729,7 @@ static void process_inode( xfs_agf_t *agf, xfs_agino_t agino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, int isfree) { blkmap_t *blkmap; @@ -3038,7 +3038,7 @@ process_inode( static void process_lclinode( inodata_t *id, - xfs_dinode_t *dip, + struct xfs_dinode *dip, dbm_t type, xfs_rfsblock_t *totd, xfs_rfsblock_t *toti, @@ -3697,7 +3697,7 @@ process_rtsummary( static xfs_ino_t process_sf_dir_v2( - xfs_dinode_t *dip, + struct xfs_dinode *dip, int *dot, int *dotdot, inodata_t *id) @@ -4576,7 +4576,7 @@ scanfunc_ino( isfree = XFS_INOBT_IS_FREE_DISK(&rp[i], ioff + j); if (isfree) nfree++; - dip = (xfs_dinode_t *)((char *)iocur_top->data + + dip = (struct xfs_dinode *)((char *)iocur_top->data + ((off + j) << mp->m_sb.sb_inodelog)); process_inode(agf, agino + ioff + j, dip, isfree); } diff --git a/db/field.c b/db/field.c index 51268938..90d3609a 100644 --- a/db/field.c +++ b/db/field.c @@ -203,13 +203,13 @@ const ftattr_t ftattrtab[] = { { FLDT_DINODE_A, "dinode_a", NULL, (char *)inode_a_flds, inode_a_size, FTARG_SIZE|FTARG_OKEMPTY, NULL, inode_a_flds }, { FLDT_DINODE_CORE, "dinode_core", NULL, (char *)inode_core_flds, - SI(bitsz(xfs_dinode_t)), 0, NULL, inode_core_flds }, + SI(bitsz(struct xfs_dinode)), 0, NULL, inode_core_flds }, { FLDT_DINODE_FMT, "dinode_fmt", fp_dinode_fmt, NULL, SI(bitsz(int8_t)), 0, NULL, NULL }, { FLDT_DINODE_U, "dinode_u", NULL, (char *)inode_u_flds, inode_u_size, FTARG_SIZE|FTARG_OKEMPTY, NULL, inode_u_flds }, { FLDT_DINODE_V3, "dinode_v3", NULL, (char *)inode_v3_flds, - SI(bitsz(xfs_dinode_t)), 0, NULL, inode_v3_flds }, + SI(bitsz(struct xfs_dinode)), 0, NULL, inode_v3_flds }, /* dir v2 fields */ { FLDT_DIR2, "dir2", NULL, (char *)dir2_flds, dir2_size, FTARG_SIZE, diff --git a/db/frag.c b/db/frag.c index 9bc63614..ea81b349 100644 --- a/db/frag.c +++ b/db/frag.c @@ -56,13 +56,13 @@ static int frag_f(int argc, char **argv); static int init(int argc, char **argv); static void process_bmbt_reclist(xfs_bmbt_rec_t *rp, int numrecs, extmap_t **extmapp); -static void process_btinode(xfs_dinode_t *dip, extmap_t **extmapp, +static void process_btinode(struct xfs_dinode *dip, extmap_t **extmapp, int whichfork); -static void process_exinode(xfs_dinode_t *dip, extmap_t **extmapp, +static void process_exinode(struct xfs_dinode *dip, extmap_t **extmapp, int whichfork); -static void process_fork(xfs_dinode_t *dip, int whichfork); +static void process_fork(struct xfs_dinode *dip, int whichfork); static void process_inode(xfs_agf_t *agf, xfs_agino_t agino, - xfs_dinode_t *dip); + struct xfs_dinode *dip); static void scan_ag(xfs_agnumber_t agno); static void scan_lbtree(xfs_fsblock_t root, int nlevels, scan_lbtree_f_t func, extmap_t **extmapp, @@ -233,7 +233,7 @@ process_bmbt_reclist( static void process_btinode( - xfs_dinode_t *dip, + struct xfs_dinode *dip, extmap_t **extmapp, int whichfork) { @@ -257,7 +257,7 @@ process_btinode( static void process_exinode( - xfs_dinode_t *dip, + struct xfs_dinode *dip, extmap_t **extmapp, int whichfork) { @@ -269,7 +269,7 @@ process_exinode( static void process_fork( - xfs_dinode_t *dip, + struct xfs_dinode *dip, int whichfork) { extmap_t *extmap; @@ -296,7 +296,7 @@ static void process_inode( xfs_agf_t *agf, xfs_agino_t agino, - xfs_dinode_t *dip) + struct xfs_dinode *dip) { uint64_t actual; uint64_t ideal; @@ -509,7 +509,7 @@ scanfunc_ino( for (j = 0; j < inodes_per_buf; j++) { if (XFS_INOBT_IS_FREE_DISK(&rp[i], ioff + j)) continue; - dip = (xfs_dinode_t *)((char *)iocur_top->data + + dip = (struct xfs_dinode *)((char *)iocur_top->data + ((off + j) << mp->m_sb.sb_inodelog)); process_inode(agf, agino + ioff + j, dip); } diff --git a/db/inode.c b/db/inode.c index 22bc63a8..083888d8 100644 --- a/db/inode.c +++ b/db/inode.c @@ -52,7 +52,7 @@ const field_t inode_crc_hfld[] = { }; /* XXX: fix this up! */ -#define OFF(f) bitize(offsetof(xfs_dinode_t, di_ ## f)) +#define OFF(f) bitize(offsetof(struct xfs_dinode, di_ ## f)) const field_t inode_flds[] = { { "core", FLDT_DINODE_CORE, OI(OFF(magic)), C1, 0, TYP_NONE }, { "next_unlinked", FLDT_AGINO, OI(OFF(next_unlinked)), C1, 0, @@ -74,7 +74,7 @@ const field_t inode_crc_flds[] = { }; -#define COFF(f) bitize(offsetof(xfs_dinode_t, di_ ## f)) +#define COFF(f) bitize(offsetof(struct xfs_dinode, di_ ## f)) const field_t inode_core_flds[] = { { "magic", FLDT_UINT16X, OI(COFF(magic)), C1, 0, TYP_NONE }, { "mode", FLDT_UINT16O, OI(COFF(mode)), C1, 0, TYP_NONE }, @@ -250,7 +250,7 @@ inode_a_bmbt_count( void *obj, int startoff) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); @@ -266,7 +266,7 @@ inode_a_bmx_count( void *obj, int startoff) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); @@ -283,7 +283,7 @@ inode_a_count( void *obj, int startoff) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(startoff == 0); dip = obj; @@ -296,7 +296,7 @@ inode_a_offset( int startoff, int idx) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(startoff == 0); ASSERT(idx == 0); @@ -310,7 +310,7 @@ inode_a_sfattr_count( void *obj, int startoff) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); @@ -328,7 +328,7 @@ inode_a_size( int idx) { struct xfs_attr_shortform *asf; - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(startoff == 0); ASSERT(idx == 0); @@ -352,7 +352,7 @@ inode_core_nlinkv1_count( void *obj, int startoff) { - xfs_dinode_t *dic; + struct xfs_dinode *dic; ASSERT(startoff == 0); ASSERT(obj == iocur_top->data); @@ -365,7 +365,7 @@ inode_core_nlinkv2_count( void *obj, int startoff) { - xfs_dinode_t *dic; + struct xfs_dinode *dic; ASSERT(startoff == 0); ASSERT(obj == iocur_top->data); @@ -378,7 +378,7 @@ inode_core_onlink_count( void *obj, int startoff) { - xfs_dinode_t *dic; + struct xfs_dinode *dic; ASSERT(startoff == 0); ASSERT(obj == iocur_top->data); @@ -391,7 +391,7 @@ inode_core_projid_count( void *obj, int startoff) { - xfs_dinode_t *dic; + struct xfs_dinode *dic; ASSERT(startoff == 0); ASSERT(obj == iocur_top->data); @@ -466,7 +466,7 @@ inode_u_offset( int startoff, int idx) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(startoff == 0); ASSERT(idx == 0); @@ -479,7 +479,7 @@ inode_u_bmbt_count( void *obj, int startoff) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); @@ -493,7 +493,7 @@ inode_u_bmx_count( void *obj, int startoff) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); @@ -508,7 +508,7 @@ inode_u_c_count( void *obj, int startoff) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); @@ -524,7 +524,7 @@ inode_u_dev_count( void *obj, int startoff) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); @@ -538,7 +538,7 @@ inode_u_muuid_count( void *obj, int startoff) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); @@ -552,7 +552,7 @@ inode_u_sfdir2_count( void *obj, int startoff) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); @@ -568,7 +568,7 @@ inode_u_sfdir3_count( void *obj, int startoff) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); @@ -585,7 +585,7 @@ inode_u_size( int startoff, int idx) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(startoff == 0); ASSERT(idx == 0); @@ -612,7 +612,7 @@ inode_u_symlink_count( void *obj, int startoff) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; ASSERT(bitoffs(startoff) == 0); ASSERT(obj == iocur_top->data); @@ -638,7 +638,7 @@ set_cur_inode( xfs_agblock_t agbno; xfs_agino_t agino; xfs_agnumber_t agno; - xfs_dinode_t *dip; + struct xfs_dinode *dip; int offset; int numblks = blkbb; xfs_agblock_t cluster_agbno; diff --git a/db/metadump.c b/db/metadump.c index 48cda88a..057a3729 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -1234,7 +1234,7 @@ generate_obfuscated_name( static void process_sf_dir( - xfs_dinode_t *dip) + struct xfs_dinode *dip) { struct xfs_dir2_sf_hdr *sfp; xfs_dir2_sf_entry_t *sfep; @@ -1339,7 +1339,7 @@ obfuscate_path_components( static void process_sf_symlink( - xfs_dinode_t *dip) + struct xfs_dinode *dip) { uint64_t len; char *buf; @@ -1363,7 +1363,7 @@ process_sf_symlink( static void process_sf_attr( - xfs_dinode_t *dip) + struct xfs_dinode *dip) { /* * with extended attributes, obfuscate the names and fill the actual @@ -2193,7 +2193,7 @@ scanfunc_bmap( static int process_btinode( - xfs_dinode_t *dip, + struct xfs_dinode *dip, typnm_t itype) { xfs_bmdr_block_t *dib; @@ -2273,7 +2273,7 @@ process_btinode( static int process_exinode( - xfs_dinode_t *dip, + struct xfs_dinode *dip, typnm_t itype) { int whichfork; @@ -2303,7 +2303,7 @@ process_exinode( static int process_inode_data( - xfs_dinode_t *dip, + struct xfs_dinode *dip, typnm_t itype) { switch (dip->di_format) { @@ -2333,7 +2333,7 @@ process_inode_data( static int process_dev_inode( - xfs_dinode_t *dip) + struct xfs_dinode *dip) { if (XFS_DFORK_NEXTENTS(dip, XFS_DATA_FORK)) { if (show_warnings) @@ -2362,7 +2362,7 @@ static int process_inode( xfs_agnumber_t agno, xfs_agino_t agino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, bool free_inode) { int success; @@ -2534,9 +2534,9 @@ copy_inode_chunk( } for (i = 0; i < inodes_per_buf; i++) { - xfs_dinode_t *dip; + struct xfs_dinode *dip; - dip = (xfs_dinode_t *)((char *)iocur_top->data + + dip = (struct xfs_dinode *)((char *)iocur_top->data + ((off + i) << mp->m_sb.sb_inodelog)); /* process_inode handles free inodes, too */ diff --git a/estimate/xfs_estimate.c b/estimate/xfs_estimate.c index 9e01ccec..5c7dbccd 100644 --- a/estimate/xfs_estimate.c +++ b/estimate/xfs_estimate.c @@ -214,7 +214,7 @@ ffn(const char *path, const struct stat *stb, int flags, struct FTW *f) nfiles++; break; case S_IFLNK: /* symbolic links */ - if (stb->st_size >= (INODESIZE - (sizeof(xfs_dinode_t)+4))) + if (stb->st_size >= (INODESIZE - (sizeof(struct xfs_dinode)+4))) fullblocks+=FBLOCKS(stb->st_size + blocksize-1); nslinks++; break; diff --git a/libxfs/util.c b/libxfs/util.c index 69cc477c..9f1ca907 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -336,7 +336,7 @@ libxfs_iflush_int( struct xfs_buf *bp) { struct xfs_inode_log_item *iip; - xfs_dinode_t *dip; + struct xfs_dinode *dip; xfs_mount_t *mp; ASSERT(ip->i_df.if_format != XFS_DINODE_FMT_BTREE || diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 2d7057b7..347c291c 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -780,7 +780,7 @@ static inline time64_t xfs_bigtime_to_unix(uint64_t ondisk_seconds) * padding field for v3 inodes. */ #define XFS_DINODE_MAGIC 0x494e /* 'IN' */ -typedef struct xfs_dinode { +struct xfs_dinode { __be16 di_magic; /* inode magic # = XFS_DINODE_MAGIC */ __be16 di_mode; /* mode and type of file */ __u8 di_version; /* inode version */ @@ -825,7 +825,7 @@ typedef struct xfs_dinode { uuid_t di_uuid; /* UUID of the filesystem */ /* structure must be padded to 64 bit alignment */ -} xfs_dinode_t; +}; #define XFS_DINODE_CRC_OFF offsetof(struct xfs_dinode, di_crc) diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c index 68bd5f52..e22e49a4 100644 --- a/libxfs/xfs_inode_buf.c +++ b/libxfs/xfs_inode_buf.c @@ -48,9 +48,9 @@ xfs_inode_buf_verify( agno = xfs_daddr_to_agno(mp, xfs_buf_daddr(bp)); ni = XFS_BB_TO_FSB(mp, bp->b_length) * mp->m_sb.sb_inopblock; for (i = 0; i < ni; i++) { - int di_ok; - xfs_dinode_t *dip; - xfs_agino_t unlinked_ino; + struct xfs_dinode *dip; + xfs_agino_t unlinked_ino; + int di_ok; dip = xfs_buf_offset(bp, (i << mp->m_sb.sb_inodelog)); unlinked_ino = be32_to_cpu(dip->di_next_unlinked); diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index 1a49c41f..bd581fe8 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -65,10 +65,10 @@ xfs_init_local_fork( */ STATIC int xfs_iformat_local( - xfs_inode_t *ip, - xfs_dinode_t *dip, - int whichfork, - int size) + struct xfs_inode *ip, + struct xfs_dinode *dip, + int whichfork, + int size) { /* * If the size is unreasonable, then something @@ -160,8 +160,8 @@ xfs_iformat_extents( */ STATIC int xfs_iformat_btree( - xfs_inode_t *ip, - xfs_dinode_t *dip, + struct xfs_inode *ip, + struct xfs_dinode *dip, int whichfork) { struct xfs_mount *mp = ip->i_mount; @@ -578,8 +578,8 @@ xfs_iextents_copy( */ void xfs_iflush_fork( - xfs_inode_t *ip, - xfs_dinode_t *dip, + struct xfs_inode *ip, + struct xfs_dinode *dip, struct xfs_inode_log_item *iip, int whichfork) { diff --git a/repair/attr_repair.c b/repair/attr_repair.c index 927dd095..50c46619 100644 --- a/repair/attr_repair.c +++ b/repair/attr_repair.c @@ -207,7 +207,7 @@ static int process_shortform_attr( struct xfs_mount *mp, xfs_ino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, int *repair) { struct xfs_attr_shortform *asf; @@ -881,7 +881,7 @@ static int process_node_attr( xfs_mount_t *mp, xfs_ino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, blkmap_t *blkmap) { xfs_dablk_t bno; @@ -1205,7 +1205,7 @@ int process_attributes( xfs_mount_t *mp, xfs_ino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, blkmap_t *blkmap, int *repair) /* returned if we did repair */ { diff --git a/repair/attr_repair.h b/repair/attr_repair.h index 2771d7eb..dc53d8a6 100644 --- a/repair/attr_repair.h +++ b/repair/attr_repair.h @@ -97,7 +97,7 @@ typedef struct xfs_cap_set { * External functions */ struct blkmap; -extern int process_attributes (xfs_mount_t *, xfs_ino_t, xfs_dinode_t *, +extern int process_attributes (xfs_mount_t *, xfs_ino_t, struct xfs_dinode *, struct blkmap *, int *); #endif /* _XR_ATTRREPAIR_H */ diff --git a/repair/da_util.h b/repair/da_util.h index 2e26178c..587ba68b 100644 --- a/repair/da_util.h +++ b/repair/da_util.h @@ -19,7 +19,7 @@ typedef struct da_bt_cursor { int active; /* highest level in tree (# levels-1) */ xfs_ino_t ino; xfs_dablk_t greatest_bno; - xfs_dinode_t *dip; + struct xfs_dinode *dip; struct da_level_state level[XFS_DA_NODE_MAXDEPTH]; struct blkmap *blkmap; } da_bt_cursor_t; diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c index 51cd06f0..67f86c7a 100644 --- a/repair/dino_chunks.c +++ b/repair/dino_chunks.c @@ -27,7 +27,7 @@ check_aginode_block(xfs_mount_t *mp, xfs_agblock_t agbno) { - xfs_dinode_t *dino_p; + struct xfs_dinode *dino_p; int i; int cnt = 0; struct xfs_buf *bp; @@ -598,7 +598,7 @@ process_inode_chunk( xfs_ino_t parent; ino_tree_node_t *ino_rec; struct xfs_buf **bplist; - xfs_dinode_t *dino; + struct xfs_dinode *dino; int icnt; int status; int bp_found; diff --git a/repair/dinode.c b/repair/dinode.c index 4da39dcc..a9ab3d99 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -57,7 +57,7 @@ get_forkname(int whichfork) */ static int -clear_dinode_attr(xfs_mount_t *mp, xfs_dinode_t *dino, xfs_ino_t ino_num) +clear_dinode_attr(xfs_mount_t *mp, struct xfs_dinode *dino, xfs_ino_t ino_num) { ASSERT(dino->di_forkoff != 0); @@ -106,7 +106,7 @@ _("would have cleared inode %" PRIu64 " attributes\n"), ino_num); } static void -clear_dinode_core(struct xfs_mount *mp, xfs_dinode_t *dinoc, xfs_ino_t ino_num) +clear_dinode_core(struct xfs_mount *mp, struct xfs_dinode *dinoc, xfs_ino_t ino_num) { memset(dinoc, 0, sizeof(*dinoc)); dinoc->di_magic = cpu_to_be16(XFS_DINODE_MAGIC); @@ -126,7 +126,7 @@ clear_dinode_core(struct xfs_mount *mp, xfs_dinode_t *dinoc, xfs_ino_t ino_num) } static void -clear_dinode_unlinked(xfs_mount_t *mp, xfs_dinode_t *dino) +clear_dinode_unlinked(xfs_mount_t *mp, struct xfs_dinode *dino) { dino->di_next_unlinked = cpu_to_be32(NULLAGINO); @@ -137,7 +137,7 @@ clear_dinode_unlinked(xfs_mount_t *mp, xfs_dinode_t *dino) * until after the agi unlinked lists are walked in phase 3. */ static void -clear_dinode(xfs_mount_t *mp, xfs_dinode_t *dino, xfs_ino_t ino_num) +clear_dinode(xfs_mount_t *mp, struct xfs_dinode *dino, xfs_ino_t ino_num) { clear_dinode_core(mp, dino, ino_num); clear_dinode_unlinked(mp, dino); @@ -744,7 +744,7 @@ process_btinode( xfs_mount_t *mp, xfs_agnumber_t agno, xfs_agino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, int type, int *dirty, xfs_rfsblock_t *tot, @@ -919,7 +919,7 @@ process_exinode( xfs_mount_t *mp, xfs_agnumber_t agno, xfs_agino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, int type, int *dirty, xfs_rfsblock_t *tot, @@ -974,7 +974,7 @@ process_lclinode( xfs_mount_t *mp, xfs_agnumber_t agno, xfs_agino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, int whichfork) { struct xfs_attr_shortform *asf; @@ -1010,7 +1010,7 @@ process_lclinode( } static int -process_symlink_extlist(xfs_mount_t *mp, xfs_ino_t lino, xfs_dinode_t *dino) +process_symlink_extlist(xfs_mount_t *mp, xfs_ino_t lino, struct xfs_dinode *dino) { xfs_fileoff_t expected_offset; xfs_bmbt_rec_t *rp; @@ -1324,7 +1324,7 @@ static int process_symlink( xfs_mount_t *mp, xfs_ino_t lino, - xfs_dinode_t *dino, + struct xfs_dinode *dino, blkmap_t *blkmap) { char *symlink; @@ -1388,7 +1388,7 @@ _("found illegal null character in symlink inode %" PRIu64 "\n"), */ static int process_misc_ino_types(xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, xfs_ino_t lino, int type) { @@ -1480,14 +1480,14 @@ _("size of fifo inode %" PRIu64 " != 0 (%" PRIu64 " blocks)\n"), static inline int dinode_fmt( - xfs_dinode_t *dino) + struct xfs_dinode *dino) { return be16_to_cpu(dino->di_mode) & S_IFMT; } static inline void change_dinode_fmt( - xfs_dinode_t *dino, + struct xfs_dinode *dino, int new_fmt) { int mode = be16_to_cpu(dino->di_mode); @@ -1501,7 +1501,7 @@ change_dinode_fmt( static int check_dinode_mode_format( - xfs_dinode_t *dinoc) + struct xfs_dinode *dinoc) { if (dinoc->di_format >= XFS_DINODE_FMT_UUID) return -1; /* FMT_UUID is not used */ @@ -1538,7 +1538,7 @@ check_dinode_mode_format( static int process_check_sb_inodes( xfs_mount_t *mp, - xfs_dinode_t *dinoc, + struct xfs_dinode *dinoc, xfs_ino_t lino, int *type, int *dirty) @@ -1643,7 +1643,7 @@ _("bad # of extents (%u) for realtime bitmap inode %" PRIu64 "\n"), static int process_check_inode_sizes( xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, xfs_ino_t lino, int type) { @@ -1735,7 +1735,7 @@ _("realtime summary inode %" PRIu64 " has bad size %" PRId64 " (should be %d)\n" static int process_check_inode_forkoff( xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, xfs_ino_t lino) { if (dino->di_forkoff == 0) @@ -1773,7 +1773,7 @@ _("bad attr fork offset %d in inode %" PRIu64 ", max=%zu\n"), */ static int process_inode_blocks_and_extents( - xfs_dinode_t *dino, + struct xfs_dinode *dino, xfs_rfsblock_t nblocks, uint64_t nextents, uint64_t anextents, @@ -1862,7 +1862,7 @@ process_inode_data_fork( xfs_mount_t *mp, xfs_agnumber_t agno, xfs_agino_t ino, - xfs_dinode_t *dino, + struct xfs_dinode *dino, int type, int *dirty, xfs_rfsblock_t *totblocks, @@ -1971,7 +1971,7 @@ process_inode_attr_fork( xfs_mount_t *mp, xfs_agnumber_t agno, xfs_agino_t ino, - xfs_dinode_t *dino, + struct xfs_dinode *dino, int type, int *dirty, xfs_rfsblock_t *atotblocks, @@ -2125,7 +2125,7 @@ process_inode_attr_fork( static int process_check_inode_nlink_version( - xfs_dinode_t *dino, + struct xfs_dinode *dino, xfs_ino_t lino) { int dirty = 0; @@ -2240,7 +2240,7 @@ _("Bad extent size hint %u on inode %" PRIu64 ", "), */ static int process_dinode_int(xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, xfs_agnumber_t agno, xfs_agino_t ino, int was_free, /* 1 if inode is currently free */ @@ -2922,7 +2922,7 @@ _("Bad CoW extent size %u on inode %" PRIu64 ", "), int process_dinode( xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, xfs_agnumber_t agno, xfs_agino_t ino, int was_free, @@ -2954,7 +2954,7 @@ process_dinode( int verify_dinode( xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, xfs_agnumber_t agno, xfs_agino_t ino) { @@ -2980,7 +2980,7 @@ verify_dinode( int verify_uncertain_dinode( xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, xfs_agnumber_t agno, xfs_agino_t ino) { diff --git a/repair/dinode.h b/repair/dinode.h index 1bd0e0b7..4ed8b46f 100644 --- a/repair/dinode.h +++ b/repair/dinode.h @@ -44,7 +44,7 @@ update_rootino(xfs_mount_t *mp); int process_dinode(xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, xfs_agnumber_t agno, xfs_agino_t ino, int was_free, @@ -58,13 +58,13 @@ process_dinode(xfs_mount_t *mp, int verify_dinode(xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, xfs_agnumber_t agno, xfs_agino_t ino); int verify_uncertain_dinode(xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, xfs_agnumber_t agno, xfs_agino_t ino); diff --git a/repair/dir2.c b/repair/dir2.c index 946e729e..0b3e8e1b 100644 --- a/repair/dir2.c +++ b/repair/dir2.c @@ -118,7 +118,7 @@ process_sf_dir2_fixi8( static void process_sf_dir2_fixoff( xfs_mount_t *mp, - xfs_dinode_t *dip) + struct xfs_dinode *dip) { int i; int offset; @@ -147,7 +147,7 @@ static int process_sf_dir2( xfs_mount_t *mp, xfs_ino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, int ino_discovery, int *dino_dirty, /* out - 1 if dinode buffer dirty */ char *dirname, /* directory pathname */ @@ -566,7 +566,7 @@ static int process_dir2_data( xfs_mount_t *mp, xfs_ino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, int ino_discovery, char *dirname, /* directory pathname */ xfs_ino_t *parent, /* out - NULLFSINO if entry not exist */ @@ -962,7 +962,7 @@ static int process_block_dir2( xfs_mount_t *mp, xfs_ino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, int ino_discovery, int *dino_dirty, /* out - 1 if dinode buffer dirty */ char *dirname, /* directory pathname */ @@ -1249,7 +1249,7 @@ static int process_node_dir2( xfs_mount_t *mp, xfs_ino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, blkmap_t *blkmap, int *repair) { @@ -1309,7 +1309,7 @@ static int process_leaf_node_dir2( xfs_mount_t *mp, xfs_ino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, int ino_discovery, char *dirname, /* directory pathname */ xfs_ino_t *parent, /* out - NULLFSINO if entry not exist */ @@ -1407,7 +1407,7 @@ int process_dir2( xfs_mount_t *mp, xfs_ino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, int ino_discovery, int *dino_dirty, char *dirname, diff --git a/repair/dir2.h b/repair/dir2.h index af4cfb1d..f3b24cc0 100644 --- a/repair/dir2.h +++ b/repair/dir2.h @@ -14,7 +14,7 @@ int process_dir2( xfs_mount_t *mp, xfs_ino_t ino, - xfs_dinode_t *dip, + struct xfs_dinode *dip, int ino_discovery, int *dirty, char *dirname, diff --git a/repair/incore.h b/repair/incore.h index 65c03dde..c5365899 100644 --- a/repair/incore.h +++ b/repair/incore.h @@ -630,7 +630,7 @@ typedef struct bm_level_state { typedef struct bm_cursor { int num_levels; xfs_ino_t ino; - xfs_dinode_t *dip; + struct xfs_dinode *dip; bm_level_state_t level[XR_MAX_BMLEVELS]; } bmap_cursor_t; diff --git a/repair/prefetch.c b/repair/prefetch.c index 83af5bc7..a1c69612 100644 --- a/repair/prefetch.c +++ b/repair/prefetch.c @@ -350,7 +350,7 @@ pf_scanfunc_bmap( static void pf_read_btinode( prefetch_args_t *args, - xfs_dinode_t *dino, + struct xfs_dinode *dino, int isadir) { xfs_bmdr_block_t *dib; @@ -390,7 +390,7 @@ pf_read_btinode( static void pf_read_exinode( prefetch_args_t *args, - xfs_dinode_t *dino) + struct xfs_dinode *dino) { pf_read_bmbt_reclist(args, (xfs_bmbt_rec_t *)XFS_DFORK_DPTR(dino), be32_to_cpu(dino->di_nextents)); @@ -401,7 +401,7 @@ pf_read_inode_dirs( prefetch_args_t *args, struct xfs_buf *bp) { - xfs_dinode_t *dino; + struct xfs_dinode *dino; int icnt = 0; int hasdir = 0; int isadir; diff --git a/repair/rt.c b/repair/rt.c index 793efb80..73f88316 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -154,7 +154,7 @@ check_summary(xfs_mount_t *mp) */ void process_rtbitmap(xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, blkmap_t *blkmap) { int error; @@ -239,7 +239,7 @@ process_rtbitmap(xfs_mount_t *mp, */ void process_rtsummary(xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, blkmap_t *blkmap) { xfs_fsblock_t bno; diff --git a/repair/rt.h b/repair/rt.h index 4558d1a2..f6cd55d2 100644 --- a/repair/rt.h +++ b/repair/rt.h @@ -21,7 +21,7 @@ check_summary(xfs_mount_t *mp); void process_rtbitmap(xfs_mount_t *mp, - xfs_dinode_t *dino, + struct xfs_dinode *dino, struct blkmap *blkmap); void From patchwork Thu Jan 20 00:23:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E47B4C433EF for ; Thu, 20 Jan 2022 00:23:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240560AbiATAXw (ORCPT ); Wed, 19 Jan 2022 19:23:52 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60204 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237314AbiATAXw (ORCPT ); Wed, 19 Jan 2022 19:23:52 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C99FE61518 for ; Thu, 20 Jan 2022 00:23:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D5EEC004E1; Thu, 20 Jan 2022 00:23:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638231; bh=9a8TdlSNB7FLZOEqyE9/9fySGogyun37pta63CEanco=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=jTgmeOBSLESKTE/KFYieIq5cSwx5xml8IaZvMpjlyiSnA5ojYpoXI85I9NMuoC422 VbYK+L1UBsuljfhsJ3mxOtUGxBRyFXYMWCeck7+Owngw5p0wVPUTk+7BoUeYif6LyO YgE5+DYy4pfLxBCm902N4N4svX8S5Zy1J3BOc700sZsSKHgIVhjR9EJ06PNz8X0zhr uzQrWMaO1mk1KJjM3XmY5PiFXB0HYxBzpDwg2udDqC44ULXDWM8Ys5CPPx0up5K0Vm nkCFSzs0BNKZX34tWajzXU6A3FpLQiTaGoK/67h688v2AdNvztlN40CBXs8LvLatdd RY/EGKd7UOFRA== Subject: [PATCH 07/48] xfs: remove the xfs_dsb_t typedef From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:23:50 -0800 Message-ID: <164263823084.865554.3241633670572014327.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Christoph Hellwig Source kernel commit: ed67ebfd7c4061b4b505ac42eb00e08dd09f4d38 Remove the few leftover instances of the xfs_dinode_t typedef. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- copy/xfs_copy.c | 2 +- copy/xfs_copy.h | 2 +- libxfs/xfs_format.h | 4 ++-- libxfs/xfs_sb.c | 4 ++-- logprint/logprint.c | 2 +- mdrestore/xfs_mdrestore.c | 6 +++--- repair/sb.c | 6 +++--- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 2642114f..41f594bd 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -471,7 +471,7 @@ read_ag_header(int fd, xfs_agnumber_t agno, wbuf *buf, ag_header_t *ag, read_wbuf(fd, buf, mp); ASSERT(buf->length >= length); - ag->xfs_sb = (xfs_dsb_t *) (buf->data + diff); + ag->xfs_sb = (struct xfs_dsb *) (buf->data + diff); ASSERT(be32_to_cpu(ag->xfs_sb->sb_magicnum) == XFS_SB_MAGIC); ag->xfs_agf = (xfs_agf_t *) (buf->data + diff + sectorsize); ASSERT(be32_to_cpu(ag->xfs_agf->agf_magicnum) == XFS_AGF_MAGIC); diff --git a/copy/xfs_copy.h b/copy/xfs_copy.h index 0b0ec0ea..1eb168d3 100644 --- a/copy/xfs_copy.h +++ b/copy/xfs_copy.h @@ -18,7 +18,7 @@ * each of which is an AG and has an ag_header at the beginning. */ typedef struct ag_header { - xfs_dsb_t *xfs_sb; /* superblock for filesystem or AG */ + struct xfs_dsb *xfs_sb; /* superblock for filesystem or AG */ xfs_agf_t *xfs_agf; /* free space info */ xfs_agi_t *xfs_agi; /* free inode info */ struct xfs_agfl *xfs_agfl; /* AG freelist */ diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 347c291c..10f38541 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -184,7 +184,7 @@ typedef struct xfs_sb { * Superblock - on disk version. Must match the in core version above. * Must be padded to 64 bit alignment. */ -typedef struct xfs_dsb { +struct xfs_dsb { __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */ __be32 sb_blocksize; /* logical block size, bytes */ __be64 sb_dblocks; /* number of data blocks */ @@ -263,7 +263,7 @@ typedef struct xfs_dsb { uuid_t sb_meta_uuid; /* metadata file system unique id */ /* must be padded to 64 bit alignment */ -} xfs_dsb_t; +}; /* * Misc. Flags - warning - these will be cleared by xfs_repair unless diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index d7e3526c..986f9466 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -493,7 +493,7 @@ xfs_sb_quota_from_disk(struct xfs_sb *sbp) static void __xfs_sb_from_disk( struct xfs_sb *to, - xfs_dsb_t *from, + struct xfs_dsb *from, bool convert_xquota) { to->sb_magicnum = be32_to_cpu(from->sb_magicnum); @@ -569,7 +569,7 @@ __xfs_sb_from_disk( void xfs_sb_from_disk( struct xfs_sb *to, - xfs_dsb_t *from) + struct xfs_dsb *from) { __xfs_sb_from_disk(to, from, true); } diff --git a/logprint/logprint.c b/logprint/logprint.c index 3514d013..9a8811f4 100644 --- a/logprint/logprint.c +++ b/logprint/logprint.c @@ -79,7 +79,7 @@ logstat(xfs_mount_t *mp) * Conjure up a mount structure */ sb = &mp->m_sb; - libxfs_sb_from_disk(sb, (xfs_dsb_t *)buf); + libxfs_sb_from_disk(sb, (struct xfs_dsb *)buf); mp->m_features |= libxfs_sb_version_to_features(&mp->m_sb); mp->m_blkbb_log = sb->sb_blocklog - BBSHIFT; diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 1cd399db..7c1a66c4 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -89,7 +89,7 @@ perform_restore( if (fread(block_buffer, mb_count << mbp->mb_blocklog, 1, src_f) != 1) fatal("error reading from metadump file\n"); - libxfs_sb_from_disk(&sb, (xfs_dsb_t *)block_buffer); + libxfs_sb_from_disk(&sb, (struct xfs_dsb *)block_buffer); if (sb.sb_magicnum != XFS_SB_MAGIC) fatal("bad magic number for primary superblock\n"); @@ -104,7 +104,7 @@ perform_restore( sb.sb_sectsize > max_indices * block_size) fatal("bad sector size %u in metadump image\n", sb.sb_sectsize); - ((xfs_dsb_t*)block_buffer)->sb_inprogress = 1; + ((struct xfs_dsb*)block_buffer)->sb_inprogress = 1; if (is_target_file) { /* ensure regular files are correctly sized */ @@ -163,7 +163,7 @@ perform_restore( memset(block_buffer, 0, sb.sb_sectsize); sb.sb_inprogress = 0; - libxfs_sb_to_disk((xfs_dsb_t *)block_buffer, &sb); + libxfs_sb_to_disk((struct xfs_dsb *)block_buffer, &sb); if (xfs_sb_version_hascrc(&sb)) { xfs_update_cksum(block_buffer, sb.sb_sectsize, offsetof(struct xfs_sb, sb_crc)); diff --git a/repair/sb.c b/repair/sb.c index 90f32e74..7391cf04 100644 --- a/repair/sb.c +++ b/repair/sb.c @@ -141,7 +141,7 @@ __find_secondary_sb( */ for (i = 0; !done && i < bsize; i += BBSIZE) { c_bufsb = (char *)sb + i; - libxfs_sb_from_disk(&bufsb, (xfs_dsb_t *)c_bufsb); + libxfs_sb_from_disk(&bufsb, (struct xfs_dsb *)c_bufsb); if (verify_sb(c_bufsb, &bufsb, 0) != XR_OK) continue; @@ -521,7 +521,7 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb) void write_primary_sb(xfs_sb_t *sbp, int size) { - xfs_dsb_t *buf; + struct xfs_dsb *buf; if (no_modify) return; @@ -558,7 +558,7 @@ int get_sb(xfs_sb_t *sbp, xfs_off_t off, int size, xfs_agnumber_t agno) { int error, rval; - xfs_dsb_t *buf; + struct xfs_dsb *buf; buf = memalign(libxfs_device_alignment(), size); if (buf == NULL) { From patchwork Thu Jan 20 00:23:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717971 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 928C1C433F5 for ; Thu, 20 Jan 2022 00:23:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345251AbiATAX6 (ORCPT ); Wed, 19 Jan 2022 19:23:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240611AbiATAX5 (ORCPT ); Wed, 19 Jan 2022 19:23:57 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B465DC061574 for ; Wed, 19 Jan 2022 16:23:57 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 544F561514 for ; Thu, 20 Jan 2022 00:23:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE1AFC004E1; Thu, 20 Jan 2022 00:23:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638236; bh=kKSCEh9Brtps/lreAEL6ivx8QhPzfkPU/WSCnbhG6ao=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=r3hEP4innc9Ynm02jWM0IA4GbqrNKllWv5kpMxN+AB7Q/WdY6SbNKo0mAnQ5uJqLo etAx4GspEWpxZiTDI2hBjDZMYaKPialbfIufrIJqGEd+QTgq4R6D81gYtHkgyAWNdE +Ly4zN704mOveNvACGDYFGPdgilii23Rh5VFe3sM5MA4k+vRsE2G5bxBJdJxfAQHVo 8ayvGykA0x9hvJ63cVUDPw7lm59gyoQPxi9g2X7mCMHsJhOkiezPI1COlueuqCsFdK fpRhETEkvzKW+gZ8ytdKdZ1i/4QKNMOsIK3YW5sMzT76UYw1UOC5eUKVu1EoOUYKWh sgi3B1vEWaffw== Subject: [PATCH 08/48] xfs: remove the xfs_dqblk_t typedef From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:23:56 -0800 Message-ID: <164263823637.865554.14010692926217489679.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Christoph Hellwig Source kernel commit: 11a83f4c393040dc3a6a368c6399785dbfae7602 Remove the few leftover instances of the xfs_dinode_t typedef. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- db/check.c | 2 +- db/dquot.c | 8 ++++---- db/field.c | 2 +- libxfs/xfs_dquot_buf.c | 4 ++-- libxfs/xfs_format.h | 4 ++-- logprint/log_print_all.c | 2 +- repair/dinode.c | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/db/check.c b/db/check.c index 496a4da3..654631a5 100644 --- a/db/check.c +++ b/db/check.c @@ -3461,7 +3461,7 @@ process_quota( { xfs_fsblock_t bno; int cb; - xfs_dqblk_t *dqb; + struct xfs_dqblk *dqb; xfs_dqid_t dqid; uint8_t exp_flags = 0; uint i; diff --git a/db/dquot.c b/db/dquot.c index e52000f2..76853a72 100644 --- a/db/dquot.c +++ b/db/dquot.c @@ -32,8 +32,8 @@ const field_t dqblk_hfld[] = { { NULL } }; -#define DDOFF(f) bitize(offsetof(xfs_dqblk_t, dd_ ## f)) -#define DDSZC(f) szcount(xfs_dqblk_t, dd_ ## f) +#define DDOFF(f) bitize(offsetof(struct xfs_dqblk, dd_ ## f)) +#define DDSZC(f) szcount(struct xfs_dqblk, dd_ ## f) const field_t dqblk_flds[] = { { "diskdq", FLDT_DISK_DQUOT, OI(DDOFF(diskdq)), C1, 0, TYP_NONE }, { "fill", FLDT_CHARS, OI(DDOFF(fill)), CI(DDSZC(fill)), FLD_SKIPALL, @@ -138,7 +138,7 @@ dquot_f( dbprintf(_("bad %s id for dquot %s\n"), s, argv[optind]); return 0; } - perblock = (int)(mp->m_sb.sb_blocksize / sizeof(xfs_dqblk_t)); + perblock = (int)(mp->m_sb.sb_blocksize / sizeof(struct xfs_dqblk)); qbno = (xfs_fileoff_t)id / perblock; qoff = (int)(id % perblock); push_cur(); @@ -153,7 +153,7 @@ dquot_f( set_cur(&typtab[TYP_DQBLK], XFS_FSB_TO_DADDR(mp, bm.startblock), blkbb, DB_RING_IGN, NULL); iocur_top->dquot_buf = 1; - off_cur(qoff * (int)sizeof(xfs_dqblk_t), sizeof(xfs_dqblk_t)); + off_cur(qoff * (int)sizeof(struct xfs_dqblk), sizeof(struct xfs_dqblk)); ring_add(); return 0; } diff --git a/db/field.c b/db/field.c index 90d3609a..0a089b56 100644 --- a/db/field.c +++ b/db/field.c @@ -290,7 +290,7 @@ const ftattr_t ftattrtab[] = { fa_dirblock, NULL }, { FLDT_DISK_DQUOT, "disk_dquot", NULL, (char *)disk_dquot_flds, SI(bitsz(struct xfs_disk_dquot)), 0, NULL, disk_dquot_flds }, - { FLDT_DQBLK, "dqblk", NULL, (char *)dqblk_flds, SI(bitsz(xfs_dqblk_t)), + { FLDT_DQBLK, "dqblk", NULL, (char *)dqblk_flds, SI(bitsz(struct xfs_dqblk)), 0, NULL, dqblk_flds }, { FLDT_DQID, "dqid", fp_num, "%d", SI(bitsz(xfs_dqid_t)), 0, NULL, NULL }, diff --git a/libxfs/xfs_dquot_buf.c b/libxfs/xfs_dquot_buf.c index ecb4a002..db603cab 100644 --- a/libxfs/xfs_dquot_buf.c +++ b/libxfs/xfs_dquot_buf.c @@ -20,7 +20,7 @@ xfs_calc_dquots_per_chunk( unsigned int nbblks) /* basic block units */ { ASSERT(nbblks > 0); - return BBTOB(nbblks) / sizeof(xfs_dqblk_t); + return BBTOB(nbblks) / sizeof(struct xfs_dqblk); } /* @@ -125,7 +125,7 @@ xfs_dqblk_repair( * Typically, a repair is only requested by quotacheck. */ ASSERT(id != -1); - memset(dqb, 0, sizeof(xfs_dqblk_t)); + memset(dqb, 0, sizeof(struct xfs_dqblk)); dqb->dd_diskdq.d_magic = cpu_to_be16(XFS_DQUOT_MAGIC); dqb->dd_diskdq.d_version = XFS_DQUOT_VERSION; diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 10f38541..d665c04e 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -1215,7 +1215,7 @@ struct xfs_disk_dquot { * This is what goes on disk. This is separated from the xfs_disk_dquot because * carrying the unnecessary padding would be a waste of memory. */ -typedef struct xfs_dqblk { +struct xfs_dqblk { struct xfs_disk_dquot dd_diskdq; /* portion living incore as well */ char dd_fill[4];/* filling for posterity */ @@ -1225,7 +1225,7 @@ typedef struct xfs_dqblk { __be32 dd_crc; /* checksum */ __be64 dd_lsn; /* last modification in log */ uuid_t dd_uuid; /* location information */ -} xfs_dqblk_t; +}; #define XFS_DQUOT_CRC_OFF offsetof(struct xfs_dqblk, dd_crc) diff --git a/logprint/log_print_all.c b/logprint/log_print_all.c index c9c453f6..182b9d53 100644 --- a/logprint/log_print_all.c +++ b/logprint/log_print_all.c @@ -172,7 +172,7 @@ xlog_recover_print_buffer( printf(_(" UIDs 0x%lx-0x%lx\n"), (unsigned long)be32_to_cpu(ddq->d_id), (unsigned long)be32_to_cpu(ddq->d_id) + - (BBTOB(f->blf_len) / sizeof(xfs_dqblk_t)) - 1); + (BBTOB(f->blf_len) / sizeof(struct xfs_dqblk)) - 1); } else { printf(_(" BUF DATA\n")); if (!print_buffer) continue; diff --git a/repair/dinode.c b/repair/dinode.c index a9ab3d99..909fea8e 100644 --- a/repair/dinode.c +++ b/repair/dinode.c @@ -1142,7 +1142,7 @@ process_quota_inode( qbno = NULLFILEOFF; while ((qbno = blkmap_next_off(blkmap, qbno, &t)) != NULLFILEOFF) { - xfs_dqblk_t *dqb; + struct xfs_dqblk *dqb; int writebuf = 0; fsbno = blkmap_get(blkmap, qbno); From patchwork Thu Jan 20 00:24:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717972 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA4FAC433EF for ; Thu, 20 Jan 2022 00:24:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234599AbiATAYF (ORCPT ); Wed, 19 Jan 2022 19:24:05 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:47804 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345222AbiATAYE (ORCPT ); Wed, 19 Jan 2022 19:24:04 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5FAE2B81AD5 for ; Thu, 20 Jan 2022 00:24:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A60DC004E1; Thu, 20 Jan 2022 00:24:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638242; bh=MtsU0qxh8RAaQl3qgouNWvDMiIp0ssPAgnX+F8hw5IQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=c7poxNPNRd8LLmt6dgsMaHwX7UZBzthi/voav2ywa08ik29Vg5qpl4xA5ddgiVCZv jeUZtL14vbDQUEKaO+6zmxhowhEwChcKIVVGtMFaoR56TROzQmPismTughqYRAecUf oNbo9IMqDlNIHCvIwyMiEhhGpUgqSzeM5/2hpMr95YnGTZ3Wd/3+kDCgzjfSVRGq/h XQZz9D5R1K9laX2oHm4IQ13cK8fbw1M/1WO3qLSmeqGhaZZZ9yKUbT+Vpwp/Gltily +nyRS4n+JEqOeNmFRYH41oniShGYCiBltxEgyI1hGMuohJZ18rN73Gb385Jp0HisZv zUhXoPtG2YUkQ== Subject: [PATCH 09/48] xfs: fold perag loop iteration logic into helper function From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Brian Foster , Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:24:01 -0800 Message-ID: <164263824189.865554.51073696809603760.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Brian Foster Source kernel commit: bf2307b195135ed9c95eebb38920d8bd41843092 Fold the loop iteration logic into a helper in preparation for further fixups. No functional change in this patch. Signed-off-by: Brian Foster Reviewed-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- libxfs/xfs_ag.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 2522f766..95570df0 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -126,12 +126,22 @@ void xfs_perag_put(struct xfs_perag *pag); * for_each_perag_from() because they terminate at sb_agcount where there are * no perag structures in tree beyond end_agno. */ +static inline struct xfs_perag * +xfs_perag_next( + struct xfs_perag *pag, + xfs_agnumber_t *next_agno) +{ + struct xfs_mount *mp = pag->pag_mount; + + *next_agno = pag->pag_agno + 1; + xfs_perag_put(pag); + return xfs_perag_get(mp, *next_agno); +} + #define for_each_perag_range(mp, next_agno, end_agno, pag) \ for ((pag) = xfs_perag_get((mp), (next_agno)); \ (pag) != NULL && (next_agno) <= (end_agno); \ - (next_agno) = (pag)->pag_agno + 1, \ - xfs_perag_put(pag), \ - (pag) = xfs_perag_get((mp), (next_agno))) + (pag) = xfs_perag_next((pag), &(next_agno))) #define for_each_perag_from(mp, next_agno, pag) \ for_each_perag_range((mp), (next_agno), (mp)->m_sb.sb_agcount, (pag)) From patchwork Thu Jan 20 00:24:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717973 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F605C433F5 for ; Thu, 20 Jan 2022 00:24:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240529AbiATAYJ (ORCPT ); Wed, 19 Jan 2022 19:24:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345270AbiATAYJ (ORCPT ); Wed, 19 Jan 2022 19:24:09 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2DCCC061574 for ; Wed, 19 Jan 2022 16:24:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 52D056150C for ; Thu, 20 Jan 2022 00:24:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA89CC004E1; Thu, 20 Jan 2022 00:24:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638247; bh=rTgVrWZOtLUovkIrG3Srjb0+iCsMoJi6djpPtRr0Axw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=GPw0gUWRBQZeMQKCid1IljDZ+X/WwMloEETGfQATiDi/Cr+1v443+EDkk1ZlYvnfL f6+QPVTVV8MtGg+Uxgn8JcRla/tqWLDmUn7KJyTi8jbpKxwAL9G8twR8kFfs22Q3HB XSlGyXy3l8eAdXg8yFJB2QpNvq3FkSgbsNZYGsrlWAuEcZror6aNuKXGQBH2lNUjZ1 uZpFB0ujhsw4Gavni2INTfE9QxVa9Iqo419yt8ZA82A9v+EJV8tbRP9Y3OHDOvr/R+ 9474w7VEZVObd6TdRNOUn4lYkhJOBoBmEnqPgZXQA/BSCb8mdU8uupUfx3DmYFNcx+ 03UvOGtyM3+cg== Subject: [PATCH 10/48] xfs: rename the next_agno perag iteration variable From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Brian Foster , Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:24:07 -0800 Message-ID: <164263824735.865554.7075356687013149400.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Brian Foster Source kernel commit: f1788b5e5ee25bedf00bb4d25f82b93820d61189 Rename the next_agno variable to be consistent across the several iteration macros and shorten line length. Signed-off-by: Brian Foster Reviewed-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- libxfs/xfs_ag.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 95570df0..9cd06694 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -129,22 +129,22 @@ void xfs_perag_put(struct xfs_perag *pag); static inline struct xfs_perag * xfs_perag_next( struct xfs_perag *pag, - xfs_agnumber_t *next_agno) + xfs_agnumber_t *agno) { struct xfs_mount *mp = pag->pag_mount; - *next_agno = pag->pag_agno + 1; + *agno = pag->pag_agno + 1; xfs_perag_put(pag); - return xfs_perag_get(mp, *next_agno); + return xfs_perag_get(mp, *agno); } -#define for_each_perag_range(mp, next_agno, end_agno, pag) \ - for ((pag) = xfs_perag_get((mp), (next_agno)); \ - (pag) != NULL && (next_agno) <= (end_agno); \ - (pag) = xfs_perag_next((pag), &(next_agno))) +#define for_each_perag_range(mp, agno, end_agno, pag) \ + for ((pag) = xfs_perag_get((mp), (agno)); \ + (pag) != NULL && (agno) <= (end_agno); \ + (pag) = xfs_perag_next((pag), &(agno))) -#define for_each_perag_from(mp, next_agno, pag) \ - for_each_perag_range((mp), (next_agno), (mp)->m_sb.sb_agcount, (pag)) +#define for_each_perag_from(mp, agno, pag) \ + for_each_perag_range((mp), (agno), (mp)->m_sb.sb_agcount, (pag)) #define for_each_perag(mp, agno, pag) \ From patchwork Thu Jan 20 00:24:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717974 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 097D7C433EF for ; Thu, 20 Jan 2022 00:24:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240611AbiATAYP (ORCPT ); Wed, 19 Jan 2022 19:24:15 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:47866 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345270AbiATAYP (ORCPT ); Wed, 19 Jan 2022 19:24:15 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6282FB81911 for ; Thu, 20 Jan 2022 00:24:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B88BC004E1; Thu, 20 Jan 2022 00:24:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638253; bh=8e2jp2/c9uRFOFBQ7C0CMaAGmv600zruyRYaNi0lDxc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=bM+45Q2GGVFWXt4viOTY1T+jQrrDi8BSM06jUOQ2OlxGOScrlUl6bPnO6qcgvX9gE hQpCmz2tKb3iTIRFDYc2itbrnh32od3fkOW3CX7B+CeNqWrTptp7aTFyoKG5bqHS32 bxX3vhtrBK2R7ozsESXqsGfz1EVw+pB9/yEo0mx7ofZI7wGjDHgM5HeF3PMg5Z/ps9 72muyKzIWK1j5L/ei5m3pJMWW3Zka4juLHjHBjkkZndow1nRW6mOlQlJB7MkdYfbEB /DkQt/ixBvKVD86ilDRs92ClZfHSvx/Fb1mG9UxxTs3D7T5coCNX/AWHknb4VEuLek 9POZWlDALzRDA== Subject: [PATCH 11/48] xfs: terminate perag iteration reliably on agcount From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Brian Foster , Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:24:12 -0800 Message-ID: <164263825289.865554.13464342972383061245.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Brian Foster Source kernel commit: 8ed004eb9d07a5d6114db3e97a166707c186262d The for_each_perag_from() iteration macro relies on sb_agcount to process every perag currently within EOFS from a given starting point. It's perfectly valid to have perag structures beyond sb_agcount, however, such as if a growfs is in progress. If a perag loop happens to race with growfs in this manner, it will actually attempt to process the post-EOFS perag where ->pag_agno == sb_agcount. This is reproduced by xfs/104 and manifests as the following assert failure in superblock write verifier context: XFS: Assertion failed: agno < mp->m_sb.sb_agcount, file: fs/xfs/libxfs/xfs_types.c, line: 22 Update the corresponding macro to only process perags that are within the current sb_agcount. Fixes: 58d43a7e3263 ("xfs: pass perags around in fsmap data dev functions") Signed-off-by: Brian Foster Reviewed-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- libxfs/xfs_ag.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 9cd06694..fae2a38e 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -144,7 +144,7 @@ xfs_perag_next( (pag) = xfs_perag_next((pag), &(agno))) #define for_each_perag_from(mp, agno, pag) \ - for_each_perag_range((mp), (agno), (mp)->m_sb.sb_agcount, (pag)) + for_each_perag_range((mp), (agno), (mp)->m_sb.sb_agcount - 1, (pag)) #define for_each_perag(mp, agno, pag) \ From patchwork Thu Jan 20 00:24:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717975 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 475BAC433EF for ; Thu, 20 Jan 2022 00:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240596AbiATAYV (ORCPT ); Wed, 19 Jan 2022 19:24:21 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:47890 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345268AbiATAYV (ORCPT ); Wed, 19 Jan 2022 19:24:21 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EE2E4B81A85 for ; Thu, 20 Jan 2022 00:24:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9868DC004E1; Thu, 20 Jan 2022 00:24:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638258; bh=JAec7AUGvrm0SRaNuT9s4Px5J2p9f7Kbr9NsOjvPspE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=pK7seHISgajp349Uu2CgJdi5TJ/EaOyQEnjZL1dnzjtGKxSienDtZ0OuWKNIYHPzc reE+rCbc37Z+x2i8Ev0YEawKgsZIPdkM4GVR2sqwKFauL72q3wivDGDR0HD3I1Ja3V 8CLXJrFouI6HqfoQ14f+cklinmE0+Pr5x17qfyN5LdclFz/Qw4MmylQIfbxhOaFuJT Wt52ObRBoedRgV0mOXN5fvrueigsKEna6rDaHg4pOs4RFjKqy+DRHJ0jJ4wNwP2JFA ZOvoVJIETeYjXxfTR30BSLak4W6WJeuG/RIykpSvObtU1TDeFdRHOApG/w3JZM/WQW T6hoC0tWHLK0g== Subject: [PATCH 12/48] xfs: fix perag reference leak on iteration race with growfs From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Brian Foster , Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:24:18 -0800 Message-ID: <164263825835.865554.16091663428028357322.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Brian Foster Source kernel commit: 892a666fafa19ab04b5e948f6c92f98f1dafb489 The for_each_perag*() set of macros are hacky in that some (i.e. those based on sb_agcount) rely on the assumption that perag iteration terminates naturally with a NULL perag at the specified end_agno. Others allow for the final AG to have a valid perag and require the calling function to clean up any potential leftover xfs_perag reference on termination of the loop. Aside from providing a subtly inconsistent interface, the former variant is racy with growfs because growfs can create discoverable post-eofs perags before the final superblock update that completes the grow operation and increases sb_agcount. This leads to the following assert failure (reproduced by xfs/104) in the perag free path during unmount: XFS: Assertion failed: atomic_read(&pag->pag_ref) == 0, file: fs/xfs/libxfs/xfs_ag.c, line: 195 This occurs because one of the many for_each_perag() loops in the code that is expected to terminate with a NULL pag (and thus has no post-loop xfs_perag_put() check) raced with a growfs and found a non-NULL post-EOFS perag, but terminated naturally based on the end_agno check without releasing the post-EOFS perag. Rework the iteration logic to lift the agno check from the main for loop conditional to the iteration helper function. The for loop now purely terminates on a NULL pag and xfs_perag_next() avoids taking a reference to any perag beyond end_agno in the first place. Fixes: f250eedcf762 ("xfs: make for_each_perag... a first class citizen") Signed-off-by: Brian Foster Reviewed-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- libxfs/xfs_ag.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index fae2a38e..e411d51c 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -118,30 +118,26 @@ void xfs_perag_put(struct xfs_perag *pag); /* * Perag iteration APIs - * - * XXX: for_each_perag_range() usage really needs an iterator to clean up when - * we terminate at end_agno because we may have taken a reference to the perag - * beyond end_agno. Right now callers have to be careful to catch and clean that - * up themselves. This is not necessary for the callers of for_each_perag() and - * for_each_perag_from() because they terminate at sb_agcount where there are - * no perag structures in tree beyond end_agno. */ static inline struct xfs_perag * xfs_perag_next( struct xfs_perag *pag, - xfs_agnumber_t *agno) + xfs_agnumber_t *agno, + xfs_agnumber_t end_agno) { struct xfs_mount *mp = pag->pag_mount; *agno = pag->pag_agno + 1; xfs_perag_put(pag); + if (*agno > end_agno) + return NULL; return xfs_perag_get(mp, *agno); } #define for_each_perag_range(mp, agno, end_agno, pag) \ for ((pag) = xfs_perag_get((mp), (agno)); \ - (pag) != NULL && (agno) <= (end_agno); \ - (pag) = xfs_perag_next((pag), &(agno))) + (pag) != NULL; \ + (pag) = xfs_perag_next((pag), &(agno), (end_agno))) #define for_each_perag_from(mp, agno, pag) \ for_each_perag_range((mp), (agno), (mp)->m_sb.sb_agcount - 1, (pag)) From patchwork Thu Jan 20 00:24:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717976 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB411C433EF for ; Thu, 20 Jan 2022 00:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345269AbiATAYZ (ORCPT ); Wed, 19 Jan 2022 19:24:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345222AbiATAYZ (ORCPT ); Wed, 19 Jan 2022 19:24:25 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27B3DC061574 for ; Wed, 19 Jan 2022 16:24:25 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B88D26150C for ; Thu, 20 Jan 2022 00:24:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DD0DC004E1; Thu, 20 Jan 2022 00:24:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638264; bh=eThtSgh6puhCDl2tK7Spv6x0YBKzRogBFmeU4mq/iwo=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=BCgA7aFIHSmuLkDg/ddnA6rsqs4rJX0aqCRuWHGkAHruYeu2fjrg7ZZRLrwHcEpkR HuX2mr2qLwjpuwWbHDUxQDPwPKLgz0g7fJ9WhiexyRlOb20S4X++PLOHqoSDlQ4YJQ bAudZ/n+BJ/gjtEZc8Ope3lZaB6+HetxLy2CAw8KQGOSehCVqk+UhLzmutik2zJkel 7+jK6TeAi5O5sLXv4QTUx9G+KsjiUPtz+e+1B+QNDAdbrSZ7PCZcQ3rISjno/YZJEz QEwSQbNGowlVKzgx5N/s2tQ+xlOFWDoU76Vx+WWf1By3XfLKHZXLHcGt8xi4kspYP3 3+RSTj7SXPrJw== Subject: [PATCH 13/48] xfs: remove xfs_btree_cur.bc_blocklog From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:24:23 -0800 Message-ID: <164263826380.865554.7368372957111538202.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: cc411740472d958b718b9c6a7791ba00d88f7cef This field isn't used by anyone, so get rid of it. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- libxfs/xfs_alloc_btree.c | 1 - libxfs/xfs_bmap_btree.c | 1 - libxfs/xfs_btree.h | 1 - libxfs/xfs_ialloc_btree.c | 2 -- libxfs/xfs_refcount_btree.c | 1 - libxfs/xfs_rmap_btree.c | 1 - 6 files changed, 7 deletions(-) diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c index 03ebefc3..46d0f229 100644 --- a/libxfs/xfs_alloc_btree.c +++ b/libxfs/xfs_alloc_btree.c @@ -480,7 +480,6 @@ xfs_allocbt_init_common( cur->bc_tp = tp; cur->bc_mp = mp; cur->bc_btnum = btnum; - cur->bc_blocklog = mp->m_sb.sb_blocklog; cur->bc_ag.abt.active = false; if (btnum == XFS_BTNUM_CNT) { diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c index aea9b5a8..565e8af7 100644 --- a/libxfs/xfs_bmap_btree.c +++ b/libxfs/xfs_bmap_btree.c @@ -556,7 +556,6 @@ xfs_bmbt_init_cursor( cur->bc_mp = mp; cur->bc_nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1; cur->bc_btnum = XFS_BTNUM_BMAP; - cur->bc_blocklog = mp->m_sb.sb_blocklog; cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_bmbt_2); cur->bc_ops = &xfs_bmbt_ops; diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index 513ade4a..49ecc496 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -229,7 +229,6 @@ struct xfs_btree_cur #define XFS_BTCUR_LEFTRA 1 /* left sibling has been read-ahead */ #define XFS_BTCUR_RIGHTRA 2 /* right sibling has been read-ahead */ uint8_t bc_nlevels; /* number of levels in the tree */ - uint8_t bc_blocklog; /* log2(blocksize) of btree blocks */ xfs_btnum_t bc_btnum; /* identifies which btree type */ int bc_statoff; /* offset of btre stats array */ diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c index 1a5289ce..f1e03cfd 100644 --- a/libxfs/xfs_ialloc_btree.c +++ b/libxfs/xfs_ialloc_btree.c @@ -443,8 +443,6 @@ xfs_inobt_init_common( cur->bc_ops = &xfs_finobt_ops; } - cur->bc_blocklog = mp->m_sb.sb_blocklog; - if (xfs_has_crc(mp)) cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c index 62ef048c..f7f99cbd 100644 --- a/libxfs/xfs_refcount_btree.c +++ b/libxfs/xfs_refcount_btree.c @@ -325,7 +325,6 @@ xfs_refcountbt_init_common( cur->bc_tp = tp; cur->bc_mp = mp; cur->bc_btnum = XFS_BTNUM_REFC; - cur->bc_blocklog = mp->m_sb.sb_blocklog; cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_refcbt_2); cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c index ca72324b..bba29eea 100644 --- a/libxfs/xfs_rmap_btree.c +++ b/libxfs/xfs_rmap_btree.c @@ -455,7 +455,6 @@ xfs_rmapbt_init_common( /* Overlapping btree; 2 keys per pointer. */ cur->bc_btnum = XFS_BTNUM_RMAP; cur->bc_flags = XFS_BTREE_CRC_BLOCKS | XFS_BTREE_OVERLAPPING; - cur->bc_blocklog = mp->m_sb.sb_blocklog; cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_rmap_2); cur->bc_ops = &xfs_rmapbt_ops; From patchwork Thu Jan 20 00:24:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A058C433F5 for ; Thu, 20 Jan 2022 00:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345270AbiATAYm (ORCPT ); Wed, 19 Jan 2022 19:24:42 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60642 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345222AbiATAYa (ORCPT ); Wed, 19 Jan 2022 19:24:30 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4678861506 for ; Thu, 20 Jan 2022 00:24:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A07E0C340E4; Thu, 20 Jan 2022 00:24:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638269; bh=u6MAC080rbTQiXdhwVcHKNuOBKeulSvGZ/1GZDzIWYY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Bc8fRZSUqwMBLrT7nm1juFLLWaVgBaMwwoWC4nu1VoZ4XYhBMwSgTCDMAiT7UscLS V+BWPBUsJadG3enz9k++NMF6TXjMePXQwl/PVXbGMHepJrVQWGhMziKnn4vLUuHaJY gXGDxcWXzr3BdkZVnkFQesWlr6pwuLpiLmkUoGBLxkrRvzvOc3Vu5eml0GK25ZvkTX QYtdeP0dcVKsTkq6+mE7OAc/WqMIOAP46UlFnnSfaPNjzPyT4XzibdVGEJtulHZznl oiOSCcJqLPu5r56eO+Y3HwcdcNFGp5MMTEX3TVPuJ92qBc0SN3HGZnQm3asfqOii1F GeLqG6xyp8qow== Subject: [PATCH 14/48] xfs: reduce the size of nr_ops for refcount btree cursors From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:24:29 -0800 Message-ID: <164263826932.865554.14589270185631642317.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: efb79ea31067ae3dd0f348eb06e6b9a5e9907078 We're never going to run more than 4 billion btree operations on a refcount cursor, so shrink the field to an unsigned int to reduce the structure size. Fix whitespace alignment too. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- libxfs/xfs_btree.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index 49ecc496..1018bcc4 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -181,18 +181,18 @@ union xfs_btree_irec { /* Per-AG btree information. */ struct xfs_btree_cur_ag { - struct xfs_perag *pag; + struct xfs_perag *pag; union { struct xfs_buf *agbp; struct xbtree_afakeroot *afake; /* for staging cursor */ }; union { struct { - unsigned long nr_ops; /* # record updates */ - int shape_changes; /* # of extent splits */ + unsigned int nr_ops; /* # record updates */ + unsigned int shape_changes; /* # of extent splits */ } refc; struct { - bool active; /* allocation cursor state */ + bool active; /* allocation cursor state */ } abt; }; }; From patchwork Thu Jan 20 00:24:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47FFEC433EF for ; Thu, 20 Jan 2022 00:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345222AbiATAYm (ORCPT ); Wed, 19 Jan 2022 19:24:42 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60698 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357771AbiATAYg (ORCPT ); Wed, 19 Jan 2022 19:24:36 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CE88D61506 for ; Thu, 20 Jan 2022 00:24:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31602C004E1; Thu, 20 Jan 2022 00:24:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638275; bh=QSFXuG5yjrc+O+iyjOs4YaIS6k2LdtqbSuFv+Xdimlk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=GwRr6Nk2p9WRrFGGHfYcb9y9M0IK1wAa2+awg1BqSM2JatOsviu6JL+00hrfa/Yhe 0d8VdVpbdjisF5Fn4jYwnNEUMPZ4GuAn2r6g8dZFwqX7s0aPYa6CTk5iL6zx2ZYglF koiDgDJUknEDOvQq39iZwfbDEqd5MjSspkvDuSQJAnyH2rS4MGdK/eAtDVtl3HRP/x EnjsxTFZryqZccf8fUUseUeW3UQ+1sJcrgTYeHFm9HITS/vuFCBx+ZXrb7XbVFZx7+ c+1GnNLyY90FlPf/8ia+uzJX1K4R+0I/6pYbo0KVNsPXJx0+HYtbmn+DidCBs0kKNr H6o0Rd3apdpNw== Subject: [PATCH 15/48] xfs: prepare xfs_btree_cur for dynamic cursor heights From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , Christoph Hellwig , Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:24:34 -0800 Message-ID: <164263827485.865554.18385069093603234333.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 6ca444cfd663545e9e1c19ad2695836ffafad0a6 Split out the btree level information into a separate struct and put it at the end of the cursor structure as a VLA. Files with huge data forks (and in the future, the realtime rmap btree) will require the ability to support many more levels than a per-AG btree cursor, which means that we're going to create per-btree type cursor caches to conserve memory for the more common case. Note that a subsequent patch actually introduces dynamic cursor heights. This one merely rearranges the structure to prepare for that. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Reviewed-by: Christoph Hellwig Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- libxfs/xfs_alloc.c | 6 +- libxfs/xfs_bmap.c | 10 ++- libxfs/xfs_btree.c | 168 +++++++++++++++++++++++++++------------------------- libxfs/xfs_btree.h | 33 ++++++++-- 4 files changed, 121 insertions(+), 96 deletions(-) diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index fe050d8e..b8857204 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -484,8 +484,8 @@ xfs_alloc_fixup_trees( struct xfs_btree_block *bnoblock; struct xfs_btree_block *cntblock; - bnoblock = XFS_BUF_TO_BLOCK(bno_cur->bc_bufs[0]); - cntblock = XFS_BUF_TO_BLOCK(cnt_cur->bc_bufs[0]); + bnoblock = XFS_BUF_TO_BLOCK(bno_cur->bc_levels[0].bp); + cntblock = XFS_BUF_TO_BLOCK(cnt_cur->bc_levels[0].bp); if (XFS_IS_CORRUPT(mp, bnoblock->bb_numrecs != @@ -1508,7 +1508,7 @@ xfs_alloc_ag_vextent_lastblock( * than minlen. */ if (*len || args->alignment > 1) { - acur->cnt->bc_ptrs[0] = 1; + acur->cnt->bc_levels[0].ptr = 1; do { error = xfs_alloc_get_rec(acur->cnt, bno, len, &i); if (error) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 371aedc2..fa8d6880 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -233,10 +233,10 @@ xfs_bmap_get_bp( return NULL; for (i = 0; i < XFS_BTREE_MAXLEVELS; i++) { - if (!cur->bc_bufs[i]) + if (!cur->bc_levels[i].bp) break; - if (xfs_buf_daddr(cur->bc_bufs[i]) == bno) - return cur->bc_bufs[i]; + if (xfs_buf_daddr(cur->bc_levels[i].bp) == bno) + return cur->bc_levels[i].bp; } /* Chase down all the log items to see if the bp is there */ @@ -622,8 +622,8 @@ xfs_bmap_btree_to_extents( ip->i_nblocks--; xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, -1L); xfs_trans_binval(tp, cbp); - if (cur->bc_bufs[0] == cbp) - cur->bc_bufs[0] = NULL; + if (cur->bc_levels[0].bp == cbp) + cur->bc_levels[0].bp = NULL; xfs_iroot_realloc(ip, -1, whichfork); ASSERT(ifp->if_broot == NULL); ifp->if_format = XFS_DINODE_FMT_EXTENTS; diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 426ab7f8..2e144dc2 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -364,8 +364,8 @@ xfs_btree_del_cursor( * way we won't have initialized all the entries down to 0. */ for (i = 0; i < cur->bc_nlevels; i++) { - if (cur->bc_bufs[i]) - xfs_trans_brelse(cur->bc_tp, cur->bc_bufs[i]); + if (cur->bc_levels[i].bp) + xfs_trans_brelse(cur->bc_tp, cur->bc_levels[i].bp); else if (!error) break; } @@ -412,9 +412,9 @@ xfs_btree_dup_cursor( * For each level current, re-get the buffer and copy the ptr value. */ for (i = 0; i < new->bc_nlevels; i++) { - new->bc_ptrs[i] = cur->bc_ptrs[i]; - new->bc_ra[i] = cur->bc_ra[i]; - bp = cur->bc_bufs[i]; + new->bc_levels[i].ptr = cur->bc_levels[i].ptr; + new->bc_levels[i].ra = cur->bc_levels[i].ra; + bp = cur->bc_levels[i].bp; if (bp) { error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, xfs_buf_daddr(bp), mp->m_bsize, @@ -426,7 +426,7 @@ xfs_btree_dup_cursor( return error; } } - new->bc_bufs[i] = bp; + new->bc_levels[i].bp = bp; } *ncur = new; return 0; @@ -678,7 +678,7 @@ xfs_btree_get_block( return xfs_btree_get_iroot(cur); } - *bpp = cur->bc_bufs[level]; + *bpp = cur->bc_levels[level].bp; return XFS_BUF_TO_BLOCK(*bpp); } @@ -708,7 +708,7 @@ xfs_btree_firstrec( /* * Set the ptr value to 1, that's the first record/key. */ - cur->bc_ptrs[level] = 1; + cur->bc_levels[level].ptr = 1; return 1; } @@ -738,7 +738,7 @@ xfs_btree_lastrec( /* * Set the ptr value to numrecs, that's the last record/key. */ - cur->bc_ptrs[level] = be16_to_cpu(block->bb_numrecs); + cur->bc_levels[level].ptr = be16_to_cpu(block->bb_numrecs); return 1; } @@ -919,11 +919,11 @@ xfs_btree_readahead( (lev == cur->bc_nlevels - 1)) return 0; - if ((cur->bc_ra[lev] | lr) == cur->bc_ra[lev]) + if ((cur->bc_levels[lev].ra | lr) == cur->bc_levels[lev].ra) return 0; - cur->bc_ra[lev] |= lr; - block = XFS_BUF_TO_BLOCK(cur->bc_bufs[lev]); + cur->bc_levels[lev].ra |= lr; + block = XFS_BUF_TO_BLOCK(cur->bc_levels[lev].bp); if (cur->bc_flags & XFS_BTREE_LONG_PTRS) return xfs_btree_readahead_lblock(cur, lr, block); @@ -988,22 +988,22 @@ xfs_btree_setbuf( { struct xfs_btree_block *b; /* btree block */ - if (cur->bc_bufs[lev]) - xfs_trans_brelse(cur->bc_tp, cur->bc_bufs[lev]); - cur->bc_bufs[lev] = bp; - cur->bc_ra[lev] = 0; + if (cur->bc_levels[lev].bp) + xfs_trans_brelse(cur->bc_tp, cur->bc_levels[lev].bp); + cur->bc_levels[lev].bp = bp; + cur->bc_levels[lev].ra = 0; b = XFS_BUF_TO_BLOCK(bp); if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { if (b->bb_u.l.bb_leftsib == cpu_to_be64(NULLFSBLOCK)) - cur->bc_ra[lev] |= XFS_BTCUR_LEFTRA; + cur->bc_levels[lev].ra |= XFS_BTCUR_LEFTRA; if (b->bb_u.l.bb_rightsib == cpu_to_be64(NULLFSBLOCK)) - cur->bc_ra[lev] |= XFS_BTCUR_RIGHTRA; + cur->bc_levels[lev].ra |= XFS_BTCUR_RIGHTRA; } else { if (b->bb_u.s.bb_leftsib == cpu_to_be32(NULLAGBLOCK)) - cur->bc_ra[lev] |= XFS_BTCUR_LEFTRA; + cur->bc_levels[lev].ra |= XFS_BTCUR_LEFTRA; if (b->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK)) - cur->bc_ra[lev] |= XFS_BTCUR_RIGHTRA; + cur->bc_levels[lev].ra |= XFS_BTCUR_RIGHTRA; } } @@ -1545,7 +1545,7 @@ xfs_btree_increment( #endif /* We're done if we remain in the block after the increment. */ - if (++cur->bc_ptrs[level] <= xfs_btree_get_numrecs(block)) + if (++cur->bc_levels[level].ptr <= xfs_btree_get_numrecs(block)) goto out1; /* Fail if we just went off the right edge of the tree. */ @@ -1568,7 +1568,7 @@ xfs_btree_increment( goto error0; #endif - if (++cur->bc_ptrs[lev] <= xfs_btree_get_numrecs(block)) + if (++cur->bc_levels[lev].ptr <= xfs_btree_get_numrecs(block)) break; /* Read-ahead the right block for the next loop. */ @@ -1595,14 +1595,14 @@ xfs_btree_increment( for (block = xfs_btree_get_block(cur, lev, &bp); lev > level; ) { union xfs_btree_ptr *ptrp; - ptrp = xfs_btree_ptr_addr(cur, cur->bc_ptrs[lev], block); + ptrp = xfs_btree_ptr_addr(cur, cur->bc_levels[lev].ptr, block); --lev; error = xfs_btree_read_buf_block(cur, ptrp, 0, &block, &bp); if (error) goto error0; xfs_btree_setbuf(cur, lev, bp); - cur->bc_ptrs[lev] = 1; + cur->bc_levels[lev].ptr = 1; } out1: *stat = 1; @@ -1638,7 +1638,7 @@ xfs_btree_decrement( xfs_btree_readahead(cur, level, XFS_BTCUR_LEFTRA); /* We're done if we remain in the block after the decrement. */ - if (--cur->bc_ptrs[level] > 0) + if (--cur->bc_levels[level].ptr > 0) goto out1; /* Get a pointer to the btree block. */ @@ -1662,7 +1662,7 @@ xfs_btree_decrement( * Stop when we don't go off the left edge of a block. */ for (lev = level + 1; lev < cur->bc_nlevels; lev++) { - if (--cur->bc_ptrs[lev] > 0) + if (--cur->bc_levels[lev].ptr > 0) break; /* Read-ahead the left block for the next loop. */ xfs_btree_readahead(cur, lev, XFS_BTCUR_LEFTRA); @@ -1688,13 +1688,13 @@ xfs_btree_decrement( for (block = xfs_btree_get_block(cur, lev, &bp); lev > level; ) { union xfs_btree_ptr *ptrp; - ptrp = xfs_btree_ptr_addr(cur, cur->bc_ptrs[lev], block); + ptrp = xfs_btree_ptr_addr(cur, cur->bc_levels[lev].ptr, block); --lev; error = xfs_btree_read_buf_block(cur, ptrp, 0, &block, &bp); if (error) goto error0; xfs_btree_setbuf(cur, lev, bp); - cur->bc_ptrs[lev] = xfs_btree_get_numrecs(block); + cur->bc_levels[lev].ptr = xfs_btree_get_numrecs(block); } out1: *stat = 1; @@ -1732,7 +1732,7 @@ xfs_btree_lookup_get_block( * * Otherwise throw it away and get a new one. */ - bp = cur->bc_bufs[level]; + bp = cur->bc_levels[level].bp; error = xfs_btree_ptr_to_daddr(cur, pp, &daddr); if (error) return error; @@ -1861,7 +1861,7 @@ xfs_btree_lookup( return -EFSCORRUPTED; } - cur->bc_ptrs[0] = dir != XFS_LOOKUP_LE; + cur->bc_levels[0].ptr = dir != XFS_LOOKUP_LE; *stat = 0; return 0; } @@ -1913,7 +1913,7 @@ xfs_btree_lookup( if (error) goto error0; - cur->bc_ptrs[level] = keyno; + cur->bc_levels[level].ptr = keyno; } } @@ -1930,7 +1930,7 @@ xfs_btree_lookup( !xfs_btree_ptr_is_null(cur, &ptr)) { int i; - cur->bc_ptrs[0] = keyno; + cur->bc_levels[0].ptr = keyno; error = xfs_btree_increment(cur, 0, &i); if (error) goto error0; @@ -1941,7 +1941,7 @@ xfs_btree_lookup( } } else if (dir == XFS_LOOKUP_LE && diff > 0) keyno--; - cur->bc_ptrs[0] = keyno; + cur->bc_levels[0].ptr = keyno; /* Return if we succeeded or not. */ if (keyno == 0 || keyno > xfs_btree_get_numrecs(block)) @@ -2101,7 +2101,7 @@ __xfs_btree_updkeys( if (error) return error; #endif - ptr = cur->bc_ptrs[level]; + ptr = cur->bc_levels[level].ptr; nlkey = xfs_btree_key_addr(cur, ptr, block); nhkey = xfs_btree_high_key_addr(cur, ptr, block); if (!force_all && @@ -2168,7 +2168,7 @@ xfs_btree_update_keys( if (error) return error; #endif - ptr = cur->bc_ptrs[level]; + ptr = cur->bc_levels[level].ptr; kp = xfs_btree_key_addr(cur, ptr, block); xfs_btree_copy_keys(cur, kp, &key, 1); xfs_btree_log_keys(cur, bp, ptr, ptr); @@ -2202,7 +2202,7 @@ xfs_btree_update( goto error0; #endif /* Get the address of the rec to be updated. */ - ptr = cur->bc_ptrs[0]; + ptr = cur->bc_levels[0].ptr; rp = xfs_btree_rec_addr(cur, ptr, block); /* Fill in the new contents and log them. */ @@ -2277,7 +2277,7 @@ xfs_btree_lshift( * If the cursor entry is the one that would be moved, don't * do it... it's too complicated. */ - if (cur->bc_ptrs[level] <= 1) + if (cur->bc_levels[level].ptr <= 1) goto out0; /* Set up the left neighbor as "left". */ @@ -2411,7 +2411,7 @@ xfs_btree_lshift( goto error0; /* Slide the cursor value left one. */ - cur->bc_ptrs[level]--; + cur->bc_levels[level].ptr--; *stat = 1; return 0; @@ -2473,7 +2473,7 @@ xfs_btree_rshift( * do it... it's too complicated. */ lrecs = xfs_btree_get_numrecs(left); - if (cur->bc_ptrs[level] >= lrecs) + if (cur->bc_levels[level].ptr >= lrecs) goto out0; /* Set up the right neighbor as "right". */ @@ -2661,7 +2661,7 @@ __xfs_btree_split( */ lrecs = xfs_btree_get_numrecs(left); rrecs = lrecs / 2; - if ((lrecs & 1) && cur->bc_ptrs[level] <= rrecs + 1) + if ((lrecs & 1) && cur->bc_levels[level].ptr <= rrecs + 1) rrecs++; src_index = (lrecs - rrecs + 1); @@ -2757,9 +2757,9 @@ __xfs_btree_split( * If it's just pointing past the last entry in left, then we'll * insert there, so don't change anything in that case. */ - if (cur->bc_ptrs[level] > lrecs + 1) { + if (cur->bc_levels[level].ptr > lrecs + 1) { xfs_btree_setbuf(cur, level, rbp); - cur->bc_ptrs[level] -= lrecs; + cur->bc_levels[level].ptr -= lrecs; } /* * If there are more levels, we'll need another cursor which refers @@ -2769,7 +2769,7 @@ __xfs_btree_split( error = xfs_btree_dup_cursor(cur, curp); if (error) goto error0; - (*curp)->bc_ptrs[level + 1]++; + (*curp)->bc_levels[level + 1].ptr++; } *ptrp = rptr; *stat = 1; @@ -2935,7 +2935,7 @@ xfs_btree_new_iroot( xfs_btree_set_numrecs(block, 1); cur->bc_nlevels++; ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); - cur->bc_ptrs[level + 1] = 1; + cur->bc_levels[level + 1].ptr = 1; kp = xfs_btree_key_addr(cur, 1, block); ckp = xfs_btree_key_addr(cur, 1, cblock); @@ -3096,7 +3096,7 @@ xfs_btree_new_root( /* Fix up the cursor. */ xfs_btree_setbuf(cur, cur->bc_nlevels, nbp); - cur->bc_ptrs[cur->bc_nlevels] = nptr; + cur->bc_levels[cur->bc_nlevels].ptr = nptr; cur->bc_nlevels++; ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); *stat = 1; @@ -3155,7 +3155,7 @@ xfs_btree_make_block_unfull( return error; if (*stat) { - *oindex = *index = cur->bc_ptrs[level]; + *oindex = *index = cur->bc_levels[level].ptr; return 0; } @@ -3170,7 +3170,7 @@ xfs_btree_make_block_unfull( return error; - *index = cur->bc_ptrs[level]; + *index = cur->bc_levels[level].ptr; return 0; } @@ -3217,7 +3217,7 @@ xfs_btree_insrec( } /* If we're off the left edge, return failure. */ - ptr = cur->bc_ptrs[level]; + ptr = cur->bc_levels[level].ptr; if (ptr == 0) { *stat = 0; return 0; @@ -3560,7 +3560,7 @@ xfs_btree_kill_iroot( if (error) return error; - cur->bc_bufs[level - 1] = NULL; + cur->bc_levels[level - 1].bp = NULL; be16_add_cpu(&block->bb_level, -1); xfs_trans_log_inode(cur->bc_tp, ip, XFS_ILOG_CORE | xfs_ilog_fbroot(cur->bc_ino.whichfork)); @@ -3593,8 +3593,8 @@ xfs_btree_kill_root( if (error) return error; - cur->bc_bufs[level] = NULL; - cur->bc_ra[level] = 0; + cur->bc_levels[level].bp = NULL; + cur->bc_levels[level].ra = 0; cur->bc_nlevels--; return 0; @@ -3653,7 +3653,7 @@ xfs_btree_delrec( tcur = NULL; /* Get the index of the entry being deleted, check for nothing there. */ - ptr = cur->bc_ptrs[level]; + ptr = cur->bc_levels[level].ptr; if (ptr == 0) { *stat = 0; return 0; @@ -3963,7 +3963,7 @@ xfs_btree_delrec( xfs_btree_del_cursor(tcur, XFS_BTREE_NOERROR); tcur = NULL; if (level == 0) - cur->bc_ptrs[0]++; + cur->bc_levels[0].ptr++; *stat = 1; return 0; @@ -4100,9 +4100,9 @@ xfs_btree_delrec( * cursor to the left block, and fix up the index. */ if (bp != lbp) { - cur->bc_bufs[level] = lbp; - cur->bc_ptrs[level] += lrecs; - cur->bc_ra[level] = 0; + cur->bc_levels[level].bp = lbp; + cur->bc_levels[level].ptr += lrecs; + cur->bc_levels[level].ra = 0; } /* * If we joined with the right neighbor and there's a level above @@ -4122,16 +4122,16 @@ xfs_btree_delrec( * We can't use decrement because it would change the next level up. */ if (level > 0) - cur->bc_ptrs[level]--; + cur->bc_levels[level].ptr--; /* * We combined blocks, so we have to update the parent keys if the - * btree supports overlapped intervals. However, bc_ptrs[level + 1] - * points to the old block so that the caller knows which record to - * delete. Therefore, the caller must be savvy enough to call updkeys - * for us if we return stat == 2. The other exit points from this - * function don't require deletions further up the tree, so they can - * call updkeys directly. + * btree supports overlapped intervals. However, + * bc_levels[level + 1].ptr points to the old block so that the caller + * knows which record to delete. Therefore, the caller must be savvy + * enough to call updkeys for us if we return stat == 2. The other + * exit points from this function don't require deletions further up + * the tree, so they can call updkeys directly. */ /* Return value means the next level up has something to do. */ @@ -4185,7 +4185,7 @@ xfs_btree_delete( if (i == 0) { for (level = 1; level < cur->bc_nlevels; level++) { - if (cur->bc_ptrs[level] == 0) { + if (cur->bc_levels[level].ptr == 0) { error = xfs_btree_decrement(cur, level, &i); if (error) goto error0; @@ -4216,7 +4216,7 @@ xfs_btree_get_rec( int error; /* error return value */ #endif - ptr = cur->bc_ptrs[0]; + ptr = cur->bc_levels[0].ptr; block = xfs_btree_get_block(cur, 0, &bp); #ifdef DEBUG @@ -4664,23 +4664,25 @@ xfs_btree_overlapped_query_range( if (error) goto out; #endif - cur->bc_ptrs[level] = 1; + cur->bc_levels[level].ptr = 1; while (level < cur->bc_nlevels) { block = xfs_btree_get_block(cur, level, &bp); /* End of node, pop back towards the root. */ - if (cur->bc_ptrs[level] > be16_to_cpu(block->bb_numrecs)) { + if (cur->bc_levels[level].ptr > + be16_to_cpu(block->bb_numrecs)) { pop_up: if (level < cur->bc_nlevels - 1) - cur->bc_ptrs[level + 1]++; + cur->bc_levels[level + 1].ptr++; level++; continue; } if (level == 0) { /* Handle a leaf node. */ - recp = xfs_btree_rec_addr(cur, cur->bc_ptrs[0], block); + recp = xfs_btree_rec_addr(cur, cur->bc_levels[0].ptr, + block); cur->bc_ops->init_high_key_from_rec(&rec_hkey, recp); ldiff = cur->bc_ops->diff_two_keys(cur, &rec_hkey, @@ -4703,14 +4705,15 @@ xfs_btree_overlapped_query_range( /* Record is larger than high key; pop. */ goto pop_up; } - cur->bc_ptrs[level]++; + cur->bc_levels[level].ptr++; continue; } /* Handle an internal node. */ - lkp = xfs_btree_key_addr(cur, cur->bc_ptrs[level], block); - hkp = xfs_btree_high_key_addr(cur, cur->bc_ptrs[level], block); - pp = xfs_btree_ptr_addr(cur, cur->bc_ptrs[level], block); + lkp = xfs_btree_key_addr(cur, cur->bc_levels[level].ptr, block); + hkp = xfs_btree_high_key_addr(cur, cur->bc_levels[level].ptr, + block); + pp = xfs_btree_ptr_addr(cur, cur->bc_levels[level].ptr, block); ldiff = cur->bc_ops->diff_two_keys(cur, hkp, low_key); hdiff = cur->bc_ops->diff_two_keys(cur, high_key, lkp); @@ -4733,13 +4736,13 @@ xfs_btree_overlapped_query_range( if (error) goto out; #endif - cur->bc_ptrs[level] = 1; + cur->bc_levels[level].ptr = 1; continue; } else if (hdiff < 0) { /* The low key is larger than the upper range; pop. */ goto pop_up; } - cur->bc_ptrs[level]++; + cur->bc_levels[level].ptr++; } out: @@ -4750,13 +4753,14 @@ xfs_btree_overlapped_query_range( * with a zero-results range query, so release the buffers if we * failed to return any results. */ - if (cur->bc_bufs[0] == NULL) { + if (cur->bc_levels[0].bp == NULL) { for (i = 0; i < cur->bc_nlevels; i++) { - if (cur->bc_bufs[i]) { - xfs_trans_brelse(cur->bc_tp, cur->bc_bufs[i]); - cur->bc_bufs[i] = NULL; - cur->bc_ptrs[i] = 0; - cur->bc_ra[i] = 0; + if (cur->bc_levels[i].bp) { + xfs_trans_brelse(cur->bc_tp, + cur->bc_levels[i].bp); + cur->bc_levels[i].bp = NULL; + cur->bc_levels[i].ptr = 0; + cur->bc_levels[i].ra = 0; } } } @@ -4918,7 +4922,7 @@ xfs_btree_has_more_records( block = xfs_btree_get_block(cur, 0, &bp); /* There are still records in this block. */ - if (cur->bc_ptrs[0] < xfs_btree_get_numrecs(block)) + if (cur->bc_levels[0].ptr < xfs_btree_get_numrecs(block)) return true; /* There are more record blocks. */ diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index 1018bcc4..0181fc98 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -212,6 +212,19 @@ struct xfs_btree_cur_ino { #define XFS_BTCUR_BMBT_INVALID_OWNER (1 << 1) }; +struct xfs_btree_level { + /* buffer pointer */ + struct xfs_buf *bp; + + /* key/record number */ + uint16_t ptr; + + /* readahead info */ +#define XFS_BTCUR_LEFTRA (1 << 0) /* left sibling has been read-ahead */ +#define XFS_BTCUR_RIGHTRA (1 << 1) /* right sibling has been read-ahead */ + uint16_t ra; +}; + /* * Btree cursor structure. * This collects all information needed by the btree code in one place. @@ -223,11 +236,6 @@ struct xfs_btree_cur const struct xfs_btree_ops *bc_ops; uint bc_flags; /* btree features - below */ union xfs_btree_irec bc_rec; /* current insert/search record value */ - struct xfs_buf *bc_bufs[XFS_BTREE_MAXLEVELS]; /* buf ptr per level */ - int bc_ptrs[XFS_BTREE_MAXLEVELS]; /* key/record # */ - uint8_t bc_ra[XFS_BTREE_MAXLEVELS]; /* readahead bits */ -#define XFS_BTCUR_LEFTRA 1 /* left sibling has been read-ahead */ -#define XFS_BTCUR_RIGHTRA 2 /* right sibling has been read-ahead */ uint8_t bc_nlevels; /* number of levels in the tree */ xfs_btnum_t bc_btnum; /* identifies which btree type */ int bc_statoff; /* offset of btre stats array */ @@ -242,8 +250,22 @@ struct xfs_btree_cur struct xfs_btree_cur_ag bc_ag; struct xfs_btree_cur_ino bc_ino; }; + + /* Must be at the end of the struct! */ + struct xfs_btree_level bc_levels[]; }; +/* + * Compute the size of a btree cursor that can handle a btree of a given + * height. The bc_levels array handles node and leaf blocks, so its size + * is exactly nlevels. + */ +static inline size_t +xfs_btree_cur_sizeof(unsigned int nlevels) +{ + return struct_size((struct xfs_btree_cur *)NULL, bc_levels, nlevels); +} + /* cursor flags */ #define XFS_BTREE_LONG_PTRS (1<<0) /* pointers are 64bits long */ #define XFS_BTREE_ROOT_IN_INODE (1<<1) /* root may be variable size */ @@ -257,7 +279,6 @@ struct xfs_btree_cur */ #define XFS_BTREE_STAGING (1<<5) - #define XFS_BTREE_NOERROR 0 #define XFS_BTREE_ERROR 1 From patchwork Thu Jan 20 00:24:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717978 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D20BC4332F for ; Thu, 20 Jan 2022 00:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345268AbiATAYn (ORCPT ); Wed, 19 Jan 2022 19:24:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357802AbiATAYl (ORCPT ); Wed, 19 Jan 2022 19:24:41 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABD27C061574 for ; Wed, 19 Jan 2022 16:24:41 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4D9A36150C for ; Thu, 20 Jan 2022 00:24:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB36BC004E1; Thu, 20 Jan 2022 00:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638280; bh=vMv8nZ53aQ0LHgJKen8/xl1qEZSCpPsaBDx79Bg06SU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ovEzGiPKe8s+PBy7zjrfR3s7ccyTc9ESY5PAIfsnpHBPb7yOWdk6RtDxV0kLY2RpB PTic/nY47ogeEYlp3AAS2aOocdlkrs5P0ZFi8W80frrBgtlcDYfmKuudiccZryK6Co FVJWCyME9ZPzZebUUIaptb4Z9n6adJfWcSPyDxr+sqV7EFOtySz7u6zqBLfQoZzDUe Wapg3yxEY+TCng0EgmjcWR/JrFbvVYOJflMZXouNvGhRrTAs4NS9rysyDpFCiq7ZR6 gX60XAhsv5EF63bAS8lNCPE+KUMteAAE3hM2TkLt65ecFAsAijpVuApCJIG2vEcSks hMulul0Bd7WaQ== Subject: [PATCH 16/48] xfs: rearrange xfs_btree_cur fields for better packing From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:24:40 -0800 Message-ID: <164263828041.865554.10591791910056583870.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 69724d920e7c30ca4421af615c499e92cfcc550b Reduce the size of the btree cursor structure some more by rearranging fields to eliminate unused space. While we're at it, fix the ragged indentation and a spelling error. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- libxfs/xfs_btree.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index 0181fc98..eaffd822 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -234,11 +234,11 @@ struct xfs_btree_cur struct xfs_trans *bc_tp; /* transaction we're in, if any */ struct xfs_mount *bc_mp; /* file system mount struct */ const struct xfs_btree_ops *bc_ops; - uint bc_flags; /* btree features - below */ + unsigned int bc_flags; /* btree features - below */ + xfs_btnum_t bc_btnum; /* identifies which btree type */ union xfs_btree_irec bc_rec; /* current insert/search record value */ - uint8_t bc_nlevels; /* number of levels in the tree */ - xfs_btnum_t bc_btnum; /* identifies which btree type */ - int bc_statoff; /* offset of btre stats array */ + uint8_t bc_nlevels; /* number of levels in the tree */ + int bc_statoff; /* offset of btree stats array */ /* * Short btree pointers need an agno to be able to turn the pointers From patchwork Thu Jan 20 00:24:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717980 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25ABDC433F5 for ; Thu, 20 Jan 2022 00:24:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345275AbiATAYr (ORCPT ); Wed, 19 Jan 2022 19:24:47 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60824 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344572AbiATAYr (ORCPT ); Wed, 19 Jan 2022 19:24:47 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C832B61506 for ; Thu, 20 Jan 2022 00:24:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C6E3C004E1; Thu, 20 Jan 2022 00:24:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638286; bh=6QfY6klBepPl3Qx04+4w0wAf6pAR+f02LardHwhiQNU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Is166EEBrqnh1DvyMHQXXX3cSqg7tR9m2xNQQutG9eGW1auzQp6pThRZDTbqa48vw KRJfvoIJZvWEeWAFxIs+xDslIMP6VZiQejXDrdZe1o+S7DOI2hhai29WG+xd2HxwwT Ewg34mpSwJMhfUJOTi0efXM5J3ETArIZdb6pS5ADTY3pNm5LxdDpefpzHuPCq9oo0U s589C9n/iePZTQZtHFKWJXLla59iOo43mjoSgm/0bTHuwmqzJxLAiXFM7n6syKHyUA Tr3Y8tqW3+QB12lJXAyXz/O4uoO+cncG5yxk0PH90QnLhemJJUurX027nF+KQ/NmgJ gQbHTG6ujcbxw== Subject: [PATCH 17/48] xfs: refactor btree cursor allocation function From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , Christoph Hellwig , Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:24:45 -0800 Message-ID: <164263828587.865554.1463161547751567961.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 56370ea6e5fe3e3d6e1ca2da58f95fb0d5e1779f Refactor btree allocation to a common helper. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Reviewed-by: Christoph Hellwig Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- libxfs/xfs_alloc_btree.c | 6 +----- libxfs/xfs_bmap_btree.c | 6 +----- libxfs/xfs_btree.h | 16 ++++++++++++++++ libxfs/xfs_ialloc_btree.c | 5 +---- libxfs/xfs_refcount_btree.c | 5 +---- libxfs/xfs_rmap_btree.c | 5 +---- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c index 46d0f229..7d7618c5 100644 --- a/libxfs/xfs_alloc_btree.c +++ b/libxfs/xfs_alloc_btree.c @@ -475,11 +475,7 @@ xfs_allocbt_init_common( ASSERT(btnum == XFS_BTNUM_BNO || btnum == XFS_BTNUM_CNT); - cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); - - cur->bc_tp = tp; - cur->bc_mp = mp; - cur->bc_btnum = btnum; + cur = xfs_btree_alloc_cursor(mp, tp, btnum); cur->bc_ag.abt.active = false; if (btnum == XFS_BTNUM_CNT) { diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c index 565e8af7..c4b34cdd 100644 --- a/libxfs/xfs_bmap_btree.c +++ b/libxfs/xfs_bmap_btree.c @@ -550,12 +550,8 @@ xfs_bmbt_init_cursor( struct xfs_btree_cur *cur; ASSERT(whichfork != XFS_COW_FORK); - cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); - - cur->bc_tp = tp; - cur->bc_mp = mp; + cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_BMAP); cur->bc_nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1; - cur->bc_btnum = XFS_BTNUM_BMAP; cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_bmbt_2); cur->bc_ops = &xfs_bmbt_ops; diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index eaffd822..8e78ede8 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -578,4 +578,20 @@ void xfs_btree_copy_keys(struct xfs_btree_cur *cur, union xfs_btree_key *dst_key, const union xfs_btree_key *src_key, int numkeys); +static inline struct xfs_btree_cur * +xfs_btree_alloc_cursor( + struct xfs_mount *mp, + struct xfs_trans *tp, + xfs_btnum_t btnum) +{ + struct xfs_btree_cur *cur; + + cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); + cur->bc_tp = tp; + cur->bc_mp = mp; + cur->bc_btnum = btnum; + + return cur; +} + #endif /* __XFS_BTREE_H__ */ diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c index f1e03cfd..87a54c07 100644 --- a/libxfs/xfs_ialloc_btree.c +++ b/libxfs/xfs_ialloc_btree.c @@ -431,10 +431,7 @@ xfs_inobt_init_common( { struct xfs_btree_cur *cur; - cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); - cur->bc_tp = tp; - cur->bc_mp = mp; - cur->bc_btnum = btnum; + cur = xfs_btree_alloc_cursor(mp, tp, btnum); if (btnum == XFS_BTNUM_INO) { cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_ibt_2); cur->bc_ops = &xfs_inobt_ops; diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c index f7f99cbd..55e68613 100644 --- a/libxfs/xfs_refcount_btree.c +++ b/libxfs/xfs_refcount_btree.c @@ -321,10 +321,7 @@ xfs_refcountbt_init_common( ASSERT(pag->pag_agno < mp->m_sb.sb_agcount); - cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); - cur->bc_tp = tp; - cur->bc_mp = mp; - cur->bc_btnum = XFS_BTNUM_REFC; + cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_REFC); cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_refcbt_2); cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c index bba29eea..f6339a31 100644 --- a/libxfs/xfs_rmap_btree.c +++ b/libxfs/xfs_rmap_btree.c @@ -449,11 +449,8 @@ xfs_rmapbt_init_common( { struct xfs_btree_cur *cur; - cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); - cur->bc_tp = tp; - cur->bc_mp = mp; /* Overlapping btree; 2 keys per pointer. */ - cur->bc_btnum = XFS_BTNUM_RMAP; + cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_RMAP); cur->bc_flags = XFS_BTREE_CRC_BLOCKS | XFS_BTREE_OVERLAPPING; cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_rmap_2); cur->bc_ops = &xfs_rmapbt_ops; From patchwork Thu Jan 20 00:24:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717981 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 259F6C433EF for ; Thu, 20 Jan 2022 00:24:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344572AbiATAYz (ORCPT ); Wed, 19 Jan 2022 19:24:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240515AbiATAYz (ORCPT ); Wed, 19 Jan 2022 19:24:55 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A3AEC061574 for ; Wed, 19 Jan 2022 16:24:54 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 12B1DB81911 for ; Thu, 20 Jan 2022 00:24:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1361C004E1; Thu, 20 Jan 2022 00:24:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638291; bh=2TCNpExBva2JGev8dxDo/kR6gr+TIhLd95Kw5tZUD20=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=JK6E2Obfx5shUMlqzn7DzWVXAYUWezI1xMqeDbdY2raY9iKMxFm+z5vMEP4JYtYiQ I1vGdzOLQ9zxZk9KwvN+ybpfRoZDMWubq3DMA1pjzJXA+X2LHRLxjqY+xEo8MkvHUd Z1fOuC/qfSC3/hO3aUUgCaz8qTyYKHaIA7Zd91XY+TsgEVmYeK2Bdt2T8htL+PF7B1 AaH971X6tqSWd4V0v2XlfrGmItQ4XtgsLgis1M0becO1MautHampq//ePqVMSV7icC WIM50xvqWMO0dXqqJyFmitI+9OBN+t0LY9MH9FaUdV5EuZF3Hxj9dq965ZLWl2nX4t qn/sM0JsB+mOQ== Subject: [PATCH 18/48] xfs: encode the max btree height in the cursor From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:24:51 -0800 Message-ID: <164263829136.865554.15536525914271312006.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: c0643f6fdd6d3c448142ed1492a9a6b6505f9afb Encode the maximum btree height in the cursor, since we're soon going to allow smaller cursors for AG btrees and larger cursors for file btrees. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- libxfs/xfs_bmap.c | 2 +- libxfs/xfs_btree.c | 4 ++-- libxfs/xfs_btree.h | 2 ++ libxfs/xfs_btree_staging.c | 10 +++++----- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index fa8d6880..3b8b1b61 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -232,7 +232,7 @@ xfs_bmap_get_bp( if (!cur) return NULL; - for (i = 0; i < XFS_BTREE_MAXLEVELS; i++) { + for (i = 0; i < cur->bc_maxlevels; i++) { if (!cur->bc_levels[i].bp) break; if (xfs_buf_daddr(cur->bc_levels[i].bp) == bno) diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 2e144dc2..6a049c64 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -2934,7 +2934,7 @@ xfs_btree_new_iroot( be16_add_cpu(&block->bb_level, 1); xfs_btree_set_numrecs(block, 1); cur->bc_nlevels++; - ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); + ASSERT(cur->bc_nlevels <= cur->bc_maxlevels); cur->bc_levels[level + 1].ptr = 1; kp = xfs_btree_key_addr(cur, 1, block); @@ -3098,7 +3098,7 @@ xfs_btree_new_root( xfs_btree_setbuf(cur, cur->bc_nlevels, nbp); cur->bc_levels[cur->bc_nlevels].ptr = nptr; cur->bc_nlevels++; - ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); + ASSERT(cur->bc_nlevels <= cur->bc_maxlevels); *stat = 1; return 0; error0: diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index 8e78ede8..ed0b7d5a 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -238,6 +238,7 @@ struct xfs_btree_cur xfs_btnum_t bc_btnum; /* identifies which btree type */ union xfs_btree_irec bc_rec; /* current insert/search record value */ uint8_t bc_nlevels; /* number of levels in the tree */ + uint8_t bc_maxlevels; /* maximum levels for this btree type */ int bc_statoff; /* offset of btree stats array */ /* @@ -590,6 +591,7 @@ xfs_btree_alloc_cursor( cur->bc_tp = tp; cur->bc_mp = mp; cur->bc_btnum = btnum; + cur->bc_maxlevels = XFS_BTREE_MAXLEVELS; return cur; } diff --git a/libxfs/xfs_btree_staging.c b/libxfs/xfs_btree_staging.c index aa3d49cf..a6a90791 100644 --- a/libxfs/xfs_btree_staging.c +++ b/libxfs/xfs_btree_staging.c @@ -657,12 +657,12 @@ xfs_btree_bload_compute_geometry( * checking levels 0 and 1 here, so set bc_nlevels such that the btree * code doesn't interpret either as the root level. */ - cur->bc_nlevels = XFS_BTREE_MAXLEVELS - 1; + cur->bc_nlevels = cur->bc_maxlevels - 1; xfs_btree_bload_ensure_slack(cur, &bbl->leaf_slack, 0); xfs_btree_bload_ensure_slack(cur, &bbl->node_slack, 1); bbl->nr_records = nr_this_level = nr_records; - for (cur->bc_nlevels = 1; cur->bc_nlevels <= XFS_BTREE_MAXLEVELS;) { + for (cur->bc_nlevels = 1; cur->bc_nlevels <= cur->bc_maxlevels;) { uint64_t level_blocks; uint64_t dontcare64; unsigned int level = cur->bc_nlevels - 1; @@ -703,7 +703,7 @@ xfs_btree_bload_compute_geometry( * block-based btree level. */ cur->bc_nlevels++; - ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); + ASSERT(cur->bc_nlevels <= cur->bc_maxlevels); xfs_btree_bload_level_geometry(cur, bbl, level, nr_this_level, &avg_per_block, &level_blocks, &dontcare64); @@ -719,14 +719,14 @@ xfs_btree_bload_compute_geometry( /* Otherwise, we need another level of btree. */ cur->bc_nlevels++; - ASSERT(cur->bc_nlevels <= XFS_BTREE_MAXLEVELS); + ASSERT(cur->bc_nlevels <= cur->bc_maxlevels); } nr_blocks += level_blocks; nr_this_level = level_blocks; } - if (cur->bc_nlevels > XFS_BTREE_MAXLEVELS) + if (cur->bc_nlevels > cur->bc_maxlevels) return -EOVERFLOW; bbl->btree_height = cur->bc_nlevels; From patchwork Thu Jan 20 00:24:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717982 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A16FC433EF for ; Thu, 20 Jan 2022 00:25:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345277AbiATAY7 (ORCPT ); Wed, 19 Jan 2022 19:24:59 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:48090 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240515AbiATAY7 (ORCPT ); Wed, 19 Jan 2022 19:24:59 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 84141B81A85 for ; Thu, 20 Jan 2022 00:24:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34B46C004E1; Thu, 20 Jan 2022 00:24:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638297; bh=EMj89fi/HYAbB1a1XycIhdoMTlxAOozypzEsdxNhYqY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=qEgn+7DH+PqfcD360/h8fHitcg6ZgaB7CqVGBK3E2yT85VMqmDQlf4AIJJUcQ3Hgw Uls0KwENPco7LsNehZnq4SoLseAzxzOcY/+6TawtFEo9JjnN3MmoTBOIRCz8V5chbp 0Z0KF8y/roklfW+H4lfSdm1u2WWk+gRpvt9TsY5uD20JbUiHhOGEoqadOZaSCvBw3a zmZ6kBVnjZUUC2KthmQmVRZAKPwz3EU7o7x9vvh8EdlPtv/mAGlHRY73FMcWa7TzIV U1+BqvWzO7ptGV7LhG0XWw2QD2vF9aBy5UYGS2goD/9IXUOWTHLrZlGdtQcSawvDIu GVpEpuGgdq3CA== Subject: [PATCH 19/48] xfs: dynamically allocate cursors based on maxlevels From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:24:56 -0800 Message-ID: <164263829684.865554.3242016081675260913.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: c940a0c54a2e9333478f1d87ed40006a04fcec7e To support future btree code, we need to be able to size btree cursors dynamically for very large btrees. Switch the maxlevels computation to use the precomputed values in the superblock, and create cursors that can handle a certain height. For now, we retain the btree cursor cache that can handle up to 9-level btrees, though a subsequent patch introduces separate caches for each btree type, where each cache's objects will be exactly tall enough to handle the specific btree type. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- libxfs/xfs_alloc_btree.c | 2 +- libxfs/xfs_bmap_btree.c | 3 ++- libxfs/xfs_btree.h | 13 +++++++++++-- libxfs/xfs_ialloc_btree.c | 3 ++- libxfs/xfs_refcount_btree.c | 3 ++- libxfs/xfs_rmap_btree.c | 3 ++- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c index 7d7618c5..c1030ad1 100644 --- a/libxfs/xfs_alloc_btree.c +++ b/libxfs/xfs_alloc_btree.c @@ -475,7 +475,7 @@ xfs_allocbt_init_common( ASSERT(btnum == XFS_BTNUM_BNO || btnum == XFS_BTNUM_CNT); - cur = xfs_btree_alloc_cursor(mp, tp, btnum); + cur = xfs_btree_alloc_cursor(mp, tp, btnum, mp->m_ag_maxlevels); cur->bc_ag.abt.active = false; if (btnum == XFS_BTNUM_CNT) { diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c index c4b34cdd..9e2263ed 100644 --- a/libxfs/xfs_bmap_btree.c +++ b/libxfs/xfs_bmap_btree.c @@ -550,7 +550,8 @@ xfs_bmbt_init_cursor( struct xfs_btree_cur *cur; ASSERT(whichfork != XFS_COW_FORK); - cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_BMAP); + cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_BMAP, + mp->m_bm_maxlevels[whichfork]); cur->bc_nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1; cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_bmbt_2); diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index ed0b7d5a..b46cd983 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -94,6 +94,12 @@ uint32_t xfs_btree_magic(int crc, xfs_btnum_t btnum); #define XFS_BTREE_MAXLEVELS 9 /* max of all btrees */ +/* + * The btree cursor zone hands out cursors that can handle up to this many + * levels. This is the known maximum for all btree types. + */ +#define XFS_BTREE_CUR_CACHE_MAXLEVELS (9) + struct xfs_btree_ops { /* size of the key and record structures */ size_t key_len; @@ -583,15 +589,18 @@ static inline struct xfs_btree_cur * xfs_btree_alloc_cursor( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_btnum_t btnum) + xfs_btnum_t btnum, + uint8_t maxlevels) { struct xfs_btree_cur *cur; + ASSERT(maxlevels <= XFS_BTREE_CUR_CACHE_MAXLEVELS); + cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); cur->bc_tp = tp; cur->bc_mp = mp; cur->bc_btnum = btnum; - cur->bc_maxlevels = XFS_BTREE_MAXLEVELS; + cur->bc_maxlevels = maxlevels; return cur; } diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c index 87a54c07..be0918b7 100644 --- a/libxfs/xfs_ialloc_btree.c +++ b/libxfs/xfs_ialloc_btree.c @@ -431,7 +431,8 @@ xfs_inobt_init_common( { struct xfs_btree_cur *cur; - cur = xfs_btree_alloc_cursor(mp, tp, btnum); + cur = xfs_btree_alloc_cursor(mp, tp, btnum, + M_IGEO(mp)->inobt_maxlevels); if (btnum == XFS_BTNUM_INO) { cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_ibt_2); cur->bc_ops = &xfs_inobt_ops; diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c index 55e68613..6a716924 100644 --- a/libxfs/xfs_refcount_btree.c +++ b/libxfs/xfs_refcount_btree.c @@ -321,7 +321,8 @@ xfs_refcountbt_init_common( ASSERT(pag->pag_agno < mp->m_sb.sb_agcount); - cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_REFC); + cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_REFC, + mp->m_refc_maxlevels); cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_refcbt_2); cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c index f6339a31..4c281b71 100644 --- a/libxfs/xfs_rmap_btree.c +++ b/libxfs/xfs_rmap_btree.c @@ -450,7 +450,8 @@ xfs_rmapbt_init_common( struct xfs_btree_cur *cur; /* Overlapping btree; 2 keys per pointer. */ - cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_RMAP); + cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_RMAP, + mp->m_rmap_maxlevels); cur->bc_flags = XFS_BTREE_CRC_BLOCKS | XFS_BTREE_OVERLAPPING; cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_rmap_2); cur->bc_ops = &xfs_rmapbt_ops; From patchwork Thu Jan 20 00:25:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00E26C433FE for ; Thu, 20 Jan 2022 00:25:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345317AbiATAZE (ORCPT ); Wed, 19 Jan 2022 19:25:04 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:32768 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345290AbiATAZD (ORCPT ); Wed, 19 Jan 2022 19:25:03 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5D57E61516 for ; Thu, 20 Jan 2022 00:25:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3D13C004E1; Thu, 20 Jan 2022 00:25:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638302; bh=vJGr3/GisQboDQeGQddY5RpA1C+s8yruNRf1kbhzx44=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=QA8qHBIfE7D0NcNde6ccErDxj+5xQiNV8RWXTj7c9/LIW88FGZiD/gZod3+G4+PZ6 1pr3+iTfMm/uTbU6s7ZfL3zyOa4HBjsxsQhOggRG6Bu/A1rFFPnl/Qk4ymXbcBZf8X VXp3ebl14IY7xWd+8Y76cIyH6pSVDvBbTHO5Gee7zz5Y61yD9r1H12X/vjRemBW8j5 xknfVeo5PGrIDK7bdmf+ivLW6iVDakboVWvAgT2KTFvmjs/m/nHJdhF7rgyT4MsChV YJV+i06yuPBbVgFKg9C9liC2Z6iyPNlKgSEIX7387A4yEbguqgV8SXz1GQ8b2VOUfG R3CIL3R4TS2HA== Subject: [PATCH 20/48] xfs: rename m_ag_maxlevels to m_allocbt_maxlevels From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:25:02 -0800 Message-ID: <164263830239.865554.3465546750462142656.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 7cb3efb4cfdd4f3eb1f36b0ce39254b848ff2371 Years ago when XFS was thought to be much more simple, we introduced m_ag_maxlevels to specify the maximum btree height of per-AG btrees for a given filesystem mount. Then we observed that inode btrees don't actually have the same height and split that off; and now we have rmap and refcount btrees with much different geometries and separate maxlevels variables. The 'ag' part of the name doesn't make much sense anymore, so rename this to m_alloc_maxlevels to reinforce that this is the maximum height of the *free space* btrees. This sets us up for the next patch, which will add a variable to track the maximum height of all AG btrees. (Also take the opportunity to improve adjacent comments and fix minor style problems.) Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- include/xfs_mount.h | 2 +- libxfs/xfs_alloc.c | 19 +++++++++++-------- libxfs/xfs_alloc.h | 2 +- libxfs/xfs_alloc_btree.c | 4 ++-- libxfs/xfs_trans_resv.c | 2 +- libxfs/xfs_trans_space.h | 2 +- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/xfs_mount.h b/include/xfs_mount.h index dc2206de..308ceff0 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -71,7 +71,7 @@ typedef struct xfs_mount { uint m_rmap_mnr[2]; /* min rmap btree records */ uint m_refc_mxr[2]; /* max refc btree records */ uint m_refc_mnr[2]; /* min refc btree records */ - uint m_ag_maxlevels; /* XFS_AG_MAXLEVELS */ + uint m_alloc_maxlevels; /* max alloc btree levels */ uint m_bm_maxlevels[2]; /* XFS_BM_MAXLEVELS */ uint m_rmap_maxlevels; /* max rmap btree levels */ uint m_refc_maxlevels; /* max refc btree levels */ diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index b8857204..e20d8fb7 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -2186,13 +2186,13 @@ xfs_free_ag_extent( */ /* - * Compute and fill in value of m_ag_maxlevels. + * Compute and fill in value of m_alloc_maxlevels. */ void xfs_alloc_compute_maxlevels( xfs_mount_t *mp) /* file system mount structure */ { - mp->m_ag_maxlevels = xfs_btree_compute_maxlevels(mp->m_alloc_mnr, + mp->m_alloc_maxlevels = xfs_btree_compute_maxlevels(mp->m_alloc_mnr, (mp->m_sb.sb_agblocks + 1) / 2); } @@ -2251,14 +2251,14 @@ xfs_alloc_min_freelist( const uint8_t *levels = pag ? pag->pagf_levels : fake_levels; unsigned int min_free; - ASSERT(mp->m_ag_maxlevels > 0); + ASSERT(mp->m_alloc_maxlevels > 0); /* space needed by-bno freespace btree */ min_free = min_t(unsigned int, levels[XFS_BTNUM_BNOi] + 1, - mp->m_ag_maxlevels); + mp->m_alloc_maxlevels); /* space needed by-size freespace btree */ min_free += min_t(unsigned int, levels[XFS_BTNUM_CNTi] + 1, - mp->m_ag_maxlevels); + mp->m_alloc_maxlevels); /* space needed reverse mapping used space btree */ if (xfs_has_rmapbt(mp)) min_free += min_t(unsigned int, levels[XFS_BTNUM_RMAPi] + 1, @@ -2899,13 +2899,16 @@ xfs_agf_verify( if (be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) < 1 || be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]) < 1 || - be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) > mp->m_ag_maxlevels || - be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]) > mp->m_ag_maxlevels) + be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) > + mp->m_alloc_maxlevels || + be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]) > + mp->m_alloc_maxlevels) return __this_address; if (xfs_has_rmapbt(mp) && (be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]) < 1 || - be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]) > mp->m_rmap_maxlevels)) + be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]) > + mp->m_rmap_maxlevels)) return __this_address; if (xfs_has_rmapbt(mp) && diff --git a/libxfs/xfs_alloc.h b/libxfs/xfs_alloc.h index df4aefaf..2f3f8c2e 100644 --- a/libxfs/xfs_alloc.h +++ b/libxfs/xfs_alloc.h @@ -98,7 +98,7 @@ unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp, struct xfs_perag *pag); /* - * Compute and fill in value of m_ag_maxlevels. + * Compute and fill in value of m_alloc_maxlevels. */ void xfs_alloc_compute_maxlevels( diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c index c1030ad1..d752500b 100644 --- a/libxfs/xfs_alloc_btree.c +++ b/libxfs/xfs_alloc_btree.c @@ -314,7 +314,7 @@ xfs_allocbt_verify( if (pag && pag->pagf_init) { if (level >= pag->pagf_levels[btnum]) return __this_address; - } else if (level >= mp->m_ag_maxlevels) + } else if (level >= mp->m_alloc_maxlevels) return __this_address; return xfs_btree_sblock_verify(bp, mp->m_alloc_mxr[level != 0]); @@ -475,7 +475,7 @@ xfs_allocbt_init_common( ASSERT(btnum == XFS_BTNUM_BNO || btnum == XFS_BTNUM_CNT); - cur = xfs_btree_alloc_cursor(mp, tp, btnum, mp->m_ag_maxlevels); + cur = xfs_btree_alloc_cursor(mp, tp, btnum, mp->m_alloc_maxlevels); cur->bc_ag.abt.active = false; if (btnum == XFS_BTNUM_CNT) { diff --git a/libxfs/xfs_trans_resv.c b/libxfs/xfs_trans_resv.c index d383528d..68daefd4 100644 --- a/libxfs/xfs_trans_resv.c +++ b/libxfs/xfs_trans_resv.c @@ -69,7 +69,7 @@ xfs_allocfree_log_count( { uint blocks; - blocks = num_ops * 2 * (2 * mp->m_ag_maxlevels - 1); + blocks = num_ops * 2 * (2 * mp->m_alloc_maxlevels - 1); if (xfs_has_rmapbt(mp)) blocks += num_ops * (2 * mp->m_rmap_maxlevels - 1); if (xfs_has_reflink(mp)) diff --git a/libxfs/xfs_trans_space.h b/libxfs/xfs_trans_space.h index 50332be3..bd04cb83 100644 --- a/libxfs/xfs_trans_space.h +++ b/libxfs/xfs_trans_space.h @@ -74,7 +74,7 @@ #define XFS_DIOSTRAT_SPACE_RES(mp, v) \ (XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK) + (v)) #define XFS_GROWFS_SPACE_RES(mp) \ - (2 * (mp)->m_ag_maxlevels) + (2 * (mp)->m_alloc_maxlevels) #define XFS_GROWFSRT_SPACE_RES(mp,b) \ ((b) + XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK)) #define XFS_LINK_SPACE_RES(mp,nl) \ From patchwork Thu Jan 20 00:25:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717984 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E922C433EF for ; Thu, 20 Jan 2022 00:25:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345290AbiATAZL (ORCPT ); Wed, 19 Jan 2022 19:25:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345343AbiATAZJ (ORCPT ); Wed, 19 Jan 2022 19:25:09 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BE96C061574 for ; Wed, 19 Jan 2022 16:25:09 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D0C6361518 for ; Thu, 20 Jan 2022 00:25:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EEF7C004E1; Thu, 20 Jan 2022 00:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638308; bh=zfIjo2AYK3h2apZJv7sKGAeIJpwLOPVFWfVYLpStuaw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ojs2jSi6vxIJ7opnT7sOpTY+7i4NndURL1sBWV7P2q56YzAw41y1VtoDLxNPESQnk CN/GA+fVDejHzZ3+zerBO/niUFsf0sqWBZC3/sQrHEhAEamec46BbRLhKNe5C40KRj qSLrLSvW2FMVtI+V94VZcUTU6XDY3J/VoCWZqqnEHBWCE/9rIjk8wMnwe9DgFZrPaO ijsqSlHeV8X7NpPbDMzeWw4wnMhthO2Vhuezw9m7jogh9asBFMvSvOG9pAlctSa852 VXilVxZtzgCSHJW3E8k6vAWg2aVrPsLHdULf+uWB8e8HYdAvZxZ+sp2YY2Z9E0esvE svjndjqmOLgvw== Subject: [PATCH 21/48] xfs: compute maximum AG btree height for critical reservation calculation From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:25:07 -0800 Message-ID: <164263830791.865554.9300818337239981326.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: b74e15d720d0764345934ebb599a99a077c52533 Compute the actual maximum AG btree height for deciding if a per-AG block reservation is critically low. This only affects the sanity check condition, since we /generally/ will trigger on the 10% threshold. This is a long-winded way of saying that we're removing one more usage of XFS_BTREE_MAXLEVELS. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- include/xfs_mount.h | 1 + libxfs/init.c | 14 ++++++++++++++ libxfs/xfs_ag_resv.c | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/xfs_mount.h b/include/xfs_mount.h index 308ceff0..bd464fbb 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -75,6 +75,7 @@ typedef struct xfs_mount { uint m_bm_maxlevels[2]; /* XFS_BM_MAXLEVELS */ uint m_rmap_maxlevels; /* max rmap btree levels */ uint m_refc_maxlevels; /* max refc btree levels */ + unsigned int m_agbtree_maxlevels; /* max level of all AG btrees */ xfs_extlen_t m_ag_prealloc_blocks; /* reserved ag blocks */ uint m_alloc_set_aside; /* space we can't use */ uint m_ag_max_usable; /* max space per AG */ diff --git a/libxfs/init.c b/libxfs/init.c index f59444ab..12e25379 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -703,6 +703,18 @@ libxfs_buftarg_init( mp->m_rtdev_targp = libxfs_buftarg_alloc(mp, rtdev, rfail); } +/* Compute maximum possible height for per-AG btree types for this fs. */ +static inline void +xfs_agbtree_compute_maxlevels( + struct xfs_mount *mp) +{ + unsigned int levels; + + levels = max(mp->m_alloc_maxlevels, M_IGEO(mp)->inobt_maxlevels); + levels = max(levels, mp->m_rmap_maxlevels); + mp->m_agbtree_maxlevels = max(levels, mp->m_refc_maxlevels); +} + /* * Mount structure initialization, provides a filled-in xfs_mount_t * such that the numerous XFS_* macros can be used. If dev is zero, @@ -754,6 +766,8 @@ libxfs_mount( xfs_rmapbt_compute_maxlevels(mp); xfs_refcountbt_compute_maxlevels(mp); + xfs_agbtree_compute_maxlevels(mp); + /* * Check that the data (and log if separate) are an ok size. */ diff --git a/libxfs/xfs_ag_resv.c b/libxfs/xfs_ag_resv.c index b1392cda..546f34e8 100644 --- a/libxfs/xfs_ag_resv.c +++ b/libxfs/xfs_ag_resv.c @@ -90,7 +90,8 @@ xfs_ag_resv_critical( trace_xfs_ag_resv_critical(pag, type, avail); /* Critically low if less than 10% or max btree height remains. */ - return XFS_TEST_ERROR(avail < orig / 10 || avail < XFS_BTREE_MAXLEVELS, + return XFS_TEST_ERROR(avail < orig / 10 || + avail < pag->pag_mount->m_agbtree_maxlevels, pag->pag_mount, XFS_ERRTAG_AG_RESV_CRITICAL); } From patchwork Thu Jan 20 00:25:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717985 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 718F8C433F5 for ; Thu, 20 Jan 2022 00:25:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345289AbiATAZR (ORCPT ); Wed, 19 Jan 2022 19:25:17 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:48184 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345320AbiATAZQ (ORCPT ); Wed, 19 Jan 2022 19:25:16 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E7AA3B81A85 for ; Thu, 20 Jan 2022 00:25:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A93D8C004E1; Thu, 20 Jan 2022 00:25:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638313; bh=RmqhmWznKC3FJJE5sbX/QvO++2Ed1Mv+5ILNtl2NLa0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=boYRWtvJ4EkT1IKeFI1YFQLD0X3u9gXRPBjb1pvk9IBgoWEnNU5xPAs7mPrfah7Sq BugP0FA8W2IkPDCda6fnVF3sdu9ol4G/np0DveGobbpk4fGYQFtHMAdYVPWn81hWSj /TLB40VSouD1IZbYIcZIJN4sbONhbxVEANMIk/zcQ4yIwkfFmqUp70D9CeNlQ3CnI9 djAmdFUwPWvHwV1WB2fH2Zajw43c82lTskKjypbAuHaWE/NucwhsLkpLSnvLSznuo3 AZiloiF6OaI+bJWGayNYv2X6wdt88WMfxvYYtX3HbFL6jhO1XlNpIFl6ZeAeDXrB/l 49wsA81/Jbmpw== Subject: [PATCH 22/48] xfs: clean up xfs_btree_{calc_size,compute_maxlevels} From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:25:13 -0800 Message-ID: <164263831338.865554.13825367472651263860.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 1b236ad7ba800bc3e9994881a8a453eb8bf5ca0f During review of the next patch, Dave remarked that he found these two btree geometry calculation functions lacking in documentation and that they performed more work than was really necessary. These functions take the same parameters and have nearly the same logic; the only real difference is in the return values. Reword the function comment to make it clearer what each function does, and move them to be adjacent to reinforce their relation. Clean up both of them to stop opencoding the howmany functions, stop using the uint typedefs, and make them both support computations for more than 2^32 leaf records, since we're going to need all of the above for files with large data forks and large rmap btrees. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- libxfs/xfs_btree.c | 67 ++++++++++++++++++++++++++-------------------------- libxfs/xfs_btree.h | 6 +++-- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 6a049c64..5ada6cc4 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -4515,21 +4515,43 @@ xfs_btree_sblock_verify( } /* - * Calculate the number of btree levels needed to store a given number of - * records in a short-format btree. + * For the given limits on leaf and keyptr records per block, calculate the + * height of the tree needed to index the number of leaf records. */ -uint +unsigned int xfs_btree_compute_maxlevels( - uint *limits, - unsigned long len) + const unsigned int *limits, + unsigned long long records) { - uint level; - unsigned long maxblocks; + unsigned long long level_blocks = howmany_64(records, limits[0]); + unsigned int height = 1; - maxblocks = (len + limits[0] - 1) / limits[0]; - for (level = 1; maxblocks > 1; level++) - maxblocks = (maxblocks + limits[1] - 1) / limits[1]; - return level; + while (level_blocks > 1) { + level_blocks = howmany_64(level_blocks, limits[1]); + height++; + } + + return height; +} + +/* + * For the given limits on leaf and keyptr records per block, calculate the + * number of blocks needed to index the given number of leaf records. + */ +unsigned long long +xfs_btree_calc_size( + const unsigned int *limits, + unsigned long long records) +{ + unsigned long long level_blocks = howmany_64(records, limits[0]); + unsigned long long blocks = level_blocks; + + while (level_blocks > 1) { + level_blocks = howmany_64(level_blocks, limits[1]); + blocks += level_blocks; + } + + return blocks; } /* @@ -4823,29 +4845,6 @@ xfs_btree_query_all( return xfs_btree_simple_query_range(cur, &low_key, &high_key, fn, priv); } -/* - * Calculate the number of blocks needed to store a given number of records - * in a short-format (per-AG metadata) btree. - */ -unsigned long long -xfs_btree_calc_size( - uint *limits, - unsigned long long len) -{ - int level; - int maxrecs; - unsigned long long rval; - - maxrecs = limits[0]; - for (level = 0, rval = 0; len > 1; level++) { - len += maxrecs - 1; - do_div(len, maxrecs); - maxrecs = limits[1]; - rval += len; - } - return rval; -} - static int xfs_btree_count_blocks_helper( struct xfs_btree_cur *cur, diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index b46cd983..3bd69fe4 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -487,8 +487,10 @@ xfs_failaddr_t xfs_btree_lblock_v5hdr_verify(struct xfs_buf *bp, xfs_failaddr_t xfs_btree_lblock_verify(struct xfs_buf *bp, unsigned int max_recs); -uint xfs_btree_compute_maxlevels(uint *limits, unsigned long len); -unsigned long long xfs_btree_calc_size(uint *limits, unsigned long long len); +unsigned int xfs_btree_compute_maxlevels(const unsigned int *limits, + unsigned long long records); +unsigned long long xfs_btree_calc_size(const unsigned int *limits, + unsigned long long records); /* * Return codes for the query range iterator function are 0 to continue From patchwork Thu Jan 20 00:25:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717986 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F256C433F5 for ; Thu, 20 Jan 2022 00:25:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345320AbiATAZW (ORCPT ); Wed, 19 Jan 2022 19:25:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345328AbiATAZW (ORCPT ); Wed, 19 Jan 2022 19:25:22 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD430C061574 for ; Wed, 19 Jan 2022 16:25:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 741DCB81911 for ; Thu, 20 Jan 2022 00:25:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23E4DC004E1; Thu, 20 Jan 2022 00:25:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638319; bh=HpaQ+N6zmlazrfbtQbqYh7s/WecuMB4cO78CjO9T4P0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=lvWzb3TX8CykXTlDBPFGsfNhb/Bjj7aXM1ZBK25NLh2lEKyzvf/1uxcTSmp0nDAnG 7GKPKPlo4q8uabupMbVig5/s0KXD5nBcOEtTxTen275ff1ab704JYeJ6ssjUgBs37T Q5d2d9R8noreG/3R2UjP+fNv/zS4fcoOp9/gQ6r5QBzqO8CT0FQYarF8SBuU1CtkrP 2/sHxCBz+9IqjB2aWfEpKuUnJh5iQnQbl9HqIJVKunhw1PVQ7HD6d+yjZv2+IjrS8A vX3T7JVPnzV4YDIs1lMe/74EMUGKUKcmBAkSfVC/sE6cB5nMpNJ5iGhdZMYFbJZnf0 S4nync4yaL2KQ== Subject: [PATCH 23/48] xfs: compute the maximum height of the rmap btree when reflink enabled From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:25:18 -0800 Message-ID: <164263831887.865554.15211463222474360893.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 9ec691205e7d4a11190519df6561a168ae6af3a4 Instead of assuming that the hardcoded XFS_BTREE_MAXLEVELS value is big enough to handle the maximally tall rmap btree when all blocks are in use and maximally shared, let's compute the maximum height assuming the rmapbt consumes as many blocks as possible. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- libxfs/xfs_btree.c | 33 +++++++++++++++++++++++++++++++++ libxfs/xfs_btree.h | 2 ++ libxfs/xfs_rmap_btree.c | 45 +++++++++++++++++++++++++++------------------ libxfs/xfs_trans_resv.c | 16 ++++++++++++++++ libxfs/xfs_trans_space.h | 7 +++++++ 5 files changed, 85 insertions(+), 18 deletions(-) diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 5ada6cc4..e541b061 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -4554,6 +4554,39 @@ xfs_btree_calc_size( return blocks; } +/* + * Given a number of available blocks for the btree to consume with records and + * pointers, calculate the height of the tree needed to index all the records + * that space can hold based on the number of pointers each interior node + * holds. + * + * We start by assuming a single level tree consumes a single block, then track + * the number of blocks each node level consumes until we no longer have space + * to store the next node level. At this point, we are indexing all the leaf + * blocks in the space, and there's no more free space to split the tree any + * further. That's our maximum btree height. + */ +unsigned int +xfs_btree_space_to_height( + const unsigned int *limits, + unsigned long long leaf_blocks) +{ + unsigned long long node_blocks = limits[1]; + unsigned long long blocks_left = leaf_blocks - 1; + unsigned int height = 1; + + if (leaf_blocks < 1) + return 0; + + while (node_blocks < blocks_left) { + blocks_left -= node_blocks; + node_blocks *= limits[1]; + height++; + } + + return height; +} + /* * Query a regular btree for all records overlapping a given interval. * Start with a LE lookup of the key of low_rec and return all records diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index 3bd69fe4..e488bfcc 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -491,6 +491,8 @@ unsigned int xfs_btree_compute_maxlevels(const unsigned int *limits, unsigned long long records); unsigned long long xfs_btree_calc_size(const unsigned int *limits, unsigned long long records); +unsigned int xfs_btree_space_to_height(const unsigned int *limits, + unsigned long long blocks); /* * Return codes for the query range iterator function are 0 to continue diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c index 4c281b71..eeaa1e28 100644 --- a/libxfs/xfs_rmap_btree.c +++ b/libxfs/xfs_rmap_btree.c @@ -538,26 +538,35 @@ void xfs_rmapbt_compute_maxlevels( struct xfs_mount *mp) { - /* - * On a non-reflink filesystem, the maximum number of rmap - * records is the number of blocks in the AG, hence the max - * rmapbt height is log_$maxrecs($agblocks). However, with - * reflink each AG block can have up to 2^32 (per the refcount - * record format) owners, which means that theoretically we - * could face up to 2^64 rmap records. - * - * That effectively means that the max rmapbt height must be - * XFS_BTREE_MAXLEVELS. "Fortunately" we'll run out of AG - * blocks to feed the rmapbt long before the rmapbt reaches - * maximum height. The reflink code uses ag_resv_critical to - * disallow reflinking when less than 10% of the per-AG metadata - * block reservation since the fallback is a regular file copy. - */ - if (xfs_has_reflink(mp)) - mp->m_rmap_maxlevels = XFS_BTREE_MAXLEVELS; - else + if (!xfs_has_rmapbt(mp)) { + mp->m_rmap_maxlevels = 0; + return; + } + + if (xfs_has_reflink(mp)) { + /* + * Compute the asymptotic maxlevels for an rmap btree on a + * filesystem that supports reflink. + * + * On a reflink filesystem, each AG block can have up to 2^32 + * (per the refcount record format) owners, which means that + * theoretically we could face up to 2^64 rmap records. + * However, we're likely to run out of blocks in the AG long + * before that happens, which means that we must compute the + * max height based on what the btree will look like if it + * consumes almost all the blocks in the AG due to maximal + * sharing factor. + */ + mp->m_rmap_maxlevels = xfs_btree_space_to_height(mp->m_rmap_mnr, + mp->m_sb.sb_agblocks); + } else { + /* + * If there's no block sharing, compute the maximum rmapbt + * height assuming one rmap record per AG block. + */ mp->m_rmap_maxlevels = xfs_btree_compute_maxlevels( mp->m_rmap_mnr, mp->m_sb.sb_agblocks); + } } /* Calculate the refcount btree size for some records. */ diff --git a/libxfs/xfs_trans_resv.c b/libxfs/xfs_trans_resv.c index 68daefd4..61a0a1ac 100644 --- a/libxfs/xfs_trans_resv.c +++ b/libxfs/xfs_trans_resv.c @@ -813,6 +813,19 @@ xfs_trans_resv_calc( struct xfs_mount *mp, struct xfs_trans_resv *resp) { + unsigned int rmap_maxlevels = mp->m_rmap_maxlevels; + + /* + * In the early days of rmap+reflink, we always set the rmap maxlevels + * to 9 even if the AG was small enough that it would never grow to + * that height. Transaction reservation sizes influence the minimum + * log size calculation, which influences the size of the log that mkfs + * creates. Use the old value here to ensure that newly formatted + * small filesystems will mount on older kernels. + */ + if (xfs_has_rmapbt(mp) && xfs_has_reflink(mp)) + mp->m_rmap_maxlevels = XFS_OLD_REFLINK_RMAP_MAXLEVELS; + /* * The following transactions are logged in physical format and * require a permanent reservation on space. @@ -915,4 +928,7 @@ xfs_trans_resv_calc( resp->tr_clearagi.tr_logres = xfs_calc_clear_agi_bucket_reservation(mp); resp->tr_growrtzero.tr_logres = xfs_calc_growrtzero_reservation(mp); resp->tr_growrtfree.tr_logres = xfs_calc_growrtfree_reservation(mp); + + /* Put everything back the way it was. This goes at the end. */ + mp->m_rmap_maxlevels = rmap_maxlevels; } diff --git a/libxfs/xfs_trans_space.h b/libxfs/xfs_trans_space.h index bd04cb83..87b31c69 100644 --- a/libxfs/xfs_trans_space.h +++ b/libxfs/xfs_trans_space.h @@ -17,6 +17,13 @@ /* Adding one rmap could split every level up to the top of the tree. */ #define XFS_RMAPADD_SPACE_RES(mp) ((mp)->m_rmap_maxlevels) +/* + * Note that we historically set m_rmap_maxlevels to 9 when reflink is enabled, + * so we must preserve this behavior to avoid changing the transaction space + * reservations and minimum log size calculations for existing filesystems. + */ +#define XFS_OLD_REFLINK_RMAP_MAXLEVELS 9 + /* Blocks we might need to add "b" rmaps to a tree. */ #define XFS_NRMAPADD_SPACE_RES(mp, b)\ (((b + XFS_MAX_CONTIG_RMAPS_PER_BLOCK(mp) - 1) / \ From patchwork Thu Jan 20 00:25:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717987 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFC00C433F5 for ; Thu, 20 Jan 2022 00:25:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345328AbiATAZ0 (ORCPT ); Wed, 19 Jan 2022 19:25:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345332AbiATAZZ (ORCPT ); Wed, 19 Jan 2022 19:25:25 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B916C061574 for ; Wed, 19 Jan 2022 16:25:25 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3D8A261511 for ; Thu, 20 Jan 2022 00:25:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97F32C004E1; Thu, 20 Jan 2022 00:25:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638324; bh=w+EM3aWinkG4dLkKI+DyTagUgoVS8LIuqj1PXNi9WsQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=mQJuOosiiU+1PPahKWdrx6swlA/Y/yeGrjO794qNBZKKhGkM1F968qX+QnZefaD27 jVoJIDfBuEFfaIpbshCppX1kUZNFkgJ9bmnMHW+RiJrk5weyj0fkaONyhIZOVW3YUr BTPtvrPho1MEOSD/36SMG8yzSF8+DInRRwVvZnq+QMa0SQ7UH8IL2gB/9VIrqoDv9g UxgBhe8AA94ALRK4WVl+RahE2GOI7jE5Ze5p/CkPwRIe7fcyu95y/o8SujghiiwJFS 20CzWQAgvgaX7j7G5HTkOrP1Elrd6jHiMwTiXslYlwMRSHHKjjb53/O+HhrN/jOux7 Hc4unuMzTqG3A== Subject: [PATCH 24/48] xfs_db: fix metadump level comparisons From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:25:24 -0800 Message-ID: <164263832432.865554.12949672536622727220.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong It's not an error if metadump encounters a btree with the maximal height, so don't print warnings. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen --- db/metadump.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 057a3729..cc7a4a55 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -487,7 +487,7 @@ copy_free_bno_btree( "root in agf %u", root, agno); return 1; } - if (levels >= XFS_BTREE_MAXLEVELS) { + if (levels > XFS_BTREE_MAXLEVELS) { if (show_warnings) print_warning("invalid level (%u) in bnobt root " "in agf %u", levels, agno); @@ -515,7 +515,7 @@ copy_free_cnt_btree( "root in agf %u", root, agno); return 1; } - if (levels >= XFS_BTREE_MAXLEVELS) { + if (levels > XFS_BTREE_MAXLEVELS) { if (show_warnings) print_warning("invalid level (%u) in cntbt root " "in agf %u", levels, agno); @@ -587,7 +587,7 @@ copy_rmap_btree( "root in agf %u", root, agno); return 1; } - if (levels >= XFS_BTREE_MAXLEVELS) { + if (levels > XFS_BTREE_MAXLEVELS) { if (show_warnings) print_warning("invalid level (%u) in rmapbt root " "in agf %u", levels, agno); @@ -659,7 +659,7 @@ copy_refcount_btree( "root in agf %u", root, agno); return 1; } - if (levels >= XFS_BTREE_MAXLEVELS) { + if (levels > XFS_BTREE_MAXLEVELS) { if (show_warnings) print_warning("invalid level (%u) in refcntbt root " "in agf %u", levels, agno); @@ -2650,7 +2650,7 @@ copy_inodes( "root in agi %u", root, agno); return 1; } - if (levels >= XFS_BTREE_MAXLEVELS) { + if (levels > XFS_BTREE_MAXLEVELS) { if (show_warnings) print_warning("invalid level (%u) in inobt root " "in agi %u", levels, agno); From patchwork Thu Jan 20 00:25:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717988 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 611ECC433F5 for ; Thu, 20 Jan 2022 00:25:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345336AbiATAZd (ORCPT ); Wed, 19 Jan 2022 19:25:33 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:48252 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345332AbiATAZc (ORCPT ); Wed, 19 Jan 2022 19:25:32 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 87E84B81AD5 for ; Thu, 20 Jan 2022 00:25:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28E80C004E1; Thu, 20 Jan 2022 00:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638330; bh=7YLxH49vkk7lKYRIqezWy8+taCqDrL0RUWpf1BguRzg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=IqoegnwbTG1VhJ3rXFZu44i6NOYYNr4iUgJ6IHgW1bbbaa6P+NKxFKEdNN+IKFZB9 82BFo8Lj3NrSGIBgd1IzaMUJmy9xh/LPcUCuRPwPmDDs+XP6VCJhn0f9k2aQfjtk61 fC1wlVyJGTltx2GneNIqWvD6lTg+B0VmcfJjrC/Q9HW1CEEgT3+dRU4b3huKVQk4ex F2JonTtk7IJWLa0DK66/7MlNOGsvB9uKahCveRykYgGVEOtLlytds+cgML7hWC6SUI xhO3Q+5sncJRqCYVWeC2BhsvjGh3EZO6lB0YdDyqcyb0uJt9jem64LtTdJx8FwBWEs mDTpDFEH2lJRA== Subject: [PATCH 25/48] xfs_db: warn about suspicious finobt trees when metadumping From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:25:29 -0800 Message-ID: <164263832979.865554.11791034100178491501.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong We warn about suspicious roots and btree heights before metadumping the inode btree, so do the same for the free inode btree. Signed-off-by: Darrick J. Wong --- db/metadump.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/db/metadump.c b/db/metadump.c index cc7a4a55..af8b67d5 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -2664,6 +2664,21 @@ copy_inodes( root = be32_to_cpu(agi->agi_free_root); levels = be32_to_cpu(agi->agi_free_level); + if (root == 0 || root > mp->m_sb.sb_agblocks) { + if (show_warnings) + print_warning("invalid block number (%u) in " + "finobt root in agi %u", root, + agno); + return 1; + } + + if (levels > XFS_BTREE_MAXLEVELS) { + if (show_warnings) + print_warning("invalid level (%u) in finobt " + "root in agi %u", levels, agno); + return 1; + } + finobt = 1; if (!scan_btree(agno, root, levels, TYP_FINOBT, &finobt, scanfunc_ino)) From patchwork Thu Jan 20 00:25:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA8D6C433F5 for ; Thu, 20 Jan 2022 00:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345349AbiATAZj (ORCPT ); Wed, 19 Jan 2022 19:25:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345343AbiATAZi (ORCPT ); Wed, 19 Jan 2022 19:25:38 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45971C061574 for ; Wed, 19 Jan 2022 16:25:38 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 07687B81A7D for ; Thu, 20 Jan 2022 00:25:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2B8DC004E1; Thu, 20 Jan 2022 00:25:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638335; bh=2jJOdwaqK0GvwctrvBMiBH0v8JWs5VfA0lgarRhAnY4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=WBoC6FoH1oPXqEE6cR6Hup2H5WzLGs6dnhz6v9eG0/ka7WnCTQgWeughTVeA7PP8f /KEUv5a5uDRLV6+z3eiTw48uKz3QiJu/9oytqxb9VL/x3M0AU3cOStkAGItSATkvwD H4VQucPB64iJ43jqyR3mYeTksXv4uxlNyG3FtMrtADUgMzr4KjRm2oaYcH8Jl0iry/ SHb5UGMEaeytVU1QhXVcjduEuIEMTKtM69g5/23rOn4CThxa6ZpYv6gaXzVGegCTMs lS3zUZ3g8jDCJs1I1SC0aaK7lF6oej2Fck42VzlKurBe89wIC7a3iS/8WoD1e91CnQ DUzRvnptef+Pg== Subject: [PATCH 26/48] xfs_db: stop using XFS_BTREE_MAXLEVELS From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:25:35 -0800 Message-ID: <164263833535.865554.8546327352012728681.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Use the precomputed per-btree-type max height values. Signed-off-by: Darrick J. Wong --- db/metadump.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index af8b67d5..2993f06e 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -487,7 +487,7 @@ copy_free_bno_btree( "root in agf %u", root, agno); return 1; } - if (levels > XFS_BTREE_MAXLEVELS) { + if (levels > mp->m_alloc_maxlevels) { if (show_warnings) print_warning("invalid level (%u) in bnobt root " "in agf %u", levels, agno); @@ -515,7 +515,7 @@ copy_free_cnt_btree( "root in agf %u", root, agno); return 1; } - if (levels > XFS_BTREE_MAXLEVELS) { + if (levels > mp->m_alloc_maxlevels) { if (show_warnings) print_warning("invalid level (%u) in cntbt root " "in agf %u", levels, agno); @@ -587,7 +587,7 @@ copy_rmap_btree( "root in agf %u", root, agno); return 1; } - if (levels > XFS_BTREE_MAXLEVELS) { + if (levels > mp->m_rmap_maxlevels) { if (show_warnings) print_warning("invalid level (%u) in rmapbt root " "in agf %u", levels, agno); @@ -659,7 +659,7 @@ copy_refcount_btree( "root in agf %u", root, agno); return 1; } - if (levels > XFS_BTREE_MAXLEVELS) { + if (levels > mp->m_refc_maxlevels) { if (show_warnings) print_warning("invalid level (%u) in refcntbt root " "in agf %u", levels, agno); @@ -2650,7 +2650,7 @@ copy_inodes( "root in agi %u", root, agno); return 1; } - if (levels > XFS_BTREE_MAXLEVELS) { + if (levels > M_IGEO(mp)->inobt_maxlevels) { if (show_warnings) print_warning("invalid level (%u) in inobt root " "in agi %u", levels, agno); @@ -2672,7 +2672,7 @@ copy_inodes( return 1; } - if (levels > XFS_BTREE_MAXLEVELS) { + if (levels > M_IGEO(mp)->inobt_maxlevels) { if (show_warnings) print_warning("invalid level (%u) in finobt " "root in agi %u", levels, agno); From patchwork Thu Jan 20 00:25:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717990 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 038DDC433EF for ; Thu, 20 Jan 2022 00:25:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345343AbiATAZm (ORCPT ); Wed, 19 Jan 2022 19:25:42 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:33124 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345332AbiATAZm (ORCPT ); Wed, 19 Jan 2022 19:25:42 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D70A96150C for ; Thu, 20 Jan 2022 00:25:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B0DAC004E1; Thu, 20 Jan 2022 00:25:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638341; bh=XNYa3h3hs71SbYye+mKMfw7fVo1iNU559wHNDtwt0fM=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=AbqkFpnfbw+nWRgl6vDKWoBlJT5V9t+YRN++wIYJHONG5KPm4Oiyzrfo92ks8C9mf oMM/ayw0Zzvwufo2koeM1Ooe3uJPXpX5doKmApKxQ53haHWW8DjB0N1kra1ur+WIor dPMNwVS/Fu+tinbokv2OEDvLTk9YEnUJ5pe0KleEMECw3jbkJJxg1DFQZzA/e3Vk5y 3T/JikabX1mqn8wBiSeml7XSjLhNMlQ8OPWrd9xZSO+uh8MYGoJD/0ZmRw18HYS7aJ D1K2gxnXYehyrIlW+cZi7WziwZKFdRR2bXDfyHwhZ+qnYnPr9apME9DtVC0cIaxpSD M7lR2yE24kGnQ== Subject: [PATCH 27/48] xfs_repair: fix AG header btree level comparisons From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:25:41 -0800 Message-ID: <164263834099.865554.12607282164360768854.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong It's not an error if repair encounters a btree with the maximal height, so don't print warnings. Also, we don't allow zero-height btrees. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen --- repair/scan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/repair/scan.c b/repair/scan.c index 909c4494..e2d281a2 100644 --- a/repair/scan.c +++ b/repair/scan.c @@ -2297,7 +2297,7 @@ validate_agf( priv.nr_blocks = 0; levels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]); - if (levels >= XFS_BTREE_MAXLEVELS) { + if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { do_warn(_("bad levels %u for rmapbt root, agno %d\n"), levels, agno); rmap_avoid_check(); @@ -2323,7 +2323,7 @@ validate_agf( unsigned int levels; levels = be32_to_cpu(agf->agf_refcount_level); - if (levels >= XFS_BTREE_MAXLEVELS) { + if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { do_warn(_("bad levels %u for refcountbt root, agno %d\n"), levels, agno); refcount_avoid_check(); From patchwork Thu Jan 20 00:25:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717991 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01143C433F5 for ; Thu, 20 Jan 2022 00:25:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345360AbiATAZt (ORCPT ); Wed, 19 Jan 2022 19:25:49 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:48326 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345332AbiATAZt (ORCPT ); Wed, 19 Jan 2022 19:25:49 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0123BB81911 for ; Thu, 20 Jan 2022 00:25:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC771C004E1; Thu, 20 Jan 2022 00:25:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638346; bh=LfzFaPxgI4QwXT46O06inMuqusk0lGBkhp7x6r61fLY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=nja/RvRkbNTQAd3uOLtox1elOqOp+ii52AayQEgvyxaw69Ez4JJFsC3mqij47k6ni FmNQ+/Nxf4EXVo6wF4S5gFcdyqht+EBMixOUv75+jOlPy+krF5FdoBexgT421KkMjd T2ECivnhPKKCbPHdEQx9NHox54M5svsVlTdIr7KW0EIG9MzsEQ4bm+KEv2Xzn+YF/o LX4CkRTOIyRhS702XWTuNGrZqak4BUn5/j4Qm6dCKEXF1W9eGDbEMO19NJuUDcOoCC wsvJ40Pe14ZB7tHBYKOcguTF12OrIoxcSD2yyFxguBnoT0Gq0+hzYSTg41OzBUqVkE hQJYq4H0TjMlA== Subject: [PATCH 28/48] xfs_repair: warn about suspicious btree levels in AG headers From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:25:46 -0800 Message-ID: <164263834640.865554.8783708804794640296.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Warn about suspicious AG btree levels in the AGF and AGI. Signed-off-by: Darrick J. Wong --- repair/scan.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/repair/scan.c b/repair/scan.c index e2d281a2..e7bf1fde 100644 --- a/repair/scan.c +++ b/repair/scan.c @@ -2261,6 +2261,13 @@ validate_agf( { xfs_agblock_t bno; uint32_t magic; + unsigned int levels; + + levels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]); + if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { + do_warn(_("bad levels %u for btbno root, agno %d\n"), + levels, agno); + } bno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_BNO]); if (libxfs_verify_agbno(mp, agno, bno)) { @@ -2274,6 +2281,12 @@ validate_agf( bno, agno); } + levels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]); + if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { + do_warn(_("bad levels %u for btbcnt root, agno %d\n"), + levels, agno); + } + bno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_CNT]); if (libxfs_verify_agbno(mp, agno, bno)) { magic = xfs_has_crc(mp) ? XFS_ABTC_CRC_MAGIC @@ -2288,7 +2301,6 @@ validate_agf( if (xfs_has_rmapbt(mp)) { struct rmap_priv priv; - unsigned int levels; memset(&priv.high_key, 0xFF, sizeof(priv.high_key)); priv.high_key.rm_blockcount = 0; @@ -2320,8 +2332,6 @@ validate_agf( } if (xfs_has_reflink(mp)) { - unsigned int levels; - levels = be32_to_cpu(agf->agf_refcount_level); if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { do_warn(_("bad levels %u for refcountbt root, agno %d\n"), @@ -2378,6 +2388,13 @@ validate_agi( xfs_agblock_t bno; int i; uint32_t magic; + unsigned int levels; + + levels = be32_to_cpu(agi->agi_level); + if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { + do_warn(_("bad levels %u for inobt root, agno %d\n"), + levels, agno); + } bno = be32_to_cpu(agi->agi_root); if (libxfs_verify_agbno(mp, agno, bno)) { @@ -2392,6 +2409,12 @@ validate_agi( } if (xfs_has_finobt(mp)) { + levels = be32_to_cpu(agi->agi_free_level); + if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { + do_warn(_("bad levels %u for finobt root, agno %d\n"), + levels, agno); + } + bno = be32_to_cpu(agi->agi_free_root); if (libxfs_verify_agbno(mp, agno, bno)) { magic = xfs_has_crc(mp) ? From patchwork Thu Jan 20 00:25:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717992 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36936C433EF for ; Thu, 20 Jan 2022 00:25:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345332AbiATAZz (ORCPT ); Wed, 19 Jan 2022 19:25:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344725AbiATAZz (ORCPT ); Wed, 19 Jan 2022 19:25:55 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7505C061574 for ; Wed, 19 Jan 2022 16:25:54 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8C475B81AD5 for ; Thu, 20 Jan 2022 00:25:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30D69C004E1; Thu, 20 Jan 2022 00:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638352; bh=Tf/Dg444TfMG7lkqWBwqDT67pBgwYLDX5OyMsGKgazg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=KMF+e//1LhM3BDHQyGjdOulU/2Dcr2zd8Kks0ngwEWRJwCSKJc+add77jrQmUbYTi YQu1r1m15Xq3J2WsfAD12d31CRvEiVgWG2ZxPsLldXgh9xm2r8lOhZ6r25vE3FNwSA oM+ygdMTzlF0Ug2Sw2IOC2AkjlkeI4NSXECafpg3ZMs3FICeBpByDIswmfvjpSKd2u /OjQea/imzMwuS9qi39TRrS/gg9EfHctfHkqD4lmujjkfFskkTCIhnh6b/M+tNrr8R 8kcIOXJ3okQ+NdCxYFg6Vx37VwBZ8+F8K85y+H64qY7xtO+QvwtpsK9UdOzPqx1UZJ K8nsKfcaaj5Zg== Subject: [PATCH 29/48] xfs_repair: stop using XFS_BTREE_MAXLEVELS From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:25:51 -0800 Message-ID: <164263835190.865554.2981692152783837289.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Use the precomputed per-btree-type max height values. Signed-off-by: Darrick J. Wong --- repair/scan.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/repair/scan.c b/repair/scan.c index e7bf1fde..5a4b8dbd 100644 --- a/repair/scan.c +++ b/repair/scan.c @@ -2264,7 +2264,7 @@ validate_agf( unsigned int levels; levels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]); - if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { + if (levels == 0 || levels > mp->m_alloc_maxlevels) { do_warn(_("bad levels %u for btbno root, agno %d\n"), levels, agno); } @@ -2282,7 +2282,7 @@ validate_agf( } levels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]); - if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { + if (levels == 0 || levels > mp->m_alloc_maxlevels) { do_warn(_("bad levels %u for btbcnt root, agno %d\n"), levels, agno); } @@ -2309,7 +2309,7 @@ validate_agf( priv.nr_blocks = 0; levels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]); - if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { + if (levels == 0 || levels > mp->m_rmap_maxlevels) { do_warn(_("bad levels %u for rmapbt root, agno %d\n"), levels, agno); rmap_avoid_check(); @@ -2333,7 +2333,7 @@ validate_agf( if (xfs_has_reflink(mp)) { levels = be32_to_cpu(agf->agf_refcount_level); - if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { + if (levels == 0 || levels > mp->m_refc_maxlevels) { do_warn(_("bad levels %u for refcountbt root, agno %d\n"), levels, agno); refcount_avoid_check(); @@ -2391,7 +2391,7 @@ validate_agi( unsigned int levels; levels = be32_to_cpu(agi->agi_level); - if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { + if (levels == 0 || levels > M_IGEO(mp)->inobt_maxlevels) { do_warn(_("bad levels %u for inobt root, agno %d\n"), levels, agno); } @@ -2410,7 +2410,7 @@ validate_agi( if (xfs_has_finobt(mp)) { levels = be32_to_cpu(agi->agi_free_level); - if (levels == 0 || levels > XFS_BTREE_MAXLEVELS) { + if (levels == 0 || levels > M_IGEO(mp)->inobt_maxlevels) { do_warn(_("bad levels %u for finobt root, agno %d\n"), levels, agno); } From patchwork Thu Jan 20 00:25:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717993 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59947C433EF for ; Thu, 20 Jan 2022 00:26:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345400AbiATA0A (ORCPT ); Wed, 19 Jan 2022 19:26:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344725AbiATA0A (ORCPT ); Wed, 19 Jan 2022 19:26:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BD60C061574 for ; Wed, 19 Jan 2022 16:26:00 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DA112B81911 for ; Thu, 20 Jan 2022 00:25:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1476C004E1; Thu, 20 Jan 2022 00:25:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638357; bh=/scE1ITb93n5qQB3J7QMh/JXQwz1HmPzJVz/OPmSTJk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=uTMWolsppXb8QrFMyYhCtx9cq7essjEQhVk+TU3e6BQ7veW33IYdej0dlZo7yUvvi Bza4BMS7eLoyc10UvLS9ycnIER6PHdyxlbc2Z4NKsrfUUcwVdRg1Oy2tvNctxh7Rmi xI1CskbzGTYaP6ajr4HTSFBdIZGrc/fYR/1HEad90uewAeFppNiqV3l7JWjn/moiDM uSZ1wRH+uR3H/kMxSHhXNbq83KDrNnrWyfz2iMDcLMx0DmlLZuDfOF/UJQ9lxvQGeb x1c1Qi0EqTtlzGnepZK1DFLIrh8RGQsU7xL4IdWwpnobTg+AbO2vuIkUMgGEevnXFO sfCxa+r6FpAxA== Subject: [PATCH 30/48] xfs: kill XFS_BTREE_MAXLEVELS From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:25:57 -0800 Message-ID: <164263835738.865554.4017087053550319195.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: bc8883eb775dd18d8b84733d8b3a3955b72d103a Nobody uses this symbol anymore, so kill it. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- libxfs/xfs_btree.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index e488bfcc..fdf7090c 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -92,8 +92,6 @@ uint32_t xfs_btree_magic(int crc, xfs_btnum_t btnum); #define XFS_BTREE_STATS_ADD(cur, stat, val) \ XFS_STATS_ADD_OFF((cur)->bc_mp, (cur)->bc_statoff + __XBTS_ ## stat, val) -#define XFS_BTREE_MAXLEVELS 9 /* max of all btrees */ - /* * The btree cursor zone hands out cursors that can handle up to this many * levels. This is the known maximum for all btree types. From patchwork Thu Jan 20 00:26:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717994 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24506C433F5 for ; Thu, 20 Jan 2022 00:26:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345404AbiATA0G (ORCPT ); Wed, 19 Jan 2022 19:26:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344725AbiATA0G (ORCPT ); Wed, 19 Jan 2022 19:26:06 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5B02C061574 for ; Wed, 19 Jan 2022 16:26:05 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 79EF9B81A7D for ; Thu, 20 Jan 2022 00:26:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E82CC004E1; Thu, 20 Jan 2022 00:26:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638363; bh=/gU8t09UxQvuZcS9k09oxlEZINT5PZ+5vHqvCcKMzmo=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=OJR7Bs3qWeazyKheXJzEErX1XwiEg58vOgO6SihNI1QrioSklRSi0KpdIJFeD8vnD IzM025r1VAS/7WVU7s9zm8h39XsWNi+6VkSk6h2BJkRHPwWPur3j95XscPpM9ofxkz 51Lo3HguvAWJWAe9OxilYlxQCNiYGIFfEHWfycxqWDy23LF2M2klx54E3qPAc9pdZW c2jpjjpGFwsZtwamE+CeE1nOjQxoFPoBjrVla+mcKoDKaZ3HQT88y6NK8OYGrgGv4Q QHRezis/+ed6E06Rxb/qj8RJYX98irEkcz6m4E/t0ZgXzsM7UY4EKFhWqJ2n4cEIZU L46H8U7tJwsNg== Subject: [PATCH 31/48] xfs: compute absolute maximum nlevels for each btree type From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:26:02 -0800 Message-ID: <164263836283.865554.12835070575139510285.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 0ed5f7356daee74244b02e100b3cc043e886e686 Add code for all five btree types so that we can compute the absolute maximum possible btree height for each btree type. This is a setup for the next patch, which makes every btree type have its own cursor cache. The functions are exported so that we can have xfs_db report the absolute maximum btree heights for each btree type, rather than making everyone run their own ad-hoc computations. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- libxfs/xfs_alloc.c | 1 + libxfs/xfs_alloc_btree.c | 33 +++++++++++++++++++++-- libxfs/xfs_alloc_btree.h | 2 + libxfs/xfs_bmap.c | 1 + libxfs/xfs_bmap_btree.c | 31 ++++++++++++++++++++-- libxfs/xfs_bmap_btree.h | 2 + libxfs/xfs_fs.h | 2 + libxfs/xfs_ialloc.c | 1 + libxfs/xfs_ialloc_btree.c | 61 +++++++++++++++++++++++++++++++++++++++++-- libxfs/xfs_ialloc_btree.h | 2 + libxfs/xfs_refcount_btree.c | 45 ++++++++++++++++++++++++++------ libxfs/xfs_refcount_btree.h | 2 + libxfs/xfs_rmap_btree.c | 43 +++++++++++++++++++++++++++--- libxfs/xfs_rmap_btree.h | 2 + 14 files changed, 207 insertions(+), 21 deletions(-) diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index e20d8fb7..7d304160 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -2194,6 +2194,7 @@ xfs_alloc_compute_maxlevels( { mp->m_alloc_maxlevels = xfs_btree_compute_maxlevels(mp->m_alloc_mnr, (mp->m_sb.sb_agblocks + 1) / 2); + ASSERT(mp->m_alloc_maxlevels <= xfs_allocbt_maxlevels_ondisk()); } /* diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c index d752500b..6de3af37 100644 --- a/libxfs/xfs_alloc_btree.c +++ b/libxfs/xfs_alloc_btree.c @@ -564,6 +564,17 @@ xfs_allocbt_commit_staged_btree( } } +/* Calculate number of records in an alloc btree block. */ +static inline unsigned int +xfs_allocbt_block_maxrecs( + unsigned int blocklen, + bool leaf) +{ + if (leaf) + return blocklen / sizeof(xfs_alloc_rec_t); + return blocklen / (sizeof(xfs_alloc_key_t) + sizeof(xfs_alloc_ptr_t)); +} + /* * Calculate number of records in an alloc btree block. */ @@ -574,10 +585,26 @@ xfs_allocbt_maxrecs( int leaf) { blocklen -= XFS_ALLOC_BLOCK_LEN(mp); + return xfs_allocbt_block_maxrecs(blocklen, leaf); +} - if (leaf) - return blocklen / sizeof(xfs_alloc_rec_t); - return blocklen / (sizeof(xfs_alloc_key_t) + sizeof(xfs_alloc_ptr_t)); +/* Free space btrees are at their largest when every other block is free. */ +#define XFS_MAX_FREESP_RECORDS ((XFS_MAX_AG_BLOCKS + 1) / 2) + +/* Compute the max possible height for free space btrees. */ +unsigned int +xfs_allocbt_maxlevels_ondisk(void) +{ + unsigned int minrecs[2]; + unsigned int blocklen; + + blocklen = min(XFS_MIN_BLOCKSIZE - XFS_BTREE_SBLOCK_LEN, + XFS_MIN_CRC_BLOCKSIZE - XFS_BTREE_SBLOCK_CRC_LEN); + + minrecs[0] = xfs_allocbt_block_maxrecs(blocklen, true) / 2; + minrecs[1] = xfs_allocbt_block_maxrecs(blocklen, false) / 2; + + return xfs_btree_compute_maxlevels(minrecs, XFS_MAX_FREESP_RECORDS); } /* Calculate the freespace btree size for some records. */ diff --git a/libxfs/xfs_alloc_btree.h b/libxfs/xfs_alloc_btree.h index 2f6b816a..c715bee5 100644 --- a/libxfs/xfs_alloc_btree.h +++ b/libxfs/xfs_alloc_btree.h @@ -60,4 +60,6 @@ extern xfs_extlen_t xfs_allocbt_calc_size(struct xfs_mount *mp, void xfs_allocbt_commit_staged_btree(struct xfs_btree_cur *cur, struct xfs_trans *tp, struct xfs_buf *agbp); +unsigned int xfs_allocbt_maxlevels_ondisk(void); + #endif /* __XFS_ALLOC_BTREE_H__ */ diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 3b8b1b61..bc8a2033 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -86,6 +86,7 @@ xfs_bmap_compute_maxlevels( maxblocks = (maxblocks + minnoderecs - 1) / minnoderecs; } mp->m_bm_maxlevels[whichfork] = level; + ASSERT(mp->m_bm_maxlevels[whichfork] <= xfs_bmbt_maxlevels_ondisk()); } unsigned int diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c index 9e2263ed..85faea1d 100644 --- a/libxfs/xfs_bmap_btree.c +++ b/libxfs/xfs_bmap_btree.c @@ -569,6 +569,17 @@ xfs_bmbt_init_cursor( return cur; } +/* Calculate number of records in a block mapping btree block. */ +static inline unsigned int +xfs_bmbt_block_maxrecs( + unsigned int blocklen, + bool leaf) +{ + if (leaf) + return blocklen / sizeof(xfs_bmbt_rec_t); + return blocklen / (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t)); +} + /* * Calculate number of records in a bmap btree block. */ @@ -579,10 +590,24 @@ xfs_bmbt_maxrecs( int leaf) { blocklen -= XFS_BMBT_BLOCK_LEN(mp); + return xfs_bmbt_block_maxrecs(blocklen, leaf); +} - if (leaf) - return blocklen / sizeof(xfs_bmbt_rec_t); - return blocklen / (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t)); +/* Compute the max possible height for block mapping btrees. */ +unsigned int +xfs_bmbt_maxlevels_ondisk(void) +{ + unsigned int minrecs[2]; + unsigned int blocklen; + + blocklen = min(XFS_MIN_BLOCKSIZE - XFS_BTREE_SBLOCK_LEN, + XFS_MIN_CRC_BLOCKSIZE - XFS_BTREE_SBLOCK_CRC_LEN); + + minrecs[0] = xfs_bmbt_block_maxrecs(blocklen, true) / 2; + minrecs[1] = xfs_bmbt_block_maxrecs(blocklen, false) / 2; + + /* One extra level for the inode root. */ + return xfs_btree_compute_maxlevels(minrecs, MAXEXTNUM) + 1; } /* diff --git a/libxfs/xfs_bmap_btree.h b/libxfs/xfs_bmap_btree.h index 729e3bc5..2a1c9e60 100644 --- a/libxfs/xfs_bmap_btree.h +++ b/libxfs/xfs_bmap_btree.h @@ -110,4 +110,6 @@ extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *, extern unsigned long long xfs_bmbt_calc_size(struct xfs_mount *mp, unsigned long long len); +unsigned int xfs_bmbt_maxlevels_ondisk(void); + #endif /* __XFS_BMAP_BTREE_H__ */ diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index bde2b4c6..c43877c8 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -268,6 +268,8 @@ typedef struct xfs_fsop_resblks { */ #define XFS_MIN_AG_BYTES (1ULL << 24) /* 16 MB */ #define XFS_MAX_AG_BYTES (1ULL << 40) /* 1 TB */ +#define XFS_MAX_AG_BLOCKS (XFS_MAX_AG_BYTES / XFS_MIN_BLOCKSIZE) +#define XFS_MAX_CRC_AG_BLOCKS (XFS_MAX_AG_BYTES / XFS_MIN_CRC_BLOCKSIZE) /* keep the maximum size under 2^31 by a small amount */ #define XFS_MAX_LOG_BYTES \ diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index 3b96e828..b18ddc4e 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -2788,6 +2788,7 @@ xfs_ialloc_setup_geometry( inodes = (1LL << XFS_INO_AGINO_BITS(mp)) >> XFS_INODES_PER_CHUNK_LOG; igeo->inobt_maxlevels = xfs_btree_compute_maxlevels(igeo->inobt_mnr, inodes); + ASSERT(igeo->inobt_maxlevels <= xfs_iallocbt_maxlevels_ondisk()); /* * Set the maximum inode count for this filesystem, being careful not diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c index be0918b7..30b1abe9 100644 --- a/libxfs/xfs_ialloc_btree.c +++ b/libxfs/xfs_ialloc_btree.c @@ -525,6 +525,17 @@ xfs_inobt_commit_staged_btree( } } +/* Calculate number of records in an inode btree block. */ +static inline unsigned int +xfs_inobt_block_maxrecs( + unsigned int blocklen, + bool leaf) +{ + if (leaf) + return blocklen / sizeof(xfs_inobt_rec_t); + return blocklen / (sizeof(xfs_inobt_key_t) + sizeof(xfs_inobt_ptr_t)); +} + /* * Calculate number of records in an inobt btree block. */ @@ -535,10 +546,54 @@ xfs_inobt_maxrecs( int leaf) { blocklen -= XFS_INOBT_BLOCK_LEN(mp); + return xfs_inobt_block_maxrecs(blocklen, leaf); +} - if (leaf) - return blocklen / sizeof(xfs_inobt_rec_t); - return blocklen / (sizeof(xfs_inobt_key_t) + sizeof(xfs_inobt_ptr_t)); +/* + * Maximum number of inode btree records per AG. Pretend that we can fill an + * entire AG completely full of inodes except for the AG headers. + */ +#define XFS_MAX_INODE_RECORDS \ + ((XFS_MAX_AG_BYTES - (4 * BBSIZE)) / XFS_DINODE_MIN_SIZE) / \ + XFS_INODES_PER_CHUNK + +/* Compute the max possible height for the inode btree. */ +static inline unsigned int +xfs_inobt_maxlevels_ondisk(void) +{ + unsigned int minrecs[2]; + unsigned int blocklen; + + blocklen = min(XFS_MIN_BLOCKSIZE - XFS_BTREE_SBLOCK_LEN, + XFS_MIN_CRC_BLOCKSIZE - XFS_BTREE_SBLOCK_CRC_LEN); + + minrecs[0] = xfs_inobt_block_maxrecs(blocklen, true) / 2; + minrecs[1] = xfs_inobt_block_maxrecs(blocklen, false) / 2; + + return xfs_btree_compute_maxlevels(minrecs, XFS_MAX_INODE_RECORDS); +} + +/* Compute the max possible height for the free inode btree. */ +static inline unsigned int +xfs_finobt_maxlevels_ondisk(void) +{ + unsigned int minrecs[2]; + unsigned int blocklen; + + blocklen = XFS_MIN_CRC_BLOCKSIZE - XFS_BTREE_SBLOCK_CRC_LEN; + + minrecs[0] = xfs_inobt_block_maxrecs(blocklen, true) / 2; + minrecs[1] = xfs_inobt_block_maxrecs(blocklen, false) / 2; + + return xfs_btree_compute_maxlevels(minrecs, XFS_MAX_INODE_RECORDS); +} + +/* Compute the max possible height for either inode btree. */ +unsigned int +xfs_iallocbt_maxlevels_ondisk(void) +{ + return max(xfs_inobt_maxlevels_ondisk(), + xfs_finobt_maxlevels_ondisk()); } /* diff --git a/libxfs/xfs_ialloc_btree.h b/libxfs/xfs_ialloc_btree.h index 8a322d40..6d3e4a33 100644 --- a/libxfs/xfs_ialloc_btree.h +++ b/libxfs/xfs_ialloc_btree.h @@ -75,4 +75,6 @@ int xfs_inobt_cur(struct xfs_mount *mp, struct xfs_trans *tp, void xfs_inobt_commit_staged_btree(struct xfs_btree_cur *cur, struct xfs_trans *tp, struct xfs_buf *agbp); +unsigned int xfs_iallocbt_maxlevels_ondisk(void); + #endif /* __XFS_IALLOC_BTREE_H__ */ diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c index 6a716924..1d7b2d7c 100644 --- a/libxfs/xfs_refcount_btree.c +++ b/libxfs/xfs_refcount_btree.c @@ -392,29 +392,58 @@ xfs_refcountbt_commit_staged_btree( xfs_btree_commit_afakeroot(cur, tp, agbp, &xfs_refcountbt_ops); } -/* - * Calculate the number of records in a refcount btree block. - */ -int -xfs_refcountbt_maxrecs( - int blocklen, +/* Calculate number of records in a refcount btree block. */ +static inline unsigned int +xfs_refcountbt_block_maxrecs( + unsigned int blocklen, bool leaf) { - blocklen -= XFS_REFCOUNT_BLOCK_LEN; - if (leaf) return blocklen / sizeof(struct xfs_refcount_rec); return blocklen / (sizeof(struct xfs_refcount_key) + sizeof(xfs_refcount_ptr_t)); } +/* + * Calculate the number of records in a refcount btree block. + */ +int +xfs_refcountbt_maxrecs( + int blocklen, + bool leaf) +{ + blocklen -= XFS_REFCOUNT_BLOCK_LEN; + return xfs_refcountbt_block_maxrecs(blocklen, leaf); +} + +/* Compute the max possible height of the maximally sized refcount btree. */ +unsigned int +xfs_refcountbt_maxlevels_ondisk(void) +{ + unsigned int minrecs[2]; + unsigned int blocklen; + + blocklen = XFS_MIN_CRC_BLOCKSIZE - XFS_BTREE_SBLOCK_CRC_LEN; + + minrecs[0] = xfs_refcountbt_block_maxrecs(blocklen, true) / 2; + minrecs[1] = xfs_refcountbt_block_maxrecs(blocklen, false) / 2; + + return xfs_btree_compute_maxlevels(minrecs, XFS_MAX_CRC_AG_BLOCKS); +} + /* Compute the maximum height of a refcount btree. */ void xfs_refcountbt_compute_maxlevels( struct xfs_mount *mp) { + if (!xfs_has_reflink(mp)) { + mp->m_refc_maxlevels = 0; + return; + } + mp->m_refc_maxlevels = xfs_btree_compute_maxlevels( mp->m_refc_mnr, mp->m_sb.sb_agblocks); + ASSERT(mp->m_refc_maxlevels <= xfs_refcountbt_maxlevels_ondisk()); } /* Calculate the refcount btree size for some records. */ diff --git a/libxfs/xfs_refcount_btree.h b/libxfs/xfs_refcount_btree.h index bd9ed9e1..d7f7c89c 100644 --- a/libxfs/xfs_refcount_btree.h +++ b/libxfs/xfs_refcount_btree.h @@ -65,4 +65,6 @@ extern int xfs_refcountbt_calc_reserves(struct xfs_mount *mp, void xfs_refcountbt_commit_staged_btree(struct xfs_btree_cur *cur, struct xfs_trans *tp, struct xfs_buf *agbp); +unsigned int xfs_refcountbt_maxlevels_ondisk(void); + #endif /* __XFS_REFCOUNT_BTREE_H__ */ diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c index eeaa1e28..eb3ef409 100644 --- a/libxfs/xfs_rmap_btree.c +++ b/libxfs/xfs_rmap_btree.c @@ -517,6 +517,18 @@ xfs_rmapbt_commit_staged_btree( xfs_btree_commit_afakeroot(cur, tp, agbp, &xfs_rmapbt_ops); } +/* Calculate number of records in a reverse mapping btree block. */ +static inline unsigned int +xfs_rmapbt_block_maxrecs( + unsigned int blocklen, + bool leaf) +{ + if (leaf) + return blocklen / sizeof(struct xfs_rmap_rec); + return blocklen / + (2 * sizeof(struct xfs_rmap_key) + sizeof(xfs_rmap_ptr_t)); +} + /* * Calculate number of records in an rmap btree block. */ @@ -526,11 +538,33 @@ xfs_rmapbt_maxrecs( int leaf) { blocklen -= XFS_RMAP_BLOCK_LEN; + return xfs_rmapbt_block_maxrecs(blocklen, leaf); +} - if (leaf) - return blocklen / sizeof(struct xfs_rmap_rec); - return blocklen / - (2 * sizeof(struct xfs_rmap_key) + sizeof(xfs_rmap_ptr_t)); +/* Compute the max possible height for reverse mapping btrees. */ +unsigned int +xfs_rmapbt_maxlevels_ondisk(void) +{ + unsigned int minrecs[2]; + unsigned int blocklen; + + blocklen = XFS_MIN_CRC_BLOCKSIZE - XFS_BTREE_SBLOCK_CRC_LEN; + + minrecs[0] = xfs_rmapbt_block_maxrecs(blocklen, true) / 2; + minrecs[1] = xfs_rmapbt_block_maxrecs(blocklen, false) / 2; + + /* + * Compute the asymptotic maxlevels for an rmapbt on any reflink fs. + * + * On a reflink filesystem, each AG block can have up to 2^32 (per the + * refcount record format) owners, which means that theoretically we + * could face up to 2^64 rmap records. However, we're likely to run + * out of blocks in the AG long before that happens, which means that + * we must compute the max height based on what the btree will look + * like if it consumes almost all the blocks in the AG due to maximal + * sharing factor. + */ + return xfs_btree_space_to_height(minrecs, XFS_MAX_CRC_AG_BLOCKS); } /* Compute the maximum height of an rmap btree. */ @@ -567,6 +601,7 @@ xfs_rmapbt_compute_maxlevels( mp->m_rmap_maxlevels = xfs_btree_compute_maxlevels( mp->m_rmap_mnr, mp->m_sb.sb_agblocks); } + ASSERT(mp->m_rmap_maxlevels <= xfs_rmapbt_maxlevels_ondisk()); } /* Calculate the refcount btree size for some records. */ diff --git a/libxfs/xfs_rmap_btree.h b/libxfs/xfs_rmap_btree.h index f2eee657..e9778b62 100644 --- a/libxfs/xfs_rmap_btree.h +++ b/libxfs/xfs_rmap_btree.h @@ -59,4 +59,6 @@ extern xfs_extlen_t xfs_rmapbt_max_size(struct xfs_mount *mp, extern int xfs_rmapbt_calc_reserves(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_perag *pag, xfs_extlen_t *ask, xfs_extlen_t *used); +unsigned int xfs_rmapbt_maxlevels_ondisk(void); + #endif /* __XFS_RMAP_BTREE_H__ */ From patchwork Thu Jan 20 00:26:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A107BC433F5 for ; Thu, 20 Jan 2022 00:26:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344725AbiATA0K (ORCPT ); Wed, 19 Jan 2022 19:26:10 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:33390 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345413AbiATA0J (ORCPT ); Wed, 19 Jan 2022 19:26:09 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 48C8E61514 for ; Thu, 20 Jan 2022 00:26:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96C4EC004E1; Thu, 20 Jan 2022 00:26:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638368; bh=rRglsgntePMG00Y6LsNAHsVpRausg4nOtwWiCnCAFYc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=G86CiwoecepoUyaxI9nbnqwRvcc7tcotwTRDFwc6hy+XhFBYuOuLmm25IJdFynJR/ kEH48VBizSwmAg/TBGBaYh9bUq8k/20PfPI02J9HmuVjaTk/zQviUiI01YkGXsq7un YtbtVB1zk2N6vh8JoGbzVknJt+evYQza7RwCT5h+liEfOzVFWDOkcZC9jD6ZaNwei8 NkLNT1lSQ9GeeXIDtm9gRQjW3Qi5rTnITXM0NYIQ7fCrS+emZowkaonkGyfqbislAD mV/HhA+8qs6pzqiuP9Q163641J1svPqqcLV7SjZlydDsKY6pH4FfWo66PDTWU9gY9b HiWUa8x0mV2PA== Subject: [PATCH 32/48] xfs: use separate btree cursor cache for each btree type From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:26:08 -0800 Message-ID: <164263836830.865554.11598846562233200947.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 9fa47bdcd33b117599e9ee3f2e315cb47939ac2d Now that we have the infrastructure to track the max possible height of each btree type, we can create a separate slab cache for cursors of each type of btree. For smaller indices like the free space btrees, this means that we can pack more cursors into a slab page, improving slab utilization. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Darrick J. Wong --- include/kmem.h | 27 +++++++++++++++++++---- include/platform_defs.h.in | 3 +++ libxfs/init.c | 11 +++++++-- libxfs/kmem.c | 22 ++++++++++++++++--- libxfs/xfs_alloc_btree.c | 23 +++++++++++++++++++ libxfs/xfs_alloc_btree.h | 3 +++ libxfs/xfs_bmap_btree.c | 23 +++++++++++++++++++ libxfs/xfs_bmap_btree.h | 3 +++ libxfs/xfs_btree.c | 51 ++++++++++++++++++++++++++++++++++++++----- libxfs/xfs_btree.h | 20 +++++++---------- libxfs/xfs_ialloc_btree.c | 23 +++++++++++++++++++ libxfs/xfs_ialloc_btree.h | 3 +++ libxfs/xfs_refcount_btree.c | 23 +++++++++++++++++++ libxfs/xfs_refcount_btree.h | 3 +++ libxfs/xfs_rmap_btree.c | 23 +++++++++++++++++++ libxfs/xfs_rmap_btree.h | 3 +++ 16 files changed, 231 insertions(+), 33 deletions(-) diff --git a/include/kmem.h b/include/kmem.h index 6d317256..c710635d 100644 --- a/include/kmem.h +++ b/include/kmem.h @@ -12,9 +12,11 @@ #define KM_NOLOCKDEP 0x0020u typedef struct kmem_zone { - int zone_unitsize; /* Size in bytes of zone unit */ - char *zone_name; /* tag name */ - int allocated; /* debug: How many currently allocated */ + int zone_unitsize; /* Size in bytes of zone unit */ + int allocated; /* debug: How many allocated? */ + unsigned int align; + const char *zone_name; /* tag name */ + void (*ctor)(void *); } kmem_zone_t; typedef unsigned int __bitwise gfp_t; @@ -26,11 +28,28 @@ typedef unsigned int __bitwise gfp_t; #define __GFP_ZERO (__force gfp_t)1 -extern kmem_zone_t *kmem_zone_init(int, char *); +kmem_zone_t * kmem_cache_create(const char *name, unsigned int size, + unsigned int align, unsigned int slab_flags, + void (*ctor)(void *)); + +static inline kmem_zone_t * +kmem_zone_init(unsigned int size, const char *name) +{ + return kmem_cache_create(name, size, 0, 0, NULL); +} + extern void *kmem_cache_alloc(kmem_zone_t *, gfp_t); extern void *kmem_cache_zalloc(kmem_zone_t *, gfp_t); extern int kmem_zone_destroy(kmem_zone_t *); + +static inline void +kmem_cache_destroy(kmem_zone_t *zone) +{ + kmem_zone_destroy(zone); +} + + static inline void kmem_cache_free(kmem_zone_t *zone, void *ptr) { diff --git a/include/platform_defs.h.in b/include/platform_defs.h.in index 6e6f26ef..315ad77c 100644 --- a/include/platform_defs.h.in +++ b/include/platform_defs.h.in @@ -134,4 +134,7 @@ static inline size_t __ab_c_size(size_t a, size_t b, size_t c) # define fallthrough do {} while (0) /* fallthrough */ #endif +/* Only needed for the kernel. */ +#define __init + #endif /* __XFS_PLATFORM_DEFS_H__ */ diff --git a/libxfs/init.c b/libxfs/init.c index 12e25379..3c1639db 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -231,6 +231,8 @@ check_open(char *path, int flags, char **rawfile, char **blockfile) static void init_zones(void) { + int error; + /* initialise zone allocation */ xfs_buf_zone = kmem_zone_init(sizeof(struct xfs_buf), "xfs_buffer"); xfs_inode_zone = kmem_zone_init(sizeof(struct xfs_inode), "xfs_inode"); @@ -241,8 +243,11 @@ init_zones(void) sizeof(struct xfs_buf_log_item), "xfs_buf_log_item"); xfs_da_state_zone = kmem_zone_init( sizeof(struct xfs_da_state), "xfs_da_state"); - xfs_btree_cur_zone = kmem_zone_init( - sizeof(struct xfs_btree_cur), "xfs_btree_cur"); + error = xfs_btree_init_cur_caches(); + if (error) { + fprintf(stderr, "Could not allocate btree cursor caches.\n"); + abort(); + } xfs_bmap_free_item_zone = kmem_zone_init( sizeof(struct xfs_extent_free_item), "xfs_bmap_free_item"); @@ -261,7 +266,7 @@ destroy_zones(void) leaked += kmem_zone_destroy(xfs_ifork_zone); leaked += kmem_zone_destroy(xfs_buf_item_zone); leaked += kmem_zone_destroy(xfs_da_state_zone); - leaked += kmem_zone_destroy(xfs_btree_cur_zone); + xfs_btree_destroy_cur_caches(); leaked += kmem_zone_destroy(xfs_bmap_free_item_zone); leaked += kmem_zone_destroy(xfs_trans_zone); diff --git a/libxfs/kmem.c b/libxfs/kmem.c index 3d72ac94..221b3480 100644 --- a/libxfs/kmem.c +++ b/libxfs/kmem.c @@ -6,9 +6,9 @@ /* * Simple memory interface */ - kmem_zone_t * -kmem_zone_init(int size, char *name) +kmem_cache_create(const char *name, unsigned int size, unsigned int align, + unsigned int slab_flags, void (*ctor)(void *)) { kmem_zone_t *ptr = malloc(sizeof(kmem_zone_t)); @@ -21,6 +21,9 @@ kmem_zone_init(int size, char *name) ptr->zone_unitsize = size; ptr->zone_name = name; ptr->allocated = 0; + ptr->align = align; + ptr->ctor = ctor; + return ptr; } @@ -41,7 +44,17 @@ kmem_zone_destroy(kmem_zone_t *zone) void * kmem_cache_alloc(kmem_zone_t *zone, gfp_t flags) { - void *ptr = malloc(zone->zone_unitsize); + void *ptr = NULL; + + if (zone->align) { + int ret; + + ret = posix_memalign(&ptr, zone->align, zone->zone_unitsize); + if (ret) + errno = ret; + } else { + ptr = malloc(zone->zone_unitsize); + } if (ptr == NULL) { fprintf(stderr, _("%s: zone alloc failed (%s, %d bytes): %s\n"), @@ -49,6 +62,9 @@ kmem_cache_alloc(kmem_zone_t *zone, gfp_t flags) strerror(errno)); exit(1); } + + if (zone->ctor) + zone->ctor(ptr); zone->allocated++; return ptr; } diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c index 6de3af37..2176a923 100644 --- a/libxfs/xfs_alloc_btree.c +++ b/libxfs/xfs_alloc_btree.c @@ -18,6 +18,7 @@ #include "xfs_trans.h" #include "xfs_ag.h" +static kmem_zone_t *xfs_allocbt_cur_cache; STATIC struct xfs_btree_cur * xfs_allocbt_dup_cursor( @@ -475,7 +476,8 @@ xfs_allocbt_init_common( ASSERT(btnum == XFS_BTNUM_BNO || btnum == XFS_BTNUM_CNT); - cur = xfs_btree_alloc_cursor(mp, tp, btnum, mp->m_alloc_maxlevels); + cur = xfs_btree_alloc_cursor(mp, tp, btnum, mp->m_alloc_maxlevels, + xfs_allocbt_cur_cache); cur->bc_ag.abt.active = false; if (btnum == XFS_BTNUM_CNT) { @@ -615,3 +617,22 @@ xfs_allocbt_calc_size( { return xfs_btree_calc_size(mp->m_alloc_mnr, len); } + +int __init +xfs_allocbt_init_cur_cache(void) +{ + xfs_allocbt_cur_cache = kmem_cache_create("xfs_bnobt_cur", + xfs_btree_cur_sizeof(xfs_allocbt_maxlevels_ondisk()), + 0, 0, NULL); + + if (!xfs_allocbt_cur_cache) + return -ENOMEM; + return 0; +} + +void +xfs_allocbt_destroy_cur_cache(void) +{ + kmem_cache_destroy(xfs_allocbt_cur_cache); + xfs_allocbt_cur_cache = NULL; +} diff --git a/libxfs/xfs_alloc_btree.h b/libxfs/xfs_alloc_btree.h index c715bee5..45df893e 100644 --- a/libxfs/xfs_alloc_btree.h +++ b/libxfs/xfs_alloc_btree.h @@ -62,4 +62,7 @@ void xfs_allocbt_commit_staged_btree(struct xfs_btree_cur *cur, unsigned int xfs_allocbt_maxlevels_ondisk(void); +int __init xfs_allocbt_init_cur_cache(void); +void xfs_allocbt_destroy_cur_cache(void); + #endif /* __XFS_ALLOC_BTREE_H__ */ diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c index 85faea1d..cde313d7 100644 --- a/libxfs/xfs_bmap_btree.c +++ b/libxfs/xfs_bmap_btree.c @@ -20,6 +20,8 @@ #include "xfs_trace.h" #include "xfs_rmap.h" +static kmem_zone_t *xfs_bmbt_cur_cache; + /* * Convert on-disk form of btree root to in-memory form. */ @@ -551,7 +553,7 @@ xfs_bmbt_init_cursor( ASSERT(whichfork != XFS_COW_FORK); cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_BMAP, - mp->m_bm_maxlevels[whichfork]); + mp->m_bm_maxlevels[whichfork], xfs_bmbt_cur_cache); cur->bc_nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1; cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_bmbt_2); @@ -673,3 +675,22 @@ xfs_bmbt_calc_size( { return xfs_btree_calc_size(mp->m_bmap_dmnr, len); } + +int __init +xfs_bmbt_init_cur_cache(void) +{ + xfs_bmbt_cur_cache = kmem_cache_create("xfs_bmbt_cur", + xfs_btree_cur_sizeof(xfs_bmbt_maxlevels_ondisk()), + 0, 0, NULL); + + if (!xfs_bmbt_cur_cache) + return -ENOMEM; + return 0; +} + +void +xfs_bmbt_destroy_cur_cache(void) +{ + kmem_cache_destroy(xfs_bmbt_cur_cache); + xfs_bmbt_cur_cache = NULL; +} diff --git a/libxfs/xfs_bmap_btree.h b/libxfs/xfs_bmap_btree.h index 2a1c9e60..3e7a40a8 100644 --- a/libxfs/xfs_bmap_btree.h +++ b/libxfs/xfs_bmap_btree.h @@ -112,4 +112,7 @@ extern unsigned long long xfs_bmbt_calc_size(struct xfs_mount *mp, unsigned int xfs_bmbt_maxlevels_ondisk(void); +int __init xfs_bmbt_init_cur_cache(void); +void xfs_bmbt_destroy_cur_cache(void); + #endif /* __XFS_BMAP_BTREE_H__ */ diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index e541b061..4fe2378e 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -19,11 +19,11 @@ #include "xfs_alloc.h" #include "xfs_btree_staging.h" #include "xfs_ag.h" - -/* - * Cursor allocation zone. - */ -kmem_zone_t *xfs_btree_cur_zone; +#include "xfs_alloc_btree.h" +#include "xfs_ialloc_btree.h" +#include "xfs_bmap_btree.h" +#include "xfs_rmap_btree.h" +#include "xfs_refcount_btree.h" /* * Btree magic numbers. @@ -376,7 +376,7 @@ xfs_btree_del_cursor( kmem_free(cur->bc_ops); if (!(cur->bc_flags & XFS_BTREE_LONG_PTRS) && cur->bc_ag.pag) xfs_perag_put(cur->bc_ag.pag); - kmem_cache_free(xfs_btree_cur_zone, cur); + kmem_cache_free(cur->bc_cache, cur); } /* @@ -4963,3 +4963,42 @@ xfs_btree_has_more_records( else return block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK); } + +/* Set up all the btree cursor caches. */ +int __init +xfs_btree_init_cur_caches(void) +{ + int error; + + error = xfs_allocbt_init_cur_cache(); + if (error) + return error; + error = xfs_inobt_init_cur_cache(); + if (error) + goto err; + error = xfs_bmbt_init_cur_cache(); + if (error) + goto err; + error = xfs_rmapbt_init_cur_cache(); + if (error) + goto err; + error = xfs_refcountbt_init_cur_cache(); + if (error) + goto err; + + return 0; +err: + xfs_btree_destroy_cur_caches(); + return error; +} + +/* Destroy all the btree cursor caches, if they've been allocated. */ +void +xfs_btree_destroy_cur_caches(void) +{ + xfs_allocbt_destroy_cur_cache(); + xfs_inobt_destroy_cur_cache(); + xfs_bmbt_destroy_cur_cache(); + xfs_rmapbt_destroy_cur_cache(); + xfs_refcountbt_destroy_cur_cache(); +} diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index fdf7090c..7bc5a379 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -13,8 +13,6 @@ struct xfs_trans; struct xfs_ifork; struct xfs_perag; -extern kmem_zone_t *xfs_btree_cur_zone; - /* * Generic key, ptr and record wrapper structures. * @@ -92,12 +90,6 @@ uint32_t xfs_btree_magic(int crc, xfs_btnum_t btnum); #define XFS_BTREE_STATS_ADD(cur, stat, val) \ XFS_STATS_ADD_OFF((cur)->bc_mp, (cur)->bc_statoff + __XBTS_ ## stat, val) -/* - * The btree cursor zone hands out cursors that can handle up to this many - * levels. This is the known maximum for all btree types. - */ -#define XFS_BTREE_CUR_CACHE_MAXLEVELS (9) - struct xfs_btree_ops { /* size of the key and record structures */ size_t key_len; @@ -238,6 +230,7 @@ struct xfs_btree_cur struct xfs_trans *bc_tp; /* transaction we're in, if any */ struct xfs_mount *bc_mp; /* file system mount struct */ const struct xfs_btree_ops *bc_ops; + kmem_zone_t *bc_cache; /* cursor cache */ unsigned int bc_flags; /* btree features - below */ xfs_btnum_t bc_btnum; /* identifies which btree type */ union xfs_btree_irec bc_rec; /* current insert/search record value */ @@ -592,19 +585,22 @@ xfs_btree_alloc_cursor( struct xfs_mount *mp, struct xfs_trans *tp, xfs_btnum_t btnum, - uint8_t maxlevels) + uint8_t maxlevels, + kmem_zone_t *cache) { struct xfs_btree_cur *cur; - ASSERT(maxlevels <= XFS_BTREE_CUR_CACHE_MAXLEVELS); - - cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); + cur = kmem_cache_zalloc(cache, GFP_NOFS | __GFP_NOFAIL); cur->bc_tp = tp; cur->bc_mp = mp; cur->bc_btnum = btnum; cur->bc_maxlevels = maxlevels; + cur->bc_cache = cache; return cur; } +int __init xfs_btree_init_cur_caches(void); +void xfs_btree_destroy_cur_caches(void); + #endif /* __XFS_BTREE_H__ */ diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c index 30b1abe9..539e7c03 100644 --- a/libxfs/xfs_ialloc_btree.c +++ b/libxfs/xfs_ialloc_btree.c @@ -21,6 +21,8 @@ #include "xfs_rmap.h" #include "xfs_ag.h" +static kmem_zone_t *xfs_inobt_cur_cache; + STATIC int xfs_inobt_get_minrecs( struct xfs_btree_cur *cur, @@ -432,7 +434,7 @@ xfs_inobt_init_common( struct xfs_btree_cur *cur; cur = xfs_btree_alloc_cursor(mp, tp, btnum, - M_IGEO(mp)->inobt_maxlevels); + M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache); if (btnum == XFS_BTNUM_INO) { cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_ibt_2); cur->bc_ops = &xfs_inobt_ops; @@ -811,3 +813,22 @@ xfs_iallocbt_calc_size( { return xfs_btree_calc_size(M_IGEO(mp)->inobt_mnr, len); } + +int __init +xfs_inobt_init_cur_cache(void) +{ + xfs_inobt_cur_cache = kmem_cache_create("xfs_inobt_cur", + xfs_btree_cur_sizeof(xfs_inobt_maxlevels_ondisk()), + 0, 0, NULL); + + if (!xfs_inobt_cur_cache) + return -ENOMEM; + return 0; +} + +void +xfs_inobt_destroy_cur_cache(void) +{ + kmem_cache_destroy(xfs_inobt_cur_cache); + xfs_inobt_cur_cache = NULL; +} diff --git a/libxfs/xfs_ialloc_btree.h b/libxfs/xfs_ialloc_btree.h index 6d3e4a33..26451cb7 100644 --- a/libxfs/xfs_ialloc_btree.h +++ b/libxfs/xfs_ialloc_btree.h @@ -77,4 +77,7 @@ void xfs_inobt_commit_staged_btree(struct xfs_btree_cur *cur, unsigned int xfs_iallocbt_maxlevels_ondisk(void); +int __init xfs_inobt_init_cur_cache(void); +void xfs_inobt_destroy_cur_cache(void); + #endif /* __XFS_IALLOC_BTREE_H__ */ diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c index 1d7b2d7c..2c02e33e 100644 --- a/libxfs/xfs_refcount_btree.c +++ b/libxfs/xfs_refcount_btree.c @@ -20,6 +20,8 @@ #include "xfs_rmap.h" #include "xfs_ag.h" +static kmem_zone_t *xfs_refcountbt_cur_cache; + static struct xfs_btree_cur * xfs_refcountbt_dup_cursor( struct xfs_btree_cur *cur) @@ -322,7 +324,7 @@ xfs_refcountbt_init_common( ASSERT(pag->pag_agno < mp->m_sb.sb_agcount); cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_REFC, - mp->m_refc_maxlevels); + mp->m_refc_maxlevels, xfs_refcountbt_cur_cache); cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_refcbt_2); cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; @@ -513,3 +515,22 @@ xfs_refcountbt_calc_reserves( return error; } + +int __init +xfs_refcountbt_init_cur_cache(void) +{ + xfs_refcountbt_cur_cache = kmem_cache_create("xfs_refcbt_cur", + xfs_btree_cur_sizeof(xfs_refcountbt_maxlevels_ondisk()), + 0, 0, NULL); + + if (!xfs_refcountbt_cur_cache) + return -ENOMEM; + return 0; +} + +void +xfs_refcountbt_destroy_cur_cache(void) +{ + kmem_cache_destroy(xfs_refcountbt_cur_cache); + xfs_refcountbt_cur_cache = NULL; +} diff --git a/libxfs/xfs_refcount_btree.h b/libxfs/xfs_refcount_btree.h index d7f7c89c..d66b3725 100644 --- a/libxfs/xfs_refcount_btree.h +++ b/libxfs/xfs_refcount_btree.h @@ -67,4 +67,7 @@ void xfs_refcountbt_commit_staged_btree(struct xfs_btree_cur *cur, unsigned int xfs_refcountbt_maxlevels_ondisk(void); +int __init xfs_refcountbt_init_cur_cache(void); +void xfs_refcountbt_destroy_cur_cache(void); + #endif /* __XFS_REFCOUNT_BTREE_H__ */ diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c index eb3ef409..ae3329b5 100644 --- a/libxfs/xfs_rmap_btree.c +++ b/libxfs/xfs_rmap_btree.c @@ -20,6 +20,8 @@ #include "xfs_ag.h" #include "xfs_ag_resv.h" +static kmem_zone_t *xfs_rmapbt_cur_cache; + /* * Reverse map btree. * @@ -451,7 +453,7 @@ xfs_rmapbt_init_common( /* Overlapping btree; 2 keys per pointer. */ cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_RMAP, - mp->m_rmap_maxlevels); + mp->m_rmap_maxlevels, xfs_rmapbt_cur_cache); cur->bc_flags = XFS_BTREE_CRC_BLOCKS | XFS_BTREE_OVERLAPPING; cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_rmap_2); cur->bc_ops = &xfs_rmapbt_ops; @@ -672,3 +674,22 @@ xfs_rmapbt_calc_reserves( return error; } + +int __init +xfs_rmapbt_init_cur_cache(void) +{ + xfs_rmapbt_cur_cache = kmem_cache_create("xfs_rmapbt_cur", + xfs_btree_cur_sizeof(xfs_rmapbt_maxlevels_ondisk()), + 0, 0, NULL); + + if (!xfs_rmapbt_cur_cache) + return -ENOMEM; + return 0; +} + +void +xfs_rmapbt_destroy_cur_cache(void) +{ + kmem_cache_destroy(xfs_rmapbt_cur_cache); + xfs_rmapbt_cur_cache = NULL; +} diff --git a/libxfs/xfs_rmap_btree.h b/libxfs/xfs_rmap_btree.h index e9778b62..3244715d 100644 --- a/libxfs/xfs_rmap_btree.h +++ b/libxfs/xfs_rmap_btree.h @@ -61,4 +61,7 @@ extern int xfs_rmapbt_calc_reserves(struct xfs_mount *mp, struct xfs_trans *tp, unsigned int xfs_rmapbt_maxlevels_ondisk(void); +int __init xfs_rmapbt_init_cur_cache(void); +void xfs_rmapbt_destroy_cur_cache(void); + #endif /* __XFS_RMAP_BTREE_H__ */ From patchwork Thu Jan 20 00:26:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717996 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 404A2C433F5 for ; Thu, 20 Jan 2022 00:26:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345413AbiATA0Q (ORCPT ); Wed, 19 Jan 2022 19:26:16 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:48470 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344774AbiATA0Q (ORCPT ); Wed, 19 Jan 2022 19:26:16 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5A6DCB81A7D for ; Thu, 20 Jan 2022 00:26:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 230E1C004E1; Thu, 20 Jan 2022 00:26:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638374; bh=Ijy9qu8+sYyaO5KQj/F5JhVes6gpzkoeUPGs5LkZw/U=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=XTq1Np8dEQJbL/zH4jEK+lH+8Mqm2uZc0iX/UQih1ZDPshccgRnqaSYduwwrIPS17 kOemM5RpQ0+5NVS+Rmbuh8sGWfbtGrZRFtGVxOF3kPDjOZYTRUifPJ3s+AZitDcNDA gkv5E53ShWG/UUM7va3gDDNWIgQMG3FsPlNRuJ9IQGpLMBh8WZu4rMOsNGd887DVdn eUuXZuS0I9HUHw02DBF+MoK73VcPSO80d9MH0jqXHAOq3cYALc6duikRxVrWhlfGO7 2WHrsOmr4XBd2sWJni/HzVpsDFkO/W3X3kJaTaI8Ce7aS8+r6QqKWAuoc6O88jGDRc OkDoW2MKpbcqg== Subject: [PATCH 33/48] xfs_db: support computing btheight for all cursor types From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:26:13 -0800 Message-ID: <164263837382.865554.13379551225158713817.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Add the special magic btree type value 'all' to the btheight command so that we can display information about all known btree types at once. Signed-off-by: Darrick J. Wong --- db/btheight.c | 26 +++++++++++++++++++++++--- man/man8/xfs_db.8 | 3 +++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/db/btheight.c b/db/btheight.c index 8aa17c89..e4cd4eda 100644 --- a/db/btheight.c +++ b/db/btheight.c @@ -57,7 +57,7 @@ btheight_help(void) " -w min -- Show only the worst case scenario.\n" "\n" " Supported btree types:\n" -" " +" all " )); for (i = 0, m = maps; i < ARRAY_SIZE(maps); i++, m++) printf("%s ", m->tag); @@ -107,7 +107,7 @@ calc_height( static int construct_records_per_block( - char *tag, + const char *tag, int blocksize, unsigned int *records_per_block) { @@ -235,7 +235,7 @@ _("%s: pointer size must be less than selected block size (%u bytes).\n"), static void report( - char *tag, + const char *tag, unsigned int report_what, unsigned long long nr_records, unsigned int blocksize) @@ -297,6 +297,19 @@ _("%s: worst case per %u-byte block: %u records (leaf) / %u keyptrs (node)\n"), } } +static void +report_all( + unsigned int report_what, + unsigned long long nr_records, + unsigned int blocksize) +{ + struct btmap *m; + int i; + + for (i = 0, m = maps; i < ARRAY_SIZE(maps); i++, m++) + report(m->tag, report_what, nr_records, blocksize); +} + static int btheight_f( int argc, @@ -366,6 +379,13 @@ _("The smallest block size this command will consider is 128 bytes.\n")); return 0; } + for (i = optind; i < argc; i++) { + if (!strcmp(argv[i], "all")) { + report_all(report_what, nr_records, blocksize); + return 0; + } + } + for (i = optind; i < argc; i++) report(argv[i], report_what, nr_records, blocksize); diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index 58727495..55ac3487 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -420,6 +420,9 @@ The supported btree types are: .IR refcountbt , and .IR rmapbt . +The magic value +.I all +can be used to walk through all btree types. Options are as follows: .RS 1.0i From patchwork Thu Jan 20 00:26:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717997 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37696C433F5 for ; Thu, 20 Jan 2022 00:26:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345458AbiATA0W (ORCPT ); Wed, 19 Jan 2022 19:26:22 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:48492 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344774AbiATA0W (ORCPT ); Wed, 19 Jan 2022 19:26:22 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 035A1B81AD5 for ; Thu, 20 Jan 2022 00:26:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BF3EC004E1; Thu, 20 Jan 2022 00:26:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638379; bh=WKg+OJ6VaxC8dya7SXRJuCmKutAMqKBcL0n1Dc3zb3I=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=P8SZcUFJwfdD4MpCzmQRGkXY7cinTOH4k6Cw1AKmXSoUhO0tZla2fZYA7NCAk4C8+ r+d/eeYQEc4+OGM3RylrcoYXq1/9vHHG/O7d3UYr0Qa54U8CkDhhcCyUZSB7/uS3aO 5VuzscbCAaD5m50LKumGhh1dSvMQFVoXixZJA/nFi8I0SR6mIUqnvQiCayX6C6lEy8 4BGy1FdNzRU9+qbNGDyqbrG7Hike5/XPCMs/GVhGCFB6kaxv6VP2nCchiq28K3VTc0 b64zR1vf6ZT6DYMvvFmWE07Y2hWPr/XXkjNpx5yaWaR7a3NezaXoXABT0HcCSKQoth IyurSal7khdyA== Subject: [PATCH 34/48] xfs_db: report absolute maxlevels for each btree type From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:26:19 -0800 Message-ID: <164263837932.865554.2100881563371751286.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Augment the xfs_db btheight command so that the debugger can display the absolute maximum btree height for each btree type. Signed-off-by: Darrick J. Wong --- db/btheight.c | 73 ++++++++++++++++++++++++++++++++++++++++------ libxfs/libxfs_api_defs.h | 5 +++ man/man8/xfs_db.8 | 5 +++ 3 files changed, 72 insertions(+), 11 deletions(-) diff --git a/db/btheight.c b/db/btheight.c index e4cd4eda..0b421ab5 100644 --- a/db/btheight.c +++ b/db/btheight.c @@ -24,16 +24,45 @@ static int rmap_maxrecs(struct xfs_mount *mp, int blocklen, int leaf) struct btmap { const char *tag; + unsigned int (*maxlevels)(void); int (*maxrecs)(struct xfs_mount *mp, int blocklen, int leaf); } maps[] = { - {"bnobt", libxfs_allocbt_maxrecs}, - {"cntbt", libxfs_allocbt_maxrecs}, - {"inobt", libxfs_inobt_maxrecs}, - {"finobt", libxfs_inobt_maxrecs}, - {"bmapbt", libxfs_bmbt_maxrecs}, - {"refcountbt", refc_maxrecs}, - {"rmapbt", rmap_maxrecs}, + { + .tag = "bnobt", + .maxlevels = libxfs_allocbt_maxlevels_ondisk, + .maxrecs = libxfs_allocbt_maxrecs, + }, + { + .tag = "cntbt", + .maxlevels = libxfs_allocbt_maxlevels_ondisk, + .maxrecs = libxfs_allocbt_maxrecs, + }, + { + .tag = "inobt", + .maxlevels = libxfs_iallocbt_maxlevels_ondisk, + .maxrecs = libxfs_inobt_maxrecs, + }, + { + .tag = "finobt", + .maxlevels = libxfs_iallocbt_maxlevels_ondisk, + .maxrecs = libxfs_inobt_maxrecs, + }, + { + .tag = "bmapbt", + .maxlevels = libxfs_bmbt_maxlevels_ondisk, + .maxrecs = libxfs_bmbt_maxrecs, + }, + { + .tag = "refcountbt", + .maxlevels = libxfs_refcountbt_maxlevels_ondisk, + .maxrecs = refc_maxrecs, + }, + { + .tag = "rmapbt", + .maxlevels = libxfs_rmapbt_maxlevels_ondisk, + .maxrecs = rmap_maxrecs, + }, }; static void @@ -55,6 +84,7 @@ btheight_help(void) " -n -- Number of records we want to store.\n" " -w max -- Show only the best case scenario.\n" " -w min -- Show only the worst case scenario.\n" +" -w absmax -- Print the maximum possible btree height for all filesystems.\n" "\n" " Supported btree types:\n" " all " @@ -232,6 +262,22 @@ _("%s: pointer size must be less than selected block size (%u bytes).\n"), #define REPORT_DEFAULT (-1U) #define REPORT_MAX (1 << 0) #define REPORT_MIN (1 << 1) +#define REPORT_ABSMAX (1 << 2) + +static void +report_absmax(const char *tag) +{ + struct btmap *m; + int i; + + for (i = 0, m = maps; i < ARRAY_SIZE(maps); i++, m++) { + if (!strcmp(m->tag, tag)) { + printf("%s: %u\n", tag, m->maxlevels()); + return; + } + } + printf(_("%s: Don't know how to report max height.\n"), tag); +} static void report( @@ -243,6 +289,11 @@ report( unsigned int records_per_block[2]; int ret; + if (report_what == REPORT_ABSMAX) { + report_absmax(tag); + return; + } + ret = construct_records_per_block(tag, blocksize, records_per_block); if (ret) return; @@ -344,6 +395,8 @@ btheight_f( report_what = REPORT_MIN; else if (!strcmp(optarg, "max")) report_what = REPORT_MAX; + else if (!strcmp(optarg, "absmax")) + report_what = REPORT_ABSMAX; else { btheight_help(); return 0; @@ -355,20 +408,20 @@ btheight_f( } } - if (nr_records == 0) { + if (report_what != REPORT_ABSMAX && nr_records == 0) { fprintf(stderr, _("Number of records must be greater than zero.\n")); return 0; } - if (blocksize > INT_MAX) { + if (report_what != REPORT_ABSMAX && blocksize > INT_MAX) { fprintf(stderr, _("The largest block size this command will consider is %u bytes.\n"), INT_MAX); return 0; } - if (blocksize < 128) { + if (report_what != REPORT_ABSMAX && blocksize < 128) { fprintf(stderr, _("The smallest block size this command will consider is 128 bytes.\n")); return 0; diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 0862d4b0..8abbd231 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -23,6 +23,7 @@ #define xfs_ag_block_count libxfs_ag_block_count #define xfs_alloc_ag_max_usable libxfs_alloc_ag_max_usable +#define xfs_allocbt_maxlevels_ondisk libxfs_allocbt_maxlevels_ondisk #define xfs_allocbt_maxrecs libxfs_allocbt_maxrecs #define xfs_allocbt_stage_cursor libxfs_allocbt_stage_cursor #define xfs_alloc_fix_freelist libxfs_alloc_fix_freelist @@ -39,6 +40,7 @@ #define xfs_bmapi_read libxfs_bmapi_read #define xfs_bmapi_write libxfs_bmapi_write #define xfs_bmap_last_offset libxfs_bmap_last_offset +#define xfs_bmbt_maxlevels_ondisk libxfs_bmbt_maxlevels_ondisk #define xfs_bmbt_maxrecs libxfs_bmbt_maxrecs #define xfs_bmdr_maxrecs libxfs_bmdr_maxrecs @@ -109,6 +111,7 @@ #define xfs_highbit32 libxfs_highbit32 #define xfs_highbit64 libxfs_highbit64 #define xfs_ialloc_calc_rootino libxfs_ialloc_calc_rootino +#define xfs_iallocbt_maxlevels_ondisk libxfs_iallocbt_maxlevels_ondisk #define xfs_idata_realloc libxfs_idata_realloc #define xfs_idestroy_fork libxfs_idestroy_fork #define xfs_iext_lookup_extent libxfs_iext_lookup_extent @@ -138,6 +141,7 @@ #define xfs_refc_block libxfs_refc_block #define xfs_refcountbt_calc_reserves libxfs_refcountbt_calc_reserves #define xfs_refcountbt_init_cursor libxfs_refcountbt_init_cursor +#define xfs_refcountbt_maxlevels_ondisk libxfs_refcountbt_maxlevels_ondisk #define xfs_refcountbt_maxrecs libxfs_refcountbt_maxrecs #define xfs_refcountbt_stage_cursor libxfs_refcountbt_stage_cursor #define xfs_refcount_get_rec libxfs_refcount_get_rec @@ -146,6 +150,7 @@ #define xfs_rmap_alloc libxfs_rmap_alloc #define xfs_rmapbt_calc_reserves libxfs_rmapbt_calc_reserves #define xfs_rmapbt_init_cursor libxfs_rmapbt_init_cursor +#define xfs_rmapbt_maxlevels_ondisk libxfs_rmapbt_maxlevels_ondisk #define xfs_rmapbt_maxrecs libxfs_rmapbt_maxrecs #define xfs_rmapbt_stage_cursor libxfs_rmapbt_stage_cursor #define xfs_rmap_compare libxfs_rmap_compare diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index 55ac3487..1a2bb7e9 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -402,7 +402,7 @@ If the cursor points at an inode, dump the extended attribute block mapping btre Dump all keys and pointers in intermediate btree nodes, and all records in leaf btree nodes. .RE .TP -.BI "btheight [\-b " blksz "] [\-n " recs "] [\-w " max "|\-w " min "] btree types..." +.BI "btheight [\-b " blksz "] [\-n " recs "] [\-w " max "|" min "|" absmax "] btree types..." For a given number of btree records and a btree type, report the number of records and blocks for each level of the btree, and the total number of blocks. The btree type must be given after the options. @@ -435,6 +435,9 @@ The default is the filesystem block size. is used to specify the number of records to store. This argument is required. .TP +.B \-w absmax +shows the maximum possible height for the given btree types. +.TP .B \-w max shows only the best case scenario, which is when the btree blocks are maximally loaded. From patchwork Thu Jan 20 00:26:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717998 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35601C433F5 for ; Thu, 20 Jan 2022 00:26:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344774AbiATA00 (ORCPT ); Wed, 19 Jan 2022 19:26:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbiATA00 (ORCPT ); Wed, 19 Jan 2022 19:26:26 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3578EC061574 for ; Wed, 19 Jan 2022 16:26:26 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C6B2261511 for ; Thu, 20 Jan 2022 00:26:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 274D8C004E1; Thu, 20 Jan 2022 00:26:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638385; bh=fY9WkZ6L+oIaIsdiwbHYtPXBKc+S93y2WmghOWclxvY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=i9Wd9VeazAuzpLAuHzcwv2DbrM4/TlLAz1EzWcN8G0wnZWyULLUvV7wiXR4COLvT5 BNSbF2UriK9jLgQpflB3Fd8l6c1ueqqCaBuEPPwGrxPoVLKM7/xHKpJtf+kqTLzZiJ 7TZIVTGXTkzhfB18g+o3nTIWsTB8zepTzTnEN8iRZLPWVwnzCtQXiu6rhBpYXfiMGM mu7ed3l54qaq6etZHOEclsJDkas3cJ4drmAxwq+H38FTjWNGLUO/1WKTOABtgW5GgO P7kiz9/bE/fF2Qs5PqlQIJRNckanclCGkcPeJadmGbbseJFhNNiJTWwKW9ZH4fHKSI Ozo2G3/ZpFYdw== Subject: [PATCH 35/48] libxfs: remove kmem_zone_destroy From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:26:24 -0800 Message-ID: <164263838482.865554.14373297919353166186.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Convert all kmem cache users to call kmem_cache_destroy, and make leak checking an explicit operation. This gets us closer to the kernel interface. Signed-off-by: Darrick J. Wong --- include/kmem.h | 14 +++++--------- libxfs/init.c | 32 ++++++++++++++------------------ libxfs/kmem.c | 21 +++++++++++++++------ 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/include/kmem.h b/include/kmem.h index c710635d..53a2b37a 100644 --- a/include/kmem.h +++ b/include/kmem.h @@ -6,6 +6,9 @@ #ifndef __KMEM_H__ #define __KMEM_H__ +void kmem_start_leak_check(void); +bool kmem_found_leaks(void); + #define KM_NOFS 0x0004u #define KM_MAYFAIL 0x0008u #define KM_LARGE 0x0010u @@ -38,17 +41,10 @@ kmem_zone_init(unsigned int size, const char *name) return kmem_cache_create(name, size, 0, 0, NULL); } +void kmem_cache_destroy(kmem_zone_t *); + extern void *kmem_cache_alloc(kmem_zone_t *, gfp_t); extern void *kmem_cache_zalloc(kmem_zone_t *, gfp_t); -extern int kmem_zone_destroy(kmem_zone_t *); - - -static inline void -kmem_cache_destroy(kmem_zone_t *zone) -{ - kmem_zone_destroy(zone); -} - static inline void kmem_cache_free(kmem_zone_t *zone, void *ptr) diff --git a/libxfs/init.c b/libxfs/init.c index 3c1639db..0d693848 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -255,22 +255,18 @@ init_zones(void) sizeof(struct xfs_trans), "xfs_trans"); } -static int -destroy_zones(void) +static void +destroy_kmem_caches(void) { - int leaked = 0; - - leaked += kmem_zone_destroy(xfs_buf_zone); - leaked += kmem_zone_destroy(xfs_ili_zone); - leaked += kmem_zone_destroy(xfs_inode_zone); - leaked += kmem_zone_destroy(xfs_ifork_zone); - leaked += kmem_zone_destroy(xfs_buf_item_zone); - leaked += kmem_zone_destroy(xfs_da_state_zone); + kmem_cache_destroy(xfs_buf_zone); + kmem_cache_destroy(xfs_ili_zone); + kmem_cache_destroy(xfs_inode_zone); + kmem_cache_destroy(xfs_ifork_zone); + kmem_cache_destroy(xfs_buf_item_zone); + kmem_cache_destroy(xfs_da_state_zone); xfs_btree_destroy_cur_caches(); - leaked += kmem_zone_destroy(xfs_bmap_free_item_zone); - leaked += kmem_zone_destroy(xfs_trans_zone); - - return leaked; + kmem_cache_destroy(xfs_bmap_free_item_zone); + kmem_cache_destroy(xfs_trans_zone); } static void @@ -1025,17 +1021,17 @@ void libxfs_destroy( struct libxfs_xinit *li) { - int leaked; - + kmem_start_leak_check(); libxfs_close_devices(li); /* Free everything from the buffer cache before freeing buffer zone */ libxfs_bcache_purge(); libxfs_bcache_free(); cache_destroy(libxfs_bcache); - leaked = destroy_zones(); + destroy_kmem_caches(); rcu_unregister_thread(); - if (getenv("LIBXFS_LEAK_CHECK") && leaked) + + if (kmem_found_leaks()) exit(1); } diff --git a/libxfs/kmem.c b/libxfs/kmem.c index 221b3480..804d4b3c 100644 --- a/libxfs/kmem.c +++ b/libxfs/kmem.c @@ -3,6 +3,18 @@ #include "libxfs_priv.h" +static bool leaked; + +void kmem_start_leak_check(void) +{ + leaked = false; +} + +bool kmem_found_leaks(void) +{ + return leaked; +} + /* * Simple memory interface */ @@ -27,18 +39,15 @@ kmem_cache_create(const char *name, unsigned int size, unsigned int align, return ptr; } -int -kmem_zone_destroy(kmem_zone_t *zone) +void +kmem_cache_destroy(kmem_zone_t *zone) { - int leaked = 0; - if (getenv("LIBXFS_LEAK_CHECK") && zone->allocated) { - leaked = 1; + leaked = true; fprintf(stderr, "zone %s freed with %d items allocated\n", zone->zone_name, zone->allocated); } free(zone); - return leaked; } void * From patchwork Thu Jan 20 00:26:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12717999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BED21C433EF for ; Thu, 20 Jan 2022 00:26:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345472AbiATA0c (ORCPT ); Wed, 19 Jan 2022 19:26:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbiATA0b (ORCPT ); Wed, 19 Jan 2022 19:26:31 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B75A4C061574 for ; Wed, 19 Jan 2022 16:26:31 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 541FB6150C for ; Thu, 20 Jan 2022 00:26:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A76E3C004E1; Thu, 20 Jan 2022 00:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638390; bh=mQcLPvAhosN3AyQdUhe6J7tSnWO7rd7AvTMlyQvfEb0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=LLmnZjX/IS21ta46PoGQwS4FnQXvL4nwd6gKZmWkWarwMoe3Ip6onDQR8k5vUT00G CCiTwUqD3iiOz+umbzxcPW536mIkHA+myLtqBiQp/sxH1tXaOKgpRJfeHOS2g7P+e2 gYeHtSQN/dANMe+QjBVXGZPSAscM3muBZzN4C4ZdET6lO9rtTOT9OD0OCwD0YrK8D3 vgPSJinzWffZCnslabp++xI1XdUE+fXUb6VhEi4T30oTefdFwtz1FYHLALxxO3BFVi UglRWsrKzVp+f03DeKZDcyuk+QZWljXNf718HzACl75P/ExjaesMM5Apx5EC7JwWxZ 7tXuXUerqGaPg== Subject: [PATCH 36/48] libxfs: remove kmem_zone_init From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:26:30 -0800 Message-ID: <164263839036.865554.118213994124696686.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Port all callers to kmem_cache_create, to sync with kernel API. Signed-off-by: Darrick J. Wong --- include/kmem.h | 7 ------- libxfs/init.c | 32 ++++++++++++++++++-------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/include/kmem.h b/include/kmem.h index 53a2b37a..36acd20d 100644 --- a/include/kmem.h +++ b/include/kmem.h @@ -34,13 +34,6 @@ typedef unsigned int __bitwise gfp_t; kmem_zone_t * kmem_cache_create(const char *name, unsigned int size, unsigned int align, unsigned int slab_flags, void (*ctor)(void *)); - -static inline kmem_zone_t * -kmem_zone_init(unsigned int size, const char *name) -{ - return kmem_cache_create(name, size, 0, 0, NULL); -} - void kmem_cache_destroy(kmem_zone_t *); extern void *kmem_cache_alloc(kmem_zone_t *, gfp_t); diff --git a/libxfs/init.c b/libxfs/init.c index 0d693848..155b12fa 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -234,25 +234,29 @@ init_zones(void) int error; /* initialise zone allocation */ - xfs_buf_zone = kmem_zone_init(sizeof(struct xfs_buf), "xfs_buffer"); - xfs_inode_zone = kmem_zone_init(sizeof(struct xfs_inode), "xfs_inode"); - xfs_ifork_zone = kmem_zone_init(sizeof(struct xfs_ifork), "xfs_ifork"); - xfs_ili_zone = kmem_zone_init( - sizeof(struct xfs_inode_log_item),"xfs_inode_log_item"); - xfs_buf_item_zone = kmem_zone_init( - sizeof(struct xfs_buf_log_item), "xfs_buf_log_item"); - xfs_da_state_zone = kmem_zone_init( - sizeof(struct xfs_da_state), "xfs_da_state"); + xfs_buf_zone = kmem_cache_create("xfs_buffer", + sizeof(struct xfs_buf), 0, 0, NULL); + xfs_inode_zone = kmem_cache_create("xfs_inode", + sizeof(struct xfs_inode), 0, 0, NULL); + xfs_ifork_zone = kmem_cache_create("xfs_ifork", + sizeof(struct xfs_ifork), 0, 0, NULL); + xfs_ili_zone = kmem_cache_create("xfs_inode_log_item", + sizeof(struct xfs_inode_log_item), 0, 0, NULL); + xfs_buf_item_zone = kmem_cache_create("xfs_buf_log_item", + sizeof(struct xfs_buf_log_item), 0, 0, NULL); + xfs_da_state_zone = kmem_cache_create("xfs_da_state", + sizeof(struct xfs_da_state), 0, 0, NULL); + error = xfs_btree_init_cur_caches(); if (error) { fprintf(stderr, "Could not allocate btree cursor caches.\n"); abort(); } - xfs_bmap_free_item_zone = kmem_zone_init( - sizeof(struct xfs_extent_free_item), - "xfs_bmap_free_item"); - xfs_trans_zone = kmem_zone_init( - sizeof(struct xfs_trans), "xfs_trans"); + + xfs_bmap_free_item_zone = kmem_cache_create("xfs_bmap_free_item", + sizeof(struct xfs_extent_free_item), 0, 0, NULL); + xfs_trans_zone = kmem_cache_create("xfs_trans", + sizeof(struct xfs_trans), 0, 0, NULL); } static void From patchwork Thu Jan 20 00:26:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12718000 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA333C433F5 for ; Thu, 20 Jan 2022 00:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345036AbiATA0h (ORCPT ); Wed, 19 Jan 2022 19:26:37 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:33702 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbiATA0h (ORCPT ); Wed, 19 Jan 2022 19:26:37 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C74F361511 for ; Thu, 20 Jan 2022 00:26:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 311D4C004E1; Thu, 20 Jan 2022 00:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638396; bh=/T0n0tF0XDg5UTpWkbW/sNTm3NNBNpRjZ9wBZUR8RO0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=TmTRVV6V98qkKeGSw/gP3l9slIOJDQehPmEAtzf9jmt5+DhjawT7ElrO6QtobQMii WTvT5CIXAMnzTNyIRd60/5Cc2/ORZwaNvP+fooLqBclxqLvFxy/IZUx14lKcAEeFa2 T0fonug3bpDg++yXxgcuDkPO5CMEFbXtzPIufbJ+cYZcvlsdzuZuNBl4juV8bDkc0Y Vp2fljSDcx/QIAiw+2Ww+zs+cdX6KkdBB3XdANjgQBgKrzRMtqVxd6A5XtToW0lKyE C7Hh5SbpHkUA3beOqnL8u1Nx/iTlBBA4GC9Koyre3C7MBmtD5Ynuugmc2vPP/Oe2JC sgMWGm2BLaUvQ== Subject: [PATCH 37/48] xfs: remove kmem_zone typedef From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:26:35 -0800 Message-ID: <164263839587.865554.17835087857585889463.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: e7720afad068a6729d9cd3aaa08212f2f5a7ceff Remove these typedefs by referencing kmem_cache directly. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Signed-off-by: Darrick J. Wong --- include/kmem.h | 14 +++++++------- libxfs/kmem.c | 12 ++++++------ libxfs/libxfs_priv.h | 10 +++++----- libxfs/logitem.c | 4 ++-- libxfs/rdwr.c | 6 +++--- libxfs/trans.c | 4 ++-- libxfs/xfs_alloc.c | 2 +- libxfs/xfs_alloc_btree.c | 2 +- libxfs/xfs_bmap.c | 2 +- libxfs/xfs_bmap.h | 2 +- libxfs/xfs_bmap_btree.c | 2 +- libxfs/xfs_btree.h | 4 ++-- libxfs/xfs_da_btree.c | 2 +- libxfs/xfs_da_btree.h | 2 +- libxfs/xfs_ialloc_btree.c | 2 +- libxfs/xfs_inode_fork.c | 2 +- libxfs/xfs_inode_fork.h | 2 +- libxfs/xfs_refcount_btree.c | 2 +- libxfs/xfs_rmap_btree.c | 2 +- 19 files changed, 39 insertions(+), 39 deletions(-) diff --git a/include/kmem.h b/include/kmem.h index 36acd20d..7aba4914 100644 --- a/include/kmem.h +++ b/include/kmem.h @@ -14,13 +14,13 @@ bool kmem_found_leaks(void); #define KM_LARGE 0x0010u #define KM_NOLOCKDEP 0x0020u -typedef struct kmem_zone { +struct kmem_cache { int zone_unitsize; /* Size in bytes of zone unit */ int allocated; /* debug: How many allocated? */ unsigned int align; const char *zone_name; /* tag name */ void (*ctor)(void *); -} kmem_zone_t; +}; typedef unsigned int __bitwise gfp_t; @@ -31,16 +31,16 @@ typedef unsigned int __bitwise gfp_t; #define __GFP_ZERO (__force gfp_t)1 -kmem_zone_t * kmem_cache_create(const char *name, unsigned int size, +struct kmem_cache * kmem_cache_create(const char *name, unsigned int size, unsigned int align, unsigned int slab_flags, void (*ctor)(void *)); -void kmem_cache_destroy(kmem_zone_t *); +void kmem_cache_destroy(struct kmem_cache *); -extern void *kmem_cache_alloc(kmem_zone_t *, gfp_t); -extern void *kmem_cache_zalloc(kmem_zone_t *, gfp_t); +extern void *kmem_cache_alloc(struct kmem_cache *, gfp_t); +extern void *kmem_cache_zalloc(struct kmem_cache *, gfp_t); static inline void -kmem_cache_free(kmem_zone_t *zone, void *ptr) +kmem_cache_free(struct kmem_cache *zone, void *ptr) { zone->allocated--; free(ptr); diff --git a/libxfs/kmem.c b/libxfs/kmem.c index 804d4b3c..a176a9d8 100644 --- a/libxfs/kmem.c +++ b/libxfs/kmem.c @@ -18,15 +18,15 @@ bool kmem_found_leaks(void) /* * Simple memory interface */ -kmem_zone_t * +struct kmem_cache * kmem_cache_create(const char *name, unsigned int size, unsigned int align, unsigned int slab_flags, void (*ctor)(void *)) { - kmem_zone_t *ptr = malloc(sizeof(kmem_zone_t)); + struct kmem_cache *ptr = malloc(sizeof(struct kmem_cache)); if (ptr == NULL) { fprintf(stderr, _("%s: zone init failed (%s, %d bytes): %s\n"), - progname, name, (int)sizeof(kmem_zone_t), + progname, name, (int)sizeof(struct kmem_cache), strerror(errno)); exit(1); } @@ -40,7 +40,7 @@ kmem_cache_create(const char *name, unsigned int size, unsigned int align, } void -kmem_cache_destroy(kmem_zone_t *zone) +kmem_cache_destroy(struct kmem_cache *zone) { if (getenv("LIBXFS_LEAK_CHECK") && zone->allocated) { leaked = true; @@ -51,7 +51,7 @@ kmem_cache_destroy(kmem_zone_t *zone) } void * -kmem_cache_alloc(kmem_zone_t *zone, gfp_t flags) +kmem_cache_alloc(struct kmem_cache *zone, gfp_t flags) { void *ptr = NULL; @@ -79,7 +79,7 @@ kmem_cache_alloc(kmem_zone_t *zone, gfp_t flags) } void * -kmem_cache_zalloc(kmem_zone_t *zone, gfp_t flags) +kmem_cache_zalloc(struct kmem_cache *zone, gfp_t flags) { void *ptr = kmem_cache_alloc(zone, flags); diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 466865f7..5b04db84 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -59,11 +59,11 @@ #include /* Zones used in libxfs allocations that aren't in shared header files */ -extern kmem_zone_t *xfs_buf_item_zone; -extern kmem_zone_t *xfs_ili_zone; -extern kmem_zone_t *xfs_buf_zone; -extern kmem_zone_t *xfs_inode_zone; -extern kmem_zone_t *xfs_trans_zone; +extern struct kmem_cache *xfs_buf_item_zone; +extern struct kmem_cache *xfs_ili_zone; +extern struct kmem_cache *xfs_buf_zone; +extern struct kmem_cache *xfs_inode_zone; +extern struct kmem_cache *xfs_trans_zone; /* fake up iomap, (not) used in xfs_bmap.[ch] */ #define IOMAP_F_SHARED 0x04 diff --git a/libxfs/logitem.c b/libxfs/logitem.c index e6debb6d..dde90502 100644 --- a/libxfs/logitem.c +++ b/libxfs/logitem.c @@ -16,8 +16,8 @@ #include "xfs_inode.h" #include "xfs_trans.h" -kmem_zone_t *xfs_buf_item_zone; -kmem_zone_t *xfs_ili_zone; /* inode log item zone */ +struct kmem_cache *xfs_buf_item_zone; +struct kmem_cache *xfs_ili_zone; /* inode log item zone */ /* * Following functions from fs/xfs/xfs_trans_buf.c diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c index b43527e4..315e6d1f 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -161,7 +161,7 @@ libxfs_getsb( return bp; } -kmem_zone_t *xfs_buf_zone; +struct kmem_cache *xfs_buf_zone; static struct cache_mru xfs_buf_freelist = {{&xfs_buf_freelist.cm_list, &xfs_buf_freelist.cm_list}, @@ -1053,8 +1053,8 @@ xfs_verify_magic16( * Inode cache stubs. */ -kmem_zone_t *xfs_inode_zone; -extern kmem_zone_t *xfs_ili_zone; +struct kmem_cache *xfs_inode_zone; +extern struct kmem_cache *xfs_ili_zone; int libxfs_iget( diff --git a/libxfs/trans.c b/libxfs/trans.c index 8c16cb8d..f87a65c5 100644 --- a/libxfs/trans.c +++ b/libxfs/trans.c @@ -30,7 +30,7 @@ static int __xfs_trans_commit(struct xfs_trans *tp, bool regrant); * Simple transaction interface */ -kmem_zone_t *xfs_trans_zone; +struct kmem_cache *xfs_trans_zone; /* * Initialize the precomputed transaction reservation values @@ -868,7 +868,7 @@ buf_item_done( { struct xfs_buf *bp; int hold; - extern kmem_zone_t *xfs_buf_item_zone; + extern struct kmem_cache *xfs_buf_item_zone; bp = bip->bli_buf; ASSERT(bp != NULL); diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 7d304160..c99497fd 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -23,7 +23,7 @@ #include "xfs_ag_resv.h" #include "xfs_bmap.h" -extern kmem_zone_t *xfs_bmap_free_item_zone; +extern struct kmem_cache *xfs_bmap_free_item_zone; struct workqueue_struct *xfs_alloc_wq; diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c index 2176a923..2ba6d44a 100644 --- a/libxfs/xfs_alloc_btree.c +++ b/libxfs/xfs_alloc_btree.c @@ -18,7 +18,7 @@ #include "xfs_trans.h" #include "xfs_ag.h" -static kmem_zone_t *xfs_allocbt_cur_cache; +static struct kmem_cache *xfs_allocbt_cur_cache; STATIC struct xfs_btree_cur * xfs_allocbt_dup_cursor( diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index bc8a2033..ecf79e24 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -31,7 +31,7 @@ #include "xfs_refcount.h" -kmem_zone_t *xfs_bmap_free_item_zone; +struct kmem_cache *xfs_bmap_free_item_zone; /* * Miscellaneous helper functions diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index 67641f66..171a72ee 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -13,7 +13,7 @@ struct xfs_inode; struct xfs_mount; struct xfs_trans; -extern kmem_zone_t *xfs_bmap_free_item_zone; +extern struct kmem_cache *xfs_bmap_free_item_zone; /* * Argument structure for xfs_bmap_alloc. diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c index cde313d7..8e850751 100644 --- a/libxfs/xfs_bmap_btree.c +++ b/libxfs/xfs_bmap_btree.c @@ -20,7 +20,7 @@ #include "xfs_trace.h" #include "xfs_rmap.h" -static kmem_zone_t *xfs_bmbt_cur_cache; +static struct kmem_cache *xfs_bmbt_cur_cache; /* * Convert on-disk form of btree root to in-memory form. diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index 7bc5a379..22d9f411 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -230,7 +230,7 @@ struct xfs_btree_cur struct xfs_trans *bc_tp; /* transaction we're in, if any */ struct xfs_mount *bc_mp; /* file system mount struct */ const struct xfs_btree_ops *bc_ops; - kmem_zone_t *bc_cache; /* cursor cache */ + struct kmem_cache *bc_cache; /* cursor cache */ unsigned int bc_flags; /* btree features - below */ xfs_btnum_t bc_btnum; /* identifies which btree type */ union xfs_btree_irec bc_rec; /* current insert/search record value */ @@ -586,7 +586,7 @@ xfs_btree_alloc_cursor( struct xfs_trans *tp, xfs_btnum_t btnum, uint8_t maxlevels, - kmem_zone_t *cache) + struct kmem_cache *cache) { struct xfs_btree_cur *cur; diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c index 0e504d2d..f1ae5d4d 100644 --- a/libxfs/xfs_da_btree.c +++ b/libxfs/xfs_da_btree.c @@ -69,7 +69,7 @@ STATIC int xfs_da3_blk_unlink(xfs_da_state_t *state, xfs_da_state_blk_t *save_blk); -kmem_zone_t *xfs_da_state_zone; /* anchor for state struct zone */ +struct kmem_cache *xfs_da_state_zone; /* anchor for state struct zone */ /* * Allocate a dir-state structure. diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h index ad5dd324..da845e32 100644 --- a/libxfs/xfs_da_btree.h +++ b/libxfs/xfs_da_btree.h @@ -227,6 +227,6 @@ void xfs_da3_node_hdr_from_disk(struct xfs_mount *mp, void xfs_da3_node_hdr_to_disk(struct xfs_mount *mp, struct xfs_da_intnode *to, struct xfs_da3_icnode_hdr *from); -extern struct kmem_zone *xfs_da_state_zone; +extern struct kmem_cache *xfs_da_state_zone; #endif /* __XFS_DA_BTREE_H__ */ diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c index 539e7c03..1dbb5360 100644 --- a/libxfs/xfs_ialloc_btree.c +++ b/libxfs/xfs_ialloc_btree.c @@ -21,7 +21,7 @@ #include "xfs_rmap.h" #include "xfs_ag.h" -static kmem_zone_t *xfs_inobt_cur_cache; +static struct kmem_cache *xfs_inobt_cur_cache; STATIC int xfs_inobt_get_minrecs( diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index bd581fe8..c80b4066 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -24,7 +24,7 @@ #include "xfs_types.h" #include "xfs_errortag.h" -kmem_zone_t *xfs_ifork_zone; +struct kmem_cache *xfs_ifork_zone; void xfs_init_local_fork( diff --git a/libxfs/xfs_inode_fork.h b/libxfs/xfs_inode_fork.h index a6f7897b..cb296bd5 100644 --- a/libxfs/xfs_inode_fork.h +++ b/libxfs/xfs_inode_fork.h @@ -221,7 +221,7 @@ static inline bool xfs_iext_peek_prev_extent(struct xfs_ifork *ifp, xfs_iext_get_extent((ifp), (ext), (got)); \ xfs_iext_next((ifp), (ext))) -extern struct kmem_zone *xfs_ifork_zone; +extern struct kmem_cache *xfs_ifork_zone; extern void xfs_ifork_init_cow(struct xfs_inode *ip); diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c index 2c02e33e..19ead6a2 100644 --- a/libxfs/xfs_refcount_btree.c +++ b/libxfs/xfs_refcount_btree.c @@ -20,7 +20,7 @@ #include "xfs_rmap.h" #include "xfs_ag.h" -static kmem_zone_t *xfs_refcountbt_cur_cache; +static struct kmem_cache *xfs_refcountbt_cur_cache; static struct xfs_btree_cur * xfs_refcountbt_dup_cursor( diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c index ae3329b5..f0fe78d3 100644 --- a/libxfs/xfs_rmap_btree.c +++ b/libxfs/xfs_rmap_btree.c @@ -20,7 +20,7 @@ #include "xfs_ag.h" #include "xfs_ag_resv.h" -static kmem_zone_t *xfs_rmapbt_cur_cache; +static struct kmem_cache *xfs_rmapbt_cur_cache; /* * Reverse map btree. From patchwork Thu Jan 20 00:26:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12718001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5660C433F5 for ; Thu, 20 Jan 2022 00:26:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345514AbiATA0p (ORCPT ); Wed, 19 Jan 2022 19:26:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbiATA0o (ORCPT ); Wed, 19 Jan 2022 19:26:44 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F9D6C061574 for ; Wed, 19 Jan 2022 16:26:44 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E5B99B81A7C for ; Thu, 20 Jan 2022 00:26:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC2E6C004E1; Thu, 20 Jan 2022 00:26:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638401; bh=HuPeDHf3POVAQfKUcIGEgYDntQZy6e7lw//stzd8okM=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=SQIjZlsl3zV+2312Rgt7s3hCT2JbcqiZR1T2KIzYmxBuk/5+ie1LUGO+eO466vuIY 1nZ+ZniC2z1G6eYKKSjw4AFhS6dgQr/Wu4d+buk0UyRbv8hOfG120BihAhC/BobSNK vHdUf1lMrshqlNxwH+7nfCzWveB9tm3vzn3SMRsrOFN9B9aY0VEF3T5IOQbZkMzSdy BwwTjdLIV6hlISrfIHHmvs8UJvcjXfJ7PGfJZ8y6sAr4rB4tloUyzEE2qPbmyoS6di d7RCiabIL5I3yCGO06DGBOnU7rUPE2IuMwnc0Z2qjr+tnmmEJFpuKM+glev9X2vISi RUo5tMbG8cemg== Subject: [PATCH 38/48] xfs: rename _zone variables to _cache From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:26:41 -0800 Message-ID: <164263840138.865554.3713835353478500099.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 182696fb021fc196e5cbe641565ca40fcf0f885a Now that we've gotten rid of the kmem_zone_t typedef, rename the variables to _cache since that's what they are. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Signed-off-by: Darrick J. Wong --- libxfs/init.c | 12 ++++++------ libxfs/rdwr.c | 4 ++-- libxfs/xfs_alloc.c | 6 +++--- libxfs/xfs_attr_leaf.c | 2 +- libxfs/xfs_bmap.c | 6 +++--- libxfs/xfs_bmap.h | 2 +- libxfs/xfs_da_btree.c | 6 +++--- libxfs/xfs_da_btree.h | 3 +-- libxfs/xfs_inode_fork.c | 8 ++++---- libxfs/xfs_inode_fork.h | 2 +- 10 files changed, 25 insertions(+), 26 deletions(-) diff --git a/libxfs/init.c b/libxfs/init.c index 155b12fa..4a5b0d2e 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -238,13 +238,13 @@ init_zones(void) sizeof(struct xfs_buf), 0, 0, NULL); xfs_inode_zone = kmem_cache_create("xfs_inode", sizeof(struct xfs_inode), 0, 0, NULL); - xfs_ifork_zone = kmem_cache_create("xfs_ifork", + xfs_ifork_cache = kmem_cache_create("xfs_ifork", sizeof(struct xfs_ifork), 0, 0, NULL); xfs_ili_zone = kmem_cache_create("xfs_inode_log_item", sizeof(struct xfs_inode_log_item), 0, 0, NULL); xfs_buf_item_zone = kmem_cache_create("xfs_buf_log_item", sizeof(struct xfs_buf_log_item), 0, 0, NULL); - xfs_da_state_zone = kmem_cache_create("xfs_da_state", + xfs_da_state_cache = kmem_cache_create("xfs_da_state", sizeof(struct xfs_da_state), 0, 0, NULL); error = xfs_btree_init_cur_caches(); @@ -253,7 +253,7 @@ init_zones(void) abort(); } - xfs_bmap_free_item_zone = kmem_cache_create("xfs_bmap_free_item", + xfs_bmap_free_item_cache = kmem_cache_create("xfs_bmap_free_item", sizeof(struct xfs_extent_free_item), 0, 0, NULL); xfs_trans_zone = kmem_cache_create("xfs_trans", sizeof(struct xfs_trans), 0, 0, NULL); @@ -265,11 +265,11 @@ destroy_kmem_caches(void) kmem_cache_destroy(xfs_buf_zone); kmem_cache_destroy(xfs_ili_zone); kmem_cache_destroy(xfs_inode_zone); - kmem_cache_destroy(xfs_ifork_zone); + kmem_cache_destroy(xfs_ifork_cache); kmem_cache_destroy(xfs_buf_item_zone); - kmem_cache_destroy(xfs_da_state_zone); + kmem_cache_destroy(xfs_da_state_cache); xfs_btree_destroy_cur_caches(); - kmem_cache_destroy(xfs_bmap_free_item_zone); + kmem_cache_destroy(xfs_bmap_free_item_cache); kmem_cache_destroy(xfs_trans_zone); } diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c index 315e6d1f..c6a2c607 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -1115,11 +1115,11 @@ libxfs_idestroy(xfs_inode_t *ip) } if (ip->i_afp) { libxfs_idestroy_fork(ip->i_afp); - kmem_cache_free(xfs_ifork_zone, ip->i_afp); + kmem_cache_free(xfs_ifork_cache, ip->i_afp); } if (ip->i_cowfp) { libxfs_idestroy_fork(ip->i_cowfp); - kmem_cache_free(xfs_ifork_zone, ip->i_cowfp); + kmem_cache_free(xfs_ifork_cache, ip->i_cowfp); } } diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index c99497fd..06e870a8 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -23,7 +23,7 @@ #include "xfs_ag_resv.h" #include "xfs_bmap.h" -extern struct kmem_cache *xfs_bmap_free_item_zone; +extern struct kmem_cache *xfs_bmap_free_item_cache; struct workqueue_struct *xfs_alloc_wq; @@ -2455,10 +2455,10 @@ xfs_defer_agfl_block( struct xfs_mount *mp = tp->t_mountp; struct xfs_extent_free_item *new; /* new element */ - ASSERT(xfs_bmap_free_item_zone != NULL); + ASSERT(xfs_bmap_free_item_cache != NULL); ASSERT(oinfo != NULL); - new = kmem_cache_alloc(xfs_bmap_free_item_zone, + new = kmem_cache_alloc(xfs_bmap_free_item_cache, GFP_KERNEL | __GFP_NOFAIL); new->xefi_startblock = XFS_AGB_TO_FSB(mp, agno, agbno); new->xefi_blockcount = 1; diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index 76a52573..31eddb54 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -767,7 +767,7 @@ xfs_attr_fork_remove( ASSERT(ip->i_afp->if_nextents == 0); xfs_idestroy_fork(ip->i_afp); - kmem_cache_free(xfs_ifork_zone, ip->i_afp); + kmem_cache_free(xfs_ifork_cache, ip->i_afp); ip->i_afp = NULL; ip->i_forkoff = 0; xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index ecf79e24..0514d6e5 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -31,7 +31,7 @@ #include "xfs_refcount.h" -struct kmem_cache *xfs_bmap_free_item_zone; +struct kmem_cache *xfs_bmap_free_item_cache; /* * Miscellaneous helper functions @@ -548,9 +548,9 @@ __xfs_bmap_add_free( ASSERT(len < mp->m_sb.sb_agblocks); ASSERT(agbno + len <= mp->m_sb.sb_agblocks); #endif - ASSERT(xfs_bmap_free_item_zone != NULL); + ASSERT(xfs_bmap_free_item_cache != NULL); - new = kmem_cache_alloc(xfs_bmap_free_item_zone, + new = kmem_cache_alloc(xfs_bmap_free_item_cache, GFP_KERNEL | __GFP_NOFAIL); new->xefi_startblock = bno; new->xefi_blockcount = (xfs_extlen_t)len; diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index 171a72ee..2cd7717c 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -13,7 +13,7 @@ struct xfs_inode; struct xfs_mount; struct xfs_trans; -extern struct kmem_cache *xfs_bmap_free_item_zone; +extern struct kmem_cache *xfs_bmap_free_item_cache; /* * Argument structure for xfs_bmap_alloc. diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c index f1ae5d4d..50f3ec66 100644 --- a/libxfs/xfs_da_btree.c +++ b/libxfs/xfs_da_btree.c @@ -69,7 +69,7 @@ STATIC int xfs_da3_blk_unlink(xfs_da_state_t *state, xfs_da_state_blk_t *save_blk); -struct kmem_cache *xfs_da_state_zone; /* anchor for state struct zone */ +struct kmem_cache *xfs_da_state_cache; /* anchor for dir/attr state */ /* * Allocate a dir-state structure. @@ -81,7 +81,7 @@ xfs_da_state_alloc( { struct xfs_da_state *state; - state = kmem_cache_zalloc(xfs_da_state_zone, GFP_NOFS | __GFP_NOFAIL); + state = kmem_cache_zalloc(xfs_da_state_cache, GFP_NOFS | __GFP_NOFAIL); state->args = args; state->mp = args->dp->i_mount; return state; @@ -110,7 +110,7 @@ xfs_da_state_free(xfs_da_state_t *state) #ifdef DEBUG memset((char *)state, 0, sizeof(*state)); #endif /* DEBUG */ - kmem_cache_free(xfs_da_state_zone, state); + kmem_cache_free(xfs_da_state_cache, state); } static inline int xfs_dabuf_nfsb(struct xfs_mount *mp, int whichfork) diff --git a/libxfs/xfs_da_btree.h b/libxfs/xfs_da_btree.h index da845e32..0faf7d9a 100644 --- a/libxfs/xfs_da_btree.h +++ b/libxfs/xfs_da_btree.h @@ -9,7 +9,6 @@ struct xfs_inode; struct xfs_trans; -struct zone; /* * Directory/attribute geometry information. There will be one of these for each @@ -227,6 +226,6 @@ void xfs_da3_node_hdr_from_disk(struct xfs_mount *mp, void xfs_da3_node_hdr_to_disk(struct xfs_mount *mp, struct xfs_da_intnode *to, struct xfs_da3_icnode_hdr *from); -extern struct kmem_cache *xfs_da_state_zone; +extern struct kmem_cache *xfs_da_state_cache; #endif /* __XFS_DA_BTREE_H__ */ diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index c80b4066..d6ac13ee 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -24,7 +24,7 @@ #include "xfs_types.h" #include "xfs_errortag.h" -struct kmem_cache *xfs_ifork_zone; +struct kmem_cache *xfs_ifork_cache; void xfs_init_local_fork( @@ -282,7 +282,7 @@ xfs_ifork_alloc( { struct xfs_ifork *ifp; - ifp = kmem_cache_zalloc(xfs_ifork_zone, GFP_NOFS | __GFP_NOFAIL); + ifp = kmem_cache_zalloc(xfs_ifork_cache, GFP_NOFS | __GFP_NOFAIL); ifp->if_format = format; ifp->if_nextents = nextents; return ifp; @@ -323,7 +323,7 @@ xfs_iformat_attr_fork( } if (error) { - kmem_cache_free(xfs_ifork_zone, ip->i_afp); + kmem_cache_free(xfs_ifork_cache, ip->i_afp); ip->i_afp = NULL; } return error; @@ -674,7 +674,7 @@ xfs_ifork_init_cow( if (ip->i_cowfp) return; - ip->i_cowfp = kmem_cache_zalloc(xfs_ifork_zone, + ip->i_cowfp = kmem_cache_zalloc(xfs_ifork_cache, GFP_NOFS | __GFP_NOFAIL); ip->i_cowfp->if_format = XFS_DINODE_FMT_EXTENTS; } diff --git a/libxfs/xfs_inode_fork.h b/libxfs/xfs_inode_fork.h index cb296bd5..3d64a3ac 100644 --- a/libxfs/xfs_inode_fork.h +++ b/libxfs/xfs_inode_fork.h @@ -221,7 +221,7 @@ static inline bool xfs_iext_peek_prev_extent(struct xfs_ifork *ifp, xfs_iext_get_extent((ifp), (ext), (got)); \ xfs_iext_next((ifp), (ext))) -extern struct kmem_cache *xfs_ifork_zone; +extern struct kmem_cache *xfs_ifork_cache; extern void xfs_ifork_init_cow(struct xfs_inode *ip); From patchwork Thu Jan 20 00:26:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12718002 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98A1DC433EF for ; Thu, 20 Jan 2022 00:26:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345480AbiATA0t (ORCPT ); Wed, 19 Jan 2022 19:26:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbiATA0s (ORCPT ); Wed, 19 Jan 2022 19:26:48 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4660EC061574 for ; Wed, 19 Jan 2022 16:26:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D8524614DF for ; Thu, 20 Jan 2022 00:26:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39B93C004E1; Thu, 20 Jan 2022 00:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638407; bh=EfAzIboOJK8hxfhKkPnScIuacFXejO8fBXpxG0nT2Bg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=nTP4Wt0EQh1pg5YIIOHj346m9mu9tIwPYAZFjQdnOCOQiVpxgLt+3de+PTyCOf1v6 +s+QX9K7ZElwH/rpo0xZ8VVJbLFwEzVP5/3jRfq3dM8Z0QdcoOSDI3UaYp1dieMiXH 2LFAFALlLnEauRvjB2Xb0Uz5EOdNpgdrlmARxxs8chuhRZNr6GajaLAw+goHIvrwDp osOzXvhoRi2bdGho6REwAJYeEoca7XkTbrqYZSpepvMIg4iKRrDiFE26rp5wEBRG5X kkWi1OY/MpbEle4wOt9O0UUhBC8hSnnWe8AbK9Ai+iEb63uScs/t0TxungxJNMDODD LdoAeCK6QovgA== Subject: [PATCH 39/48] libxfs: rename all the other _zone variables to _cache From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:26:46 -0800 Message-ID: <164263840689.865554.257197920220925329.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Convert all the other _zone variables that we didn't catch in the libxfs porting patches. Signed-off-by: Darrick J. Wong --- libxfs/init.c | 24 ++++++++++++------------ libxfs/libxfs_priv.h | 10 +++++----- libxfs/logitem.c | 8 ++++---- libxfs/rdwr.c | 16 ++++++++-------- libxfs/trans.c | 14 +++++++------- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/libxfs/init.c b/libxfs/init.c index 4a5b0d2e..1978a01f 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -229,20 +229,20 @@ check_open(char *path, int flags, char **rawfile, char **blockfile) * Initialize/destroy all of the zone allocators we use. */ static void -init_zones(void) +init_caches(void) { int error; /* initialise zone allocation */ - xfs_buf_zone = kmem_cache_create("xfs_buffer", + xfs_buf_cache = kmem_cache_create("xfs_buffer", sizeof(struct xfs_buf), 0, 0, NULL); - xfs_inode_zone = kmem_cache_create("xfs_inode", + xfs_inode_cache = kmem_cache_create("xfs_inode", sizeof(struct xfs_inode), 0, 0, NULL); xfs_ifork_cache = kmem_cache_create("xfs_ifork", sizeof(struct xfs_ifork), 0, 0, NULL); - xfs_ili_zone = kmem_cache_create("xfs_inode_log_item", + xfs_ili_cache = kmem_cache_create("xfs_inode_log_item", sizeof(struct xfs_inode_log_item), 0, 0, NULL); - xfs_buf_item_zone = kmem_cache_create("xfs_buf_log_item", + xfs_buf_item_cache = kmem_cache_create("xfs_buf_log_item", sizeof(struct xfs_buf_log_item), 0, 0, NULL); xfs_da_state_cache = kmem_cache_create("xfs_da_state", sizeof(struct xfs_da_state), 0, 0, NULL); @@ -255,22 +255,22 @@ init_zones(void) xfs_bmap_free_item_cache = kmem_cache_create("xfs_bmap_free_item", sizeof(struct xfs_extent_free_item), 0, 0, NULL); - xfs_trans_zone = kmem_cache_create("xfs_trans", + xfs_trans_cache = kmem_cache_create("xfs_trans", sizeof(struct xfs_trans), 0, 0, NULL); } static void destroy_kmem_caches(void) { - kmem_cache_destroy(xfs_buf_zone); - kmem_cache_destroy(xfs_ili_zone); - kmem_cache_destroy(xfs_inode_zone); + kmem_cache_destroy(xfs_buf_cache); + kmem_cache_destroy(xfs_ili_cache); + kmem_cache_destroy(xfs_inode_cache); kmem_cache_destroy(xfs_ifork_cache); - kmem_cache_destroy(xfs_buf_item_zone); + kmem_cache_destroy(xfs_buf_item_cache); kmem_cache_destroy(xfs_da_state_cache); xfs_btree_destroy_cur_caches(); kmem_cache_destroy(xfs_bmap_free_item_cache); - kmem_cache_destroy(xfs_trans_zone); + kmem_cache_destroy(xfs_trans_cache); } static void @@ -405,7 +405,7 @@ libxfs_init(libxfs_init_t *a) &libxfs_bcache_operations); use_xfs_buf_lock = a->usebuflock; xfs_dir_startup(); - init_zones(); + init_caches(); rval = 1; done: if (dpath[0]) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 5b04db84..67d9a8bb 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -59,11 +59,11 @@ #include /* Zones used in libxfs allocations that aren't in shared header files */ -extern struct kmem_cache *xfs_buf_item_zone; -extern struct kmem_cache *xfs_ili_zone; -extern struct kmem_cache *xfs_buf_zone; -extern struct kmem_cache *xfs_inode_zone; -extern struct kmem_cache *xfs_trans_zone; +extern struct kmem_cache *xfs_buf_item_cache; +extern struct kmem_cache *xfs_ili_cache; +extern struct kmem_cache *xfs_buf_cache; +extern struct kmem_cache *xfs_inode_cache; +extern struct kmem_cache *xfs_trans_cache; /* fake up iomap, (not) used in xfs_bmap.[ch] */ #define IOMAP_F_SHARED 0x04 diff --git a/libxfs/logitem.c b/libxfs/logitem.c index dde90502..98ccdaef 100644 --- a/libxfs/logitem.c +++ b/libxfs/logitem.c @@ -16,8 +16,8 @@ #include "xfs_inode.h" #include "xfs_trans.h" -struct kmem_cache *xfs_buf_item_zone; -struct kmem_cache *xfs_ili_zone; /* inode log item zone */ +struct kmem_cache *xfs_buf_item_cache; +struct kmem_cache *xfs_ili_cache; /* inode log item cache */ /* * Following functions from fs/xfs/xfs_trans_buf.c @@ -96,7 +96,7 @@ xfs_buf_item_init( } } - bip = kmem_cache_zalloc(xfs_buf_item_zone, 0); + bip = kmem_cache_zalloc(xfs_buf_item_cache, 0); #ifdef LI_DEBUG fprintf(stderr, "adding buf item %p for not-logged buffer %p\n", bip, bp); @@ -138,7 +138,7 @@ xfs_inode_item_init( struct xfs_inode_log_item *iip; ASSERT(ip->i_itemp == NULL); - iip = ip->i_itemp = kmem_cache_zalloc(xfs_ili_zone, 0); + iip = ip->i_itemp = kmem_cache_zalloc(xfs_ili_cache, 0); #ifdef LI_DEBUG fprintf(stderr, "inode_item_init for inode %llu, iip=%p\n", ip->i_ino, iip); diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c index c6a2c607..7f4aa45f 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -161,7 +161,7 @@ libxfs_getsb( return bp; } -struct kmem_cache *xfs_buf_zone; +struct kmem_cache *xfs_buf_cache; static struct cache_mru xfs_buf_freelist = {{&xfs_buf_freelist.cm_list, &xfs_buf_freelist.cm_list}, @@ -327,7 +327,7 @@ __libxfs_getbufr(int blen) bp->b_maps = NULL; } } else - bp = kmem_cache_zalloc(xfs_buf_zone, 0); + bp = kmem_cache_zalloc(xfs_buf_cache, 0); pthread_mutex_unlock(&xfs_buf_freelist.cm_mutex); bp->b_ops = NULL; if (bp->b_flags & LIBXFS_B_DIRTY) @@ -961,7 +961,7 @@ libxfs_bcache_free(void) free(bp->b_addr); if (bp->b_maps != &bp->__b_map) free(bp->b_maps); - kmem_cache_free(xfs_buf_zone, bp); + kmem_cache_free(xfs_buf_cache, bp); } } @@ -1053,8 +1053,8 @@ xfs_verify_magic16( * Inode cache stubs. */ -struct kmem_cache *xfs_inode_zone; -extern struct kmem_cache *xfs_ili_zone; +struct kmem_cache *xfs_inode_cache; +extern struct kmem_cache *xfs_ili_cache; int libxfs_iget( @@ -1068,7 +1068,7 @@ libxfs_iget( struct xfs_buf *bp; int error = 0; - ip = kmem_cache_zalloc(xfs_inode_zone, 0); + ip = kmem_cache_zalloc(xfs_inode_cache, 0); if (!ip) return -ENOMEM; @@ -1098,7 +1098,7 @@ libxfs_iget( return 0; out_destroy: - kmem_cache_free(xfs_inode_zone, ip); + kmem_cache_free(xfs_inode_cache, ip); *ipp = NULL; return error; } @@ -1132,7 +1132,7 @@ libxfs_irele( if (VFS_I(ip)->i_count == 0) { ASSERT(ip->i_itemp == NULL); libxfs_idestroy(ip); - kmem_cache_free(xfs_inode_zone, ip); + kmem_cache_free(xfs_inode_cache, ip); } } diff --git a/libxfs/trans.c b/libxfs/trans.c index f87a65c5..50d9c23d 100644 --- a/libxfs/trans.c +++ b/libxfs/trans.c @@ -30,7 +30,7 @@ static int __xfs_trans_commit(struct xfs_trans *tp, bool regrant); * Simple transaction interface */ -struct kmem_cache *xfs_trans_zone; +struct kmem_cache *xfs_trans_cache; /* * Initialize the precomputed transaction reservation values @@ -124,7 +124,7 @@ static void xfs_trans_free( struct xfs_trans *tp) { - kmem_cache_free(xfs_trans_zone, tp); + kmem_cache_free(xfs_trans_cache, tp); } /* @@ -141,7 +141,7 @@ xfs_trans_dup( { struct xfs_trans *ntp; - ntp = kmem_cache_zalloc(xfs_trans_zone, 0); + ntp = kmem_cache_zalloc(xfs_trans_cache, 0); /* * Initialize the new transaction structure. @@ -259,7 +259,7 @@ libxfs_trans_alloc( struct xfs_trans *tp; int error; - tp = kmem_cache_zalloc(xfs_trans_zone, 0); + tp = kmem_cache_zalloc(xfs_trans_cache, 0); tp->t_mountp = mp; INIT_LIST_HEAD(&tp->t_items); INIT_LIST_HEAD(&tp->t_dfops); @@ -354,7 +354,7 @@ xfs_buf_item_put( struct xfs_buf *bp = bip->bli_buf; bp->b_log_item = NULL; - kmem_cache_free(xfs_buf_item_zone, bip); + kmem_cache_free(xfs_buf_item_cache, bip); } /* from xfs_trans_buf.c */ @@ -816,7 +816,7 @@ xfs_inode_item_put( ip->i_itemp = NULL; list_del_init(&iip->ili_item.li_bio_list); - kmem_cache_free(xfs_ili_zone, iip); + kmem_cache_free(xfs_ili_cache, iip); } @@ -868,7 +868,7 @@ buf_item_done( { struct xfs_buf *bp; int hold; - extern struct kmem_cache *xfs_buf_item_zone; + extern struct kmem_cache *xfs_buf_item_cache; bp = bip->bli_buf; ASSERT(bp != NULL); From patchwork Thu Jan 20 00:26:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12718003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88E5BC433EF for ; Thu, 20 Jan 2022 00:26:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357760AbiATA0y (ORCPT ); Wed, 19 Jan 2022 19:26:54 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:33900 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbiATA0x (ORCPT ); Wed, 19 Jan 2022 19:26:53 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5D1C8614DF for ; Thu, 20 Jan 2022 00:26:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B61E8C004E1; Thu, 20 Jan 2022 00:26:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638412; bh=Sfk8IugcCE+lPEe09oy9mYurradEL30eimntCy5rr4g=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=UoDS57RAxQTDRuAtQ3FrVQvBmOBKLBulUC6DZXx7zmg4TkvrB3xmLG6m35wyieJV1 NhJXDj0sfs8hVJgOq89+TQvjLRwuoon2yQeV1il1ER95WT8o33eFs8AUwVh/7OHque Ch8pBITaO4uL+L0N9d+lwc6iaAfLU1i/SroU3wjRku170c6zcCo9na3i9ILBDJ30UJ nANAUIIqcl8JS5qGZiZ5pwj8n1vH29sQc/xufZ1H3FBKhK21AfGqE+CL9vPEZ+MdbP 54sHbUR7cNJRnwpEyyWdiiZKbCNofihVlKYIv/EctZpk65W1Zt1KorfD7fr3+16SKl m5+IHWeXNQbgg== Subject: [PATCH 40/48] libxfs: change zone to cache for all kmem functions From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:26:52 -0800 Message-ID: <164263841243.865554.8105465319420120565.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Finish our zone->cache conversion by changing the field names and local variables in kmem.[ch]. Signed-off-by: Darrick J. Wong --- include/kmem.h | 8 ++++---- libxfs/init.c | 6 +++--- libxfs/kmem.c | 40 ++++++++++++++++++++-------------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/include/kmem.h b/include/kmem.h index 7aba4914..fd90a1bc 100644 --- a/include/kmem.h +++ b/include/kmem.h @@ -15,10 +15,10 @@ bool kmem_found_leaks(void); #define KM_NOLOCKDEP 0x0020u struct kmem_cache { - int zone_unitsize; /* Size in bytes of zone unit */ + int cache_unitsize; /* Size in bytes of cache unit */ int allocated; /* debug: How many allocated? */ unsigned int align; - const char *zone_name; /* tag name */ + const char *cache_name; /* tag name */ void (*ctor)(void *); }; @@ -40,9 +40,9 @@ extern void *kmem_cache_alloc(struct kmem_cache *, gfp_t); extern void *kmem_cache_zalloc(struct kmem_cache *, gfp_t); static inline void -kmem_cache_free(struct kmem_cache *zone, void *ptr) +kmem_cache_free(struct kmem_cache *cache, void *ptr) { - zone->allocated--; + cache->allocated--; free(ptr); } diff --git a/libxfs/init.c b/libxfs/init.c index 1978a01f..b0be28e3 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -226,14 +226,14 @@ check_open(char *path, int flags, char **rawfile, char **blockfile) } /* - * Initialize/destroy all of the zone allocators we use. + * Initialize/destroy all of the cache allocators we use. */ static void init_caches(void) { int error; - /* initialise zone allocation */ + /* initialise cache allocation */ xfs_buf_cache = kmem_cache_create("xfs_buffer", sizeof(struct xfs_buf), 0, 0, NULL); xfs_inode_cache = kmem_cache_create("xfs_inode", @@ -1028,7 +1028,7 @@ libxfs_destroy( kmem_start_leak_check(); libxfs_close_devices(li); - /* Free everything from the buffer cache before freeing buffer zone */ + /* Free everything from the buffer cache before freeing buffer cache */ libxfs_bcache_purge(); libxfs_bcache_free(); cache_destroy(libxfs_bcache); diff --git a/libxfs/kmem.c b/libxfs/kmem.c index a176a9d8..f4505696 100644 --- a/libxfs/kmem.c +++ b/libxfs/kmem.c @@ -25,13 +25,13 @@ kmem_cache_create(const char *name, unsigned int size, unsigned int align, struct kmem_cache *ptr = malloc(sizeof(struct kmem_cache)); if (ptr == NULL) { - fprintf(stderr, _("%s: zone init failed (%s, %d bytes): %s\n"), + fprintf(stderr, _("%s: cache init failed (%s, %d bytes): %s\n"), progname, name, (int)sizeof(struct kmem_cache), strerror(errno)); exit(1); } - ptr->zone_unitsize = size; - ptr->zone_name = name; + ptr->cache_unitsize = size; + ptr->cache_name = name; ptr->allocated = 0; ptr->align = align; ptr->ctor = ctor; @@ -40,50 +40,50 @@ kmem_cache_create(const char *name, unsigned int size, unsigned int align, } void -kmem_cache_destroy(struct kmem_cache *zone) +kmem_cache_destroy(struct kmem_cache *cache) { - if (getenv("LIBXFS_LEAK_CHECK") && zone->allocated) { + if (getenv("LIBXFS_LEAK_CHECK") && cache->allocated) { leaked = true; - fprintf(stderr, "zone %s freed with %d items allocated\n", - zone->zone_name, zone->allocated); + fprintf(stderr, "cache %s freed with %d items allocated\n", + cache->cache_name, cache->allocated); } - free(zone); + free(cache); } void * -kmem_cache_alloc(struct kmem_cache *zone, gfp_t flags) +kmem_cache_alloc(struct kmem_cache *cache, gfp_t flags) { void *ptr = NULL; - if (zone->align) { + if (cache->align) { int ret; - ret = posix_memalign(&ptr, zone->align, zone->zone_unitsize); + ret = posix_memalign(&ptr, cache->align, cache->cache_unitsize); if (ret) errno = ret; } else { - ptr = malloc(zone->zone_unitsize); + ptr = malloc(cache->cache_unitsize); } if (ptr == NULL) { - fprintf(stderr, _("%s: zone alloc failed (%s, %d bytes): %s\n"), - progname, zone->zone_name, zone->zone_unitsize, + fprintf(stderr, _("%s: cache alloc failed (%s, %d bytes): %s\n"), + progname, cache->cache_name, cache->cache_unitsize, strerror(errno)); exit(1); } - if (zone->ctor) - zone->ctor(ptr); - zone->allocated++; + if (cache->ctor) + cache->ctor(ptr); + cache->allocated++; return ptr; } void * -kmem_cache_zalloc(struct kmem_cache *zone, gfp_t flags) +kmem_cache_zalloc(struct kmem_cache *cache, gfp_t flags) { - void *ptr = kmem_cache_alloc(zone, flags); + void *ptr = kmem_cache_alloc(cache, flags); - memset(ptr, 0, zone->zone_unitsize); + memset(ptr, 0, cache->cache_unitsize); return ptr; } From patchwork Thu Jan 20 00:26:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12718004 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4695CC433EF for ; Thu, 20 Jan 2022 00:27:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357653AbiATA07 (ORCPT ); Wed, 19 Jan 2022 19:26:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbiATA07 (ORCPT ); Wed, 19 Jan 2022 19:26:59 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A90DC061574 for ; Wed, 19 Jan 2022 16:26:59 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EE9A661511 for ; Thu, 20 Jan 2022 00:26:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 504D7C004E1; Thu, 20 Jan 2022 00:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638418; bh=mcM4Qh4uy4jiKN55wmGVnb5YajDug06iq3p3in2MhG4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=PjOPRyN3DvdVhfWG0+/BkrW8LKN5s4LB9+xDJ8+d2F3jylh5snBSiOvIFV7NBlija SudI4hkMnBarIOdzWgXRCuCRGq5i30dB8L7aWtNYAt+HPLlM1n+/SJXv+tpmDzEI0Z ZI4g4/uSlacpUu15u1SMFdqTiPFlcAPI0ucwH77aegmM/z0xJWMOYUts+lAM2nU01I 6ec3bbxqTt3T5Lj0+1sWJm16Bq2n/LCyZWl2SX9Lx70J76PCgU9BKjWjrfrhMK3lLF sCSFHLhwu5zwydn/JYLkTHcBz1igX5n3sVmRtjBROVc0VwvfcVqT5qAlR/6JdGI3Ny un4dOUVIcvHdw== Subject: [PATCH 41/48] xfs: compact deferred intent item structures From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:26:57 -0800 Message-ID: <164263841795.865554.12508860123797088374.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 9e253954acf53227f33d307f5ac5ff94c1ca5880 Rearrange these structs to reduce the amount of unused padding bytes. This saves eight bytes for each of the three structs changed here, which means they're now all (rmap/bmap are 64 bytes, refc is 32 bytes) even powers of two. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Signed-off-by: Darrick J. Wong --- libxfs/xfs_bmap.h | 2 +- libxfs/xfs_refcount.h | 2 +- libxfs/xfs_rmap.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index 2cd7717c..db01fe83 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -257,8 +257,8 @@ enum xfs_bmap_intent_type { struct xfs_bmap_intent { struct list_head bi_list; enum xfs_bmap_intent_type bi_type; - struct xfs_inode *bi_owner; int bi_whichfork; + struct xfs_inode *bi_owner; struct xfs_bmbt_irec bi_bmap; }; diff --git a/libxfs/xfs_refcount.h b/libxfs/xfs_refcount.h index 02cb3aa4..89404596 100644 --- a/libxfs/xfs_refcount.h +++ b/libxfs/xfs_refcount.h @@ -32,8 +32,8 @@ enum xfs_refcount_intent_type { struct xfs_refcount_intent { struct list_head ri_list; enum xfs_refcount_intent_type ri_type; - xfs_fsblock_t ri_startblock; xfs_extlen_t ri_blockcount; + xfs_fsblock_t ri_startblock; }; void xfs_refcount_increase_extent(struct xfs_trans *tp, diff --git a/libxfs/xfs_rmap.h b/libxfs/xfs_rmap.h index fd67904e..85dd98ac 100644 --- a/libxfs/xfs_rmap.h +++ b/libxfs/xfs_rmap.h @@ -159,8 +159,8 @@ enum xfs_rmap_intent_type { struct xfs_rmap_intent { struct list_head ri_list; enum xfs_rmap_intent_type ri_type; - uint64_t ri_owner; int ri_whichfork; + uint64_t ri_owner; struct xfs_bmbt_irec ri_bmap; }; From patchwork Thu Jan 20 00:27:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12718005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7273C433F5 for ; Thu, 20 Jan 2022 00:27:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357764AbiATA1H (ORCPT ); Wed, 19 Jan 2022 19:27:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbiATA1G (ORCPT ); Wed, 19 Jan 2022 19:27:06 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D591C061574 for ; Wed, 19 Jan 2022 16:27:06 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 276CDB81A7C for ; Thu, 20 Jan 2022 00:27:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0503C004E1; Thu, 20 Jan 2022 00:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638424; bh=2972u8eyUJ4MrGJSzD8vf0lrWsXF4QGj4gwB/vtwo60=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=WpVHtGTUmUrBKBqGcbLnI0Z/x09jNT0rb/gYu4NR/BcZGZMyamfzS+IbBAq8RzE0W G+EJ+z9onG1HizG/yfeW29FiJNSvQz8kuz1HZmgLSOCvLtPZJ8Fz7fv1ND9uC5hcyV pA2x0H6ItEgS8rWo+DqzousKulIVENM81Y+9xbQzJ8yRF1oNXyXXfYPoLbBraTSSBL UkGRE269oF9tDKgr+ppJaeyIxp9gjnqVNtvc4vRHJXzuZLoGPoN6/1QHoMsFspRre7 88ssx7NYLVB5EtQV17JHlMY4FejVAfB/GOizkDRQmddzrqH/W7bQmStMqIf49wMtMe qJpHKaiWvkvJA== Subject: [PATCH 42/48] xfs: create slab caches for frequently-used deferred items From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:27:03 -0800 Message-ID: <164263842354.865554.17714418783812332419.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: f3c799c22c661e181c71a0d9914fc923023f65fb Create slab caches for the high-level structures that coordinate deferred intent items, since they're used fairly heavily. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Signed-off-by: Darrick J. Wong --- libxfs/defer_item.c | 18 +++++++------- libxfs/init.c | 7 +++++ libxfs/xfs_bmap.c | 21 ++++++++++++++-- libxfs/xfs_bmap.h | 5 ++++ libxfs/xfs_defer.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++--- libxfs/xfs_defer.h | 3 ++ libxfs/xfs_refcount.c | 23 ++++++++++++++++- libxfs/xfs_refcount.h | 5 ++++ libxfs/xfs_rmap.c | 21 +++++++++++++++- libxfs/xfs_rmap.h | 5 ++++ 10 files changed, 155 insertions(+), 18 deletions(-) diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index b18182e9..1277469f 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -82,7 +82,7 @@ xfs_extent_free_finish_item( error = xfs_free_extent(tp, free->xefi_startblock, free->xefi_blockcount, &free->xefi_oinfo, XFS_AG_RESV_NONE); - kmem_free(free); + kmem_cache_free(xfs_bmap_free_item_cache, free); return error; } @@ -101,7 +101,7 @@ xfs_extent_free_cancel_item( struct xfs_extent_free_item *free; free = container_of(item, struct xfs_extent_free_item, xefi_list); - kmem_free(free); + kmem_cache_free(xfs_bmap_free_item_cache, free); } const struct xfs_defer_op_type xfs_extent_free_defer_type = { @@ -139,7 +139,7 @@ xfs_agfl_free_finish_item( if (!error) error = xfs_free_agfl_block(tp, agno, agbno, agbp, &free->xefi_oinfo); - kmem_free(free); + kmem_cache_free(xfs_bmap_free_item_cache, free); return error; } @@ -216,7 +216,7 @@ xfs_rmap_update_finish_item( rmap->ri_bmap.br_blockcount, rmap->ri_bmap.br_state, state); - kmem_free(rmap); + kmem_cache_free(xfs_rmap_intent_cache, rmap); return error; } @@ -235,7 +235,7 @@ xfs_rmap_update_cancel_item( struct xfs_rmap_intent *rmap; rmap = container_of(item, struct xfs_rmap_intent, ri_list); - kmem_free(rmap); + kmem_cache_free(xfs_rmap_intent_cache, rmap); } const struct xfs_defer_op_type xfs_rmap_update_defer_type = { @@ -319,7 +319,7 @@ xfs_refcount_update_finish_item( refc->ri_blockcount = new_aglen; return -EAGAIN; } - kmem_free(refc); + kmem_cache_free(xfs_refcount_intent_cache, refc); return error; } @@ -338,7 +338,7 @@ xfs_refcount_update_cancel_item( struct xfs_refcount_intent *refc; refc = container_of(item, struct xfs_refcount_intent, ri_list); - kmem_free(refc); + kmem_cache_free(xfs_refcount_intent_cache, refc); } const struct xfs_defer_op_type xfs_refcount_update_defer_type = { @@ -418,7 +418,7 @@ xfs_bmap_update_finish_item( bmap->bi_bmap.br_blockcount = count; return -EAGAIN; } - kmem_free(bmap); + kmem_cache_free(xfs_bmap_intent_cache, bmap); return error; } @@ -437,7 +437,7 @@ xfs_bmap_update_cancel_item( struct xfs_bmap_intent *bmap; bmap = container_of(item, struct xfs_bmap_intent, bi_list); - kmem_free(bmap); + kmem_cache_free(xfs_bmap_intent_cache, bmap); } const struct xfs_defer_op_type xfs_bmap_update_defer_type = { diff --git a/libxfs/init.c b/libxfs/init.c index b0be28e3..f6863f4c 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -253,6 +253,12 @@ init_caches(void) abort(); } + error = xfs_defer_init_item_caches(); + if (error) { + fprintf(stderr, "Could not allocate defer work item caches.\n"); + abort(); + } + xfs_bmap_free_item_cache = kmem_cache_create("xfs_bmap_free_item", sizeof(struct xfs_extent_free_item), 0, 0, NULL); xfs_trans_cache = kmem_cache_create("xfs_trans", @@ -268,6 +274,7 @@ destroy_kmem_caches(void) kmem_cache_destroy(xfs_ifork_cache); kmem_cache_destroy(xfs_buf_item_cache); kmem_cache_destroy(xfs_da_state_cache); + xfs_defer_destroy_item_caches(); xfs_btree_destroy_cur_caches(); kmem_cache_destroy(xfs_bmap_free_item_cache); kmem_cache_destroy(xfs_trans_cache); diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 0514d6e5..c261d119 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -30,7 +30,7 @@ #include "xfs_ag_resv.h" #include "xfs_refcount.h" - +struct kmem_cache *xfs_bmap_intent_cache; struct kmem_cache *xfs_bmap_free_item_cache; /* @@ -6183,7 +6183,7 @@ __xfs_bmap_add( bmap->br_blockcount, bmap->br_state); - bi = kmem_alloc(sizeof(struct xfs_bmap_intent), KM_NOFS); + bi = kmem_cache_alloc(xfs_bmap_intent_cache, GFP_NOFS | __GFP_NOFAIL); INIT_LIST_HEAD(&bi->bi_list); bi->bi_type = type; bi->bi_owner = ip; @@ -6294,3 +6294,20 @@ xfs_bmap_validate_extent( return __this_address; return NULL; } + +int __init +xfs_bmap_intent_init_cache(void) +{ + xfs_bmap_intent_cache = kmem_cache_create("xfs_bmap_intent", + sizeof(struct xfs_bmap_intent), + 0, 0, NULL); + + return xfs_bmap_intent_cache != NULL ? 0 : -ENOMEM; +} + +void +xfs_bmap_intent_destroy_cache(void) +{ + kmem_cache_destroy(xfs_bmap_intent_cache); + xfs_bmap_intent_cache = NULL; +} diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index db01fe83..fa73a568 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -290,4 +290,9 @@ int xfs_bmapi_remap(struct xfs_trans *tp, struct xfs_inode *ip, xfs_fileoff_t bno, xfs_filblks_t len, xfs_fsblock_t startblock, int flags); +extern struct kmem_cache *xfs_bmap_intent_cache; + +int __init xfs_bmap_intent_init_cache(void); +void xfs_bmap_intent_destroy_cache(void); + #endif /* __XFS_BMAP_H__ */ diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 40d49abc..f71bb055 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -14,6 +14,11 @@ #include "xfs_trans.h" #include "xfs_inode.h" #include "xfs_trace.h" +#include "xfs_rmap.h" +#include "xfs_refcount.h" +#include "xfs_bmap.h" + +static struct kmem_cache *xfs_defer_pending_cache; /* * Deferred Operations in XFS @@ -361,7 +366,7 @@ xfs_defer_cancel_list( ops->cancel_item(pwi); } ASSERT(dfp->dfp_count == 0); - kmem_free(dfp); + kmem_cache_free(xfs_defer_pending_cache, dfp); } } @@ -458,7 +463,7 @@ xfs_defer_finish_one( /* Done with the dfp, free it. */ list_del(&dfp->dfp_list); - kmem_free(dfp); + kmem_cache_free(xfs_defer_pending_cache, dfp); out: if (ops->finish_cleanup) ops->finish_cleanup(tp, state, error); @@ -592,8 +597,8 @@ xfs_defer_add( dfp = NULL; } if (!dfp) { - dfp = kmem_alloc(sizeof(struct xfs_defer_pending), - KM_NOFS); + dfp = kmem_cache_zalloc(xfs_defer_pending_cache, + GFP_NOFS | __GFP_NOFAIL); dfp->dfp_type = type; dfp->dfp_intent = NULL; dfp->dfp_done = NULL; @@ -805,3 +810,55 @@ xfs_defer_resources_rele( dres->dr_bufs = 0; dres->dr_ordered = 0; } + +static inline int __init +xfs_defer_init_cache(void) +{ + xfs_defer_pending_cache = kmem_cache_create("xfs_defer_pending", + sizeof(struct xfs_defer_pending), + 0, 0, NULL); + + return xfs_defer_pending_cache != NULL ? 0 : -ENOMEM; +} + +static inline void +xfs_defer_destroy_cache(void) +{ + kmem_cache_destroy(xfs_defer_pending_cache); + xfs_defer_pending_cache = NULL; +} + +/* Set up caches for deferred work items. */ +int __init +xfs_defer_init_item_caches(void) +{ + int error; + + error = xfs_defer_init_cache(); + if (error) + return error; + error = xfs_rmap_intent_init_cache(); + if (error) + goto err; + error = xfs_refcount_intent_init_cache(); + if (error) + goto err; + error = xfs_bmap_intent_init_cache(); + if (error) + goto err; + + return 0; +err: + xfs_defer_destroy_item_caches(); + return error; +} + +/* Destroy all the deferred work item caches, if they've been allocated. */ +void +xfs_defer_destroy_item_caches(void) +{ + xfs_bmap_intent_destroy_cache(); + xfs_refcount_intent_destroy_cache(); + xfs_rmap_intent_destroy_cache(); + xfs_defer_destroy_cache(); +} diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index 7952695c..7bb8a31a 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -122,4 +122,7 @@ void xfs_defer_ops_capture_free(struct xfs_mount *mp, struct xfs_defer_capture *d); void xfs_defer_resources_rele(struct xfs_defer_resources *dres); +int __init xfs_defer_init_item_caches(void); +void xfs_defer_destroy_item_caches(void); + #endif /* __XFS_DEFER_H__ */ diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 2aa64d3e..da3cd7d5 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -23,6 +23,8 @@ #include "xfs_rmap.h" #include "xfs_ag.h" +struct kmem_cache *xfs_refcount_intent_cache; + /* Allowable refcount adjustment amounts. */ enum xfs_refc_adjust_op { XFS_REFCOUNT_ADJUST_INCREASE = 1, @@ -1234,8 +1236,8 @@ __xfs_refcount_add( type, XFS_FSB_TO_AGBNO(tp->t_mountp, startblock), blockcount); - ri = kmem_alloc(sizeof(struct xfs_refcount_intent), - KM_NOFS); + ri = kmem_cache_alloc(xfs_refcount_intent_cache, + GFP_NOFS | __GFP_NOFAIL); INIT_LIST_HEAD(&ri->ri_list); ri->ri_type = type; ri->ri_startblock = startblock; @@ -1781,3 +1783,20 @@ xfs_refcount_has_record( return xfs_btree_has_record(cur, &low, &high, exists); } + +int __init +xfs_refcount_intent_init_cache(void) +{ + xfs_refcount_intent_cache = kmem_cache_create("xfs_refc_intent", + sizeof(struct xfs_refcount_intent), + 0, 0, NULL); + + return xfs_refcount_intent_cache != NULL ? 0 : -ENOMEM; +} + +void +xfs_refcount_intent_destroy_cache(void) +{ + kmem_cache_destroy(xfs_refcount_intent_cache); + xfs_refcount_intent_cache = NULL; +} diff --git a/libxfs/xfs_refcount.h b/libxfs/xfs_refcount.h index 89404596..9eb01edb 100644 --- a/libxfs/xfs_refcount.h +++ b/libxfs/xfs_refcount.h @@ -83,4 +83,9 @@ extern void xfs_refcount_btrec_to_irec(const union xfs_btree_rec *rec, extern int xfs_refcount_insert(struct xfs_btree_cur *cur, struct xfs_refcount_irec *irec, int *stat); +extern struct kmem_cache *xfs_refcount_intent_cache; + +int __init xfs_refcount_intent_init_cache(void); +void xfs_refcount_intent_destroy_cache(void); + #endif /* __XFS_REFCOUNT_H__ */ diff --git a/libxfs/xfs_rmap.c b/libxfs/xfs_rmap.c index e93010ff..d6601a65 100644 --- a/libxfs/xfs_rmap.c +++ b/libxfs/xfs_rmap.c @@ -23,6 +23,8 @@ #include "xfs_inode.h" #include "xfs_ag.h" +struct kmem_cache *xfs_rmap_intent_cache; + /* * Lookup the first record less than or equal to [bno, len, owner, offset] * in the btree given by cur. @@ -2484,7 +2486,7 @@ __xfs_rmap_add( bmap->br_blockcount, bmap->br_state); - ri = kmem_alloc(sizeof(struct xfs_rmap_intent), KM_NOFS); + ri = kmem_cache_alloc(xfs_rmap_intent_cache, GFP_NOFS | __GFP_NOFAIL); INIT_LIST_HEAD(&ri->ri_list); ri->ri_type = type; ri->ri_owner = owner; @@ -2778,3 +2780,20 @@ const struct xfs_owner_info XFS_RMAP_OINFO_REFC = { const struct xfs_owner_info XFS_RMAP_OINFO_COW = { .oi_owner = XFS_RMAP_OWN_COW, }; + +int __init +xfs_rmap_intent_init_cache(void) +{ + xfs_rmap_intent_cache = kmem_cache_create("xfs_rmap_intent", + sizeof(struct xfs_rmap_intent), + 0, 0, NULL); + + return xfs_rmap_intent_cache != NULL ? 0 : -ENOMEM; +} + +void +xfs_rmap_intent_destroy_cache(void) +{ + kmem_cache_destroy(xfs_rmap_intent_cache); + xfs_rmap_intent_cache = NULL; +} diff --git a/libxfs/xfs_rmap.h b/libxfs/xfs_rmap.h index 85dd98ac..b718ebed 100644 --- a/libxfs/xfs_rmap.h +++ b/libxfs/xfs_rmap.h @@ -215,4 +215,9 @@ extern const struct xfs_owner_info XFS_RMAP_OINFO_INODES; extern const struct xfs_owner_info XFS_RMAP_OINFO_REFC; extern const struct xfs_owner_info XFS_RMAP_OINFO_COW; +extern struct kmem_cache *xfs_rmap_intent_cache; + +int __init xfs_rmap_intent_init_cache(void); +void xfs_rmap_intent_destroy_cache(void); + #endif /* __XFS_RMAP_H__ */ From patchwork Thu Jan 20 00:27:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12718006 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55A09C433F5 for ; Thu, 20 Jan 2022 00:27:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357765AbiATA1M (ORCPT ); Wed, 19 Jan 2022 19:27:12 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:48742 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbiATA1M (ORCPT ); Wed, 19 Jan 2022 19:27:12 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CF80BB8180B for ; Thu, 20 Jan 2022 00:27:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83EF2C004E1; Thu, 20 Jan 2022 00:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638429; bh=Y0+TJRca3sH+TWp5Hof+CCmua+3LVo8pvbRNkCu2f/s=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=U6zrQDW7+4UFJaAsuLy3aTKctOx+7T+V6BkC+S8pZmP0+eT1twRJtKd13GyoeIr1e BVPw0jnEPjSh5QAIwfSOuMd2KusZXrQPWEhQkrIOcS/JSQQbE13BPoEkeC33SK9oOV RC2UMsfgyDh668gpi2+nS/vP4rar9ykVZZ9SzpSlmu1D+yoJy7XPIrTVDT7OYhquiv 9rPG+CIq+1p/RD8SQwjnt/IS3Z5E4KVYMDWoeYz5jX7wXxU+ARTpEht6LM5swGQeBJ M+VLgoVgqIKHtBSyeuz6JnWKjiNLZETmidT+fSxQuxYTkyb6Byfee8p4yaSXrbqN4x uiRzyDwV4sqnw== Subject: [PATCH 43/48] xfs: rename xfs_bmap_add_free to xfs_free_extent_later From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:27:09 -0800 Message-ID: <164263842911.865554.6161469106705967318.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: c201d9ca5392b20f04882848a071025b0e194c17 xfs_bmap_add_free isn't a block mapping function; it schedules deferred freeing operations for a later point in a compound transaction chain. While it's primarily used by bunmapi, its use has expanded beyond that. Move it to xfs_alloc.c and rename the function since it's now general freeing functionality. Bring the slab cache bits in line with the way we handle the other intent items. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Signed-off-by: Darrick J. Wong --- libxfs/defer_item.c | 6 ++-- libxfs/init.c | 3 -- libxfs/libxfs_api_defs.h | 1 - libxfs/xfs_ag.c | 2 + libxfs/xfs_alloc.c | 71 +++++++++++++++++++++++++++++++++++++++++++--- libxfs/xfs_alloc.h | 32 +++++++++++++++++++++ libxfs/xfs_bmap.c | 55 +----------------------------------- libxfs/xfs_bmap.h | 28 ------------------ libxfs/xfs_bmap_btree.c | 2 + libxfs/xfs_defer.c | 5 +++ libxfs/xfs_ialloc.c | 4 +-- libxfs/xfs_refcount.c | 6 ++-- 12 files changed, 116 insertions(+), 99 deletions(-) diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index 1277469f..e7cba838 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -82,7 +82,7 @@ xfs_extent_free_finish_item( error = xfs_free_extent(tp, free->xefi_startblock, free->xefi_blockcount, &free->xefi_oinfo, XFS_AG_RESV_NONE); - kmem_cache_free(xfs_bmap_free_item_cache, free); + kmem_cache_free(xfs_extfree_item_cache, free); return error; } @@ -101,7 +101,7 @@ xfs_extent_free_cancel_item( struct xfs_extent_free_item *free; free = container_of(item, struct xfs_extent_free_item, xefi_list); - kmem_cache_free(xfs_bmap_free_item_cache, free); + kmem_cache_free(xfs_extfree_item_cache, free); } const struct xfs_defer_op_type xfs_extent_free_defer_type = { @@ -139,7 +139,7 @@ xfs_agfl_free_finish_item( if (!error) error = xfs_free_agfl_block(tp, agno, agbno, agbp, &free->xefi_oinfo); - kmem_cache_free(xfs_bmap_free_item_cache, free); + kmem_cache_free(xfs_extfree_item_cache, free); return error; } diff --git a/libxfs/init.c b/libxfs/init.c index f6863f4c..94a80234 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -259,8 +259,6 @@ init_caches(void) abort(); } - xfs_bmap_free_item_cache = kmem_cache_create("xfs_bmap_free_item", - sizeof(struct xfs_extent_free_item), 0, 0, NULL); xfs_trans_cache = kmem_cache_create("xfs_trans", sizeof(struct xfs_trans), 0, 0, NULL); } @@ -276,7 +274,6 @@ destroy_kmem_caches(void) kmem_cache_destroy(xfs_da_state_cache); xfs_defer_destroy_item_caches(); xfs_btree_destroy_cur_caches(); - kmem_cache_destroy(xfs_bmap_free_item_cache); kmem_cache_destroy(xfs_trans_cache); } diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 8abbd231..064fb48c 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -36,7 +36,6 @@ #define xfs_attr_namecheck libxfs_attr_namecheck #define xfs_attr_set libxfs_attr_set -#define __xfs_bmap_add_free __libxfs_bmap_add_free #define xfs_bmapi_read libxfs_bmapi_read #define xfs_bmapi_write libxfs_bmapi_write #define xfs_bmap_last_offset libxfs_bmap_last_offset diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index c95e8b26..c8181d7f 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -850,7 +850,7 @@ xfs_ag_shrink_space( if (err2 != -ENOSPC) goto resv_err; - __xfs_bmap_add_free(*tpp, args.fsbno, delta, NULL, true); + __xfs_free_extent_later(*tpp, args.fsbno, delta, NULL, true); /* * Roll the transaction before trying to re-init the per-ag diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 06e870a8..f1da8292 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -23,7 +23,7 @@ #include "xfs_ag_resv.h" #include "xfs_bmap.h" -extern struct kmem_cache *xfs_bmap_free_item_cache; +struct kmem_cache *xfs_extfree_item_cache; struct workqueue_struct *xfs_alloc_wq; @@ -2436,7 +2436,7 @@ xfs_agfl_reset( /* * Defer an AGFL block free. This is effectively equivalent to - * xfs_bmap_add_free() with some special handling particular to AGFL blocks. + * xfs_free_extent_later() 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 @@ -2455,10 +2455,10 @@ xfs_defer_agfl_block( struct xfs_mount *mp = tp->t_mountp; struct xfs_extent_free_item *new; /* new element */ - ASSERT(xfs_bmap_free_item_cache != NULL); + ASSERT(xfs_extfree_item_cache != NULL); ASSERT(oinfo != NULL); - new = kmem_cache_alloc(xfs_bmap_free_item_cache, + new = kmem_cache_alloc(xfs_extfree_item_cache, GFP_KERNEL | __GFP_NOFAIL); new->xefi_startblock = XFS_AGB_TO_FSB(mp, agno, agbno); new->xefi_blockcount = 1; @@ -2470,6 +2470,52 @@ xfs_defer_agfl_block( xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_AGFL_FREE, &new->xefi_list); } +/* + * Add the extent to the list of extents to be free at transaction end. + * The list is maintained sorted (by block number). + */ +void +__xfs_free_extent_later( + struct xfs_trans *tp, + xfs_fsblock_t bno, + xfs_filblks_t len, + const struct xfs_owner_info *oinfo, + bool skip_discard) +{ + struct xfs_extent_free_item *new; /* new element */ +#ifdef DEBUG + struct xfs_mount *mp = tp->t_mountp; + xfs_agnumber_t agno; + xfs_agblock_t agbno; + + ASSERT(bno != NULLFSBLOCK); + ASSERT(len > 0); + ASSERT(len <= MAXEXTLEN); + ASSERT(!isnullstartblock(bno)); + agno = XFS_FSB_TO_AGNO(mp, bno); + agbno = XFS_FSB_TO_AGBNO(mp, bno); + ASSERT(agno < mp->m_sb.sb_agcount); + ASSERT(agbno < mp->m_sb.sb_agblocks); + ASSERT(len < mp->m_sb.sb_agblocks); + ASSERT(agbno + len <= mp->m_sb.sb_agblocks); +#endif + ASSERT(xfs_extfree_item_cache != NULL); + + new = kmem_cache_alloc(xfs_extfree_item_cache, + GFP_KERNEL | __GFP_NOFAIL); + new->xefi_startblock = bno; + new->xefi_blockcount = (xfs_extlen_t)len; + if (oinfo) + new->xefi_oinfo = *oinfo; + else + new->xefi_oinfo = XFS_RMAP_OINFO_SKIP_UPDATE; + new->xefi_skip_discard = skip_discard; + trace_xfs_bmap_free_defer(tp->t_mountp, + XFS_FSB_TO_AGNO(tp->t_mountp, bno), 0, + XFS_FSB_TO_AGBNO(tp->t_mountp, bno), len); + xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_FREE, &new->xefi_list); +} + #ifdef DEBUG /* * Check if an AGF has a free extent record whose length is equal to @@ -3495,3 +3541,20 @@ xfs_agfl_walk( return 0; } + +int __init +xfs_extfree_intent_init_cache(void) +{ + xfs_extfree_item_cache = kmem_cache_create("xfs_extfree_intent", + sizeof(struct xfs_extent_free_item), + 0, 0, NULL); + + return xfs_extfree_item_cache != NULL ? 0 : -ENOMEM; +} + +void +xfs_extfree_intent_destroy_cache(void) +{ + kmem_cache_destroy(xfs_extfree_item_cache); + xfs_extfree_item_cache = NULL; +} diff --git a/libxfs/xfs_alloc.h b/libxfs/xfs_alloc.h index 2f3f8c2e..b61aeb6f 100644 --- a/libxfs/xfs_alloc.h +++ b/libxfs/xfs_alloc.h @@ -248,4 +248,36 @@ xfs_buf_to_agfl_bno( return bp->b_addr; } +void __xfs_free_extent_later(struct xfs_trans *tp, xfs_fsblock_t bno, + xfs_filblks_t len, const struct xfs_owner_info *oinfo, + bool skip_discard); + +/* + * List of extents to be free "later". + * The list is kept sorted on xbf_startblock. + */ +struct xfs_extent_free_item { + struct list_head xefi_list; + xfs_fsblock_t xefi_startblock;/* starting fs block number */ + xfs_extlen_t xefi_blockcount;/* number of blocks in extent */ + bool xefi_skip_discard; + struct xfs_owner_info xefi_oinfo; /* extent owner */ +}; + +static inline void +xfs_free_extent_later( + struct xfs_trans *tp, + xfs_fsblock_t bno, + xfs_filblks_t len, + const struct xfs_owner_info *oinfo) +{ + __xfs_free_extent_later(tp, bno, len, oinfo, false); +} + + +extern struct kmem_cache *xfs_extfree_item_cache; + +int __init xfs_extfree_intent_init_cache(void); +void xfs_extfree_intent_destroy_cache(void); + #endif /* __XFS_ALLOC_H__ */ diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index c261d119..8906265a 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -31,7 +31,6 @@ #include "xfs_refcount.h" struct kmem_cache *xfs_bmap_intent_cache; -struct kmem_cache *xfs_bmap_free_item_cache; /* * Miscellaneous helper functions @@ -515,56 +514,6 @@ xfs_bmap_validate_ret( #define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0) #endif /* DEBUG */ -/* - * bmap free list manipulation functions - */ - -/* - * Add the extent to the list of extents to be free at transaction end. - * The list is maintained sorted (by block number). - */ -void -__xfs_bmap_add_free( - struct xfs_trans *tp, - xfs_fsblock_t bno, - xfs_filblks_t len, - const struct xfs_owner_info *oinfo, - bool skip_discard) -{ - struct xfs_extent_free_item *new; /* new element */ -#ifdef DEBUG - struct xfs_mount *mp = tp->t_mountp; - xfs_agnumber_t agno; - xfs_agblock_t agbno; - - ASSERT(bno != NULLFSBLOCK); - ASSERT(len > 0); - ASSERT(len <= MAXEXTLEN); - ASSERT(!isnullstartblock(bno)); - agno = XFS_FSB_TO_AGNO(mp, bno); - agbno = XFS_FSB_TO_AGBNO(mp, bno); - ASSERT(agno < mp->m_sb.sb_agcount); - ASSERT(agbno < mp->m_sb.sb_agblocks); - ASSERT(len < mp->m_sb.sb_agblocks); - ASSERT(agbno + len <= mp->m_sb.sb_agblocks); -#endif - ASSERT(xfs_bmap_free_item_cache != NULL); - - new = kmem_cache_alloc(xfs_bmap_free_item_cache, - GFP_KERNEL | __GFP_NOFAIL); - new->xefi_startblock = bno; - new->xefi_blockcount = (xfs_extlen_t)len; - if (oinfo) - new->xefi_oinfo = *oinfo; - else - new->xefi_oinfo = XFS_RMAP_OINFO_SKIP_UPDATE; - new->xefi_skip_discard = skip_discard; - trace_xfs_bmap_free_defer(tp->t_mountp, - XFS_FSB_TO_AGNO(tp->t_mountp, bno), 0, - XFS_FSB_TO_AGBNO(tp->t_mountp, bno), len); - xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_FREE, &new->xefi_list); -} - /* * Inode fork format manipulation functions */ @@ -619,7 +568,7 @@ xfs_bmap_btree_to_extents( if ((error = xfs_btree_check_block(cur, cblock, 0, cbp))) return error; xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, whichfork); - xfs_bmap_add_free(cur->bc_tp, cbno, 1, &oinfo); + xfs_free_extent_later(cur->bc_tp, cbno, 1, &oinfo); ip->i_nblocks--; xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, -1L); xfs_trans_binval(tp, cbp); @@ -5290,7 +5239,7 @@ xfs_bmap_del_extent_real( if (xfs_is_reflink_inode(ip) && whichfork == XFS_DATA_FORK) { xfs_refcount_decrease_extent(tp, del); } else { - __xfs_bmap_add_free(tp, del->br_startblock, + __xfs_free_extent_later(tp, del->br_startblock, del->br_blockcount, NULL, (bflags & XFS_BMAPI_NODISCARD) || del->br_state == XFS_EXT_UNWRITTEN); diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index fa73a568..03d9aaf8 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -13,8 +13,6 @@ struct xfs_inode; struct xfs_mount; struct xfs_trans; -extern struct kmem_cache *xfs_bmap_free_item_cache; - /* * Argument structure for xfs_bmap_alloc. */ @@ -44,19 +42,6 @@ struct xfs_bmalloca { int flags; }; -/* - * List of extents to be free "later". - * The list is kept sorted on xbf_startblock. - */ -struct xfs_extent_free_item -{ - xfs_fsblock_t xefi_startblock;/* starting fs block number */ - xfs_extlen_t xefi_blockcount;/* number of blocks in extent */ - bool xefi_skip_discard; - struct list_head xefi_list; - struct xfs_owner_info xefi_oinfo; /* extent owner */ -}; - #define XFS_BMAP_MAX_NMAP 4 /* @@ -189,9 +174,6 @@ unsigned int xfs_bmap_compute_attr_offset(struct xfs_mount *mp); int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd); void xfs_bmap_local_to_extents_empty(struct xfs_trans *tp, struct xfs_inode *ip, int whichfork); -void __xfs_bmap_add_free(struct xfs_trans *tp, xfs_fsblock_t bno, - xfs_filblks_t len, const struct xfs_owner_info *oinfo, - bool skip_discard); void xfs_bmap_compute_maxlevels(struct xfs_mount *mp, int whichfork); int xfs_bmap_first_unused(struct xfs_trans *tp, struct xfs_inode *ip, xfs_extlen_t len, xfs_fileoff_t *unused, int whichfork); @@ -239,16 +221,6 @@ int xfs_bmap_add_extent_unwritten_real(struct xfs_trans *tp, struct xfs_iext_cursor *icur, struct xfs_btree_cur **curp, struct xfs_bmbt_irec *new, int *logflagsp); -static inline void -xfs_bmap_add_free( - struct xfs_trans *tp, - xfs_fsblock_t bno, - xfs_filblks_t len, - const struct xfs_owner_info *oinfo) -{ - __xfs_bmap_add_free(tp, bno, len, oinfo, false); -} - enum xfs_bmap_intent_type { XFS_BMAP_MAP = 1, XFS_BMAP_UNMAP, diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c index 8e850751..ba239d6e 100644 --- a/libxfs/xfs_bmap_btree.c +++ b/libxfs/xfs_bmap_btree.c @@ -286,7 +286,7 @@ xfs_bmbt_free_block( struct xfs_owner_info oinfo; xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, cur->bc_ino.whichfork); - xfs_bmap_add_free(cur->bc_tp, fsbno, 1, &oinfo); + xfs_free_extent_later(cur->bc_tp, fsbno, 1, &oinfo); ip->i_nblocks--; xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index f71bb055..ece44692 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -17,6 +17,7 @@ #include "xfs_rmap.h" #include "xfs_refcount.h" #include "xfs_bmap.h" +#include "xfs_alloc.h" static struct kmem_cache *xfs_defer_pending_cache; @@ -844,6 +845,9 @@ xfs_defer_init_item_caches(void) if (error) goto err; error = xfs_bmap_intent_init_cache(); + if (error) + goto err; + error = xfs_extfree_intent_init_cache(); if (error) goto err; @@ -857,6 +861,7 @@ xfs_defer_init_item_caches(void) void xfs_defer_destroy_item_caches(void) { + xfs_extfree_intent_destroy_cache(); xfs_bmap_intent_destroy_cache(); xfs_refcount_intent_destroy_cache(); xfs_rmap_intent_destroy_cache(); diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index b18ddc4e..82d6a3e8 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -1822,7 +1822,7 @@ xfs_difree_inode_chunk( if (!xfs_inobt_issparse(rec->ir_holemask)) { /* not sparse, calculate extent info directly */ - xfs_bmap_add_free(tp, XFS_AGB_TO_FSB(mp, agno, sagbno), + xfs_free_extent_later(tp, XFS_AGB_TO_FSB(mp, agno, sagbno), M_IGEO(mp)->ialloc_blks, &XFS_RMAP_OINFO_INODES); return; @@ -1867,7 +1867,7 @@ xfs_difree_inode_chunk( ASSERT(agbno % mp->m_sb.sb_spino_align == 0); ASSERT(contigblk % mp->m_sb.sb_spino_align == 0); - xfs_bmap_add_free(tp, XFS_AGB_TO_FSB(mp, agno, agbno), + xfs_free_extent_later(tp, XFS_AGB_TO_FSB(mp, agno, agbno), contigblk, &XFS_RMAP_OINFO_INODES); /* reset range to current bit and carry on... */ diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index da3cd7d5..6bc43f44 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -975,7 +975,7 @@ xfs_refcount_adjust_extents( fsbno = XFS_AGB_TO_FSB(cur->bc_mp, cur->bc_ag.pag->pag_agno, tmp.rc_startblock); - xfs_bmap_add_free(cur->bc_tp, fsbno, + xfs_free_extent_later(cur->bc_tp, fsbno, tmp.rc_blockcount, oinfo); } @@ -1020,7 +1020,7 @@ xfs_refcount_adjust_extents( fsbno = XFS_AGB_TO_FSB(cur->bc_mp, cur->bc_ag.pag->pag_agno, ext.rc_startblock); - xfs_bmap_add_free(cur->bc_tp, fsbno, ext.rc_blockcount, + xfs_free_extent_later(cur->bc_tp, fsbno, ext.rc_blockcount, oinfo); } @@ -1743,7 +1743,7 @@ xfs_refcount_recover_cow_leftovers( rr->rr_rrec.rc_blockcount); /* Free the block. */ - xfs_bmap_add_free(tp, fsb, rr->rr_rrec.rc_blockcount, NULL); + xfs_free_extent_later(tp, fsb, rr->rr_rrec.rc_blockcount, NULL); error = xfs_trans_commit(tp); if (error) From patchwork Thu Jan 20 00:27:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12718007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01166C433EF for ; Thu, 20 Jan 2022 00:27:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357632AbiATA1S (ORCPT ); Wed, 19 Jan 2022 19:27:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbiATA1S (ORCPT ); Wed, 19 Jan 2022 19:27:18 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6306C061574 for ; Wed, 19 Jan 2022 16:27:17 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6C442B81A85 for ; Thu, 20 Jan 2022 00:27:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18417C004E1; Thu, 20 Jan 2022 00:27:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638435; bh=fAWy2s2hCAoAa/NfjC6pZJBjp/mgkOvHhOFPFu93Zmk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=cMEKrU13ZtahvsHVQhb0U8usIlYxNq+cGjUrU7qZJ3UNeOlT3haIj9Q1bKN029SC2 9q6rmMa0cGA+4U6hmF4HpJls17XkabWRHMTnfyXV4Ljn8Vg+8dQcv/kd7HAYLCBdyF x17ivaKMIhj2lMeL2/57rCpPrtxmEvfrasGCnm0wiUxLYq0K1iZl0fccveKOV6nANm Ddcvhwvo8jnXAvAqE3Sox+WWrJ1mkx11lZh0Z7tVQBvy+KTrDKVug5OKGElcl2zExy LZI7S9iWQ4FledRUrZSdr0f7vkM5L2uCbnIcu6VtsDwftSdaPQxbwEaK10RZ3cxuoL OhXuwPtkzu6qQ== Subject: [PATCH 44/48] xfs: reduce the size of struct xfs_extent_free_item From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:27:14 -0800 Message-ID: <164263843473.865554.8468624471819753623.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: b3b5ff412ab04afd99173bb12d3cc146ee478ae7 We only use EFIs to free metadata blocks -- not regular data/attr fork extents. Remove all the fields that we never use, for a net reduction of 16 bytes. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Signed-off-by: Darrick J. Wong --- libxfs/defer_item.c | 14 ++++++++++---- libxfs/xfs_alloc.c | 25 ++++++++++++++++--------- libxfs/xfs_alloc.h | 8 ++++++-- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index e7cba838..d82ce7e0 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -75,13 +75,18 @@ xfs_extent_free_finish_item( struct list_head *item, struct xfs_btree_cur **state) { + struct xfs_owner_info oinfo = { }; struct xfs_extent_free_item *free; int error; free = container_of(item, struct xfs_extent_free_item, xefi_list); + oinfo.oi_owner = free->xefi_owner; + if (free->xefi_flags & XFS_EFI_ATTR_FORK) + oinfo.oi_flags |= XFS_OWNER_INFO_ATTR_FORK; + if (free->xefi_flags & XFS_EFI_BMBT_BLOCK) + oinfo.oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK; error = xfs_free_extent(tp, free->xefi_startblock, - free->xefi_blockcount, &free->xefi_oinfo, - XFS_AG_RESV_NONE); + free->xefi_blockcount, &oinfo, XFS_AG_RESV_NONE); kmem_cache_free(xfs_extfree_item_cache, free); return error; } @@ -123,6 +128,7 @@ xfs_agfl_free_finish_item( struct list_head *item, struct xfs_btree_cur **state) { + struct xfs_owner_info oinfo = { }; struct xfs_mount *mp = tp->t_mountp; struct xfs_extent_free_item *free; struct xfs_buf *agbp; @@ -134,11 +140,11 @@ xfs_agfl_free_finish_item( ASSERT(free->xefi_blockcount == 1); agno = XFS_FSB_TO_AGNO(mp, free->xefi_startblock); agbno = XFS_FSB_TO_AGBNO(mp, free->xefi_startblock); + oinfo.oi_owner = free->xefi_owner; error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp); if (!error) - error = xfs_free_agfl_block(tp, agno, agbno, agbp, - &free->xefi_oinfo); + error = xfs_free_agfl_block(tp, agno, agbno, agbp, &oinfo); kmem_cache_free(xfs_extfree_item_cache, free); return error; } diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index f1da8292..1d5aa67f 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -2458,12 +2458,11 @@ xfs_defer_agfl_block( ASSERT(xfs_extfree_item_cache != NULL); ASSERT(oinfo != NULL); - new = kmem_cache_alloc(xfs_extfree_item_cache, + new = kmem_cache_zalloc(xfs_extfree_item_cache, GFP_KERNEL | __GFP_NOFAIL); new->xefi_startblock = XFS_AGB_TO_FSB(mp, agno, agbno); new->xefi_blockcount = 1; - new->xefi_oinfo = *oinfo; - new->xefi_skip_discard = false; + new->xefi_owner = oinfo->oi_owner; trace_xfs_agfl_free_defer(mp, agno, 0, agbno, 1); @@ -2501,15 +2500,23 @@ __xfs_free_extent_later( #endif ASSERT(xfs_extfree_item_cache != NULL); - new = kmem_cache_alloc(xfs_extfree_item_cache, + new = kmem_cache_zalloc(xfs_extfree_item_cache, GFP_KERNEL | __GFP_NOFAIL); new->xefi_startblock = bno; new->xefi_blockcount = (xfs_extlen_t)len; - if (oinfo) - new->xefi_oinfo = *oinfo; - else - new->xefi_oinfo = XFS_RMAP_OINFO_SKIP_UPDATE; - new->xefi_skip_discard = skip_discard; + if (skip_discard) + new->xefi_flags |= XFS_EFI_SKIP_DISCARD; + if (oinfo) { + ASSERT(oinfo->oi_offset == 0); + + if (oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK) + new->xefi_flags |= XFS_EFI_ATTR_FORK; + if (oinfo->oi_flags & XFS_OWNER_INFO_BMBT_BLOCK) + new->xefi_flags |= XFS_EFI_BMBT_BLOCK; + new->xefi_owner = oinfo->oi_owner; + } else { + new->xefi_owner = XFS_RMAP_OWN_NULL; + } trace_xfs_bmap_free_defer(tp->t_mountp, XFS_FSB_TO_AGNO(tp->t_mountp, bno), 0, XFS_FSB_TO_AGBNO(tp->t_mountp, bno), len); diff --git a/libxfs/xfs_alloc.h b/libxfs/xfs_alloc.h index b61aeb6f..1c14a0b1 100644 --- a/libxfs/xfs_alloc.h +++ b/libxfs/xfs_alloc.h @@ -258,12 +258,16 @@ void __xfs_free_extent_later(struct xfs_trans *tp, xfs_fsblock_t bno, */ struct xfs_extent_free_item { struct list_head xefi_list; + uint64_t xefi_owner; xfs_fsblock_t xefi_startblock;/* starting fs block number */ xfs_extlen_t xefi_blockcount;/* number of blocks in extent */ - bool xefi_skip_discard; - struct xfs_owner_info xefi_oinfo; /* extent owner */ + unsigned int xefi_flags; }; +#define XFS_EFI_SKIP_DISCARD (1U << 0) /* don't issue discard */ +#define XFS_EFI_ATTR_FORK (1U << 1) /* freeing attr fork block */ +#define XFS_EFI_BMBT_BLOCK (1U << 2) /* freeing bmap btree block */ + static inline void xfs_free_extent_later( struct xfs_trans *tp, From patchwork Thu Jan 20 00:27:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12718008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F30BCC433F5 for ; Thu, 20 Jan 2022 00:27:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231437AbiATA1Y (ORCPT ); Wed, 19 Jan 2022 19:27:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357781AbiATA1X (ORCPT ); Wed, 19 Jan 2022 19:27:23 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40780C061574 for ; Wed, 19 Jan 2022 16:27:23 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EF768B81A7C for ; Thu, 20 Jan 2022 00:27:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9538AC004E1; Thu, 20 Jan 2022 00:27:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638440; bh=CvGyY4kYHQ2QgG/aQ1XqG749GiCdgekr2C81md+pAXY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=XiFT6rpi/lAOV1hxNkfPyd9nCr5L0vXVTAc4d3LH9gZ2wwtHcNjF+6ZiU7jN3MjWm RGYscBw+amoImS3lCAP0gYF6cs0G+AsLRGkbDEgGNaNuS0/VezD/V2TW6grKj6LtnB YigywOw/lnBUzSLd9MF2Hqnum3ZWzzIBtnhgqp1eINQWkJlEvT+x5fl+0sZEIN2BsA RFcC3h2qipGCO6j+Zu4EBj57iqjs+9d+h9HnOqlvzqevTEePXQLDbQxjN6K25Iqxbp 23VQO9i2x2apyVZhpRVLJ6EMEsPmqXSA72JnLTe+S6HfSlaqzqHU0diaeJ8Vbqx734 gcGOIV+PzRUTw== Subject: [PATCH 45/48] xfs: remove unused parameter from refcount code From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:27:20 -0800 Message-ID: <164263844028.865554.10944114276804321111.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: c04c51c524697cd68d668d595f8ebc381ffe426b The owner info parameter is always NULL, so get rid of the parameter. Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Signed-off-by: Darrick J. Wong --- libxfs/xfs_refcount.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 6bc43f44..076752ce 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -917,8 +917,7 @@ xfs_refcount_adjust_extents( struct xfs_btree_cur *cur, xfs_agblock_t *agbno, xfs_extlen_t *aglen, - enum xfs_refc_adjust_op adj, - struct xfs_owner_info *oinfo) + enum xfs_refc_adjust_op adj) { struct xfs_refcount_irec ext, tmp; int error; @@ -976,7 +975,7 @@ xfs_refcount_adjust_extents( cur->bc_ag.pag->pag_agno, tmp.rc_startblock); xfs_free_extent_later(cur->bc_tp, fsbno, - tmp.rc_blockcount, oinfo); + tmp.rc_blockcount, NULL); } (*agbno) += tmp.rc_blockcount; @@ -1020,8 +1019,8 @@ xfs_refcount_adjust_extents( fsbno = XFS_AGB_TO_FSB(cur->bc_mp, cur->bc_ag.pag->pag_agno, ext.rc_startblock); - xfs_free_extent_later(cur->bc_tp, fsbno, ext.rc_blockcount, - oinfo); + xfs_free_extent_later(cur->bc_tp, fsbno, + ext.rc_blockcount, NULL); } skip: @@ -1049,8 +1048,7 @@ xfs_refcount_adjust( xfs_extlen_t aglen, xfs_agblock_t *new_agbno, xfs_extlen_t *new_aglen, - enum xfs_refc_adjust_op adj, - struct xfs_owner_info *oinfo) + enum xfs_refc_adjust_op adj) { bool shape_changed; int shape_changes = 0; @@ -1093,8 +1091,7 @@ xfs_refcount_adjust( cur->bc_ag.refc.shape_changes++; /* Now that we've taken care of the ends, adjust the middle extents */ - error = xfs_refcount_adjust_extents(cur, new_agbno, new_aglen, - adj, oinfo); + error = xfs_refcount_adjust_extents(cur, new_agbno, new_aglen, adj); if (error) goto out_error; @@ -1189,12 +1186,12 @@ xfs_refcount_finish_one( switch (type) { case XFS_REFCOUNT_INCREASE: error = xfs_refcount_adjust(rcur, bno, blockcount, &new_agbno, - new_len, XFS_REFCOUNT_ADJUST_INCREASE, NULL); + new_len, XFS_REFCOUNT_ADJUST_INCREASE); *new_fsb = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno); break; case XFS_REFCOUNT_DECREASE: error = xfs_refcount_adjust(rcur, bno, blockcount, &new_agbno, - new_len, XFS_REFCOUNT_ADJUST_DECREASE, NULL); + new_len, XFS_REFCOUNT_ADJUST_DECREASE); *new_fsb = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno); break; case XFS_REFCOUNT_ALLOC_COW: From patchwork Thu Jan 20 00:27:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12718009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30980C433F5 for ; Thu, 20 Jan 2022 00:27:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357781AbiATA13 (ORCPT ); Wed, 19 Jan 2022 19:27:29 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:48824 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357790AbiATA12 (ORCPT ); Wed, 19 Jan 2022 19:27:28 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 616D5B81A85 for ; Thu, 20 Jan 2022 00:27:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C555C340ED; Thu, 20 Jan 2022 00:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638446; bh=OUqDkAvdCzmaPUJc8Kg6qJKz2fkcWfq2TrBq9wMl/0c=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=KVj7uWUWieABNerDDAKRXO8Dv3Rv0Eau7F3qsYxxDvp9elQamHmdWjlzkqGkShOMi +Se0OuWn74bCCm6zWRCMUJKvdLo0+bDJ/ta880U3B46zyFCRvaAFXo7f01/VxUdVsH Hf/7ZziTZd5B/LQ9GyAPvxKR016Npqs/RfA7G1hm6ZaDaqA67vNuUKvWLjChaqOE48 IUYH4UI8l/KJzs3+Q/IeHumsVZTwPI8+Hoe6IvIg/tSbMlW38elryygEnagAg5WKmx EsheuozIP7yM13YN0bfwG1gR7SYT5bcqjiM4hn8kH45KlQlNA7P/2eC7unTLsy4F7f mPIB4szR5RenA== Subject: [PATCH 46/48] xfs: use swap() to make dabtree code cleaner From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Zeal Robot , Yang Guang , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:27:25 -0800 Message-ID: <164263844581.865554.18015260649075833934.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Yang Guang Source kernel commit: d3d48fb93ba48bd3cb5c564235bfbc96fe4d0d7f Use the macro 'swap()' defined in 'include/linux/minmax.h' to avoid opencoding it. Reported-by: Zeal Robot Signed-off-by: Yang Guang Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- libxfs/xfs_da_btree.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c index 50f3ec66..1f39c108 100644 --- a/libxfs/xfs_da_btree.c +++ b/libxfs/xfs_da_btree.c @@ -861,7 +861,6 @@ xfs_da3_node_rebalance( { struct xfs_da_intnode *node1; struct xfs_da_intnode *node2; - struct xfs_da_intnode *tmpnode; struct xfs_da_node_entry *btree1; struct xfs_da_node_entry *btree2; struct xfs_da_node_entry *btree_s; @@ -891,9 +890,7 @@ xfs_da3_node_rebalance( ((be32_to_cpu(btree2[0].hashval) < be32_to_cpu(btree1[0].hashval)) || (be32_to_cpu(btree2[nodehdr2.count - 1].hashval) < be32_to_cpu(btree1[nodehdr1.count - 1].hashval)))) { - tmpnode = node1; - node1 = node2; - node2 = tmpnode; + swap(node1, node2); xfs_da3_node_hdr_from_disk(dp->i_mount, &nodehdr1, node1); xfs_da3_node_hdr_from_disk(dp->i_mount, &nodehdr2, node2); btree1 = nodehdr1.btree; From patchwork Thu Jan 20 00:27:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12718010 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69BFFC433EF for ; Thu, 20 Jan 2022 00:27:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357783AbiATA1d (ORCPT ); Wed, 19 Jan 2022 19:27:33 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:34394 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345552AbiATA1c (ORCPT ); Wed, 19 Jan 2022 19:27:32 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4B73061512 for ; Thu, 20 Jan 2022 00:27:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2AA2C004E1; Thu, 20 Jan 2022 00:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638451; bh=cadZE/SvhtXDl0TUEfnnb8JpU0nSL/2yE1Rk1o+m7kg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=U2EHuncK/HJ9ZS0IPhType0Mb+8IP1bP6scu9HhFu/grR7XB3EkQKmdOHwtAM2xd3 8+wi6qlPs13g0f4MBj6kNfIIvStlRHcbuks+5/Ru4dnoLpwBRIPlHbayqF68kmsHd2 Zk76aQTJiBBuBHYb705T3AJsB45/dNkT/9P58dN7COOmh8kvkkEBoRTcnVbasQMxKv OrAyTQQyBnAT36j+UeVjSiS9SiesH7vuvWLsvERCgNuzv7MnjkR5IBIqHZMgHFvsKn F0ZZRzT4ZHuONof1pDCI+mPVsuR6dRYjRRSD3jB3Ss64jNh+OEt3mG22eX0xrcNuBX LlBURMyaKnhTQ== Subject: [PATCH 47/48] xfs: Fix the free logic of state in xfs_attr_node_hasname From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Yang Xu , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:27:31 -0800 Message-ID: <164263845135.865554.611783670909878436.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Yang Xu Source kernel commit: a1de97fe296c52eafc6590a3506f4bbd44ecb19a When testing xfstests xfs/126 on lastest upstream kernel, it will hang on some machine. Adding a getxattr operation after xattr corrupted, I can reproduce it 100%. The deadlock as below: [983.923403] task:setfattr state:D stack: 0 pid:17639 ppid: 14687 flags:0x00000080 [ 983.923405] Call Trace: [ 983.923410] __schedule+0x2c4/0x700 [ 983.923412] schedule+0x37/0xa0 [ 983.923414] schedule_timeout+0x274/0x300 [ 983.923416] __down+0x9b/0xf0 [ 983.923451] ? xfs_buf_find.isra.29+0x3c8/0x5f0 [xfs] [ 983.923453] down+0x3b/0x50 [ 983.923471] xfs_buf_lock+0x33/0xf0 [xfs] [ 983.923490] xfs_buf_find.isra.29+0x3c8/0x5f0 [xfs] [ 983.923508] xfs_buf_get_map+0x4c/0x320 [xfs] [ 983.923525] xfs_buf_read_map+0x53/0x310 [xfs] [ 983.923541] ? xfs_da_read_buf+0xcf/0x120 [xfs] [ 983.923560] xfs_trans_read_buf_map+0x1cf/0x360 [xfs] [ 983.923575] ? xfs_da_read_buf+0xcf/0x120 [xfs] [ 983.923590] xfs_da_read_buf+0xcf/0x120 [xfs] [ 983.923606] xfs_da3_node_read+0x1f/0x40 [xfs] [ 983.923621] xfs_da3_node_lookup_int+0x69/0x4a0 [xfs] [ 983.923624] ? kmem_cache_alloc+0x12e/0x270 [ 983.923637] xfs_attr_node_hasname+0x6e/0xa0 [xfs] [ 983.923651] xfs_has_attr+0x6e/0xd0 [xfs] [ 983.923664] xfs_attr_set+0x273/0x320 [xfs] [ 983.923683] xfs_xattr_set+0x87/0xd0 [xfs] [ 983.923686] __vfs_removexattr+0x4d/0x60 [ 983.923688] __vfs_removexattr_locked+0xac/0x130 [ 983.923689] vfs_removexattr+0x4e/0xf0 [ 983.923690] removexattr+0x4d/0x80 [ 983.923693] ? __check_object_size+0xa8/0x16b [ 983.923695] ? strncpy_from_user+0x47/0x1a0 [ 983.923696] ? getname_flags+0x6a/0x1e0 [ 983.923697] ? _cond_resched+0x15/0x30 [ 983.923699] ? __sb_start_write+0x1e/0x70 [ 983.923700] ? mnt_want_write+0x28/0x50 [ 983.923701] path_removexattr+0x9b/0xb0 [ 983.923702] __x64_sys_removexattr+0x17/0x20 [ 983.923704] do_syscall_64+0x5b/0x1a0 [ 983.923705] entry_SYSCALL_64_after_hwframe+0x65/0xca [ 983.923707] RIP: 0033:0x7f080f10ee1b When getxattr calls xfs_attr_node_get function, xfs_da3_node_lookup_int fails with EFSCORRUPTED in xfs_attr_node_hasname because we have use blocktrash to random it in xfs/126. So it free state in internal and xfs_attr_node_get doesn't do xfs_buf_trans release job. Then subsequent removexattr will hang because of it. This bug was introduced by kernel commit 07120f1abdff ("xfs: Add xfs_has_attr and subroutines"). It adds xfs_attr_node_hasname helper and said caller will be responsible for freeing the state in this case. But xfs_attr_node_hasname will free state itself instead of caller if xfs_da3_node_lookup_int fails. Fix this bug by moving the step of free state into caller. Also, use "goto error/out" instead of returning error directly in xfs_attr_node_addname_find_attr and xfs_attr_node_removename_setup function because we should free state ourselves. Fixes: 07120f1abdff ("xfs: Add xfs_has_attr and subroutines") Signed-off-by: Yang Xu Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- libxfs/xfs_attr.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index e44b68e1..9a9da459 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -1076,22 +1076,19 @@ xfs_attr_node_hasname( int retval, error; state = xfs_da_state_alloc(args); - if (statep != NULL) - *statep = NULL; - - /* - * Search to see if name exists, and get back a pointer to it. - */ - error = xfs_da3_node_lookup_int(state, &retval); - if (error) { - xfs_da_state_free(state); - return error; - } - if (statep != NULL) *statep = state; - else + + /* + * Search to see if name exists, and get back a pointer to it. + */ + error = xfs_da3_node_lookup_int(state, &retval); + if (error) + retval = error; + + if (!statep) xfs_da_state_free(state); + return retval; } @@ -1112,7 +1109,7 @@ xfs_attr_node_addname_find_attr( */ retval = xfs_attr_node_hasname(args, &dac->da_state); if (retval != -ENOATTR && retval != -EEXIST) - return retval; + goto error; if (retval == -ENOATTR && (args->attr_flags & XATTR_REPLACE)) goto error; @@ -1337,7 +1334,7 @@ int xfs_attr_node_removename_setup( error = xfs_attr_node_hasname(args, state); if (error != -EEXIST) - return error; + goto out; error = 0; ASSERT((*state)->path.blk[(*state)->path.active - 1].bp != NULL); From patchwork Thu Jan 20 00:27:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12718011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7EDBC433EF for ; Thu, 20 Jan 2022 00:27:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345544AbiATA1i (ORCPT ); Wed, 19 Jan 2022 19:27:38 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:34448 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345543AbiATA1i (ORCPT ); Wed, 19 Jan 2022 19:27:38 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C4CF661511 for ; Thu, 20 Jan 2022 00:27:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27140C004E1; Thu, 20 Jan 2022 00:27:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642638457; bh=WAqXzCNen8KeQSBhNG1jkqCPzWsEewgC2lQdsPPQ5RU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=h215dYAnsmKcFzscL4wk1/Zhd//uKBjZF4hYrCeGixAUkL80N5WEvZgLXnrzVdJcr 9p+lfkLMB0215aKwLNmlE2DFWPSmljJ/ODZfNtuXkeO/rWA/1DEyLKEiec1xZleW9q 6NnCVVXru+R317KlKppT2m85477cI0rOObELxUHRbRwS9omLqvBQOIIlMLj6CbDr6P hy1dBsF5mVGzm9d0WeTwjhVptiZNEGI7Ob8ZKsQcmDNn6HcsnVi6U1tnJupsJ6FMmq m7s7tyUIlqZqd6HgPc0FwTeL7wGO6BCZsn5hxunCGAluEz1EnE0bekkX2i7+ZW3om2 PWJMEDG69Lhag== Subject: [PATCH 48/48] libxfs: remove kernel stubs from xfs_shared.h From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Eric Sandeen , linux-xfs@vger.kernel.org Date: Wed, 19 Jan 2022 16:27:36 -0800 Message-ID: <164263845686.865554.7985182153330834877.stgit@magnolia> In-Reply-To: <164263819185.865554.6000499997543946756.stgit@magnolia> References: <164263819185.865554.6000499997543946756.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong The kernel stubs added to xfs_shared.h don't belong there, and are mostly unnecessary with the #ifdef __KERNEL__ bits added to the xfs_ag.[ch] files. Move the one remaining needed stub in libxfs_priv.h. Signed-off-by: Eric Sandeen Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- libxfs/libxfs_priv.h | 2 ++ libxfs/xfs_shared.h | 20 -------------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 67d9a8bb..167bd8c0 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -75,6 +75,8 @@ extern struct kmem_cache *xfs_trans_cache; /* fake up kernel's iomap, (not) used in xfs_bmap.[ch] */ struct iomap; +#define cancel_delayed_work_sync(work) do { } while(0) + #include "xfs_cksum.h" /* diff --git a/libxfs/xfs_shared.h b/libxfs/xfs_shared.h index bafee48c..25c4cab5 100644 --- a/libxfs/xfs_shared.h +++ b/libxfs/xfs_shared.h @@ -180,24 +180,4 @@ struct xfs_ino_geometry { }; -/* Faked up kernel bits */ -struct rb_root { -}; - -#define RB_ROOT (struct rb_root) { } - -typedef struct wait_queue_head { -} wait_queue_head_t; - -#define init_waitqueue_head(wqh) do { } while(0) - -struct rhashtable { -}; - -struct delayed_work { -}; - -#define INIT_DELAYED_WORK(work, func) do { } while(0) -#define cancel_delayed_work_sync(work) do { } while(0) - #endif /* __XFS_SHARED_H__ */