Skip to contentSkip to conversation

mm: replace PF_KCOMPACTD/PF_KSWAPD with kthread_func()

PATCH Applied Kefeng Wang 11 participants 34 messages Sep 2 – Sep 15 2 messages not in the archive

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

cover mm: replace PF_KCOMPACTD/PF_KSWAPD with kthread_func()

The task_struct->flags field is a limited 32-bit resource. Two flag bits, PF_KCOMPACTD and PF_KSWAPD, are used to identify whether a kernel thread is kcompactd or kswapd. Converting these to use kthread_func() frees up two valuable flag bits for future use.

Kefeng Wang (4):
xfs: remove dead kswapd flag inheritance from btree split worker
iomap: simplify writepages reclaim guard
mm: replace PF_KSWAPD flag with kthread_func() check
mm: replace PF_KCOMPACTD flag with kthread_func() check

 fs/iomap/buffered-io.c                   |  3 +--
 fs/xfs/libxfs/xfs_btree.c                | 18 +-----------------
 fs/xfs/xfs_platform.h                    |  4 ----
 include/linux/compaction.h               | 11 ++++++-----
 include/linux/sched.h                    |  4 ++--
 include/linux/swap.h                     |  7 +------
 mm/compaction.c                          |  9 ++++++---
 mm/vmscan.c                              | 10 ++++++++--
 tools/sched_ext/include/scx/common.bpf.h |  2 --
 9 files changed, 25 insertions(+), 43 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/4 xfs: remove dead kswapd flag inheritance from btree split worker

Commit 1f6d64829db7 ("xfs: block allocation work needs to be kswapd aware") added PF_MEMALLOC | PF_KSWAPD inheritance to xfs_btree_split_worker() so that block allocation offloaded from kswapd to a workqueue thread could access emergency memory reserves and avoid reclaim throttling.

pageout() no longer calls ->writepage() for filesystem folios -- it returns PAGE_ACTIVATE for non-shmem, non-anon pages. kswapd therefore never enters XFS writeback and cannot reach btree split. The only path that offloads btree splits is unwritten extent conversion at IO completion (xfs_end_io -> xfs_iomap_write_unwritten), which runs in a workqueue context where current_is_kswapd() is always false.

Let's remove the dead kswapd flag and related codes.

---
 fs/xfs/libxfs/xfs_btree.c | 18 +-----------------
 fs/xfs/xfs_platform.h     |  4 ----
 2 files changed, 1 insertion(+), 21 deletions(-)
fs/xfs/libxfs/xfs_btree.c +1 -17
index 60ef7f08b1d3..6738d9d1511b 100644
@@ -2994,7 +2994,6 @@ struct xfs_btree_split_args {
 	struct xfs_btree_cur	**curp;
 	int			*stat;		/* success/failure */
 	int			result;
-	bool			kswapd;	/* allocation in kswapd context */
 	struct completion	*done;
 	struct work_struct	work;
 };
@@ -3008,33 +3007,18 @@ xfs_btree_split_worker(
 {
 	struct xfs_btree_split_args	*args = container_of(work,
 						struct xfs_btree_split_args, work);
-	unsigned long		pflags;
-	unsigned long		new_pflags = 0;
-
-	/*
-	 * we are in a transaction context here, but may also be doing work
-	 * in kswapd context, and hence we may need to inherit that state
-	 * temporarily to ensure that we don't block waiting for memory reclaim
-	 * in any way.
-	 */
-	if (args->kswapd)
-		new_pflags |= PF_MEMALLOC | PF_KSWAPD;
-
-	current_set_flags_nested(&pflags, new_pflags);
 	xfs_trans_set_context(args->cur->bc_tp);
 
 	args->result = __xfs_btree_split(args->cur, args->level, args->ptrp,
 					 args->key, args->curp, args->stat);
 
 	xfs_trans_clear_context(args->cur->bc_tp);
-	current_restore_flags_nested(&pflags, new_pflags);
 
 	/*
 	 * Do not access args after complete() has run here. We don't own args
 	 * and the owner may run and free args before we return here.
 	 */
 	complete(args->done);
-
 }
 
 /*
@@ -3078,7 +3062,7 @@ xfs_btree_split(
 	args.curp = curp;
 	args.stat = stat;
 	args.done = &done;
-	args.kswapd = current_is_kswapd();
+
 	INIT_WORK_ONSTACK(&args.work, xfs_btree_split_worker);
 	queue_work(xfs_alloc_wq, &args.work);
 	wait_for_completion(&done);
fs/xfs/xfs_platform.h +0 -4
index 5d542e95fe44..a49fa159894d 100644
@@ -115,10 +115,6 @@ typedef __u32			xfs_nlink_t;
 #define xfs_blockgc_secs	xfs_params.blockgc_timer.val
 
 #define current_cpu()		(raw_smp_processor_id())
-#define current_set_flags_nested(sp, f)		\
-		(*(sp) = current->flags, current->flags |= (f))
-#define current_restore_flags_nested(sp, f)	\
-		(current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
 
 #define NBBY		8		/* number of bits per byte */
 
Signature · 1 line
2.55.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] xfs: remove dead kswapd flag inheritance from btree split worker

Quoted 6 lines · Kefeng Wang

Commit 1f6d64829db7 ("xfs: block allocation work needs to be kswapd aware") added PF_MEMALLOC | PF_KSWAPD inheritance to xfs_btree_split_worker() so that block allocation offloaded from kswapd to a workqueue thread could access emergency memory reserves and avoid reclaim throttling.

Quoted 8 lines

pageout() no longer calls ->writepage() for filesystem folios -- it returns PAGE_ACTIVATE for non-shmem, non-anon pages. kswapd therefore never enters XFS writeback and cannot reach btree split. The only path that offloads btree splits is unwritten extent conversion at IO completion (xfs_end_io -> xfs_iomap_write_unwritten), which runs in a workqueue context where current_is_kswapd() is always false.

Let's remove the dead kswapd flag and related codes.

Nice!

reviewer Reviewed-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] xfs: remove dead kswapd flag inheritance from btree split worker

In reply to Kefeng Wang
Quoted 13 lines · Kefeng Wang

Commit 1f6d64829db7 ("xfs: block allocation work needs to be kswapd aware") added PF_MEMALLOC | PF_KSWAPD inheritance to xfs_btree_split_worker() so that block allocation offloaded from kswapd to a workqueue thread could access emergency memory reserves and avoid reclaim throttling.

pageout() no longer calls ->writepage() for filesystem folios -- it returns PAGE_ACTIVATE for non-shmem, non-anon pages. kswapd therefore never enters XFS writeback and cannot reach btree split. The only path that offloads btree splits is unwritten extent conversion at IO completion (xfs_end_io -> xfs_iomap_write_unwritten), which runs in a workqueue context where current_is_kswapd() is always false.

Quoted 3 lines

Let's remove the dead kswapd flag and related codes.

#4 lore raw

PATCH 2/4 iomap: simplify writepages reclaim guard

In reply to Kefeng Wang

Now that kswapd can no longer reach filesystem writeback (pageout() returns PAGE_ACTIVATE for non-shmem, non-anon folios), any PF_MEMALLOC context in iomap_writepages() indicates a VM regression, simplify the check by removing PF_KSWAPD.

---
 fs/iomap/buffered-io.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/iomap/buffered-io.c +1 -2
index 0a5ebfda90f1..6306ca747f3b 100644
@@ -2077,8 +2077,7 @@ iomap_writepages(struct iomap_writepage_ctx *wpc)
 	 * Writeback from reclaim context should never happen except in the case
 	 * of a VM regression so warn about it and refuse to write the data.
 	 */
-	if (WARN_ON_ONCE((current->flags & (PF_MEMALLOC | PF_KSWAPD)) ==
-			PF_MEMALLOC))
+	if (WARN_ON_ONCE((current->flags & PF_MEMALLOC)))
 		return -EIO;
 
 	while ((folio = writeback_iter(mapping, wpc->wbc, folio, &error))) {
Signature · 1 line
2.55.0
#5 lore raw

Re: [PATCH 2/4] iomap: simplify writepages reclaim guard

fs/iomap/buffered-io.c iomap_writepages(struct iomap_writepage_ctx *wpc) · line 2080

Quoted 10 lines · Kefeng Wang

index 0a5ebfda90f1..6306ca747f3b 100644

fs/iomap/buffered-io.c +1 -2
@@ -2077,8 +2077,7 @@ iomap_writepages(struct iomap_writepage_ctx *wpc)
 	 * Writeback from reclaim context should never happen except in the case
 	 * of a VM regression so warn about it and refuse to write the data.
 	 */
-	if (WARN_ON_ONCE((current->flags & (PF_MEMALLOC | PF_KSWAPD)) ==
-			PF_MEMALLOC))
+	if (WARN_ON_ONCE((current->flags & PF_MEMALLOC)))

You can drop one set of braces here. Otherwise this looks good.

#6 lore raw

Re: [PATCH 2/4] iomap: simplify writepages reclaim guard

Quoted 14 lines · Christoph Hellwig

fs/iomap/buffered-io.c iomap_writepages(struct iomap_writepage_ctx *wpc) · line 2080

Quoted 10 lines · Kefeng Wang

index 0a5ebfda90f1..6306ca747f3b 100644

fs/iomap/buffered-io.c +1 -2
@@ -2077,8 +2077,7 @@ iomap_writepages(struct iomap_writepage_ctx *wpc)
  	 * Writeback from reclaim context should never happen except in the case
  	 * of a VM regression so warn about it and refuse to write the data.
  	 */
-	if (WARN_ON_ONCE((current->flags & (PF_MEMALLOC | PF_KSWAPD)) ==
-			PF_MEMALLOC))
+	if (WARN_ON_ONCE((current->flags & PF_MEMALLOC)))

You can drop one set of braces here. Otherwise this looks good.

Yes, missing it, thanks for your review.

Hi Andrew, I see that you have merged it into mm-new. Could you help fix it, or I will send a fix patch.

reviewer Reviewed-by on v1 2/4
#7 lore raw

Re: [PATCH 2/4] iomap: simplify writepages reclaim guard

In reply to Kefeng Wang
Quoted 6 lines · Kefeng Wang

Now that kswapd can no longer reach filesystem writeback (pageout() returns PAGE_ACTIVATE for non-shmem, non-anon folios), any PF_MEMALLOC context in iomap_writepages() indicates a VM regression, simplify the check by removing PF_KSWAPD.

#8 lore raw

PATCH 3/4 mm: replace PF_KSWAPD flag with kthread_func() check

In reply to Kefeng Wang

The preceding commits removed the last consumer that propagated PF_KSWAPD beyond kswapd itself (XFS btree split worker inheritance). The only remaining setter of PF_KSWAPD is kswapd(), and every current_is_kswapd() caller only needs to check whether the current task *is* the kswapd thread, not whether it inherited the flag.

Replace the flag-based test with kthread_func(current) == kswapd, freeing the 0x00020000 PF flag bit.

---
 include/linux/sched.h                    |  2 +-
 include/linux/swap.h                     |  7 +------
 mm/vmscan.c                              | 10 ++++++++--
 tools/sched_ext/include/scx/common.bpf.h |  1 -
 4 files changed, 10 insertions(+), 10 deletions(-)
include/linux/sched.h +1 -1
index 8b3d47a325cc..86394121b6c0 100644
@@ -1809,7 +1809,7 @@ extern struct pid *cad_pid;
 #define PF_USER_WORKER		0x00004000	/* Kernel thread cloned from userspace thread */
 #define PF_NOFREEZE		0x00008000	/* This thread should not be frozen */
 #define PF_KCOMPACTD		0x00010000	/* I am kcompactd */
-#define PF_KSWAPD		0x00020000	/* I am kswapd */
+#define PF__HOLE__00020000	0x00020000
 #define PF_MEMALLOC_NOFS	0x00040000	/* All allocations inherit GFP_NOFS. See memalloc_nfs_save() */
 #define PF_MEMALLOC_NOIO	0x00080000	/* All allocations inherit GFP_NOIO. See memalloc_noio_save() */
 #define PF_LOCAL_THROTTLE	0x00100000	/* Throttle writes only against the bdi I write to,
include/linux/swap.h +1 -6
index a72ecf12c00d..fc290e29e4a9 100644
@@ -25,12 +25,6 @@
 #define SWAP_FLAGS_VALID	(SWAP_FLAG_PRIO_MASK | SWAP_FLAG_PREFER | \
 				 SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE | \
 				 SWAP_FLAG_DISCARD_PAGES)
-
-static inline int current_is_kswapd(void)
-{
-	return current->flags & PF_KSWAPD;
-}
-
 /*
  * MAX_SWAPFILES defines the maximum number of swaptypes: things which can
  * be swapped to.  The swap type and the offset into that swap type are
@@ -339,6 +333,7 @@ void check_move_unevictable_folios(struct folio_batch *fbatch);
 
 extern void __meminit kswapd_run(int nid);
 extern void __meminit kswapd_stop(int nid);
+bool current_is_kswapd(void);
 
 #ifdef CONFIG_SWAP
 int add_swap_extent(struct swap_info_struct *sis, unsigned long start_page,
mm/vmscan.c +8 -2
index 07ba86634b84..775d3f71a9de 100644
@@ -7468,7 +7468,7 @@ static int kswapd(void *p)
 	 * us from recursively trying to free more memory as we're
 	 * trying to free the first piece of memory in the first place).
 	 */
-	tsk->flags |= PF_MEMALLOC | PF_KSWAPD;
+	tsk->flags |= PF_MEMALLOC;
 	set_freezable();
 
 	WRITE_ONCE(pgdat->kswapd_order, 0);
@@ -7518,11 +7518,17 @@ static int kswapd(void *p)
 			goto kswapd_try_sleep;
 	}
 
-	tsk->flags &= ~(PF_MEMALLOC | PF_KSWAPD);
+	tsk->flags &= ~PF_MEMALLOC;
 
 	return 0;
 }
 
+bool current_is_kswapd(void)
+{
+	return kthread_func(current) == kswapd;
+}
+EXPORT_SYMBOL_GPL(current_is_kswapd);
+
 /*
  * A zone is low on free memory or too fragmented for high-order memory.  If
  * kswapd should reclaim (direct reclaim is deferred), wake it up for the zone's
tools/sched_ext/include/scx/common.bpf.h +0 -1
index 76f5e025e107..3e095343ae84 100644
@@ -32,7 +32,6 @@
 #define PF_IO_WORKER			0x00000010	/* Task is an IO worker */
 #define PF_WQ_WORKER			0x00000020	/* I'm a workqueue worker */
 #define PF_KCOMPACTD			0x00010000      /* I am kcompactd */
-#define PF_KSWAPD			0x00020000      /* I am kswapd */
 #define PF_KTHREAD			0x00200000	/* I am a kernel thread */
 #define PF_EXITING			0x00000004
 #define CLOCK_MONOTONIC			1
Signature · 1 line
2.55.0
reviewer Acked-by on v1 3/4
#9 lore raw

Re: [PATCH 3/4] mm: replace PF_KSWAPD flag with kthread_func() check

Quoted 10 lines · Kefeng Wang

The preceding commits removed the last consumer that propagated PF_KSWAPD beyond kswapd itself (XFS btree split worker inheritance). The only remaining setter of PF_KSWAPD is kswapd(), and every current_is_kswapd() caller only needs to check whether the current task *is* the kswapd thread, not whether it inherited the flag.

Replace the flag-based test with kthread_func(current) == kswapd, freeing the 0x00020000 PF flag bit.

maintainer Acked-by on v1 3/4
#10 lore raw

Re: [PATCH 3/4] mm: replace PF_KSWAPD flag with kthread_func() check

In reply to Kefeng Wang
Quoted 10 lines · Kefeng Wang

The preceding commits removed the last consumer that propagated PF_KSWAPD beyond kswapd itself (XFS btree split worker inheritance). The only remaining setter of PF_KSWAPD is kswapd(), and every current_is_kswapd() caller only needs to check whether the current task *is* the kswapd thread, not whether it inherited the flag.

Replace the flag-based test with kthread_func(current) == kswapd, freeing the 0x00020000 PF flag bit.

Quoted 89 lines
---
 include/linux/sched.h                    |  2 +-
 include/linux/swap.h                     |  7 +------
 mm/vmscan.c                              | 10 ++++++++--
 tools/sched_ext/include/scx/common.bpf.h |  1 -
 4 files changed, 10 insertions(+), 10 deletions(-)
include/linux/sched.h +1 -1
index 8b3d47a325cc..86394121b6c0 100644
@@ -1809,7 +1809,7 @@ extern struct pid *cad_pid;
 #define PF_USER_WORKER		0x00004000	/* Kernel thread cloned from userspace thread */
 #define PF_NOFREEZE		0x00008000	/* This thread should not be frozen */
 #define PF_KCOMPACTD		0x00010000	/* I am kcompactd */
-#define PF_KSWAPD		0x00020000	/* I am kswapd */
+#define PF__HOLE__00020000	0x00020000
 #define PF_MEMALLOC_NOFS	0x00040000	/* All allocations inherit GFP_NOFS. See memalloc_nfs_save() */
 #define PF_MEMALLOC_NOIO	0x00080000	/* All allocations inherit GFP_NOIO. See memalloc_noio_save() */
 #define PF_LOCAL_THROTTLE	0x00100000	/* Throttle writes only against the bdi I write to,
include/linux/swap.h +1 -6
index a72ecf12c00d..fc290e29e4a9 100644
@@ -25,12 +25,6 @@
 #define SWAP_FLAGS_VALID	(SWAP_FLAG_PRIO_MASK | SWAP_FLAG_PREFER | \
 				 SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE | \
 				 SWAP_FLAG_DISCARD_PAGES)
-
-static inline int current_is_kswapd(void)
-{
-	return current->flags & PF_KSWAPD;
-}
-
 /*
  * MAX_SWAPFILES defines the maximum number of swaptypes: things which can
  * be swapped to.  The swap type and the offset into that swap type are
@@ -339,6 +333,7 @@ void check_move_unevictable_folios(struct folio_batch *fbatch);
 
 extern void __meminit kswapd_run(int nid);
 extern void __meminit kswapd_stop(int nid);
+bool current_is_kswapd(void);
 
 #ifdef CONFIG_SWAP
 int add_swap_extent(struct swap_info_struct *sis, unsigned long start_page,
mm/vmscan.c +8 -2
index 07ba86634b84..775d3f71a9de 100644
@@ -7468,7 +7468,7 @@ static int kswapd(void *p)
 	 * us from recursively trying to free more memory as we're
 	 * trying to free the first piece of memory in the first place).
 	 */
-	tsk->flags |= PF_MEMALLOC | PF_KSWAPD;
+	tsk->flags |= PF_MEMALLOC;
 	set_freezable();
 
 	WRITE_ONCE(pgdat->kswapd_order, 0);
@@ -7518,11 +7518,17 @@ static int kswapd(void *p)
 			goto kswapd_try_sleep;
 	}
 
-	tsk->flags &= ~(PF_MEMALLOC | PF_KSWAPD);
+	tsk->flags &= ~PF_MEMALLOC;
 
 	return 0;
 }
 
+bool current_is_kswapd(void)
+{
+	return kthread_func(current) == kswapd;
+}
+EXPORT_SYMBOL_GPL(current_is_kswapd);
+
 /*
  * A zone is low on free memory or too fragmented for high-order memory.  If
  * kswapd should reclaim (direct reclaim is deferred), wake it up for the zone's
tools/sched_ext/include/scx/common.bpf.h +0 -1
index 76f5e025e107..3e095343ae84 100644
@@ -32,7 +32,6 @@
 #define PF_IO_WORKER			0x00000010	/* Task is an IO worker */
 #define PF_WQ_WORKER			0x00000020	/* I'm a workqueue worker */
 #define PF_KCOMPACTD			0x00010000      /* I am kcompactd */
-#define PF_KSWAPD			0x00020000      /* I am kswapd */
 #define PF_KTHREAD			0x00200000	/* I am a kernel thread */
 #define PF_EXITING			0x00000004
 #define CLOCK_MONOTONIC			1
reviewer Acked-by on v1 3/4
#11 lore raw

Re: [PATCH 3/4] mm: replace PF_KSWAPD flag with kthread_func() check

In reply to Kefeng Wang
Quoted 9 lines · Kefeng Wang

The preceding commits removed the last consumer that propagated PF_KSWAPD beyond kswapd itself (XFS btree split worker inheritance). The only remaining setter of PF_KSWAPD is kswapd(), and every current_is_kswapd() caller only needs to check whether the current task *is* the kswapd thread, not whether it inherited the flag.

Replace the flag-based test with kthread_func(current) == kswapd, freeing the 0x00020000 PF flag bit.

Quoted 8 lines
---
 include/linux/sched.h                    |  2 +-
 include/linux/swap.h                     |  7 +------
 mm/vmscan.c                              | 10 ++++++++--
 tools/sched_ext/include/scx/common.bpf.h |  1 -
 4 files changed, 10 insertions(+), 10 deletions(-)

LGTM.

Signature · 2 lines
Best Regards,
Yan, Zi
#12 lore raw

Re: [PATCH 3/4] mm: replace PF_KSWAPD flag with kthread_func() check

In reply to Kefeng Wang
Quoted 1 line · Kefeng Wang

The preceding commits removed the last consumer that propagated

We avoid talking about commits or patches.

"There are no more consumers that ..."

Signature · 3 lines
Cheers,

David
#13 lore raw

PATCH 4/4 mm: replace PF_KCOMPACTD flag with kthread_func() check

In reply to Kefeng Wang

PF_KCOMPACTD was introduced by commit ce6d9c1c2b5c ("NFS: fix nfs_release_folio() to not deadlock via kcompactd writeback") so nfs_release_folio() could detect kcompactd context and skip writeback. The flag is only consumed by current_is_kcompactd(), whose sole caller is nfs_release_folio().

Replace the flag-based check with kthread_func(current) == kcompactd, freeing the 0x00010000 PF flag bit.

---
 include/linux/compaction.h               | 11 ++++++-----
 include/linux/sched.h                    |  2 +-
 mm/compaction.c                          |  9 ++++++---
 tools/sched_ext/include/scx/common.bpf.h |  1 -
 4 files changed, 13 insertions(+), 10 deletions(-)
include/linux/compaction.h +6 -5
index 66a2f70e9e01..691c09f0a697 100644
@@ -81,10 +81,6 @@ static inline unsigned long compact_gap(unsigned int order)
 	return min(2UL << order, COMPACT_CLUSTER_MAX);
 }
 
-static inline int current_is_kcompactd(void)
-{
-	return current->flags & PF_KCOMPACTD;
-}
 
 #ifdef CONFIG_COMPACTION
 
@@ -103,7 +99,7 @@ extern void compaction_defer_reset(struct zone *zone, int order,
 
 bool compaction_zonelist_suitable(struct alloc_context *ac, int order,
 					int alloc_flags, gfp_t gfp_mask);
-
+bool current_is_kcompactd(void);
 extern void __meminit kcompactd_run(int nid);
 extern void __meminit kcompactd_stop(int nid);
 extern void wakeup_kcompactd(pg_data_t *pgdat, int order, int highest_zoneidx);
@@ -120,6 +116,11 @@ static inline bool compaction_suitable(struct zone *zone, int order,
 	return false;
 }
 
+static inline bool current_is_kcompactd(void)
+{
+	return false;
+}
+
 static inline void kcompactd_run(int nid)
 {
 }
include/linux/sched.h +1 -1
index 86394121b6c0..eb12ff4cea6c 100644
@@ -1808,7 +1808,7 @@ extern struct pid *cad_pid;
 #define PF_USED_MATH		0x00002000	/* If unset the fpu must be initialized before use */
 #define PF_USER_WORKER		0x00004000	/* Kernel thread cloned from userspace thread */
 #define PF_NOFREEZE		0x00008000	/* This thread should not be frozen */
-#define PF_KCOMPACTD		0x00010000	/* I am kcompactd */
+#define PF__HOLE__00010000	0x00010000
 #define PF__HOLE__00020000	0x00020000
 #define PF_MEMALLOC_NOFS	0x00040000	/* All allocations inherit GFP_NOFS. See memalloc_nfs_save() */
 #define PF_MEMALLOC_NOIO	0x00080000	/* All allocations inherit GFP_NOIO. See memalloc_noio_save() */
mm/compaction.c +6 -3
index a049415512c6..4994e200bbec 100644
@@ -3197,7 +3197,6 @@ static int kcompactd(void *p)
 	long default_timeout = msecs_to_jiffies(HPAGE_FRAG_CHECK_INTERVAL_MSEC);
 	long timeout = default_timeout;
 
-	current->flags |= PF_KCOMPACTD;
 	set_freezable();
 
 	pgdat->kcompactd_max_order = 0;
@@ -3254,11 +3253,15 @@ static int kcompactd(void *p)
 			pgdat->proactive_compact_trigger = false;
 	}
 
-	current->flags &= ~PF_KCOMPACTD;
-
 	return 0;
 }
 
+bool current_is_kcompactd(void)
+{
+	return kthread_func(current) == kcompactd;
+}
+EXPORT_SYMBOL_GPL(current_is_kcompactd);
+
 /*
  * This kcompactd start function will be called by init and node-hot-add.
  * On node-hot-add, kcompactd will moved to proper cpus if cpus are hot-added.
tools/sched_ext/include/scx/common.bpf.h +0 -1
index 3e095343ae84..807ef881ce2d 100644
@@ -31,7 +31,6 @@
 #define PF_IDLE				0x00000002	/* I am an IDLE thread */
 #define PF_IO_WORKER			0x00000010	/* Task is an IO worker */
 #define PF_WQ_WORKER			0x00000020	/* I'm a workqueue worker */
-#define PF_KCOMPACTD			0x00010000      /* I am kcompactd */
 #define PF_KTHREAD			0x00200000	/* I am a kernel thread */
 #define PF_EXITING			0x00000004
 #define CLOCK_MONOTONIC			1
Signature · 1 line
2.55.0
reviewer Acked-by on v1 4/4
#14 lore raw

Re: [PATCH 4/4] mm: replace PF_KCOMPACTD flag with kthread_func() check

Quoted 10 lines · Kefeng Wang

PF_KCOMPACTD was introduced by commit ce6d9c1c2b5c ("NFS: fix nfs_release_folio() to not deadlock via kcompactd writeback") so nfs_release_folio() could detect kcompactd context and skip writeback. The flag is only consumed by current_is_kcompactd(), whose sole caller is nfs_release_folio().

Replace the flag-based check with kthread_func(current) == kcompactd, freeing the 0x00010000 PF flag bit.

maintainer Acked-by on v1 4/4
#15 lore raw

Re: [PATCH 4/4] mm: replace PF_KCOMPACTD flag with kthread_func() check

In reply to Kefeng Wang
Quoted 10 lines · Kefeng Wang

PF_KCOMPACTD was introduced by commit ce6d9c1c2b5c ("NFS: fix nfs_release_folio() to not deadlock via kcompactd writeback") so nfs_release_folio() could detect kcompactd context and skip writeback. The flag is only consumed by current_is_kcompactd(), whose sole caller is nfs_release_folio().

Replace the flag-based check with kthread_func(current) == kcompactd, freeing the 0x00010000 PF flag bit.

reviewer Acked-by on v1 4/4
#16 lore raw

Re: [PATCH 4/4] mm: replace PF_KCOMPACTD flag with kthread_func() check

In reply to Kefeng Wang
Quoted 9 lines · Kefeng Wang

PF_KCOMPACTD was introduced by commit ce6d9c1c2b5c ("NFS: fix nfs_release_folio() to not deadlock via kcompactd writeback") so nfs_release_folio() could detect kcompactd context and skip writeback. The flag is only consumed by current_is_kcompactd(), whose sole caller is nfs_release_folio().

Replace the flag-based check with kthread_func(current) == kcompactd, freeing the 0x00010000 PF flag bit.

Quoted 8 lines
---
 include/linux/compaction.h               | 11 ++++++-----
 include/linux/sched.h                    |  2 +-
 mm/compaction.c                          |  9 ++++++---
 tools/sched_ext/include/scx/common.bpf.h |  1 -
 4 files changed, 13 insertions(+), 10 deletions(-)
Signature · 2 lines
Best Regards,
Yan, Zi
reviewer Reviewed-by on v1 4/4
#17 lore raw

Re: [PATCH 4/4] mm: replace PF_KCOMPACTD flag with kthread_func() check

In reply to Kefeng Wang
Quoted 11 lines · Kefeng Wang

PF_KCOMPACTD was introduced by commit ce6d9c1c2b5c ("NFS: fix nfs_release_folio() to not deadlock via kcompactd writeback") so nfs_release_folio() could detect kcompactd context and skip writeback. The flag is only consumed by current_is_kcompactd(), whose sole caller is nfs_release_folio().

Replace the flag-based check with kthread_func(current) == kcompactd, freeing the 0x00010000 PF flag bit.

---

Signature · 3 lines
Cheers,

David
reviewer
#18 lore raw
In reply to Kefeng Wang
Quoted 4 lines · Kefeng Wang

The task_struct->flags field is a limited 32-bit resource. Two flag bits, PF_KCOMPACTD and PF_KSWAPD, are used to identify whether a kernel thread is kcompactd or kswapd. Converting these to use kthread_func() frees up two valuable flag bits for future use.

I wouldn't call it a limited resource. We can have more fields in task_struct but I like the cleanups.

Quoted 21 lines

Kefeng Wang (4):
xfs: remove dead kswapd flag inheritance from btree split worker
iomap: simplify writepages reclaim guard
mm: replace PF_KSWAPD flag with kthread_func() check
mm: replace PF_KCOMPACTD flag with kthread_func() check

 fs/iomap/buffered-io.c                   |  3 +--
 fs/xfs/libxfs/xfs_btree.c                | 18 +-----------------
 fs/xfs/xfs_platform.h                    |  4 ----
 include/linux/compaction.h               | 11 ++++++-----
 include/linux/sched.h                    |  4 ++--
 include/linux/swap.h                     |  7 +------
 mm/compaction.c                          |  9 ++++++---
 mm/vmscan.c                              | 10 ++++++++--
 tools/sched_ext/include/scx/common.bpf.h |  2 --
 9 files changed, 25 insertions(+), 43 deletions(-)
Signature · 1 line
2.55.0
maintainer
#19 lore raw
In reply to Kefeng Wang
Quoted 4 lines · On Wed, 2 Sep 2026 21:16:49 +0800 Kefeng Wang <[email protected]>…

The task_struct->flags field is a limited 32-bit resource. Two flag bits, PF_KCOMPACTD and PF_KSWAPD, are used to identify whether a kernel thread is kcompactd or kswapd. Converting these to use kthread_func() frees up two valuable flag bits for future use.

Well that was popular.

Sashiko might have found a problem in the existing XFS code:

	https://sashiko.dev/#/patchset/[email protected]
#20 lore raw

PATCH 1/1 xfs: fix NOFS state corruption in btree split worker

xfs_btree_split_worker() calls xfs_trans_set_context() and xfs_trans_clear_context() on the caller's transaction, overwriting tp->t_pflags with the worker's NOFS state. When the caller already has PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io), the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear the caller's NOFS protection.

Use memalloc_nofs_save/restore with a local variable instead so tp->t_pflags is never touched.

Fixes 756b1c343333 ("xfs: use current->journal_info for detecting transaction recursion")
---
 fs/xfs/libxfs/xfs_btree.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_btree.c +8 -2
index 6738d9d1511b..8ae4b94e6995 100644
@@ -3007,12 +3007,18 @@ xfs_btree_split_worker(
 {
 	struct xfs_btree_split_args	*args = container_of(work,
 						struct xfs_btree_split_args, work);
-	xfs_trans_set_context(args->cur->bc_tp);
+	unsigned int			nofs_flags;
+
+	/*
+	 * Don't use xfs_trans_set_context() here: it would overwrite the
+	 * caller's saved NOFS state in tp->t_pflags.  Use a local scope.
+	 */
+	nofs_flags = memalloc_nofs_save();
 
 	args->result = __xfs_btree_split(args->cur, args->level, args->ptrp,
 					 args->key, args->curp, args->stat);
 
-	xfs_trans_clear_context(args->cur->bc_tp);
+	memalloc_nofs_restore(nofs_flags);
 
 	/*
 	 * Do not access args after complete() has run here. We don't own args
Signature · 1 line
2.55.0
#21 lore raw

Re: [PATCH] xfs: fix NOFS state corruption in btree split worker

Quoted 7 lines · Kefeng Wang

xfs_btree_split_worker() calls xfs_trans_set_context() and xfs_trans_clear_context() on the caller's transaction, overwriting tp->t_pflags with the worker's NOFS state. When the caller already has PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io), the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear the caller's NOFS protection.

Quoted 7 lines

Use memalloc_nofs_save/restore with a local variable instead so tp->t_pflags is never touched.

Fixes 756b1c343333 ("xfs: use current->journal_info for detecting transaction recursion")

---

I agree that the Sashiko analysis looks correct. The only thing I wonder is whether it might be a bit cleaner to have the set_context() helper return the context instead of hardcode the assignment to ->t_pflags so it can be used in both places. The reasoning is just that the current arrangement kind of makes it easy to repeat this mistake in the future.

Then again, it's a single line helper so maybe another option could be to just remove and open code it. I suppose the pro of keeping the helper is that it's a decent spot to document the concern and why it returns a value, etc. *shrug* Thoughts?

(Please don't change this patch just on my comments alone. Let's see if others have input first..).

Brian

Quoted 32 lines
 fs/xfs/libxfs/xfs_btree.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_btree.c +8 -2
index 6738d9d1511b..8ae4b94e6995 100644
@@ -3007,12 +3007,18 @@ xfs_btree_split_worker(
 {
 	struct xfs_btree_split_args	*args = container_of(work,
 						struct xfs_btree_split_args, work);
-	xfs_trans_set_context(args->cur->bc_tp);
+	unsigned int			nofs_flags;
+
+	/*
+	 * Don't use xfs_trans_set_context() here: it would overwrite the
+	 * caller's saved NOFS state in tp->t_pflags.  Use a local scope.
+	 */
+	nofs_flags = memalloc_nofs_save();
 
 	args->result = __xfs_btree_split(args->cur, args->level, args->ptrp,
 					 args->key, args->curp, args->stat);
 
-	xfs_trans_clear_context(args->cur->bc_tp);
+	memalloc_nofs_restore(nofs_flags);
 
 	/*
 	 * Do not access args after complete() has run here. We don't own args
Signature · 1 line
2.55.0
#22 lore raw

Re: [PATCH] xfs: fix NOFS state corruption in btree split worker

Quoted 22 lines · Brian Foster
Quoted 7 lines · Kefeng Wang

xfs_btree_split_worker() calls xfs_trans_set_context() and xfs_trans_clear_context() on the caller's transaction, overwriting tp->t_pflags with the worker's NOFS state. When the caller already has PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io), the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear the caller's NOFS protection.

Quoted 7 lines

Use memalloc_nofs_save/restore with a local variable instead so tp->t_pflags is never touched.

Fixes 756b1c343333 ("xfs: use current->journal_info for detecting transaction recursion")

---

I agree that the Sashiko analysis looks correct. The only thing I wonder is whether it might be a bit cleaner to have the set_context() helper return the context instead of hardcode the assignment to ->t_pflags so it can be used in both places. The reasoning is just that the current arrangement kind of makes it easy to repeat this mistake in the future.

Quoted 4 lines

Then again, it's a single line helper so maybe another option could be to just remove and open code it. I suppose the pro of keeping the helper is that it's a decent spot to document the concern and why it returns a value, etc. *shrug* Thoughts?

I personally tend to remove the helper functions, but let's see what others think.

Quoted 40 lines

(Please don't change this patch just on my comments alone. Let's see if others have input first..).

Brian

Quoted 32 lines
  fs/xfs/libxfs/xfs_btree.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_btree.c +8 -2
index 6738d9d1511b..8ae4b94e6995 100644
@@ -3007,12 +3007,18 @@ xfs_btree_split_worker(
  {
  	struct xfs_btree_split_args	*args = container_of(work,
  						struct xfs_btree_split_args, work);
-	xfs_trans_set_context(args->cur->bc_tp);
+	unsigned int			nofs_flags;
+
+	/*
+	 * Don't use xfs_trans_set_context() here: it would overwrite the
+	 * caller's saved NOFS state in tp->t_pflags.  Use a local scope.
+	 */
+	nofs_flags = memalloc_nofs_save();
 
  	args->result = __xfs_btree_split(args->cur, args->level, args->ptrp,
  					 args->key, args->curp, args->stat);
 
-	xfs_trans_clear_context(args->cur->bc_tp);
+	memalloc_nofs_restore(nofs_flags);
 
  	/*
  	 * Do not access args after complete() has run here. We don't own args
Signature · 1 line
2.55.0
Reviewed-by
#23 lore raw

Re: [PATCH] xfs: fix NOFS state corruption in btree split worker

Quoted 25 lines · Kefeng Wang
Quoted 22 lines · Brian Foster
Quoted 7 lines · Kefeng Wang

xfs_btree_split_worker() calls xfs_trans_set_context() and xfs_trans_clear_context() on the caller's transaction, overwriting tp->t_pflags with the worker's NOFS state. When the caller already has PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io), the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear the caller's NOFS protection.

Quoted 7 lines

Use memalloc_nofs_save/restore with a local variable instead so tp->t_pflags is never touched.

Fixes 756b1c343333 ("xfs: use current->journal_info for detecting transaction recursion")

---

I agree that the Sashiko analysis looks correct. The only thing I wonder is whether it might be a bit cleaner to have the set_context() helper return the context instead of hardcode the assignment to ->t_pflags so it can be used in both places. The reasoning is just that the current arrangement kind of makes it easy to repeat this mistake in the future.

Quoted 9 lines
Quoted 4 lines

Then again, it's a single line helper so maybe another option could be to just remove and open code it. I suppose the pro of keeping the helper is that it's a decent spot to document the concern and why it returns a value, etc. *shrug* Thoughts?

I personally tend to remove the helper functions, but let's see what others think.

I noticed after writing this that there were many more open coded nofs calls than I originally thought, so this is a fair point. After some thought I think this is a reasonable approach regardless:

You might want to send as a standalone patch though..

Brian

Quoted 38 lines
Quoted 37 lines

(Please don't change this patch just on my comments alone. Let's see if others have input first..).

Brian

Quoted 29 lines
  fs/xfs/libxfs/xfs_btree.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_btree.c +8 -2
index 6738d9d1511b..8ae4b94e6995 100644
@@ -3007,12 +3007,18 @@ xfs_btree_split_worker(
  {
  	struct xfs_btree_split_args	*args = container_of(work,
  						struct xfs_btree_split_args, work);
-	xfs_trans_set_context(args->cur->bc_tp);
+	unsigned int			nofs_flags;
+
+	/*
+	 * Don't use xfs_trans_set_context() here: it would overwrite the
+	 * caller's saved NOFS state in tp->t_pflags.  Use a local scope.
+	 */
+	nofs_flags = memalloc_nofs_save();
  	args->result = __xfs_btree_split(args->cur, args->level, args->ptrp,
  					 args->key, args->curp, args->stat);
-	xfs_trans_clear_context(args->cur->bc_tp);
+	memalloc_nofs_restore(nofs_flags);
  	/*
  	 * Do not access args after complete() has run here. We don't own args
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#24 lore raw

Re: [PATCH] xfs: fix NOFS state corruption in btree split worker

In reply to Kefeng Wang

Adding Yun Zhou, whoch touched this area recently.

Quoted 9 lines · Kefeng Wang

xfs_btree_split_worker() calls xfs_trans_set_context() and xfs_trans_clear_context() on the caller's transaction, overwriting tp->t_pflags with the worker's NOFS state. When the caller already has PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io), the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear the caller's NOFS protection.

Use memalloc_nofs_save/restore with a local variable instead so tp->t_pflags is never touched.

Looks good:

Btw, if you have some spare time, it would be nice to kill xfs_trans_set_context/xfs_trans_clear_context as follow up given that they keep causing confusion.

#25 lore raw

Re: [PATCH] xfs: fix NOFS state corruption in btree split worker

Quoted 13 lines · Christoph Hellwig

Adding Yun Zhou, whoch touched this area recently.

Quoted 9 lines · Kefeng Wang

xfs_btree_split_worker() calls xfs_trans_set_context() and xfs_trans_clear_context() on the caller's transaction, overwriting tp->t_pflags with the worker's NOFS state. When the caller already has PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io), the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear the caller's NOFS protection.

Use memalloc_nofs_save/restore with a local variable instead so tp->t_pflags is never touched.

Quoted 7 lines

Looks good:

Btw, if you have some spare time, it would be nice to kill xfs_trans_set_context/xfs_trans_clear_context as follow up given that they keep causing confusion.

Yes please, the wrappers have not been useful for making anyone's life easier. :/

--D

#26 lore raw

Re: [PATCH] xfs: fix NOFS state corruption in btree split worker

In reply to Christoph Hellwig
Quoted 13 lines · Christoph Hellwig

Adding Yun Zhou, whoch touched this area recently.

Quoted 9 lines · Kefeng Wang

xfs_btree_split_worker() calls xfs_trans_set_context() and xfs_trans_clear_context() on the caller's transaction, overwriting tp->t_pflags with the worker's NOFS state. When the caller already has PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io), the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear the caller's NOFS protection.

Use memalloc_nofs_save/restore with a local variable instead so tp->t_pflags is never touched.

Quoted 7 lines

Looks good:

Btw, if you have some spare time, it would be nice to kill xfs_trans_set_context/xfs_trans_clear_context as follow up given that they keep causing confusion.

Yes, you finished reviewing this patch [1] in July. However, I'm not sure about its current status. Perhaps I should ping Carlos to check?

[1] https://lore.kernel.org/all/[email protected]/

Thanks,
Yun

maintainer
#27 lore raw

Re: [PATCH] xfs: fix NOFS state corruption in btree split worker

Quoted 24 lines · Yun
Quoted 13 lines · Christoph Hellwig

Adding Yun Zhou, whoch touched this area recently.

Quoted 9 lines · Kefeng Wang

xfs_btree_split_worker() calls xfs_trans_set_context() and xfs_trans_clear_context() on the caller's transaction, overwriting tp->t_pflags with the worker's NOFS state. When the caller already has PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io), the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear the caller's NOFS protection.

Use memalloc_nofs_save/restore with a local variable instead so tp->t_pflags is never touched.

Quoted 7 lines

Looks good:

Btw, if you have some spare time, it would be nice to kill xfs_trans_set_context/xfs_trans_clear_context as follow up given that they keep causing confusion.

Quoted 5 lines

Yes, you finished reviewing this patch [1] in July. However, I'm not sure about its current status. Perhaps I should ping Carlos to check?

[1]
https://lore.kernel.org/all/[email protected]/

Ok, now I see why Kefeng Wang re-sent these patches...

The first submission in July slipped through the cracks (I was on vacation that specific week FWIW). Feel free to give me a heads up if something don't get pulled in 1 or 2 weeks.

This one though is buried in a multi-subsystem series because you sent the patch In-Reply-To one of the emails in that thread. Please don't send patches as In-Reply-To something else, specially to a multi-subsystem series because it's really easy to skip such patches.

And then I got a "Re-Send" series with zero information why it has been re-sent, and one of the patches in that series was already picked up by Andrew. So I can't simply merge that here and mess up with what Andrew already planned.

If this patch can be merged before:

commit 14ec230f93fa928090507cfdc67ca67e928d0c9f (linux-mm)

Author: Kefeng Wang <[email protected]>
Date:   Wed Sep 2 21:16:50 2026 +0800

xfs: remove dead kswapd flag inheritance from btree split worker

then please re-send it, otherwise wait for the above patch to land in Linus's tree, rebase and re-send.

Cheers,
Carlos

#28 lore raw

Re: [PATCH] xfs: fix NOFS state corruption in btree split worker

Quoted 46 lines · Carlos Maiolino
Quoted 22 lines · Christoph Hellwig
Quoted 13 lines

Adding Yun Zhou, whoch touched this area recently.

Quoted 9 lines · Kefeng Wang

xfs_btree_split_worker() calls xfs_trans_set_context() and xfs_trans_clear_context() on the caller's transaction, overwriting tp->t_pflags with the worker's NOFS state. When the caller already has PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io), the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear the caller's NOFS protection.

Use memalloc_nofs_save/restore with a local variable instead so tp->t_pflags is never touched.

Quoted 7 lines

Looks good:

Btw, if you have some spare time, it would be nice to kill xfs_trans_set_context/xfs_trans_clear_context as follow up given that they keep causing confusion.

Quoted 5 lines

Yes, you finished reviewing this patch [1] in July. However, I'm not sure about its current status. Perhaps I should ping Carlos to check?

[1]
https://lore.kernel.org/all/[email protected]/

Ok, now I see why Kefeng Wang re-sent these patches...

The first submission in July slipped through the cracks (I was on vacation that specific week FWIW). Feel free to give me a heads up if something don't get pulled in 1 or 2 weeks.

This one though is buried in a multi-subsystem series because you sent the patch In-Reply-To one of the emails in that thread. Please don't send patches as In-Reply-To something else, specially to a multi-subsystem series because it's really easy to skip such patches.

And then I got a "Re-Send" series with zero information why it has been re-sent, and one of the patches in that series was already picked up by Andrew. So I can't simply merge that here and mess up with what Andrew already planned.

If this patch can be merged before:

Quoted 9 lines

commit 14ec230f93fa928090507cfdc67ca67e928d0c9f (linux-mm)

Author: Kefeng Wang <[email protected]>
Date:   Wed Sep 2 21:16:50 2026 +0800

xfs: remove dead kswapd flag inheritance from btree split worker

then please re-send it, otherwise wait for the above patch to land in Linus's tree, rebase and re-send.

To be honest, I was on vacation in August, and I've been busy catching up on backlogged work since I returned. I admit I lost track of some patches' status. That is entirely my fault, and I sincerely apologize.

More importantly, my patch modifies the same code in xfs_btree_split_worker() as Kefeng's series, which is already under review and heading in the same direction. Therefore, there's no point in my resending mine. Please just ignore my patch and let Kefeng's series cover it.

Thanks,
Yun

maintainer
#29 lore raw

Re: [PATCH] xfs: fix NOFS state corruption in btree split worker

Quoted 53 lines · Yun
Quoted 50 lines · Carlos Maiolino
Quoted 22 lines · Christoph Hellwig
Quoted 13 lines

Adding Yun Zhou, whoch touched this area recently.

Quoted 9 lines · Kefeng Wang

xfs_btree_split_worker() calls xfs_trans_set_context() and xfs_trans_clear_context() on the caller's transaction, overwriting tp->t_pflags with the worker's NOFS state. When the caller already has PF_MEMALLOC_NOFS set (e.g. xfs_end_ioend_write, xfs_dio_write_end_io), the corrupted tp->t_pflags causes xfs_trans_free() to erroneously clear the caller's NOFS protection.

Use memalloc_nofs_save/restore with a local variable instead so tp->t_pflags is never touched.

Quoted 7 lines

Looks good:

Btw, if you have some spare time, it would be nice to kill xfs_trans_set_context/xfs_trans_clear_context as follow up given that they keep causing confusion.

Quoted 5 lines

Yes, you finished reviewing this patch [1] in July. However, I'm not sure about its current status. Perhaps I should ping Carlos to check?

[1]
https://lore.kernel.org/all/[email protected]/

Ok, now I see why Kefeng Wang re-sent these patches...

The first submission in July slipped through the cracks (I was on vacation that specific week FWIW). Feel free to give me a heads up if something don't get pulled in 1 or 2 weeks.

This one though is buried in a multi-subsystem series because you sent the patch In-Reply-To one of the emails in that thread. Please don't send patches as In-Reply-To something else, specially to a multi-subsystem series because it's really easy to skip such patches.

And then I got a "Re-Send" series with zero information why it has been re-sent, and one of the patches in that series was already picked up by Andrew. So I can't simply merge that here and mess up with what Andrew already planned.

If this patch can be merged before:

commit 14ec230f93fa928090507cfdc67ca67e928d0c9f (linux-mm)

Author: Kefeng Wang <[email protected]>
Date:   Wed Sep 2 21:16:50 2026 +0800
Quoted 8 lines
Quoted 5 lines

xfs: remove dead kswapd flag inheritance from btree split worker

then please re-send it, otherwise wait for the above patch to land in Linus's tree, rebase and re-send.

To be honest, I was on vacation in August, and I've been busy catching up on backlogged work since I returned. I admit I lost track of some patches' status. That is entirely my fault, and I sincerely apologize.

There are no need for apologies, my point is if you have/had a patch
and it wasn't picked up for whatever reason, feel free to ask/ping about the status...

Specially nowadays with the huge increase in the patches inflow, thanks to LLMs, this is subject to happen more often.

Quoted 5 lines

More importantly, my patch modifies the same code in xfs_btree_split_worker() as Kefeng's series, which is already under review and heading in the same direction. Therefore, there's no point in my resending mine. Please just ignore my patch and let Kefeng's series cover it.

np,
Carlos

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): aqLqeTsbKBMEsl-G@bfoster

#32 lore raw

Re: [PATCH] xfs: kill xfs_trans_set/clear_context() helpers

+Cc list

Quoted 10 lines · Brian Foster
Quoted 7 lines · Kefeng Wang

Open code the helpers so that tp->t_pflags access is explicit, reducing the risk of misusing them outside the transaction owner thread as seen in xfs_btree_split_worker().

---

Any reason this is not cc'd to the list? That aside:

Oh,my bad, sorry for missing it, should I resend it?

Another question is the target repository for merging this patch.
Both this patch and the previous bug fix are based on the mm-new
branch. Merging into xfs separately (if an independent branch exists) might cause conflicts.

Quoted 3 lines

Thanks.

#33 lore raw

Re: [PATCH] xfs: kill xfs_trans_set/clear_context() helpers

Quoted 4 lines · Kefeng Wang

Another question is the target repository for merging this patch. Both this patch and the previous bug fix are based on the mm-new branch. Merging into xfs separately (if an independent branch exists) might cause conflicts.

Your first follow up fixes a xfs bug that can have somewhat nasty consequences. So I'd suggest you send us a standalone series that we can get into 7.3 and -stable with as few dependencies as possible. mm-new can get rebased on top of that, and then we can delay the pure cleanups for xfs until after that is merged

#34 lore raw

Re: [PATCH] xfs: kill xfs_trans_set/clear_context() helpers

Quoted 11 lines · Christoph Hellwig
Quoted 4 lines · Kefeng Wang

Another question is the target repository for merging this patch. Both this patch and the previous bug fix are based on the mm-new branch. Merging into xfs separately (if an independent branch exists) might cause conflicts.

Your first follow up fixes a xfs bug that can have somewhat nasty consequences. So I'd suggest you send us a standalone series that we can get into 7.3 and -stable with as few dependencies as possible. mm-new can get rebased on top of that, and then we can delay the pure cleanups for xfs until after that is merged

Thank you for your suggestion. I rebase on v7.3-rc2 and resend them.
https://lore.kernel.org/linux-xfs/[email protected]/T/#t

#35 lore raw
In reply to Andrew Morton
Quoted 7 lines · Andrew Morton
Quoted 4 lines · On Wed, 2 Sep 2026 21:16:49 +0800 Kefeng Wang <[email protected]>…

The task_struct->flags field is a limited 32-bit resource. Two flag bits, PF_KCOMPACTD and PF_KSWAPD, are used to identify whether a kernel thread is kcompactd or kswapd. Converting these to use kthread_func() frees up two valuable flag bits for future use.

Quoted 6 lines

Well that was popular.

Sashiko might have found a problem in the existing XFS code:

	https://sashiko.dev/#/patchset/[email protected]

Sashiko looks correct, I sent a fix patch, hoping it will work properly.