From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from va-1-113.ptr.blmpb.com (va-1-113.ptr.blmpb.com [209.127.230.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F615531AE1 for ; Tue, 8 Sep 2026 12:26:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.113 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788870407; cv=none; b=oQKptkEgbujCX43B6CIziSfCGbB880TBwkIC/1wv3JdG/5mK7FuQD5/B95BTgEHgvr4fZX+zHgRat0bPJELtU7od1xBJioJUkQtYc5SE4waQOyy/aOP4/kyG+G7eul1IlDgBfiu7DIOGaGSPmw6TGHBpx2mdDSsN+8agDs67ROQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788870407; c=relaxed/simple; bh=TN7rGqqZ9OR376TXWS3MUze3xcTmiMRRJNOqSnu0G5Q=; h=Content-Type:Cc:Mime-Version:To:From:References:In-Reply-To: Subject:Date:Message-Id; b=eqf1BM1NDwCwyo7+2QJZeesSlSX5YEgdVEhNv8dtu/SUESllZ2Pyn7ahMF2v2zqptU2R8OQpPijoPqrgcfM6SSjmtX5Tp8oesG6+RPRBkjWMNrbW3M+wE6/J7Uj9DFISjjYcz16OfH7oMVms67xNN/dmh1cSWgxaFRTMHzda+ME= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=BTzGz8RR; arc=none smtp.client-ip=209.127.230.113 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="BTzGz8RR" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1788870400; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=j33x67pAIPEvtU7LsKxL/lIGzZa4GlqosjlcpBVmf4g=; b=BTzGz8RRpWuVcr8EKWpkSwI3cIr99NYmZ3nn89gU413ahc8ehjOw08V+Ctpei92RK8e5U0 +lCoenJSYb0IUJ+f7NOGcKNzEdWlseqvO/CfFadgb6EsQqwZKZEkmapPgauKmRgvftwHPt o/KsnN2Jelvh5RhE35FaQe9l9x3zNOvY6lIDpP6xtujwzbMjDIljn61dSWjZG9GIZIIriI 9jdlcBfWwPidUOfTnnoFu9/BMgTcFyIIbEiHIh1Mqlg49kKJ7IYO7ylfM08M+AJMCNvwGH BVvFY/vlyg7EQA/XytrVBCh1RrcWPTXa0la9tML9scg29MD2gXaGOhpkYZ9glQ== X-Lms-Return-Path: X-Mailer: git-send-email 2.45.2 Content-Type: text/plain; charset=UTF-8 Cc: , , , Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 To: , , , , , , , , , From: "Li Zhe" X-Original-From: Li Zhe References: <20260908122446.56708-1-lizhe.67@bytedance.com> In-Reply-To: <20260908122446.56708-1-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 Message-Id: <20260908122446.56708-3-lizhe.67@bytedance.com> Content-Transfer-Encoding: 7bit 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 --- 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 #include #include +#include #include #include #include @@ -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