From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: <brauner@kernel.org>, <djwong@kernel.org>, <cem@kernel.org>,
<akpm@linux-foundation.org>, <vbabka@kernel.org>,
<surenb@google.com>, <mhocko@suse.com>,
<brendan.jackman@linux.dev>, <hannes@cmpxchg.org>,
<ziy@nvidia.com>, <david@kernel.org>, <qi.zheng@linux.dev>,
<shakeel.butt@linux.dev>, <ljs@kernel.org>
Cc: <linux-xfs@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>,
<linux-mm@kvack.org>, Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: [PATCH 4/4] mm: replace PF_KCOMPACTD flag with kthread_func() check
Date: Wed, 2 Sep 2026 21:16:53 +0800 [thread overview]
Message-ID: <20260902131653.1338227-5-wangkefeng.wang@huawei.com> (raw)
In-Reply-To: <20260902131653.1338227-1-wangkefeng.wang@huawei.com>
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.
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
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(-)
diff --git a/include/linux/compaction.h b/include/linux/compaction.h
index 66a2f70e9e01..691c09f0a697 100644
--- a/include/linux/compaction.h
+++ b/include/linux/compaction.h
@@ -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)
{
}
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 86394121b6c0..eb12ff4cea6c 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -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() */
diff --git a/mm/compaction.c b/mm/compaction.c
index a049415512c6..4994e200bbec 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -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.
diff --git a/tools/sched_ext/include/scx/common.bpf.h b/tools/sched_ext/include/scx/common.bpf.h
index 3e095343ae84..807ef881ce2d 100644
--- a/tools/sched_ext/include/scx/common.bpf.h
+++ b/tools/sched_ext/include/scx/common.bpf.h
@@ -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
--
2.55.0
next prev parent reply other threads:[~2026-09-02 13:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 13:16 [PATCH 0/4] mm: replace PF_KCOMPACTD/PF_KSWAPD with kthread_func() Kefeng Wang
2026-09-02 13:16 ` [PATCH 1/4] xfs: remove dead kswapd flag inheritance from btree split worker Kefeng Wang
2026-09-02 14:32 ` Christoph Hellwig
2026-09-02 15:33 ` Shakeel Butt
2026-09-02 13:16 ` [PATCH 2/4] iomap: simplify writepages reclaim guard Kefeng Wang
2026-09-02 14:32 ` Christoph Hellwig
2026-09-03 13:46 ` Kefeng Wang
2026-09-02 15:34 ` Shakeel Butt
2026-09-02 13:16 ` [PATCH 3/4] mm: replace PF_KSWAPD flag with kthread_func() check Kefeng Wang
2026-09-02 15:36 ` Shakeel Butt
2026-09-02 16:35 ` Vlastimil Babka (SUSE)
2026-09-02 16:39 ` Zi Yan
2026-09-02 13:16 ` Kefeng Wang [this message]
2026-09-02 15:37 ` [PATCH 4/4] mm: replace PF_KCOMPACTD " Shakeel Butt
2026-09-02 16:36 ` Vlastimil Babka (SUSE)
2026-09-02 16:40 ` Zi Yan
2026-09-02 15:31 ` [PATCH 0/4] mm: replace PF_KCOMPACTD/PF_KSWAPD with kthread_func() Shakeel Butt
2026-09-02 20:44 ` Andrew Morton
2026-09-03 13:37 ` [PATCH] xfs: fix NOFS state corruption in btree split worker Kefeng Wang
2026-09-03 13:52 ` Brian Foster
2026-09-04 0:41 ` Kefeng Wang
2026-09-04 11:57 ` Brian Foster
2026-09-03 13:40 ` [PATCH 0/4] mm: replace PF_KCOMPACTD/PF_KSWAPD with kthread_func() Kefeng Wang
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=20260902131653.1338227-5-wangkefeng.wang@huawei.com \
--to=wangkefeng.wang@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=brendan.jackman@linux.dev \
--cc=cem@kernel.org \
--cc=david@kernel.org \
--cc=djwong@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=qi.zheng@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.com \
/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