Linux Documentation
 help / color / mirror / Atom feed
From: "Li Zhe" <lizhe.67@bytedance.com>
To: <mingo@redhat.com>, <peterz@infradead.org>,
	<juri.lelli@redhat.com>,  <vincent.guittot@linaro.org>,
	<dietmar.eggemann@arm.com>,  <rostedt@goodmis.org>,
	<bsegall@google.com>, <mgorman@suse.de>,  <vschneid@redhat.com>,
	<kprateek.nayak@amd.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>,
	 <linux-doc@vger.kernel.org>, <lizhe.67@bytedance.com>
Subject: [PATCH 2/4] sched/numa: Add prctl controls for process mode
Date: Tue,  8 Sep 2026 20:24:44 +0800	[thread overview]
Message-ID: <20260908122446.56708-3-lizhe.67@bytedance.com> (raw)
In-Reply-To: <20260908122446.56708-1-lizhe.67@bytedance.com>

Expose the process automatic NUMA balancing mode through prctl().
PR_SET_NUMA_BALANCING accepts PR_NUMA_BALANCING_DISABLE to opt the whole
thread group out of future NUMA scanning and PR_NUMA_BALANCING_ENABLE to
allow it to participate again when global NUMA balancing and memory
policy permit it.

PR_GET_NUMA_BALANCING returns the configured process mode, not the
effective state after combining the global sysctl/static key and memory
policy restrictions. This keeps the ABI weak and predictable: a process
can observe and restore the value it configured, while administrators
retain kernel.numa_balancing as the top-level hard-off switch.

Signed-off-by: Li Zhe <lizhe.67@bytedance.com>
---
 include/uapi/linux/prctl.h |  6 ++++++
 kernel/sys.c               | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h
index b6ec6f693719..5bc0a2a2a930 100644
--- a/include/uapi/linux/prctl.h
+++ b/include/uapi/linux/prctl.h
@@ -416,4 +416,10 @@ struct prctl_mm_map {
 # define PR_CFI_DISABLE		_BITUL(1)
 # define PR_CFI_LOCK		_BITUL(2)
 
+/* Per-process automatic NUMA balancing control */
+#define PR_SET_NUMA_BALANCING	82
+#define PR_GET_NUMA_BALANCING	83
+# define PR_NUMA_BALANCING_DISABLE	0
+# define PR_NUMA_BALANCING_ENABLE	1
+
 #endif /* _LINUX_PRCTL_H */
diff --git a/kernel/sys.c b/kernel/sys.c
index 35b538ba843c..fb01841c0ce9 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -60,6 +60,7 @@
 #include <linux/sched/stat.h>
 #include <linux/sched/mm.h>
 #include <linux/sched/coredump.h>
+#include <linux/sched/numa_balancing.h>
 #include <linux/sched/task.h>
 #include <linux/sched/cputime.h>
 #include <linux/rcupdate.h>
@@ -2907,6 +2908,23 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 		if (arg3 & PR_CFI_LOCK && !(arg3 & PR_CFI_DISABLE))
 			error = arch_prctl_lock_branch_landing_pad_state(me);
 		break;
+	case PR_SET_NUMA_BALANCING:
+		if (arg3 || arg4 || arg5)
+			return -EINVAL;
+		if (arg2 != PR_NUMA_BALANCING_DISABLE &&
+		    arg2 != PR_NUMA_BALANCING_ENABLE)
+			return -EINVAL;
+		error = task_numa_balancing_set_current(arg2 ==
+							 PR_NUMA_BALANCING_ENABLE);
+		break;
+	case PR_GET_NUMA_BALANCING:
+		if (arg2 || arg3 || arg4 || arg5)
+			return -EINVAL;
+		error = task_numa_balancing_get_current();
+		if (error >= 0)
+			error = error ? PR_NUMA_BALANCING_ENABLE :
+				PR_NUMA_BALANCING_DISABLE;
+		break;
 	default:
 		trace_task_prctl_unknown(option, arg2, arg3, arg4, arg5);
 		error = -EINVAL;
-- 
2.20.1

  parent reply	other threads:[~2026-09-08 12:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 12:24 [PATCH 0/4] sched/numa: Add per-process automatic NUMA balancing control Li Zhe
2026-09-08 12:24 ` [PATCH 1/4] sched/numa: Track per-process automatic NUMA balancing mode Li Zhe
2026-09-08 12:24 ` Li Zhe [this message]
2026-09-08 12:24 ` [PATCH 3/4] proc: Report process " Li Zhe
2026-09-08 12:24 ` [PATCH 4/4] Documentation: Describe per-process NUMA balancing control Li Zhe

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=20260908122446.56708-3-lizhe.67@bytedance.com \
    --to=lizhe.67@bytedance.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.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