Re: [PATCH 2/6] sched/numa: Leave the placement of a BPF-scheduled task to its scheduler

From: K Prateek Nayak

Date: Tue Oct 27 2026 - 01:46:50 EST


Hello Andrea,

On 10/27/2026 9:43 AM, Andrea Righi wrote:
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 36df9a4dde534..5064c7b707f4d 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -3267,8 +3267,13 @@ static bool task_numa_compare(struct task_numa_env *env,
>
> rcu_read_lock();
> cur = rcu_dereference_all(dst_rq->curr);
> + /*
> + * Never pick a task under a BPF scheduler as the swap partner: its
> + * placement is left to that scheduler, see numa_migrate_preferred().
> + * Moving the faulting task alone to the destination is still allowed.
> + */
> if (cur && ((cur->flags & (PF_EXITING | PF_KTHREAD)) ||
> - !cur->mm))
> + !cur->mm || task_on_scx(cur)))

So if you are here, it must be from:

task_numa_migrate()
task_numa_find_cpu()
task_numa_compare()

but task_on_scx(p) would skip this and it means a fair task is looking
for a swap candidate when scx running in partial mode right?

At that point, it feels fair class should be well within its rights to
call shots on the swap candidate even if it is an scx task.

If scx has a ops.set_numa() defined, it would have accumulated hinting
faults and the CPU it is running on is a wrong node anyways so the
migration shouldn't be bad in grand scheme of things. If ops.set_numa()
is not defined, then the scheduler doesn't care about NUMA placement
and it should be okay for a fair task to acquire that CPU.

> cur = NULL;
>
> /*
> @@ -3645,6 +3650,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;
> +

Restricting ext on this path seems fine.

> /* Otherwise, try migrate to a CPU on the preferred node */
> task_numa_migrate(p);
> }

--
Thanks and Regards,
Prateek