From patchwork Fri Mar 26 00:21:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12165261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE8FEC433C1 for ; Fri, 26 Mar 2021 00:22:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69F7B61A42 for ; Fri, 26 Mar 2021 00:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229639AbhCZAVl (ORCPT ); Thu, 25 Mar 2021 20:21:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:35066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230166AbhCZAVT (ORCPT ); Thu, 25 Mar 2021 20:21:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DC733619D3; Fri, 26 Mar 2021 00:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616718079; bh=SJP/YVcaIepGnVJ0PH+9yfWSD4b7hNQQ8/ziU0VnUxE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=jOf32yO7wdtPXGYal/jXmn109IehGg9dhvBZSNEGKPrXFMpUYwlZJn6tk0U9VQJWZ +Yucjk3pk7LXbePFnj9I7T/QNvrYatjX6seuc57tuUGWFbUkEg9+VJSwktEDjynGM6 zH2rs0BvSfmuzhP7PAxDhAJWY9xG9BT60XI0sAennz5pn9aAYr0EOdsP6NRDBcUkT+ op5mAldwUjvHv9aFbtlaQCEXDmd6SQPYo+4aUm3wM8pz7SIB0lD0/03GK7yaZii7Ai W2JsKlfKRbQ7SQ5Z7841VI0l8/gRAqePZX/KQIRMnMvwLpmioYQhDSbDXUBXN+UT9N cboBM95C/A9wA== Subject: [PATCH 1/6] xfs: use s_inodes in xfs_qm_dqrele_all_inodes From: "Darrick J. Wong" To: djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org, hch@infradead.org Date: Thu, 25 Mar 2021 17:21:18 -0700 Message-ID: <161671807853.621936.16639622639548774275.stgit@magnolia> In-Reply-To: <161671807287.621936.13471099564526590235.stgit@magnolia> References: <161671807287.621936.13471099564526590235.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 Using xfs_inode_walk in xfs_qm_dqrele_all_inodes is complete overkill, given that function simplify wants to iterate all live inodes known to the VFS. Just iterate over the s_inodes list. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_icache.c | 2 +- fs/xfs/xfs_icache.h | 2 ++ fs/xfs/xfs_qm_syscalls.c | 56 +++++++++++++++++++++++++++++----------------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index 3c81daca0e9a..9a307bb738bd 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -235,7 +235,7 @@ xfs_inode_clear_reclaim_tag( xfs_perag_clear_reclaim_tag(pag); } -static void +void xfs_inew_wait( struct xfs_inode *ip) { diff --git a/fs/xfs/xfs_icache.h b/fs/xfs/xfs_icache.h index d1fddb152420..d70d93c2bb10 100644 --- a/fs/xfs/xfs_icache.h +++ b/fs/xfs/xfs_icache.h @@ -78,4 +78,6 @@ int xfs_icache_inode_is_allocated(struct xfs_mount *mp, struct xfs_trans *tp, void xfs_blockgc_stop(struct xfs_mount *mp); void xfs_blockgc_start(struct xfs_mount *mp); +void xfs_inew_wait(struct xfs_inode *ip); + #endif diff --git a/fs/xfs/xfs_qm_syscalls.c b/fs/xfs/xfs_qm_syscalls.c index 11f1e2fbf22f..76efae956fa8 100644 --- a/fs/xfs/xfs_qm_syscalls.c +++ b/fs/xfs/xfs_qm_syscalls.c @@ -748,41 +748,27 @@ xfs_qm_scall_getquota_next( return error; } -STATIC int +static void xfs_dqrele_inode( struct xfs_inode *ip, - void *args) + uint flags) { - uint *flags = args; - - /* skip quota inodes */ - if (ip == ip->i_mount->m_quotainfo->qi_uquotaip || - ip == ip->i_mount->m_quotainfo->qi_gquotaip || - ip == ip->i_mount->m_quotainfo->qi_pquotaip) { - ASSERT(ip->i_udquot == NULL); - ASSERT(ip->i_gdquot == NULL); - ASSERT(ip->i_pdquot == NULL); - return 0; - } - xfs_ilock(ip, XFS_ILOCK_EXCL); - if ((*flags & XFS_UQUOTA_ACCT) && ip->i_udquot) { + if ((flags & XFS_UQUOTA_ACCT) && ip->i_udquot) { xfs_qm_dqrele(ip->i_udquot); ip->i_udquot = NULL; } - if ((*flags & XFS_GQUOTA_ACCT) && ip->i_gdquot) { + if ((flags & XFS_GQUOTA_ACCT) && ip->i_gdquot) { xfs_qm_dqrele(ip->i_gdquot); ip->i_gdquot = NULL; } - if ((*flags & XFS_PQUOTA_ACCT) && ip->i_pdquot) { + if ((flags & XFS_PQUOTA_ACCT) && ip->i_pdquot) { xfs_qm_dqrele(ip->i_pdquot); ip->i_pdquot = NULL; } xfs_iunlock(ip, XFS_ILOCK_EXCL); - return 0; } - /* * Go thru all the inodes in the file system, releasing their dquots. * @@ -794,7 +780,35 @@ xfs_qm_dqrele_all_inodes( struct xfs_mount *mp, uint flags) { + struct super_block *sb = mp->m_super; + struct inode *inode, *old_inode = NULL; + ASSERT(mp->m_quotainfo); - xfs_inode_walk(mp, XFS_INODE_WALK_INEW_WAIT, xfs_dqrele_inode, - &flags, XFS_ICI_NO_TAG); + + spin_lock(&sb->s_inode_list_lock); + list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { + struct xfs_inode *ip = XFS_I(inode); + + if (XFS_FORCED_SHUTDOWN(mp)) + break; + if (xfs_is_quota_inode(&mp->m_sb, ip->i_ino)) + continue; + if (xfs_iflags_test(ip, XFS_IRECLAIMABLE | XFS_IRECLAIM)) + continue; + if (!igrab(inode)) + continue; + spin_unlock(&sb->s_inode_list_lock); + + iput(old_inode); + old_inode = inode; + + if (xfs_iflags_test(ip, XFS_INEW)) + xfs_inew_wait(ip); + xfs_dqrele_inode(ip, flags); + + spin_lock(&sb->s_inode_list_lock); + } + spin_unlock(&sb->s_inode_list_lock); + + iput(old_inode); } From patchwork Fri Mar 26 00:21:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12165263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E882BC433E3 for ; Fri, 26 Mar 2021 00:22:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC49D619D3 for ; Fri, 26 Mar 2021 00:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230105AbhCZAVn (ORCPT ); Thu, 25 Mar 2021 20:21:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:35104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230202AbhCZAVY (ORCPT ); Thu, 25 Mar 2021 20:21:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6E56761A3C; Fri, 26 Mar 2021 00:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616718084; bh=AJ72v+tVpnKcjiU4hWQoFbYR1+z4k0YugYA9S+c89pM=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=D3rjGXYSiFCKPA3CBsJBhSbXlAXhioaczWNRDAEEKIq1VMMBKIEa3LXe/FfT2IemC CHpwYFrKWk0au/fgjbZFrzf0DskXUXQwYvbD59H3UMk+ntqlg+h5Mx2C1MxlAFgcwF U/ZzngP+aMfGCCb6a93Jig7iOiOgQL6aRetSoBxX7aUFjENkPBmSJrEBanN83K70QH CYdSfIgGFzx0XQBN5k2AqSqr6NVNyOBtfwrePCZykBpU+92SV9tyaUgzFQPcOlsAOV WazWPsilGdKGdUHoKqlijmm9qRO2dmKv6DkKHhq8qoGppgtmqWKH8vso4QODYFetJd PK+2NPyrt/eIg== Subject: [PATCH 2/6] xfs: remove iter_flags parameter from xfs_inode_walk_* From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@infradead.org Date: Thu, 25 Mar 2021 17:21:24 -0700 Message-ID: <161671808412.621936.9290234722714661435.stgit@magnolia> In-Reply-To: <161671807287.621936.13471099564526590235.stgit@magnolia> References: <161671807287.621936.13471099564526590235.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 sole iter_flags is XFS_INODE_WALK_INEW_WAIT, and there are no users. Remove the flag, and the parameter, and all the code that used it. Since there are no longer any external callers of xfs_inode_walk, make it static. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_icache.c | 22 +++++++--------------- fs/xfs/xfs_icache.h | 9 --------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index 9a307bb738bd..16392e96be91 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -730,11 +730,9 @@ xfs_icache_inode_is_allocated( */ STATIC bool xfs_inode_walk_ag_grab( - struct xfs_inode *ip, - int flags) + struct xfs_inode *ip) { struct inode *inode = VFS_I(ip); - bool newinos = !!(flags & XFS_INODE_WALK_INEW_WAIT); ASSERT(rcu_read_lock_held()); @@ -744,8 +742,7 @@ xfs_inode_walk_ag_grab( goto out_unlock_noent; /* avoid new or reclaimable inodes. Leave for reclaim code to flush */ - if ((!newinos && __xfs_iflags_test(ip, XFS_INEW)) || - __xfs_iflags_test(ip, XFS_IRECLAIMABLE | XFS_IRECLAIM)) + if (__xfs_iflags_test(ip, XFS_INEW | XFS_IRECLAIMABLE | XFS_IRECLAIM)) goto out_unlock_noent; spin_unlock(&ip->i_flags_lock); @@ -772,7 +769,6 @@ xfs_inode_walk_ag_grab( STATIC int xfs_inode_walk_ag( struct xfs_perag *pag, - int iter_flags, int (*execute)(struct xfs_inode *ip, void *args), void *args, int tag) @@ -818,7 +814,7 @@ xfs_inode_walk_ag( for (i = 0; i < nr_found; i++) { struct xfs_inode *ip = batch[i]; - if (done || !xfs_inode_walk_ag_grab(ip, iter_flags)) + if (done || !xfs_inode_walk_ag_grab(ip)) batch[i] = NULL; /* @@ -846,9 +842,6 @@ xfs_inode_walk_ag( for (i = 0; i < nr_found; i++) { if (!batch[i]) continue; - if ((iter_flags & XFS_INODE_WALK_INEW_WAIT) && - xfs_iflags_test(batch[i], XFS_INEW)) - xfs_inew_wait(batch[i]); error = execute(batch[i], args); xfs_irele(batch[i]); if (error == -EAGAIN) { @@ -890,10 +883,9 @@ xfs_inode_walk_get_perag( * Call the @execute function on all incore inodes matching the radix tree * @tag. */ -int +static int xfs_inode_walk( struct xfs_mount *mp, - int iter_flags, int (*execute)(struct xfs_inode *ip, void *args), void *args, int tag) @@ -906,7 +898,7 @@ xfs_inode_walk( ag = 0; while ((pag = xfs_inode_walk_get_perag(mp, ag, tag))) { ag = pag->pag_agno + 1; - error = xfs_inode_walk_ag(pag, iter_flags, execute, args, tag); + error = xfs_inode_walk_ag(pag, execute, args, tag); xfs_perag_put(pag); if (error) { last_error = error; @@ -1618,7 +1610,7 @@ xfs_blockgc_worker( if (!sb_start_write_trylock(mp->m_super)) return; - error = xfs_inode_walk_ag(pag, 0, xfs_blockgc_scan_inode, NULL, + error = xfs_inode_walk_ag(pag, xfs_blockgc_scan_inode, NULL, XFS_ICI_BLOCKGC_TAG); if (error) xfs_info(mp, "AG %u preallocation gc worker failed, err=%d", @@ -1637,7 +1629,7 @@ xfs_blockgc_free_space( { trace_xfs_blockgc_free_space(mp, eofb, _RET_IP_); - return xfs_inode_walk(mp, 0, xfs_blockgc_scan_inode, eofb, + return xfs_inode_walk(mp, xfs_blockgc_scan_inode, eofb, XFS_ICI_BLOCKGC_TAG); } diff --git a/fs/xfs/xfs_icache.h b/fs/xfs/xfs_icache.h index d70d93c2bb10..d52c041093a3 100644 --- a/fs/xfs/xfs_icache.h +++ b/fs/xfs/xfs_icache.h @@ -34,11 +34,6 @@ struct xfs_eofblocks { #define XFS_IGET_DONTCACHE 0x4 #define XFS_IGET_INCORE 0x8 /* don't read from disk or reinit */ -/* - * flags for AG inode iterator - */ -#define XFS_INODE_WALK_INEW_WAIT 0x1 /* wait on new inodes */ - int xfs_iget(struct xfs_mount *mp, struct xfs_trans *tp, xfs_ino_t ino, uint flags, uint lock_flags, xfs_inode_t **ipp); @@ -68,10 +63,6 @@ void xfs_inode_clear_cowblocks_tag(struct xfs_inode *ip); void xfs_blockgc_worker(struct work_struct *work); -int xfs_inode_walk(struct xfs_mount *mp, int iter_flags, - int (*execute)(struct xfs_inode *ip, void *args), - void *args, int tag); - int xfs_icache_inode_is_allocated(struct xfs_mount *mp, struct xfs_trans *tp, xfs_ino_t ino, bool *inuse); From patchwork Fri Mar 26 00:21:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12165259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8E1FC433E2 for ; Fri, 26 Mar 2021 00:22:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A2E661A3C for ; Fri, 26 Mar 2021 00:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbhCZAVp (ORCPT ); Thu, 25 Mar 2021 20:21:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:35120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbhCZAVa (ORCPT ); Thu, 25 Mar 2021 20:21:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F35B6619F3; Fri, 26 Mar 2021 00:21:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616718090; bh=i3WPJ2W82O46E+4a3Y+EK8kHO7Brh1wMILD42+EvWnk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=OasdCv/8FTEL8xs0jkfcRPHCuWV4QKYXTXVrkDRpy2IGjwRNar4D4uJfH0075m+ud Yated+jxdBnX5QPzmsD1b34rLot9e05GhQTKScqzaSf+SpiPYys2i0W4cY8wT+z1Z5 0+vfe/Z3S9c2T2fUzjxP8mmaaKvg7WDtt+w1CP081bG99QPB0IM545t95g6giPsaFz xdrP2byy3rg9iXUu0rKGaIRSlBXqEUIZv/BOzPyRmM4qEPDSDUUjtDayK4phvdnhNf pkJ57fCEqBvjCYjmxLWF+ilZUKYJLVkxrf8YpYipDVDM/32BVCoXSDggPa5hQIA0qZ aWIA1zXUWfiiA== Subject: [PATCH 3/6] xfs: remove indirect calls from xfs_inode_walk{,_ag} From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@infradead.org Date: Thu, 25 Mar 2021 17:21:29 -0700 Message-ID: <161671808966.621936.3793779587892431825.stgit@magnolia> In-Reply-To: <161671807287.621936.13471099564526590235.stgit@magnolia> References: <161671807287.621936.13471099564526590235.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 turns out that there is a 1:1 mapping between the execute and tag parameters that are passed to xfs_inode_walk_ag: xfs_blockgc_scan_inode <=> XFS_ICI_BLOCKGC_TAG Since the only user of the inode walk function is the blockgc code, we don't need the tag parameter or the execute function pointer. The inode deferred inactivation changes in the next series will add a second tag:function pair, so we'll leave the tag parameter for now. For the price of a forward static declaration, we can eliminate the indirect function call. This likely has a negligible impact on performance (since the execute function runs transactions), but it also simplifies the function signature. Radix tree tags are unsigned ints, so fix the type usage for all those tags. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_sb.c | 2 + fs/xfs/libxfs/xfs_sb.h | 4 +- fs/xfs/xfs_icache.c | 77 ++++++++++++++++++++---------------------------- 3 files changed, 35 insertions(+), 48 deletions(-) diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index 60e6d255e5e2..f72f6d7fef33 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -61,7 +61,7 @@ struct xfs_perag * xfs_perag_get_tag( struct xfs_mount *mp, xfs_agnumber_t first, - int tag) + unsigned int tag) { struct xfs_perag *pag; int found; diff --git a/fs/xfs/libxfs/xfs_sb.h b/fs/xfs/libxfs/xfs_sb.h index f79f9dc632b6..e5f1c2d879eb 100644 --- a/fs/xfs/libxfs/xfs_sb.h +++ b/fs/xfs/libxfs/xfs_sb.h @@ -17,8 +17,8 @@ struct xfs_perag; * perag get/put wrappers for ref counting */ extern struct xfs_perag *xfs_perag_get(struct xfs_mount *, xfs_agnumber_t); -extern struct xfs_perag *xfs_perag_get_tag(struct xfs_mount *, xfs_agnumber_t, - int tag); +struct xfs_perag *xfs_perag_get_tag(struct xfs_mount *mp, xfs_agnumber_t agno, + unsigned int tag); extern void xfs_perag_put(struct xfs_perag *pag); extern int xfs_initialize_perag_data(struct xfs_mount *, xfs_agnumber_t); diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index 16392e96be91..f4c4f6e15d77 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -26,6 +26,9 @@ #include +/* Forward declarations to reduce indirect calls */ +static int xfs_blockgc_scan_inode(struct xfs_inode *ip, void *args); + /* * Allocate and initialise an xfs_inode. */ @@ -723,13 +726,17 @@ xfs_icache_inode_is_allocated( */ #define XFS_LOOKUP_BATCH 32 +/* Don't try to run block gc on an inode that's in any of these states. */ +#define XFS_BLOCKGC_INELIGIBLE_IFLAGS (XFS_INEW | \ + XFS_IRECLAIMABLE | \ + XFS_IRECLAIM) /* - * Decide if the given @ip is eligible to be a part of the inode walk, and - * grab it if so. Returns true if it's ready to go or false if we should just - * ignore it. + * Decide if the given @ip is eligible for garbage collection of speculative + * preallocations, and grab it if so. Returns true if it's ready to go or + * false if we should just ignore it. */ STATIC bool -xfs_inode_walk_ag_grab( +xfs_blockgc_grab( struct xfs_inode *ip) { struct inode *inode = VFS_I(ip); @@ -741,8 +748,7 @@ xfs_inode_walk_ag_grab( if (!ip->i_ino) goto out_unlock_noent; - /* avoid new or reclaimable inodes. Leave for reclaim code to flush */ - if (__xfs_iflags_test(ip, XFS_INEW | XFS_IRECLAIMABLE | XFS_IRECLAIM)) + if (__xfs_iflags_test(ip, XFS_BLOCKGC_INELIGIBLE_IFLAGS)) goto out_unlock_noent; spin_unlock(&ip->i_flags_lock); @@ -763,15 +769,14 @@ xfs_inode_walk_ag_grab( } /* - * For a given per-AG structure @pag, grab, @execute, and rele all incore - * inodes with the given radix tree @tag. + * For a given per-AG structure @pag, grab, execute a tag specific function, + * and release all incore inodes with the given radix tree @tag. */ STATIC int xfs_inode_walk_ag( struct xfs_perag *pag, - int (*execute)(struct xfs_inode *ip, void *args), - void *args, - int tag) + unsigned int tag, + void *args) { struct xfs_mount *mp = pag->pag_mount; uint32_t first_index; @@ -780,6 +785,8 @@ xfs_inode_walk_ag( bool done; int nr_found; + ASSERT(tag == XFS_ICI_BLOCKGC_TAG); + restart: done = false; skipped = 0; @@ -792,16 +799,9 @@ xfs_inode_walk_ag( rcu_read_lock(); - if (tag == XFS_ICI_NO_TAG) - nr_found = radix_tree_gang_lookup(&pag->pag_ici_root, - (void **)batch, first_index, - XFS_LOOKUP_BATCH); - else - nr_found = radix_tree_gang_lookup_tag( - &pag->pag_ici_root, - (void **) batch, first_index, - XFS_LOOKUP_BATCH, tag); - + nr_found = radix_tree_gang_lookup_tag(&pag->pag_ici_root, + (void **)batch, first_index, XFS_LOOKUP_BATCH, + tag); if (!nr_found) { rcu_read_unlock(); break; @@ -814,7 +814,7 @@ xfs_inode_walk_ag( for (i = 0; i < nr_found; i++) { struct xfs_inode *ip = batch[i]; - if (done || !xfs_inode_walk_ag_grab(ip)) + if (done || !xfs_blockgc_grab(ip)) batch[i] = NULL; /* @@ -842,7 +842,7 @@ xfs_inode_walk_ag( for (i = 0; i < nr_found; i++) { if (!batch[i]) continue; - error = execute(batch[i], args); + error = xfs_blockgc_scan_inode(batch[i], args); xfs_irele(batch[i]); if (error == -EAGAIN) { skipped++; @@ -867,38 +867,27 @@ xfs_inode_walk_ag( return last_error; } -/* Fetch the next (possibly tagged) per-AG structure. */ -static inline struct xfs_perag * -xfs_inode_walk_get_perag( - struct xfs_mount *mp, - xfs_agnumber_t agno, - int tag) -{ - if (tag == XFS_ICI_NO_TAG) - return xfs_perag_get(mp, agno); - return xfs_perag_get_tag(mp, agno, tag); -} - /* - * Call the @execute function on all incore inodes matching the radix tree + * Call a tag-specific function on all incore inodes matching the radix tree * @tag. */ static int xfs_inode_walk( struct xfs_mount *mp, - int (*execute)(struct xfs_inode *ip, void *args), - void *args, - int tag) + unsigned int tag, + void *args) { struct xfs_perag *pag; int error = 0; int last_error = 0; xfs_agnumber_t ag; + ASSERT(tag == XFS_ICI_BLOCKGC_TAG); + ag = 0; - while ((pag = xfs_inode_walk_get_perag(mp, ag, tag))) { + while ((pag = xfs_perag_get_tag(mp, ag, tag))) { ag = pag->pag_agno + 1; - error = xfs_inode_walk_ag(pag, execute, args, tag); + error = xfs_inode_walk_ag(pag, tag, args); xfs_perag_put(pag); if (error) { last_error = error; @@ -1610,8 +1599,7 @@ xfs_blockgc_worker( if (!sb_start_write_trylock(mp->m_super)) return; - error = xfs_inode_walk_ag(pag, xfs_blockgc_scan_inode, NULL, - XFS_ICI_BLOCKGC_TAG); + error = xfs_inode_walk_ag(pag, XFS_ICI_BLOCKGC_TAG, NULL); if (error) xfs_info(mp, "AG %u preallocation gc worker failed, err=%d", pag->pag_agno, error); @@ -1629,8 +1617,7 @@ xfs_blockgc_free_space( { trace_xfs_blockgc_free_space(mp, eofb, _RET_IP_); - return xfs_inode_walk(mp, xfs_blockgc_scan_inode, eofb, - XFS_ICI_BLOCKGC_TAG); + return xfs_inode_walk(mp, XFS_ICI_BLOCKGC_TAG, eofb); } /* From patchwork Fri Mar 26 00:21:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12165265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24311C433E4 for ; Fri, 26 Mar 2021 00:22:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9F9061A3C for ; Fri, 26 Mar 2021 00:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229951AbhCZAVq (ORCPT ); Thu, 25 Mar 2021 20:21:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:35136 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbhCZAVg (ORCPT ); Thu, 25 Mar 2021 20:21:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 83ABA619F3; Fri, 26 Mar 2021 00:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616718095; bh=7I50jn9/th23/A/nNysNVGrqKWaNERcrkUgKW6o3bKg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=GCX1tlLs5oJdlkDxjONBBQ27P/cXXRR2siBJBoclZdhMxr7xKftNTnAdWKrKINdOJ ZFCIA/fzP6naIa45KpDonU0Shhhom5314WmWpSOcbA7lf1k4Rpw+v1hYmIsk2ttsS9 L37m37TTzg0HtVwphFIRWTk/xbwkB5ySWp/jaHoZcldPiC1O9bsN3s0BxFppEESyBJ YmsjziUvpIrhw+xOw3JFiCyoPW83TgsWtbzQOkbf+7ujuc7ySi2JmW5NOGs/SXNcuj y8EhJNT0CBiEy1uWnk1otQogshWsfAd7rkxkliWUdL49yqxUcduM15e2YPYzvYY0M3 eBPpQvhS3TTIg== Subject: [PATCH 4/6] xfs: pass struct xfs_eofblocks to the inode scan callback From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@infradead.org Date: Thu, 25 Mar 2021 17:21:35 -0700 Message-ID: <161671809523.621936.2714947336807513527.stgit@magnolia> In-Reply-To: <161671807287.621936.13471099564526590235.stgit@magnolia> References: <161671807287.621936.13471099564526590235.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 Pass a pointer to the actual eofb structure around the inode scanner functions instead of a void pointer, now that none of the functions is used as a callback. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_icache.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index f4c4f6e15d77..b02b4b349ee9 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -27,7 +27,8 @@ #include /* Forward declarations to reduce indirect calls */ -static int xfs_blockgc_scan_inode(struct xfs_inode *ip, void *args); +static int xfs_blockgc_scan_inode(struct xfs_inode *ip, + struct xfs_eofblocks *eofb); /* * Allocate and initialise an xfs_inode. @@ -776,7 +777,7 @@ STATIC int xfs_inode_walk_ag( struct xfs_perag *pag, unsigned int tag, - void *args) + struct xfs_eofblocks *eofb) { struct xfs_mount *mp = pag->pag_mount; uint32_t first_index; @@ -842,7 +843,7 @@ xfs_inode_walk_ag( for (i = 0; i < nr_found; i++) { if (!batch[i]) continue; - error = xfs_blockgc_scan_inode(batch[i], args); + error = xfs_blockgc_scan_inode(batch[i], eofb); xfs_irele(batch[i]); if (error == -EAGAIN) { skipped++; @@ -875,7 +876,7 @@ static int xfs_inode_walk( struct xfs_mount *mp, unsigned int tag, - void *args) + struct xfs_eofblocks *eofb) { struct xfs_perag *pag; int error = 0; @@ -887,7 +888,7 @@ xfs_inode_walk( ag = 0; while ((pag = xfs_perag_get_tag(mp, ag, tag))) { ag = pag->pag_agno + 1; - error = xfs_inode_walk_ag(pag, tag, args); + error = xfs_inode_walk_ag(pag, tag, eofb); xfs_perag_put(pag); if (error) { last_error = error; @@ -1266,10 +1267,9 @@ xfs_reclaim_worker( STATIC int xfs_inode_free_eofblocks( struct xfs_inode *ip, - void *args, + struct xfs_eofblocks *eofb, unsigned int *lockflags) { - struct xfs_eofblocks *eofb = args; bool wait; wait = eofb && (eofb->eof_flags & XFS_EOF_FLAGS_SYNC); @@ -1473,10 +1473,9 @@ xfs_prep_free_cowblocks( STATIC int xfs_inode_free_cowblocks( struct xfs_inode *ip, - void *args, + struct xfs_eofblocks *eofb, unsigned int *lockflags) { - struct xfs_eofblocks *eofb = args; bool wait; int ret = 0; @@ -1571,16 +1570,16 @@ xfs_blockgc_start( static int xfs_blockgc_scan_inode( struct xfs_inode *ip, - void *args) + struct xfs_eofblocks *eofb) { unsigned int lockflags = 0; int error; - error = xfs_inode_free_eofblocks(ip, args, &lockflags); + error = xfs_inode_free_eofblocks(ip, eofb, &lockflags); if (error) goto unlock; - error = xfs_inode_free_cowblocks(ip, args, &lockflags); + error = xfs_inode_free_cowblocks(ip, eofb, &lockflags); unlock: if (lockflags) xfs_iunlock(ip, lockflags); From patchwork Fri Mar 26 00:21:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12165271 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23F47C433E0 for ; Fri, 26 Mar 2021 00:22:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA4FA619F3 for ; Fri, 26 Mar 2021 00:22:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230182AbhCZAWN (ORCPT ); Thu, 25 Mar 2021 20:22:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:35186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230100AbhCZAVl (ORCPT ); Thu, 25 Mar 2021 20:21:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 23A5661A48; Fri, 26 Mar 2021 00:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616718101; bh=VlYJoA+BcNA8nhDNwLrEAMiF6GglFppZFDn3VtHVDxY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=DJbe3d5/TeDZjo2zjhpKn/jZK3nLsRuCvqJEIcmzDWTpItKbPNQj4k89ZoP2hrXam e4PJHmrk2kpXteK27K/nSi8LDjnLHcZv1Ubyy+hTJ564g5x0JOvNrr3X9eSAjMAxX4 zyyZNB8vO8bmw8y/+sA5PljsiHZ1IrtPfy+wMFXNlLu6Y05JP2YQsxMg5Hs6jT+e+7 fJR1a5pvsjjOKrDRkNX8Nlt9hv8capALg1y3rqXvKeMuyab52kJQ0uNKNNRXyrolLm 29vEe1YYcnIl2tL4aTf+fJYfyalHrUxShV9HuwitsFwKYvURbELBo56C6sI0Ienucn tLcUQVFwjf8Mw== Subject: [PATCH 5/6] xfs: merge xfs_reclaim_inodes_ag into xfs_inode_walk_ag From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@infradead.org Date: Thu, 25 Mar 2021 17:21:40 -0700 Message-ID: <161671810078.621936.339407186528826628.stgit@magnolia> In-Reply-To: <161671807287.621936.13471099564526590235.stgit@magnolia> References: <161671807287.621936.13471099564526590235.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 Merge these two inode walk loops together, since they're pretty similar now. Get rid of XFS_ICI_NO_TAG since nobody uses it. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_icache.c | 154 ++++++++++++++++----------------------------------- fs/xfs/xfs_icache.h | 5 +- 2 files changed, 52 insertions(+), 107 deletions(-) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index b02b4b349ee9..2b25fe679b0e 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -29,6 +29,8 @@ /* Forward declarations to reduce indirect calls */ static int xfs_blockgc_scan_inode(struct xfs_inode *ip, struct xfs_eofblocks *eofb); +static bool xfs_reclaim_inode_grab(struct xfs_inode *ip); +static void xfs_reclaim_inode(struct xfs_inode *ip, struct xfs_perag *pag); /* * Allocate and initialise an xfs_inode. @@ -769,6 +771,21 @@ xfs_blockgc_grab( return false; } +static inline bool +selected_for_walk( + unsigned int tag, + struct xfs_inode *ip) +{ + switch (tag) { + case XFS_ICI_BLOCKGC_TAG: + return xfs_blockgc_grab(ip); + case XFS_ICI_RECLAIM_TAG: + return xfs_reclaim_inode_grab(ip); + default: + return false; + } +} + /* * For a given per-AG structure @pag, grab, execute a tag specific function, * and release all incore inodes with the given radix tree @tag. @@ -786,12 +803,14 @@ xfs_inode_walk_ag( bool done; int nr_found; - ASSERT(tag == XFS_ICI_BLOCKGC_TAG); + ASSERT(tag < RADIX_TREE_MAX_TAGS); restart: done = false; skipped = 0; first_index = 0; + if (tag == XFS_ICI_RECLAIM_TAG) + first_index = READ_ONCE(pag->pag_ici_reclaim_cursor); nr_found = 0; do { struct xfs_inode *batch[XFS_LOOKUP_BATCH]; @@ -804,6 +823,7 @@ xfs_inode_walk_ag( (void **)batch, first_index, XFS_LOOKUP_BATCH, tag); if (!nr_found) { + done = true; rcu_read_unlock(); break; } @@ -815,7 +835,7 @@ xfs_inode_walk_ag( for (i = 0; i < nr_found; i++) { struct xfs_inode *ip = batch[i]; - if (done || !xfs_blockgc_grab(ip)) + if (done || !selected_for_walk(tag, ip)) batch[i] = NULL; /* @@ -843,8 +863,16 @@ xfs_inode_walk_ag( for (i = 0; i < nr_found; i++) { if (!batch[i]) continue; - error = xfs_blockgc_scan_inode(batch[i], eofb); - xfs_irele(batch[i]); + switch (tag) { + case XFS_ICI_BLOCKGC_TAG: + error = xfs_blockgc_scan_inode(batch[i], eofb); + xfs_irele(batch[i]); + break; + case XFS_ICI_RECLAIM_TAG: + xfs_reclaim_inode(batch[i], pag); + error = 0; + break; + } if (error == -EAGAIN) { skipped++; continue; @@ -858,9 +886,19 @@ xfs_inode_walk_ag( break; cond_resched(); - + if (tag == XFS_ICI_RECLAIM_TAG && eofb) { + eofb->nr_to_scan -= XFS_LOOKUP_BATCH; + if (eofb->nr_to_scan < 0) + break; + } } while (nr_found && !done); + if (tag == XFS_ICI_RECLAIM_TAG) { + if (done) + first_index = 0; + WRITE_ONCE(pag->pag_ici_reclaim_cursor, first_index); + } + if (skipped) { delay(1); goto restart; @@ -883,7 +921,7 @@ xfs_inode_walk( int last_error = 0; xfs_agnumber_t ag; - ASSERT(tag == XFS_ICI_BLOCKGC_TAG); + ASSERT(tag < RADIX_TREE_MAX_TAGS); ag = 0; while ((pag = xfs_perag_get_tag(mp, ag, tag))) { @@ -1027,108 +1065,13 @@ xfs_reclaim_inode( xfs_iflags_clear(ip, XFS_IRECLAIM); } -/* - * Walk the AGs and reclaim the inodes in them. Even if the filesystem is - * corrupted, we still want to try to reclaim all the inodes. If we don't, - * then a shut down during filesystem unmount reclaim walk leak all the - * unreclaimed inodes. - * - * Returns non-zero if any AGs or inodes were skipped in the reclaim pass - * so that callers that want to block until all dirty inodes are written back - * and reclaimed can sanely loop. - */ -static void -xfs_reclaim_inodes_ag( - struct xfs_mount *mp, - int *nr_to_scan) -{ - struct xfs_perag *pag; - xfs_agnumber_t ag = 0; - - while ((pag = xfs_perag_get_tag(mp, ag, XFS_ICI_RECLAIM_TAG))) { - unsigned long first_index = 0; - int done = 0; - int nr_found = 0; - - ag = pag->pag_agno + 1; - - first_index = READ_ONCE(pag->pag_ici_reclaim_cursor); - do { - struct xfs_inode *batch[XFS_LOOKUP_BATCH]; - int i; - - rcu_read_lock(); - nr_found = radix_tree_gang_lookup_tag( - &pag->pag_ici_root, - (void **)batch, first_index, - XFS_LOOKUP_BATCH, - XFS_ICI_RECLAIM_TAG); - if (!nr_found) { - done = 1; - rcu_read_unlock(); - break; - } - - /* - * Grab the inodes before we drop the lock. if we found - * nothing, nr == 0 and the loop will be skipped. - */ - for (i = 0; i < nr_found; i++) { - struct xfs_inode *ip = batch[i]; - - if (done || !xfs_reclaim_inode_grab(ip)) - batch[i] = NULL; - - /* - * Update the index for the next lookup. Catch - * overflows into the next AG range which can - * occur if we have inodes in the last block of - * the AG and we are currently pointing to the - * last inode. - * - * Because we may see inodes that are from the - * wrong AG due to RCU freeing and - * reallocation, only update the index if it - * lies in this AG. It was a race that lead us - * to see this inode, so another lookup from - * the same index will not find it again. - */ - if (XFS_INO_TO_AGNO(mp, ip->i_ino) != - pag->pag_agno) - continue; - first_index = XFS_INO_TO_AGINO(mp, ip->i_ino + 1); - if (first_index < XFS_INO_TO_AGINO(mp, ip->i_ino)) - done = 1; - } - - /* unlock now we've grabbed the inodes. */ - rcu_read_unlock(); - - for (i = 0; i < nr_found; i++) { - if (batch[i]) - xfs_reclaim_inode(batch[i], pag); - } - - *nr_to_scan -= XFS_LOOKUP_BATCH; - cond_resched(); - } while (nr_found && !done && *nr_to_scan > 0); - - if (done) - first_index = 0; - WRITE_ONCE(pag->pag_ici_reclaim_cursor, first_index); - xfs_perag_put(pag); - } -} - void xfs_reclaim_inodes( struct xfs_mount *mp) { - int nr_to_scan = INT_MAX; - while (radix_tree_tagged(&mp->m_perag_tree, XFS_ICI_RECLAIM_TAG)) { xfs_ail_push_all_sync(mp->m_ail); - xfs_reclaim_inodes_ag(mp, &nr_to_scan); + xfs_inode_walk(mp, XFS_ICI_RECLAIM_TAG, NULL); } } @@ -1144,11 +1087,13 @@ xfs_reclaim_inodes_nr( struct xfs_mount *mp, int nr_to_scan) { + struct xfs_eofblocks eofb = { .nr_to_scan = nr_to_scan }; + /* kick background reclaimer and push the AIL */ xfs_reclaim_work_queue(mp); xfs_ail_push_all(mp->m_ail); - xfs_reclaim_inodes_ag(mp, &nr_to_scan); + xfs_inode_walk(mp, XFS_ICI_RECLAIM_TAG, &eofb); return 0; } @@ -1258,9 +1203,8 @@ xfs_reclaim_worker( { struct xfs_mount *mp = container_of(to_delayed_work(work), struct xfs_mount, m_reclaim_work); - int nr_to_scan = INT_MAX; - xfs_reclaim_inodes_ag(mp, &nr_to_scan); + xfs_inode_walk(mp, XFS_ICI_RECLAIM_TAG, NULL); xfs_reclaim_work_queue(mp); } diff --git a/fs/xfs/xfs_icache.h b/fs/xfs/xfs_icache.h index d52c041093a3..bde7bab84230 100644 --- a/fs/xfs/xfs_icache.h +++ b/fs/xfs/xfs_icache.h @@ -15,13 +15,14 @@ struct xfs_eofblocks { kgid_t eof_gid; prid_t eof_prid; __u64 eof_min_file_size; + + /* Number of inodes to scan, currently limited to reclaim */ + int nr_to_scan; }; /* * tags for inode radix tree */ -#define XFS_ICI_NO_TAG (-1) /* special flag for an untagged lookup - in xfs_inode_walk */ #define XFS_ICI_RECLAIM_TAG 0 /* inode is to be reclaimed */ /* Inode has speculative preallocations (posteof or cow) to clean. */ #define XFS_ICI_BLOCKGC_TAG 1 From patchwork Fri Mar 26 00:21:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12165269 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F651C433E3 for ; Fri, 26 Mar 2021 00:22:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2EA3E619F3 for ; Fri, 26 Mar 2021 00:22:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230114AbhCZAWN (ORCPT ); Thu, 25 Mar 2021 20:22:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:35248 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230013AbhCZAVr (ORCPT ); Thu, 25 Mar 2021 20:21:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AE9CD619F3; Fri, 26 Mar 2021 00:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616718106; bh=TtIV9zfltyjI46cZ9DXdSU5VY5/ylTT8elRgQUKG2wM=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=j1xVZfo2sgh4EUNn4ADpLWFoF0JZRu20eZ2bw1aqzZ59JpwRkZbSxzZNGKTmZ7fc0 zFDz9XwTaJno5Tv2p2Jn7wcU5sATb+aMjbzfvNWmClcnBn6/6e1DK7a0rLCsSe6rgO FSwXayL2r2gNZEvj8UqWpz019mVMl0QlD+bu2Pc6C4Xa3mkiFnpH1AYhkeZaZiL/Mp 5/efR21UAzTgKYaptPt/Bb+OlGhtDtnJWiBqCpY8CQ9PMwk2clRQsdacYY7mNb9iuz gU4YO74ECwnzf00RsOIvqciU/D6eCLWxADXPSsEEB4l1opAVRf/COCTSuuo71nlhb9 qoCTheai+MLPg== Subject: [PATCH 6/6] xfs: refactor per-AG inode tagging functions From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@infradead.org Date: Thu, 25 Mar 2021 17:21:46 -0700 Message-ID: <161671810634.621936.14531357513724748267.stgit@magnolia> In-Reply-To: <161671807287.621936.13471099564526590235.stgit@magnolia> References: <161671807287.621936.13471099564526590235.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 In preparation for adding another incore inode tree tag, refactor the code that sets and clears tags from the per-AG inode tree and the tree of per-AG structures, and remove the open-coded versions used by the blockgc code. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_icache.c | 127 ++++++++++++++++++++++++--------------------------- fs/xfs/xfs_icache.h | 2 - fs/xfs/xfs_super.c | 2 - fs/xfs/xfs_trace.h | 6 +- 4 files changed, 65 insertions(+), 72 deletions(-) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index 2b25fe679b0e..4c124bc98f39 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -29,6 +29,7 @@ /* Forward declarations to reduce indirect calls */ static int xfs_blockgc_scan_inode(struct xfs_inode *ip, struct xfs_eofblocks *eofb); +static inline void xfs_blockgc_queue(struct xfs_perag *pag); static bool xfs_reclaim_inode_grab(struct xfs_inode *ip); static void xfs_reclaim_inode(struct xfs_inode *ip, struct xfs_perag *pag); @@ -163,46 +164,78 @@ xfs_reclaim_work_queue( rcu_read_unlock(); } +/* Set a tag on both the AG incore inode tree and the AG radix tree. */ static void -xfs_perag_set_reclaim_tag( - struct xfs_perag *pag) +xfs_perag_set_ici_tag( + struct xfs_perag *pag, + xfs_agino_t agino, + unsigned int tag) { struct xfs_mount *mp = pag->pag_mount; + bool was_tagged; lockdep_assert_held(&pag->pag_ici_lock); - if (pag->pag_ici_reclaimable++) + + was_tagged = radix_tree_tagged(&pag->pag_ici_root, tag); + radix_tree_tag_set(&pag->pag_ici_root, agino, tag); + + if (tag == XFS_ICI_RECLAIM_TAG) + pag->pag_ici_reclaimable++; + + if (was_tagged) return; - /* propagate the reclaim tag up into the perag radix tree */ + /* propagate the tag up into the perag radix tree */ spin_lock(&mp->m_perag_lock); - radix_tree_tag_set(&mp->m_perag_tree, pag->pag_agno, - XFS_ICI_RECLAIM_TAG); + radix_tree_tag_set(&mp->m_perag_tree, pag->pag_agno, tag); spin_unlock(&mp->m_perag_lock); - /* schedule periodic background inode reclaim */ - xfs_reclaim_work_queue(mp); + /* start background work */ + switch (tag) { + case XFS_ICI_RECLAIM_TAG: + xfs_reclaim_work_queue(mp); + break; + case XFS_ICI_BLOCKGC_TAG: + xfs_blockgc_queue(pag); + break; + } - trace_xfs_perag_set_reclaim(mp, pag->pag_agno, -1, _RET_IP_); + trace_xfs_perag_set_ici_tag(mp, pag->pag_agno, tag, _RET_IP_); } +/* Clear a tag on both the AG incore inode tree and the AG radix tree. */ static void -xfs_perag_clear_reclaim_tag( - struct xfs_perag *pag) +xfs_perag_clear_ici_tag( + struct xfs_perag *pag, + xfs_agino_t agino, + unsigned int tag) { struct xfs_mount *mp = pag->pag_mount; lockdep_assert_held(&pag->pag_ici_lock); - if (--pag->pag_ici_reclaimable) + + /* + * Reclaim can signal (with a null agino) that it cleared its own tag + * by removing the inode from the radix tree. + */ + if (agino != NULLAGINO) + radix_tree_tag_clear(&pag->pag_ici_root, agino, tag); + else + ASSERT(tag == XFS_ICI_RECLAIM_TAG); + + if (tag == XFS_ICI_RECLAIM_TAG) + pag->pag_ici_reclaimable--; + + if (radix_tree_tagged(&pag->pag_ici_root, tag)) return; - /* clear the reclaim tag from the perag radix tree */ + /* clear the tag from the perag radix tree */ spin_lock(&mp->m_perag_lock); - radix_tree_tag_clear(&mp->m_perag_tree, pag->pag_agno, - XFS_ICI_RECLAIM_TAG); + radix_tree_tag_clear(&mp->m_perag_tree, pag->pag_agno, tag); spin_unlock(&mp->m_perag_lock); - trace_xfs_perag_clear_reclaim(mp, pag->pag_agno, -1, _RET_IP_); -} + trace_xfs_perag_clear_ici_tag(mp, pag->pag_agno, tag, _RET_IP_); +} /* * We set the inode flag atomically with the radix tree tag. @@ -210,7 +243,7 @@ xfs_perag_clear_reclaim_tag( * can go away. */ void -xfs_inode_set_reclaim_tag( +xfs_inode_destroy( struct xfs_inode *ip) { struct xfs_mount *mp = ip->i_mount; @@ -220,9 +253,8 @@ xfs_inode_set_reclaim_tag( spin_lock(&pag->pag_ici_lock); spin_lock(&ip->i_flags_lock); - radix_tree_tag_set(&pag->pag_ici_root, XFS_INO_TO_AGINO(mp, ip->i_ino), - XFS_ICI_RECLAIM_TAG); - xfs_perag_set_reclaim_tag(pag); + xfs_perag_set_ici_tag(pag, XFS_INO_TO_AGINO(mp, ip->i_ino), + XFS_ICI_RECLAIM_TAG); __xfs_iflags_set(ip, XFS_IRECLAIMABLE); spin_unlock(&ip->i_flags_lock); @@ -230,17 +262,6 @@ xfs_inode_set_reclaim_tag( xfs_perag_put(pag); } -STATIC void -xfs_inode_clear_reclaim_tag( - struct xfs_perag *pag, - xfs_ino_t ino) -{ - radix_tree_tag_clear(&pag->pag_ici_root, - XFS_INO_TO_AGINO(pag->pag_mount, ino), - XFS_ICI_RECLAIM_TAG); - xfs_perag_clear_reclaim_tag(pag); -} - void xfs_inew_wait( struct xfs_inode *ip) @@ -439,7 +460,9 @@ xfs_iget_cache_hit( */ ip->i_flags &= ~XFS_IRECLAIM_RESET_FLAGS; ip->i_flags |= XFS_INEW; - xfs_inode_clear_reclaim_tag(pag, ip->i_ino); + xfs_perag_clear_ici_tag(pag, + XFS_INO_TO_AGINO(pag->pag_mount, ino), + XFS_ICI_RECLAIM_TAG); inode->i_state = I_NEW; ip->i_sick = 0; ip->i_checked = 0; @@ -1038,7 +1061,7 @@ xfs_reclaim_inode( if (!radix_tree_delete(&pag->pag_ici_root, XFS_INO_TO_AGINO(ip->i_mount, ino))) ASSERT(0); - xfs_perag_clear_reclaim_tag(pag); + xfs_perag_clear_ici_tag(pag, NULLAGINO, XFS_ICI_RECLAIM_TAG); spin_unlock(&pag->pag_ici_lock); /* @@ -1274,7 +1297,6 @@ xfs_blockgc_set_iflag( { struct xfs_mount *mp = ip->i_mount; struct xfs_perag *pag; - int tagged; ASSERT((iflag & ~(XFS_IEOFBLOCKS | XFS_ICOWBLOCKS)) == 0); @@ -1291,24 +1313,8 @@ xfs_blockgc_set_iflag( pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino)); spin_lock(&pag->pag_ici_lock); - tagged = radix_tree_tagged(&pag->pag_ici_root, XFS_ICI_BLOCKGC_TAG); - radix_tree_tag_set(&pag->pag_ici_root, - XFS_INO_TO_AGINO(ip->i_mount, ip->i_ino), - XFS_ICI_BLOCKGC_TAG); - if (!tagged) { - /* propagate the blockgc tag up into the perag radix tree */ - spin_lock(&ip->i_mount->m_perag_lock); - radix_tree_tag_set(&ip->i_mount->m_perag_tree, - XFS_INO_TO_AGNO(ip->i_mount, ip->i_ino), - XFS_ICI_BLOCKGC_TAG); - spin_unlock(&ip->i_mount->m_perag_lock); - - /* kick off background trimming */ - xfs_blockgc_queue(pag); - - trace_xfs_perag_set_blockgc(ip->i_mount, pag->pag_agno, -1, - _RET_IP_); - } + xfs_perag_set_ici_tag(pag, XFS_INO_TO_AGINO(mp, ip->i_ino), + XFS_ICI_BLOCKGC_TAG); spin_unlock(&pag->pag_ici_lock); xfs_perag_put(pag); @@ -1344,19 +1350,8 @@ xfs_blockgc_clear_iflag( pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino)); spin_lock(&pag->pag_ici_lock); - radix_tree_tag_clear(&pag->pag_ici_root, - XFS_INO_TO_AGINO(ip->i_mount, ip->i_ino), - XFS_ICI_BLOCKGC_TAG); - if (!radix_tree_tagged(&pag->pag_ici_root, XFS_ICI_BLOCKGC_TAG)) { - /* clear the blockgc tag from the perag radix tree */ - spin_lock(&ip->i_mount->m_perag_lock); - radix_tree_tag_clear(&ip->i_mount->m_perag_tree, - XFS_INO_TO_AGNO(ip->i_mount, ip->i_ino), - XFS_ICI_BLOCKGC_TAG); - spin_unlock(&ip->i_mount->m_perag_lock); - trace_xfs_perag_clear_blockgc(ip->i_mount, pag->pag_agno, -1, - _RET_IP_); - } + xfs_perag_clear_ici_tag(pag, XFS_INO_TO_AGINO(mp, ip->i_ino), + XFS_ICI_BLOCKGC_TAG); spin_unlock(&pag->pag_ici_lock); xfs_perag_put(pag); diff --git a/fs/xfs/xfs_icache.h b/fs/xfs/xfs_icache.h index bde7bab84230..987267797fc4 100644 --- a/fs/xfs/xfs_icache.h +++ b/fs/xfs/xfs_icache.h @@ -48,7 +48,7 @@ void xfs_reclaim_inodes(struct xfs_mount *mp); int xfs_reclaim_inodes_count(struct xfs_mount *mp); long xfs_reclaim_inodes_nr(struct xfs_mount *mp, int nr_to_scan); -void xfs_inode_set_reclaim_tag(struct xfs_inode *ip); +void xfs_inode_destroy(struct xfs_inode *ip); int xfs_blockgc_free_dquots(struct xfs_mount *mp, struct xfs_dquot *udqp, struct xfs_dquot *gdqp, struct xfs_dquot *pdqp, diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index a2dab05332ac..f5bbfd13a956 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -667,7 +667,7 @@ xfs_fs_destroy_inode( * reclaim path handles this more efficiently than we can here, so * simply let background reclaim tear down all inodes. */ - xfs_inode_set_reclaim_tag(ip); + xfs_inode_destroy(ip); } static void diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 808ae337b222..a929ebef89ec 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -153,10 +153,8 @@ DEFINE_EVENT(xfs_perag_class, name, \ DEFINE_PERAG_REF_EVENT(xfs_perag_get); DEFINE_PERAG_REF_EVENT(xfs_perag_get_tag); DEFINE_PERAG_REF_EVENT(xfs_perag_put); -DEFINE_PERAG_REF_EVENT(xfs_perag_set_reclaim); -DEFINE_PERAG_REF_EVENT(xfs_perag_clear_reclaim); -DEFINE_PERAG_REF_EVENT(xfs_perag_set_blockgc); -DEFINE_PERAG_REF_EVENT(xfs_perag_clear_blockgc); +DEFINE_PERAG_REF_EVENT(xfs_perag_set_ici_tag); +DEFINE_PERAG_REF_EVENT(xfs_perag_clear_ici_tag); DECLARE_EVENT_CLASS(xfs_ag_class, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno),