Skip to content

sched_ext: Reduce idle CPU NUMA traversal from O(N^2) to O(N)

Cheng-Yang Chou sched-ext 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 7 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2sched_ext: Cache per-node NUMA distance order in scx_idle_init_masks()kernel/sched/ext_idle.c+38 -05 replies
2/2sched_ext: Use cached NUMA order in pick_idle_cpu_from_online_nodes()kernel/sched/ext_idle.c+14 -350 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH sched_ext/for-7.1 0/2] sched_ext: Reduce idle CPU NUMA traversal from O(N^2) to O(N)

pick_idle_cpu_from_online_nodes() uses for_each_node_numadist() which performs an O(N^2) traversal on every call to find the nearest idle CPU across NUMA nodes.

Since NUMA distances are fixed at boot and do not change at runtime, the per-node traversal order can be computed once during initialization and reused on every subsequent call. This series pre-computes the sorted order into scx_numa_node_order[], reducing the per-call cost to O(N).

Patch 1 allocates and populates scx_numa_node_order[] and scx_numa_node_order_cnt[] in scx_idle_init_masks() using the existing for_each_node_numadist() traversal, paying the O(N^2) cost only once at init time.

Patch 2 switches pick_idle_cpu_from_online_nodes() to iterate the cached arrays, removes the now-unnecessary per_cpu_unvisited nodemask, and adds a node_online() check so CPU hotplug is handled correctly without needing to rebuild the arrays.

Tested with make -j only. I do not have access to a NUMA machine to run runtime tests.

Thanks,
Cheng-Yang

---

Cheng-Yang Chou (2):
sched_ext: Cache per-node NUMA distance order in scx_idle_init_masks()
sched_ext: Use cached NUMA order in pick_idle_cpu_from_online_nodes()

 kernel/sched/ext_idle.c | 81 +++++++++++++++++++++++++----------------
 1 file changed, 49 insertions(+), 32 deletions(-)
Signature · 1 line
2.48.1