sched_ext: Add NUMA balancing support
Subsystems (3)
Andrea Righi
reviewerPATCH 1/1 sched_ext: Add NUMA balancing support
Tasks running under a BPF scheduler are currently invisible to NUMA balancing:
their address space is never scanned for hinting faults, so they never record NUMA fault statistics and never acquire a preferred node. A BPF scheduler therefore has no information about where a task's memory is when deciding where to run it.
This series lets a BPF scheduler opt into the NUMA hinting-fault scan with SCX_OPS_NUMA_BALANCING. The existing scan is driven from the sched_ext tick for the tasks of such a scheduler, and the hinting faults then work for them as they do for fair tasks: the kernel maintains their NUMA fault statistics and preferred node, and migrates the memory a task accesses toward the node it runs on. The tasks themselves are not migrated: their placement is left to the BPF scheduler.
The resulting preferred node is exposed to BPF schedulers with scx_bpf_task_numa_nid(), which they can use to keep a task close to its memory when placing or balancing it. The value is advisory; nothing in the kernel acts on it for these tasks.
The ultimate goal is to give BPF schedulers both controls that NUMA balancing
combines: moving a task to the node where its memory is and moving the memory a task uses to the node where the task runs. This series provides the first: with the preferred node available, a scheduler can decide where to run the task. A second series, to follow once this one lands, will provide the second: a kfunc that hints the memory manager to migrate the task's memory toward the node its scheduler has chosen.
Vladimir Vdovin recently posted an RFC [1] that drives the scan from the sched_ext tick in the same way and skips the fair-class task migration for tasks under a BPF scheduler. This series covers what that RFC proposed and adds the opt-in flag and the kfunc on top.
Patches 1 and 2 are small preparatory changes to the generic NUMA balancing
code: the first makes the scan available to other scheduling classes, the second skips the fair-class task migration for tasks owned by a BPF scheduler. Neither changes the behavior of fair, RT or deadline tasks. Patches 3 and 4 add the opt-in flag and the kfunc and patch 5 adds a selftest.
[1] https://lore.kernel.org/r/[email protected]
Git tree:git://git.kernel.org/pub/scm/linux/kernel/git/arighi/linux.git scx-numa-balancing
Andrea Righi (5):
sched/numa: Let other scheduling classes drive NUMA scanning sched/numa: Leave the placement of a BPF-scheduled task to its scheduler
sched_ext: Scan NUMA hinting faults for opted-in BPF schedulers
sched_ext: Add scx_bpf_task_numa_nid()
selftests/sched_ext: Add a test for scx_bpf_task_numa_nid()
kernel/sched/ext/ext.c | 39 ++++++++ kernel/sched/ext/internal.h | 16 +++- kernel/sched/fair.c | 14 ++- kernel/sched/sched.h | 5 + tools/sched_ext/include/scx/compat.bpf.h | 10 ++ tools/sched_ext/include/scx/compat.h | 1 + tools/sched_ext/include/scx/enum_defs.autogen.h | 1 + tools/sched_ext/include/scx/enums_abi.autogen.h | 3 +- tools/testing/selftests/sched_ext/Makefile | 1 + tools/testing/selftests/sched_ext/numa_nid.bpf.c | 52 +++++++++++ tools/testing/selftests/sched_ext/numa_nid.c | 111 +++++++++++++++++++++++ 11 files changed, 246 insertions(+), 7 deletions(-) create mode 100644 tools/testing/selftests/sched_ext/numa_nid.bpf.c create mode 100644 tools/testing/selftests/sched_ext/numa_nid.c
Andrea Righi
reviewerPATCH 1/5 sched/numa: Let other scheduling classes drive NUMA scanning
The periodic scan that installs the NUMA hinting faults is driven by task_tick_numa(), which is reachable only from task_tick_fair(). What the scan feeds is class independent, but a task that is not in the fair class is never scanned, records no faults and never gets a preferred node.
Make task_tick_numa() available to the other scheduling classes (e.g., sched_ext). Declare it in sched.h and move the !CONFIG_NUMA_BALANCING stub there, so a class that has no interest in NUMA balancing keeps costing nothing.
No functional change: task_tick_fair() remains the only caller.
--- kernel/sched/fair.c | 6 +----- kernel/sched/sched.h | 5 +++++ 2 files changed, 6 insertions(+), 5 deletions(-)
kernel/sched/fair.c +1 -5
@@ -4431,7 +4431,7 @@ void init_numa_balancing(u64 clone_flags, struct task_struct *p)/* * Drive the periodic memory faults.. */ -static void task_tick_numa (struct rq *rq,struct task_struct *curr) +void task_tick_numa (struct rq *rq,struct task_struct *curr) {struct callback_head *work = &curr->numa_work;u64 period, now;
@@ -4497,10 +4497,6 @@ static void update_scan_period(struct task_struct *p, int new_cpu)#else /* !CONFIG_NUMA_BALANCING: */ -static void task_tick_numa (struct rq *rq,struct task_struct *curr) -{ -} -static inline void account_numa_enqueue (struct rq *rq,struct task_struct *p) { }
kernel/sched/sched.h +5 -0
@@ -2137,6 +2137,7 @@ extern int migrate_task_to(struct task_struct *p, int cpu);extern int migrate_swap (struct task_struct *p,struct task_struct *t,int cpu,int scpu);extern void init_numa_balancing (u64 clone_flags,struct task_struct *p); +extern void task_tick_numa (struct rq *rq,struct task_struct *curr);#else /* !CONFIG_NUMA_BALANCING: */
@@ -2145,6 +2146,10 @@ init_numa_balancing(u64 clone_flags, struct task_struct *p) { } +static inline void task_tick_numa (struct rq *rq,struct task_struct *curr) +{ +} +#endif /* !CONFIG_NUMA_BALANCING */ int task_llc (const struct task_struct *p);
Signature · 1 line
2.55.0
Andrea Righi
reviewerPATCH 2/5 sched/numa: Leave the placement of a BPF-scheduled task to its scheduler
In reply to Andrea RighiA task under a BPF scheduler can take NUMA hinting faults via task_numa_fault() and then reach numa_migrate_preferred(), which may migrate the task to its preferred node through task_numa_migrate().
The migration of such a task should always be driven by its BPF scheduler, which owns the placement of its tasks.
Keep collecting the statistics, which is what makes p->numa_preferred_nid worth reading, but skip the migration for a task owned by a BPF scheduler. The scheduler can read the preferred node and decide for itself whether moving the task is worth the cost.
--- kernel/sched/fair.c | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/sched/fair.c +8 -0
@@ -3446,6 +3446,14 @@ static void numa_migrate_preferred(struct task_struct *p)if (task_node (p) == p->numa_preferred_nid)return ; +/* +* A task under a BPF scheduler is placed by that scheduler. Keep the +* statistics coming, which is what makes p->numa_preferred_nid worth +* reading, but leave the placement alone. +*/ +if (task_on_scx (p)) +return ; +/* Otherwise, try migrate to a CPU on the preferred node */ task_numa_migrate (p); }
Signature · 1 line
2.55.0
Andrea Righi
reviewerPATCH 3/5 sched_ext: Scan NUMA hinting faults for opted-in BPF schedulers
In reply to Andrea RighiA task running under a BPF scheduler never has its address space scanned for NUMA hinting faults. As a result, mm/memory.c never calls task_numa_fault() and the task's NUMA fault statistics and preferred node remain empty.
Scanning is not free and a scheduler which does not use the result should not pay for it. Add SCX_OPS_NUMA_BALANCING to let a BPF scheduler request the NUMA hinting-fault scan for its tasks. Drive the scan from the sched_ext tick for tasks owned by an opted-in scheduler, the way task_tick_fair() does, under the existing sched_numa_balancing static key. The hrtick, which only fires to end the running task's slice, does not drive the scan, as in task_tick_fair().
The hinting faults then work for these tasks as they do for fair tasks:
they maintain the NUMA statistics, the preferred node and potentially migrate the memory a task accesses toward the node the task runs on. The tasks themselves are not migrated, the BPF scheduler remains responsible for placing them.
No new accounting is needed to pace the scan, task_tick_numa() spaces scans by the task's CPU time, p->se.sum_exec_runtime and sched_ext already maintains that field through update_curr_common().
--- kernel/sched/ext/ext.c | 13 +++++++++++++ kernel/sched/ext/internal.h | 16 +++++++++++++++- tools/sched_ext/include/scx/compat.h | 1 + tools/sched_ext/include/scx/enum_defs.autogen.h | 1 + tools/sched_ext/include/scx/enums_abi.autogen.h | 3 ++- 5 files changed, 32 insertions(+), 2 deletions(-)
kernel/sched/ext/ext.c +13 -0
@@ -4227,6 +4227,19 @@ static void task_tick_scx(struct rq *rq, struct task_struct *donor, int queued)else if (SCX_HAS_OP (sch, tick))SCX_CALL_OP_TASK (sch, tick, rq, donor); +/* +* If requested by the scheduler, drive the NUMA hinting-fault scan as +* task_tick_fair() does. Neither the scan nor the statistics it feeds +* depend on the scheduling class. Where the task then runs is left to +* that scheduler: numa_migrate_preferred() does not move a task it owns. +* +* The tick that only refreshes an already queued task does not scan, +* matching the @queued check in task_tick_fair(). +*/ +if (!queued && (sch->ops.flags &SCX_OPS_NUMA_BALANCING ) && +static_branch_unlikely (&sched_numa_balancing)) +task_tick_numa (rq, donor); +if (!donor->scx.slice) {/* the slice can't be trusted while bypassing */ if (READ_ONCE(donor->scx.lazy_resched) &&
kernel/sched/ext/internal.h +15 -1
@@ -243,6 +243,19 @@ enum scx_ops_flags {*/ SCX_OPS_ENQ_BLOCKED =1LLU <<10 , +/* +* If set, drive automatic NUMA hinting-fault scans for tasks owned by +* this scheduler. The faults maintain the tasks' NUMA statistics and +* preferred node, which can be queried with scx_bpf_task_numa_nid(), +* and migrate the memory a task accesses toward the node it runs on, as +* NUMA balancing does for fair tasks. Tasks themselves are never +* migrated: the BPF scheduler remains responsible for placing them. +* +* If clear, sched_ext does not initiate NUMA hinting-fault scans for the +* scheduler's tasks. +*/ +SCX_OPS_NUMA_BALANCING =1LLU <<11 , +SCX_OPS_ALL_FLAGS =SCX_OPS_KEEP_BUILTIN_IDLE |SCX_OPS_ENQ_LAST | SCX_OPS_ENQ_EXITING |
@@ -253,7 +266,8 @@ enum scx_ops_flags {SCX_OPS_ALWAYS_ENQ_IMMED |SCX_OPS_TID_TO_TASK |SCX_OPS_LAZY_RESCHED | -SCX_OPS_ENQ_BLOCKED , +SCX_OPS_ENQ_BLOCKED | +SCX_OPS_NUMA_BALANCING ,/* high 8 bits are internal, don't include in SCX_OPS_ALL_FLAGS */ __SCX_OPS_INTERNAL_MASK = 0xffLLU << 56,
tools/sched_ext/include/scx/compat.h +1 -0
@@ -215,6 +215,7 @@ static inline bool __COMPAT_struct_has_field(const char *type, const char *field#define SCX_OPS_BUILTIN_IDLE_PER_NODE SCX_OPS_FLAG(SCX_OPS_BUILTIN_IDLE_PER_NODE)#define SCX_OPS_ALWAYS_ENQ_IMMED SCX_OPS_FLAG(SCX_OPS_ALWAYS_ENQ_IMMED)#define SCX_OPS_ENQ_BLOCKED SCX_OPS_FLAG(SCX_OPS_ENQ_BLOCKED) +#define SCX_OPS_NUMA_BALANCING SCX_OPS_FLAG(SCX_OPS_NUMA_BALANCING)#define SCX_PICK_IDLE_FLAG (name) __COMPAT_ENUM_OR_ZERO("scx_pick_idle_cpu_flags", #name)
tools/sched_ext/include/scx/enum_defs.autogen.h +1 -0
@@ -172,6 +172,7 @@#define HAVE_SCX_OPS_TID_TO_TASK #define HAVE_SCX_OPS_LAZY_RESCHED #define HAVE_SCX_OPS_ENQ_BLOCKED +#define HAVE_SCX_OPS_NUMA_BALANCING #define HAVE_SCX_OPS_ALL_FLAGS #define HAVE___SCX_OPS_INTERNAL_MASK #define HAVE_SCX_OPS_HAS_CPU_PREEMPT
tools/sched_ext/include/scx/enums_abi.autogen.h +2 -1
@@ -184,7 +184,8 @@ static const struct __scx_enum_abi_val __scx_enum_abi_vals[] { "scx_ops_flags", "SCX_OPS_TID_TO_TASK", 0x100LLU }, { "scx_ops_flags", "SCX_OPS_LAZY_RESCHED", 0x200LLU }, { "scx_ops_flags", "SCX_OPS_ENQ_BLOCKED", 0x400LLU }, - { "scx_ops_flags", "SCX_OPS_ALL_FLAGS", 0x7ffLLU }, + { "scx_ops_flags", "SCX_OPS_NUMA_BALANCING", 0x800LLU }, + { "scx_ops_flags", "SCX_OPS_ALL_FLAGS", 0xfffLLU }, { "scx_ops_flags", "__SCX_OPS_INTERNAL_MASK", 0xff00000000000000LLU }, { "scx_ops_flags", "SCX_OPS_HAS_CPU_PREEMPT", 0x100000000000000LLU }, { "scx_ops_state", "SCX_OPSS_NONE", 0x0LLU },
Signature · 1 line
2.55.0
Re: [PATCH 3/5] sched_ext: Scan NUMA hinting faults for opted-in BPF schedulers
Hi Andrea,
Thanks for putting this together so quickly, and for picking up the RFC.
kernel/sched/ext/ext.c static void task_tick_scx(struct rq *rq, struct task_struct *donor, int queued) · line 4241
Quoted 3 lines · Andrea Righi
kernel/sched/ext/ext.c +3
-0+if (!queued && (sch->ops.flags &SCX_OPS_NUMA_BALANCING ) && +static_branch_unlikely (&sched_numa_balancing)) +task_tick_numa (rq, donor);
One question about proxy execution, which I may well be missing context on. Hui Su's tick series moves the fair NUMA tick to the execution context, with the reasoning that task_tick_numa() works on the mm and NUMA work state of the task that is actually running:
https://lore.kernel.org/r/[email protected]
Here the scan is driven from the donor. I understand that in your proxy execution integration SCX runtime is accounted to the donor, so maybe this is intentional to keep the pacing consistent, but then the scan would cover the donor's address space rather than the one being accessed. Is the donor the intended choice here, or should this follow rq->curr once SCHED_PROXY_EXEC no longer depends on !SCHED_CLASS_EXT?
Thanks,
Vladimir
Andrea Righi
reviewerRe: [PATCH 3/5] sched_ext: Scan NUMA hinting faults for opted-in BPF schedulers
Hi Vladimir,
Quoted 23 lines · Vladimir Vdovin
Hi Andrea,
Thanks for putting this together so quickly, and for picking up the RFC.
kernel/sched/ext/ext.c static void task_tick_scx(struct rq *rq, struct task_struct *donor, int queued) · line 4241
Quoted 3 lines · Andrea Righi
kernel/sched/ext/ext.c +3
-0+if (!queued && (sch->ops.flags &SCX_OPS_NUMA_BALANCING ) && +static_branch_unlikely (&sched_numa_balancing)) +task_tick_numa (rq, donor);One question about proxy execution, which I may well be missing context on. Hui Su's tick series moves the fair NUMA tick to the execution context, with the reasoning that
task_tick_numa()works on the mm and NUMA work state of the task that is actually running:https://lore.kernel.org/r/[email protected]
Here the scan is driven from the donor. I understand that in your proxy execution integration SCX runtime is accounted to the donor, so maybe this is intentional to keep the pacing consistent, but then the scan would cover the donor's address space rather than the one being accessed. Is the donor the intended choice here, or should this follow
rq->curronceSCHED_PROXY_EXECno longer depends on !SCHED_CLASS_EXT?
Quoted 2 lines
Thanks,
Vladimir
Yes, that's a good point, thanks for brining this up. The donor here is used just for consistency with the current task_tick_fair() implementation.
A small clarification on the accounting: under proxy exec, sched_ext charges the slice to the donor (update_curr_scx() decrements donor->scx.slice), but the task runtime, p->se.sum_exec_runtime, is charged to rq->curr by update_se(). Since task_tick_numa() paces the scan on sum_exec_runtime, passing the donor means its scan does not progress while it's blocked, which is fine, and the owner's scan is delayed until it gets ticks on its own. So nothing is scanned on the wrong
mm: task_tick_numa(rq, p) checks whether p is due for a scan and, if so, queues p's scan as task work, which runs later in p's own context and p's own mm. The owner never scans the donor's memory or the other way around. Essentially, the only effect of passing the donor is timing: during the proxy window the donor's scan may get queued, while the owner's scan waits until the owner is schedued on its own behalf.
That said, I agree the scan should follow rq->curr and Hui's series gives the right hook to do it. But I'd rather not diverge from fair for now, so the idea would be to keep the donor here and switch sched_ext together with fair when Hui's series lands.
Thanks,
-Andrea
Andrea Righi
reviewerPATCH 4/5 sched_ext: Add scx_bpf_task_numa_nid()
In reply to Andrea RighiWith the hinting-fault scan running for tasks under a BPF scheduler, p->numa_preferred_nid is maintained for them. Give schedulers a way to read it.
scx_bpf_task_numa_nid() returns the node a task's memory accesses are concentrated on, or NUMA_NO_NODE when the task has no preference. A BPF scheduler can use it to keep a task near its memory when placing or balancing it.
--- kernel/sched/ext/ext.c | 26 ++++++++++++++++++++++++ tools/sched_ext/include/scx/compat.bpf.h | 10 +++++++++ 2 files changed, 36 insertions(+)
kernel/sched/ext/ext.c +26 -0
@@ -11140,6 +11140,31 @@ __bpf_kfunc s32 scx_bpf_task_cid(const struct task_struct *p)return tbl[task_cpu (p)]; } +/** +* scx_bpf_task_numa_nid - Node NUMA balancing would prefer a task to run on +* @p: task of interest +* +* Return p->numa_preferred_nid: the node NUMA balancing has derived from @p's +* hinting faults as the best one to run @p on, which is the node with the most +* faults, adjusted for CPU-less nodes and for the NUMA group @p may be part of. +* Return NUMA_NO_NODE when @p has no preference yet. A task has none until its +* address space has been scanned a few times and every task has none with +* kernel.numa_balancing disabled. +* +* The value is a hint, not an instruction: nothing in the kernel moves a task +* under a BPF scheduler to this node and the scheduler is free to weigh it +* against its own placement rules. The value is updated under @p's rq lock, +* which this kfunc doesn't take, so it is a snapshot. +*/ +__bpf_kfunc s32 scx_bpf_task_numa_nid(const struct task_struct *p) +{ +#ifdef CONFIG_NUMA_BALANCING +return READ_ONCE (p->numa_preferred_nid); +#else +return NUMA_NO_NODE ; +#endif +} +/** * scx_bpf_locked_rq - Return the rq currently locked by SCX * @aux: implicit BPF argument to access bpf_prog_aux hidden from BPF progs
@@ -11446,6 +11471,7 @@ BTF_ID_FLAGS(func, scx_bpf_put_cpumask, KF_RELEASE) BTF_ID_FLAGS(func, scx_bpf_task_running, KF_RCU) BTF_ID_FLAGS(func, scx_bpf_task_cpu, KF_RCU) BTF_ID_FLAGS(func, scx_bpf_task_cid, KF_RCU) +BTF_ID_FLAGS(func, scx_bpf_task_numa_nid, KF_RCU) BTF_ID_FLAGS(func, scx_bpf_locked_rq, KF_IMPLICIT_ARGS | KF_RET_NULL) BTF_ID_FLAGS(func, scx_bpf_cpu_curr, KF_IMPLICIT_ARGS | KF_RET_NULL | KF_RCU_PROTECTED)BTF_ID_FLAGS (func, scx_bpf_cid_curr,KF_IMPLICIT_ARGS |KF_RET_NULL |KF_RCU_PROTECTED )
tools/sched_ext/include/scx/compat.bpf.h +10 -0
@@ -478,6 +478,16 @@ static inline void scx_bpf_task_set_dsq_vtime(struct task_struct *p, u64 vtime) p->scx.dsq_vtime = vtime; } +/* v7.4: Add scx_bpf_task_numa_nid(). */ +s32 scx_bpf_task_numa_nid___new(const struct task_struct *p) __ksym __weak; + +static inline s32 scx_bpf_task_numa_nid (const struct task_struct *p) +{ +if (bpf_ksym_exists (scx_bpf_task_numa_nid___new)) +return scx_bpf_task_numa_nid___new (p); +return NUMA_NO_NODE ; +} +/* v7.4: Add scx_bpf_task_set_lazy_resched(). */ bool scx_bpf_task_set_lazy_resched___new(struct task_struct *p, bool lazy) __ksym __weak;
Signature · 1 line
2.55.0
Andrea Righi
reviewerPATCH 5/5 selftests/sched_ext: Add a test for scx_bpf_task_numa_nid()
In reply to Andrea RighiAdd a scheduler which opts into NUMA hinting-fault scanning and reads every running task's preferred node. Check that each result is either NUMA_NO_NODE or a node reported by the kernel.
The test runs two threads touching memory for a few seconds, which on a NUMA machine with numa_balancing enabled is enough for its tasks to be scanned and acquire a preferred node. Two threads are needed because the scan skips the pages of a single-threaded process that are already on the node it runs on. Whether a node is acquired depends on the machine, so the test only reports the counts it observed and does not require one.
--- tools/testing/selftests/sched_ext/Makefile | 1 + .../selftests/sched_ext/numa_nid.bpf.c | 52 ++++++++ tools/testing/selftests/sched_ext/numa_nid.c | 111 ++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 tools/testing/selftests/sched_ext/numa_nid.bpf.c create mode 100644 tools/testing/selftests/sched_ext/numa_nid.c
tools/testing/selftests/sched_ext/Makefile +1 -0
@@ -186,6 +186,7 @@ auto-test-targets := \ non_scx_kfunc_deny \ nohz_tick \ numa \ + numa_nid \ allowed_cpus \ peek_dsq \ prog_run \
tools/testing/selftests/sched_ext/numa_nid.bpf.c new file +52 -0
52 lines not on this page · raw message
tools/testing/selftests/sched_ext/numa_nid.c new file +111 -0
111 lines not on this page · raw message
Signature · 1 line
2.55.0
Hi Andrea,
Quoted 3 lines · Andrea Righi
Tasks running under a BPF scheduler are currently invisible to NUMA balancing:
their address space is never scanned for hinting faults, so they never record NUMA fault statistics and never acquire a preferred node.
In case it's useful, I gave patches 1-3 a try on one of our KVM hosts, backported to 6.18.54 and running our in-house sched_ext scheduler.
It's not exactly the series as posted: to avoid changing the scheduler, the backport drops SCX_OPS_NUMA_BALANCING and drives the scan for all sched_ext tasks under the sched_numa_balancing static key alone, and it passes curr, as there is no donor there on 6.18. The fair.c parts are the same.
As a controlled check, I used a stress-ng --vm worker touching 4G, pinned to a CPU on node 0 and then moved to a CPU on node 1 with taskset.
Without the patches, under the same scheduler, mm->numa_scan_seq stays at 0, numa_preferred_nid stays at -1, numa_pte_updates in /proc/vmstat doesn't move, and all 4G stay on node 0.
With the backport:
- mm->numa_scan_seq advances (7 to 12 over two minutes);
- numa_preferred_nid is 0 before the move and 1 about 20s after it;
- the whole 4G (~1M pages) is migrated to node 1 within ~20s;
- the task stays on the CPU it was pinned to.
On an otherwise idle host, the vCPU threads of a running guest now get task_numa_work() calls as well. On a host running the same scheduler without the patches, a kprobe on task_numa_work() sees no calls at all in 30s, as task_tick_numa() is only reached from task_tick_fair().
Thanks for working on this,
Vladimir
Tejun Heo
reviewerHello, Andrea.
Quoted 8 lines · Andrea Righi
This series lets a BPF scheduler opt into the NUMA hinting-fault scan with
SCX_OPS_NUMA_BALANCING. The existing scan is driven from thesched_exttick for the tasks of such a scheduler, and the hinting faults then work for them as they do for fair tasks: the kernel maintains their NUMA fault statistics and preferred node, and migrates the memory a task accesses toward the node it runs on. The tasks themselves are not migrated: their placement is left to the BPF scheduler.
Quoted 4 lines
The resulting preferred node is exposed to BPF schedulers with
scx_bpf_task_numa_nid(), which they can use to keep a task close to its memory when placing or balancing it. The value is advisory; nothing in the kernel acts on it for these tasks.
Is there a reason to gate this on a separate ops flag? An alternative would be an op which is called when a task's preferred node changes, with the initial node reported on enable like ops.set_weight(), and enabling the hinting-fault scan iff the op is implemented. The scheduler then gets an event it can act on rather than a value to poll. The node has a single writer, sched_setnuma(), which already dequeues and re-enqueues the task under the rq lock, so the op can be called from there the same way ops.set_weight() is called from the reweight path.
Thanks.
Signature · 1 line
tejun
Andrea Righi
reviewerHi Tejun,
Quoted 16 lines · Tejun Heo
Hello, Andrea.
Quoted 8 lines · Andrea Righi
This series lets a BPF scheduler opt into the NUMA hinting-fault scan with
SCX_OPS_NUMA_BALANCING. The existing scan is driven from thesched_exttick for the tasks of such a scheduler, and the hinting faults then work for them as they do for fair tasks: the kernel maintains their NUMA fault statistics and preferred node, and migrates the memory a task accesses toward the node it runs on. The tasks themselves are not migrated: their placement is left to the BPF scheduler.Quoted 4 lines
The resulting preferred node is exposed to BPF schedulers with
scx_bpf_task_numa_nid(), which they can use to keep a task close to its memory when placing or balancing it. The value is advisory; nothing in the kernel acts on it for these tasks.
Quoted 8 lines
Is there a reason to gate this on a separate ops flag? An alternative would be an op which is called when a task's preferred node changes, with the initial node reported on enable like
ops.set_weight(), and enabling the hinting-fault scan iff the op is implemented. The scheduler then gets an event it can act on rather than a value to poll. The node has a single writer,sched_setnuma(), which already dequeues and re-enqueues the task under the rq lock, so the op can be called from there the same wayops.set_weight()is called from the reweight path.
Yeah, there's no particular reason to use a separate ops flag. I think I like the ops callback approach that reports the preferred node and enables the hinting-fault scan when the callback is implemented. Maybe something like:
void (*set_numa_node)(struct task_struct *p, s32 nid);
Calling it from sched_setnuma() under the rq lock should also simplify the code and lets the BPF scheduler update its placement state before the task is re-enqueued.
I'll do some experiments with this approach and send a new version.
Thanks,
-Andrea