From patchwork Mon Aug 12 06:32:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13760178 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74D5115098E for ; Mon, 12 Aug 2024 06:32:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444369; cv=none; b=B7AwakMv7uLsIKtSm/jatHyeeP0w/1rhTzg/RnkTK9xGyw/6GeNXFFtS6Mr329v5BRBZNQPQrgpD5Z1Qe6GahtaD2lOZ9qeh3oDxaQ4tUHMPMzQJbJIdER3qGCU4jA4IMxDj5g3fBX3vs/YNUCdjcP115SMUsPLeKQMrAEnpvtI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444369; c=relaxed/simple; bh=jZkXPLR7DVlQa3QZyd8cAT+BqJMsXp43O4ht54FD728=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G4QEAmjuBs/+SenBDa1ha0+wCB7T5L7fs3JMZkX5MxUh3RhRJ6H4yQMfLFbil2fEhIlUR0A669lnoW2ik480AP1BVhXHsHNUZXt+X3cmxRIgmi/+N422E03o26J2+B5uEnJ/gh2qp9QlRnZtWWdOMlNDsLvkG2HLKWlZmOt+6to= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=jthS7VGu; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="jthS7VGu" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=EZUHvCtJVPrlKrRPQJDdPVm5IjZscNg9uEKZZius/Vw=; b=jthS7VGudGJ61WUtTjNTS80hyO SvRxTu+M7epD0B+Dffv8kKG3kp4QhqOEUQsD4Nz6cLTU6Vr4Wuq/TCB/6kL5SplfRUTq5b2tkFb8v MwQi6YOjO1SBunsx/15/trBzpEiGsUafZD/d5XCcQGPib5o0N9hsUMF5CKVtA/Z8b30ws2GoMFKeF KOwKLRK4ND1A4vlGdqtopzuESVMSRAuLSuP+lqc8lM6pMDu3cIABCFmQPITyDF8j55bwtxS79fDeE yOsOSirIVTtpeQLRfoORSlGtEpxsjy0U7bMp4/yV90jhHO8JT8a93YXzpjgLs739kn3aY3vx0jDuH aYPNaGKA==; Received: from 2a02-8389-2341-5b80-ee60-2eea-6f8f-8d7f.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:ee60:2eea:6f8f:8d7f] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdObn-0000000H1dv-3Ocr; Mon, 12 Aug 2024 06:32:48 +0000 From: Christoph Hellwig To: cem@kernel.org Cc: djwong@kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 1/4] libfrog: add xarray emulation Date: Mon, 12 Aug 2024 08:32:28 +0200 Message-ID: <20240812063243.3806779-2-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812063243.3806779-1-hch@lst.de> References: <20240812063243.3806779-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Implement the simple parts of the kernel xarray API on-top of the libfrog radix-tree. Signed-off-by: Christoph Hellwig --- libfrog/radix-tree.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libfrog/radix-tree.h b/libfrog/radix-tree.h index dad5f5b72..7436b1337 100644 --- a/libfrog/radix-tree.h +++ b/libfrog/radix-tree.h @@ -63,4 +63,34 @@ int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag); static inline int radix_tree_preload(int gfp_mask) { return 0; } static inline void radix_tree_preload_end(void) { } +/* + * Emulation of the kernel xarray API. Note that unlike the kernel + * xarray, there is no internal locking so code using this should not + * allow concurrent operations in userspace. + */ +struct xarray { + struct radix_tree_root r; +}; + +static inline void xa_init(struct xarray *xa) +{ + INIT_RADIX_TREE(&xa->r, GFP_KERNEL); +} + +static inline void *xa_load(struct xarray *xa, unsigned long index) +{ + return radix_tree_lookup(&xa->r, index); +} + +static inline void *xa_erase(struct xarray *xa, unsigned long index) +{ + return radix_tree_delete(&xa->r, index); +} + +static inline int xa_set(struct xarray *xa, unsigned long index, void *entry, + unsigned int gfp) +{ + return radix_tree_insert(&xa->r, index, entry); +} + #endif /* __LIBFROG_RADIX_TREE_H__ */ From patchwork Mon Aug 12 06:32:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13760179 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25A201537D2 for ; Mon, 12 Aug 2024 06:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444372; cv=none; b=Z8wUy443wB48wvvJS4ZdXOKo1W+XG2HFvRg3CYVvkfH+DHry3RKuCQIHyOO1PPfIU5y+wehFrIbz+Lc6dsQp2ZFSYLGUuQAzs3nuMYBag4bb+glH4HH3l7YlEGB1z1ZZhalnAp8RljMfSH9HOjBsBOcXhKinLTsZ3mR2Mh25F8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444372; c=relaxed/simple; bh=z9/gSWP5gc+UZS2oathWIUHbFPf39I7xrYe/be5QB+M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tWgj9/Wk2ljHleBqsy6yCf6JjxLuwd8Crf+13cvK15m2iqOFPdWcwbIhIV/XCWdoaAZ/bAvMaGrRbKF7S7bmzKsO2o2enFqrQ05gTI8S0MneOXatIFwb07tHEZjLncoDamKJoS/n+rMJC3hztS3Kadna2SgPwcqWJGR0y99VqFM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=PVOtiZIU; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="PVOtiZIU" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=VtBha4XqRWa+BqQihXo/qeCG758gnIQFhKOOXdOKGXg=; b=PVOtiZIUaHNGDewTwBzg8lUP72 44kA6ruQsWP6uACuol+T/aLa0DywCkilg7u9ABDlkgsvL9Gu72uaPsuSMhuaQBjZWACMdp9l13DSj qK0gOgwXbdNfBlxmFUrUAGKBhPJnXpBNU7j+pzf20YklINByvOFc9sMYsodQ59iEXPwul+jQLDbxM XDWOsq9nLZFIfwPDclpS9WBpCE+xZTgXzwlht4QPMBOZprPQTU+SVT6jQ8i7NRY1K431Hj0JprgBz AFvAR8643y+jULNYoH7GAy0uRHTIyog336bRHnE+ZrJMTNCCO8t1jJMcBy4+vxWSQwxgbH3+GqGu+ /10Et28Q==; Received: from 2a02-8389-2341-5b80-ee60-2eea-6f8f-8d7f.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:ee60:2eea:6f8f:8d7f] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdObq-0000000H1ea-1edR; Mon, 12 Aug 2024 06:32:50 +0000 From: Christoph Hellwig To: cem@kernel.org Cc: djwong@kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 2/4] libxfs: add a kfree_rcu_mightsleep stub Date: Mon, 12 Aug 2024 08:32:29 +0200 Message-ID: <20240812063243.3806779-3-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812063243.3806779-1-hch@lst.de> References: <20240812063243.3806779-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Add a kfree_rcu_mightsleep stub so that code that needs to RCU free AGs in kernelspace can simply use this helper in xfsprogs. Signed-off-by: Christoph Hellwig --- include/kmem.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/kmem.h b/include/kmem.h index 8dfb2fb0b..b61385ec4 100644 --- a/include/kmem.h +++ b/include/kmem.h @@ -65,6 +65,16 @@ static inline void kfree(const void *ptr) free((void *)ptr); } +/* + * Stub for the kernel kfree_rcu_mightsleep. Does not actually wait + * for a RCU grace period, so can only be used in code that does not + * require RCU protection in userspace. + */ +static inline void kfree_rcu_mightsleep(const void *ptr) +{ + kfree(ptr); +} + __attribute__((format(printf,2,3))) char *kasprintf(gfp_t gfp, const char *fmt, ...); From patchwork Mon Aug 12 06:32:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13760180 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93E1615445E for ; Mon, 12 Aug 2024 06:32:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444375; cv=none; b=nz950LC2CNTdIQPbDGJoQNmXGP2aBxc/OEhXpKb+IK3CiMTMjfG/pFHu66r7aFZKBiDFUpqXZH1eHBWQi+uAlbgoMPbRv3rJw8nwTxGKAUCQ80Smz0So9qSZVH9M9xPJt7SXeomLZX1KsW9P5eIxE4FVZ8LTZKxdsD6IAsXpag4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444375; c=relaxed/simple; bh=TT0wn12QQoMP02iBVXXsD0XxsRPEVIERyeavF5ayv2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hn4eAvPxKZyW/UIQ/FhTKEcSl+wLH11MWyEn6BIsHELs9+8Gmo5IFXv4JsF/PSypisIm6M6RJSgYt692AIs+C25qPDvT+nYpnc+ldYMw8MQJbpzDNILkYeqy92b/SPkGGXwgKFTOEtXEC4A/7+ppTkpaDOVALJJXQechSbR8Ux4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=FwIlS1l0; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="FwIlS1l0" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=JNH+9KDGAfvUlD+jN+opZ2Q+8YcI93Y/Pb31vyKlMxs=; b=FwIlS1l0W01TxvlrvseIhYhuHw vz6yqbvKT81r/BqNH8ygUeW4eR5OWqKNxAC3PV0N92AZseyMVKoUuDt4in8heAx6vEZ481wS8lDEu QhQ9rq0XoT/dYvFKO/DK+GDTDHoMB6qjHL5G3AkJ3QgW/M8YEeGC22wV4GfUg8AmbN60BVBuEzMJK uG5YPnx5arvTxCYWz6jT4xGZGSNgMWP5u7meS5UPSfe8UHLfS1noRWrXYgztP1H1O4VWAcS7gaI2f AX6GzWNldGvsfOwIgb71kvDEW//aBiIYNFMh+NuFp6bsIL+wKq9XtHSIVi2wF6eqdKz15F02199BM my2C1JUQ==; Received: from 2a02-8389-2341-5b80-ee60-2eea-6f8f-8d7f.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:ee60:2eea:6f8f:8d7f] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdObs-0000000H1fb-3Z5o; Mon, 12 Aug 2024 06:32:53 +0000 From: Christoph Hellwig To: cem@kernel.org Cc: djwong@kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 3/4] xfs: convert perag lookup to xarray Date: Mon, 12 Aug 2024 08:32:30 +0200 Message-ID: <20240812063243.3806779-4-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812063243.3806779-1-hch@lst.de> References: <20240812063243.3806779-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Source kernel commit: ab6159870e68c198e4990faa8f82f348657d73f9 Convert the perag lookup from the legacy radix tree to the xarray, which allows for much nicer iteration and bulk lookup semantics. Note that this removes the helpers for tagged get and grab and the for_each* wrappers built around them and instead uses the xa_for_each* iteration helpers directly in xfs_icache.c, which simplifies the code nicely. Signed-off-by: Christoph Hellwig --- include/xfs_mount.h | 2 +- libxfs/init.c | 2 +- libxfs/xfs_ag.c | 81 +++++---------------------------------------- libxfs/xfs_ag.h | 11 ------ 4 files changed, 10 insertions(+), 86 deletions(-) diff --git a/include/xfs_mount.h b/include/xfs_mount.h index a9525e4e0..4289e4be2 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -91,7 +91,7 @@ typedef struct xfs_mount { 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 */ - struct radix_tree_root m_perag_tree; + struct xarray m_perags; uint64_t m_features; /* active filesystem features */ uint64_t m_low_space[XFS_LOWSP_MAX]; uint64_t m_rtxblkmask; /* rt extent block mask */ diff --git a/libxfs/init.c b/libxfs/init.c index 90a539e04..85149c7a9 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -664,7 +664,7 @@ libxfs_mount( mp->m_finobt_nores = true; xfs_set_inode32(mp); mp->m_sb = *sb; - INIT_RADIX_TREE(&mp->m_perag_tree, GFP_KERNEL); + xa_init(&mp->m_perags); sbp = &mp->m_sb; spin_lock_init(&mp->m_sb_lock); spin_lock_init(&mp->m_agirotor_lock); diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 47522d0fc..58ca12f6e 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -44,7 +44,7 @@ xfs_perag_get( struct xfs_perag *pag; rcu_read_lock(); - pag = radix_tree_lookup(&mp->m_perag_tree, agno); + pag = xa_load(&mp->m_perags, agno); if (pag) { trace_xfs_perag_get(pag, _RET_IP_); ASSERT(atomic_read(&pag->pag_ref) >= 0); @@ -54,31 +54,6 @@ xfs_perag_get( return pag; } -/* - * search from @first to find the next perag with the given tag set. - */ -struct xfs_perag * -xfs_perag_get_tag( - struct xfs_mount *mp, - xfs_agnumber_t first, - unsigned int tag) -{ - struct xfs_perag *pag; - int found; - - rcu_read_lock(); - found = radix_tree_gang_lookup_tag(&mp->m_perag_tree, - (void **)&pag, first, 1, tag); - if (found <= 0) { - rcu_read_unlock(); - return NULL; - } - trace_xfs_perag_get_tag(pag, _RET_IP_); - atomic_inc(&pag->pag_ref); - rcu_read_unlock(); - return pag; -} - /* Get a passive reference to the given perag. */ struct xfs_perag * xfs_perag_hold( @@ -115,38 +90,13 @@ xfs_perag_grab( struct xfs_perag *pag; rcu_read_lock(); - pag = radix_tree_lookup(&mp->m_perag_tree, agno); + pag = xa_load(&mp->m_perags, agno); if (pag) { trace_xfs_perag_grab(pag, _RET_IP_); if (!atomic_inc_not_zero(&pag->pag_active_ref)) pag = NULL; } - rcu_read_unlock(); - return pag; -} -/* - * search from @first to find the next perag with the given tag set. - */ -struct xfs_perag * -xfs_perag_grab_tag( - struct xfs_mount *mp, - xfs_agnumber_t first, - int tag) -{ - struct xfs_perag *pag; - int found; - - rcu_read_lock(); - found = radix_tree_gang_lookup_tag(&mp->m_perag_tree, - (void **)&pag, first, 1, tag); - if (found <= 0) { - rcu_read_unlock(); - return NULL; - } - trace_xfs_perag_grab_tag(pag, _RET_IP_); - if (!atomic_inc_not_zero(&pag->pag_active_ref)) - pag = NULL; rcu_read_unlock(); return pag; } @@ -254,9 +204,7 @@ xfs_free_perag( xfs_agnumber_t agno; for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) { - spin_lock(&mp->m_perag_lock); - pag = radix_tree_delete(&mp->m_perag_tree, agno); - spin_unlock(&mp->m_perag_lock); + pag = xa_erase(&mp->m_perags, agno); ASSERT(pag); XFS_IS_CORRUPT(pag->pag_mount, atomic_read(&pag->pag_ref) != 0); xfs_defer_drain_free(&pag->pag_intents_drain); @@ -345,9 +293,7 @@ xfs_free_unused_perag_range( xfs_agnumber_t index; for (index = agstart; index < agend; index++) { - spin_lock(&mp->m_perag_lock); - pag = radix_tree_delete(&mp->m_perag_tree, index); - spin_unlock(&mp->m_perag_lock); + pag = xa_erase(&mp->m_perags, index); if (!pag) break; xfs_buf_cache_destroy(&pag->pag_bcache); @@ -388,20 +334,11 @@ xfs_initialize_perag( pag->pag_agno = index; pag->pag_mount = mp; - error = radix_tree_preload(GFP_KERNEL | __GFP_RETRY_MAYFAIL); - if (error) - goto out_free_pag; - - spin_lock(&mp->m_perag_lock); - if (radix_tree_insert(&mp->m_perag_tree, index, pag)) { - WARN_ON_ONCE(1); - spin_unlock(&mp->m_perag_lock); - radix_tree_preload_end(); - error = -EEXIST; + error = xa_set(&mp->m_perags, index, pag, GFP_KERNEL); + if (error) { + WARN_ON_ONCE(error == -EEXIST); goto out_free_pag; } - spin_unlock(&mp->m_perag_lock); - radix_tree_preload_end(); #ifdef __KERNEL__ /* Place kernel structure only init below this point. */ @@ -449,9 +386,7 @@ xfs_initialize_perag( out_remove_pag: xfs_defer_drain_free(&pag->pag_intents_drain); - spin_lock(&mp->m_perag_lock); - radix_tree_delete(&mp->m_perag_tree, index); - spin_unlock(&mp->m_perag_lock); + pag = xa_erase(&mp->m_perags, index); out_free_pag: kfree(pag); out_unwind_new_pags: diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 35de09a25..b5eee2c78 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -156,15 +156,11 @@ void xfs_free_perag(struct xfs_mount *mp); /* Passive AG references */ struct xfs_perag *xfs_perag_get(struct xfs_mount *mp, xfs_agnumber_t agno); -struct xfs_perag *xfs_perag_get_tag(struct xfs_mount *mp, xfs_agnumber_t agno, - unsigned int tag); struct xfs_perag *xfs_perag_hold(struct xfs_perag *pag); void xfs_perag_put(struct xfs_perag *pag); /* Active AG references */ struct xfs_perag *xfs_perag_grab(struct xfs_mount *, xfs_agnumber_t); -struct xfs_perag *xfs_perag_grab_tag(struct xfs_mount *, xfs_agnumber_t, - int tag); void xfs_perag_rele(struct xfs_perag *pag); /* @@ -266,13 +262,6 @@ xfs_perag_next( (agno) = 0; \ for_each_perag_from((mp), (agno), (pag)) -#define for_each_perag_tag(mp, agno, pag, tag) \ - for ((agno) = 0, (pag) = xfs_perag_grab_tag((mp), 0, (tag)); \ - (pag) != NULL; \ - (agno) = (pag)->pag_agno + 1, \ - xfs_perag_rele(pag), \ - (pag) = xfs_perag_grab_tag((mp), (agno), (tag))) - static inline struct xfs_perag * xfs_perag_next_wrap( struct xfs_perag *pag, From patchwork Mon Aug 12 06:32:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13760181 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF8B114F9C5 for ; Mon, 12 Aug 2024 06:32:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444377; cv=none; b=uH5db48bfqSt41XKoqJN0paspzWCUzt8rE4fdqx9qV1s8x6dmYrlQj0IAGDLQHP9LxOnKaV/pKEZP3PxgHU6R/Vjq5VIIeGn0c1ayFGkyPexPWNZSj/4iJOcrnuiVi6tOSHkJeMi3+yFBdZTdztbiVh9uQMeoR3luEctj/dDemc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723444377; c=relaxed/simple; bh=4QuDUTrqyW4BE4dlfoVHnEm/ecmq2iEGILNatH70YMI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ESLwuHdQ91ooi9OJaJ+tVhg3g0NzGI/+vSQCTt0hcUmxVxLwiaP5uhfGmdbxTkMr5stg5jyGCZJUMtscIMVt8MmT/029FDO37AQ6vNYaS/ZcCYjlF896euKxJVlcQyhvv7PceMA4Vc2kOOHYQpiCSIrjCbM4vc05nIQ5HgpT/f0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=iOe5EYo1; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="iOe5EYo1" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=s3wsEKpu/FzK4PyKc3qOv9eRN4n12F02jPE3eJ6t5P0=; b=iOe5EYo1/5P0M3Qo2oznvmxxZB rthD1ciUR7VOHZYJiRA/LD9poWdLgECkzjAbaXjqmTFCZC6mPIj2uaevM+2kp1s/M8lMVIcLa+1nj w7qXyyOevMzFam1G7dvX0QpM8itQBXCvekEh3EL1kJCck3aXnIUs9Q7HI/TdrmB+/EZsXHkoh7qi8 n89oQ8z8cZbnjMHwEPu3qG3q1rtdGfT4WYUgHtaWZm0X1+RMQ8dnS7+FN63Xv6lz23sIKlUB2suSw yooLEPMdRFAyT8ySrO8RM7ZJo/qkK6aLRoNEjibNNdPNKL8qBEzPmKUZVP2Fm0WXleQ/CXIaXgbZX 6llIZ5bQ==; Received: from 2a02-8389-2341-5b80-ee60-2eea-6f8f-8d7f.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:ee60:2eea:6f8f:8d7f] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdObv-0000000H1gO-0dtm; Mon, 12 Aug 2024 06:32:55 +0000 From: Christoph Hellwig To: cem@kernel.org Cc: djwong@kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 4/4] xfs: use kfree_rcu_mightsleep to free the perag structures Date: Mon, 12 Aug 2024 08:32:31 +0200 Message-ID: <20240812063243.3806779-5-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812063243.3806779-1-hch@lst.de> References: <20240812063243.3806779-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Source kernel commit: 7344fea851552b1586ee161147a749995504b368 Using the kfree_rcu_mightsleep is simpler and removes the need for a rcu_head in the perag structure. Signed-off-by: Christoph Hellwig --- libxfs/xfs_ag.c | 12 +----------- libxfs/xfs_ag.h | 3 --- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c index 58ca12f6e..40d1d8a4b 100644 --- a/libxfs/xfs_ag.c +++ b/libxfs/xfs_ag.c @@ -183,16 +183,6 @@ out: return error; } -STATIC void -__xfs_free_perag( - struct rcu_head *head) -{ - struct xfs_perag *pag = container_of(head, struct xfs_perag, rcu_head); - - ASSERT(!delayed_work_pending(&pag->pag_blockgc_work)); - kfree(pag); -} - /* * Free up the per-ag resources associated with the mount structure. */ @@ -216,7 +206,7 @@ xfs_free_perag( xfs_perag_rele(pag); XFS_IS_CORRUPT(pag->pag_mount, atomic_read(&pag->pag_active_ref) != 0); - call_rcu(&pag->rcu_head, __xfs_free_perag); + kfree_rcu_mightsleep(pag); } } diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index b5eee2c78..d9cccd093 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -63,9 +63,6 @@ struct xfs_perag { /* Blocks reserved for the reverse mapping btree. */ struct xfs_ag_resv pag_rmapbt_resv; - /* for rcu-safe freeing */ - struct rcu_head rcu_head; - /* Precalculated geometry info */ xfs_agblock_t block_count; xfs_agblock_t min_block;