From: cem@kernel.org
To: linux-xfs@vger.kernel.org
Cc: david@fromorbit.com, hch@lst.de, djwong@kernel.org
Subject: [PATCH 1/3] xfs: add a couple helpers to alloc/free xfs_busy_extents
Date: Tue, 10 Mar 2026 13:33:14 +0100 [thread overview]
Message-ID: <20260310123324.339310-2-cem@kernel.org> (raw)
In-Reply-To: <20260310123324.339310-1-cem@kernel.org>
From: Carlos Maiolino <cem@kernel.org>
There are a couple locations which repeats the same code pattern
to alloc/free the xfs_busy_extents list
These helpers will come in handy when decoupling busy_extents
list from the cil context.
Notice though commit bf4afc53b77a removed GFP_KERNEL from the kzalloc_obj()
calls due to the new default argument.
On future usage we'll also need to pass NOFAIL here, so we need to be able
to pass some flags as argument.
The avoid calls like xfs_busy_extents_alloc(0) explicitly pass GFP_KERNEL
as argument. It looks better to me.
Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---
fs/xfs/xfs_discard.c | 12 +++++-------
fs/xfs/xfs_extent_busy.h | 17 +++++++++++++++++
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index 906221ffe9ba..f393be78dc46 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -349,18 +349,17 @@ xfs_trim_perag_extents(
do {
struct xfs_busy_extents *extents;
- extents = kzalloc_obj(*extents);
+ extents = xfs_busy_extents_alloc(GFP_KERNEL);
if (!extents) {
error = -ENOMEM;
break;
}
extents->owner = extents;
- INIT_LIST_HEAD(&extents->extent_list);
error = xfs_trim_gather_extents(pag, &tcur, extents);
if (error) {
- kfree(extents);
+ xfs_busy_extents_free(extents);
break;
}
@@ -689,7 +688,7 @@ xfs_trim_rtgroup_extents(
* trims the extents returned.
*/
do {
- tr.extents = kzalloc_obj(*tr.extents);
+ tr.extents = xfs_busy_extents_alloc(GFP_KERNEL);
if (!tr.extents) {
error = -ENOMEM;
break;
@@ -698,7 +697,6 @@ xfs_trim_rtgroup_extents(
tr.queued = 0;
tr.batch = XFS_DISCARD_MAX_EXAMINE;
tr.extents->owner = tr.extents;
- INIT_LIST_HEAD(&tr.extents->extent_list);
xfs_rtgroup_lock(rtg, XFS_RTGLOCK_BITMAP_SHARED);
error = xfs_rtalloc_query_range(rtg, tp, low, high,
@@ -707,12 +705,12 @@ xfs_trim_rtgroup_extents(
if (error == -ECANCELED)
error = 0;
if (error) {
- kfree(tr.extents);
+ xfs_busy_extents_free(tr.extents);
break;
}
if (!tr.queued) {
- kfree(tr.extents);
+ xfs_busy_extents_free(tr.extents);
break;
}
diff --git a/fs/xfs/xfs_extent_busy.h b/fs/xfs/xfs_extent_busy.h
index 3e6e019b6146..699f97a53530 100644
--- a/fs/xfs/xfs_extent_busy.h
+++ b/fs/xfs/xfs_extent_busy.h
@@ -43,6 +43,23 @@ struct xfs_busy_extents {
void *owner;
};
+static inline struct xfs_busy_extents *
+xfs_busy_extents_alloc(gfp_t flags)
+{
+ struct xfs_busy_extents *e;
+ e = kzalloc_obj(*e, flags);
+
+ if (e)
+ INIT_LIST_HEAD(&e->extent_list);
+ return e;
+}
+
+static inline void xfs_busy_extents_free(
+ struct xfs_busy_extents *e)
+{
+ kfree(e);
+}
+
void xfs_extent_busy_insert(struct xfs_trans *tp, struct xfs_group *xg,
xfs_agblock_t bno, xfs_extlen_t len, unsigned int flags);
void xfs_extent_busy_insert_discard(struct xfs_group *xg, xfs_agblock_t bno,
--
2.53.0
next prev parent reply other threads:[~2026-03-10 12:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 12:33 [PATCH 0/3] Decouple busy_extents from cil context cem
2026-03-10 12:33 ` cem [this message]
2026-03-10 13:03 ` [PATCH 1/3] xfs: add a couple helpers to alloc/free xfs_busy_extents Christoph Hellwig
2026-03-10 12:33 ` [PATCH 2/3] xfs: convert busy_extents list to a pointer within cil context cem
2026-03-10 13:04 ` Christoph Hellwig
2026-03-10 12:33 ` [PATCH 3/3] xfs: remove owner field from xfs_extent_busy cem
2026-03-10 13:06 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260310123324.339310-2-cem@kernel.org \
--to=cem@kernel.org \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox