Skip to content

sched/fair: start new threads and processes on an idle CPU of the creator's LLC - #2481

Merged
RyanTheTide merged 4 commits into
mainfrom
satchlj/sched-fork-exec-llc-20261119
Nov 26, 2026
Merged

RyanTheTide merged 4 commits into
mainfrom
satchlj/sched-fork-exec-llc-20261119

Conversation

@satchlj

@satchlj satchlj commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

What: Enable FORK_LOCAL by default so fork/clone tries an idle CPU in the creator's last-level cache domain (skipping CPUs that fail SD_BALANCE_FORK, p->cpus_ptr, sched_core_cookie_match(), or asymmetric task_fits_cpu(), and falling back to normal fork balancing if none is idle). Scanning the local LLC from its first CPU (for_each_cpu()) rather than wrapping from cpu + 1 keeps sequential fork/exec loops warm on two cores so per-CPU PELT utilization does not dilute across all cores of a cluster under schedutil (which caused the earlier posix_spawn frequency drop and +12-16% slowdown), while still filling the remaining idle cores during concurrent fan-out.

Tested:

  • Mac Studio M5 Max (J775c, T6050) at exact head 3928d792a145 (7.3.0-b108-2481+), default boot command line with MTE enabled, default schedutil governor on all 3 clusters (0-4,15, 5-9,16, 10-14,17), FORK_LOCAL enabled by default at boot (WAKE_SHORT_LOCAL FORK_LOCAL), 3 interleaved same-boot rounds toggling FORK_LOCAL vs NO_FORK_LOCAL via /sys/kernel/debug/sched/features:
Workload NO_FORK_LOCAL (3 rounds, median) FORK_LOCAL default ON (3 rounds, median) Delta
osbench thread_create_join 18.262 / 18.560 / 18.815 us (18.560 us) 8.529 / 8.515 / 8.605 us (8.529 us) -54.0% (2.18x)
osbench fork_exit_wait 90.968 / 95.961 / 97.657 us (95.961 us) 29.717 / 25.294 / 29.604 us (29.604 us) -69.2% (3.24x)
osbench posix_spawn_true 130.003 / 128.552 / 148.076 us (130.003 us) 88.241 / 85.227 / 78.058 us (85.227 us) -34.4% (1.53x)
standalone posix_spawn (unpinned) 100.098 / 99.607 / 100.379 us (100.098 us) 74.440 / 67.388 / 77.142 us (74.440 us) -25.6%
standalone posix_spawn (pinned S-cluster 10-14,17) 54.145 / 54.600 / 56.826 us (54.600 us) 52.320 / 55.982 / 54.091 us (54.091 us) -0.9% (S-cluster 4.51-4.61 GHz held)
hb pipe (10 groups, 2000 loops) 0.301 / 0.371 / 0.300 s (0.301 s) 0.331 / 0.356 / 0.373 s (0.356 s) within run-to-run noise
  • Health on 3928d792a145: 0 failed systemd units, 0 new kernel errors beyond J775c baseline, 0 BUG/WARNING/Oops/Call Trace, HDMI display active, W=1 kernel/sched/fair.o clean (0 warnings).

Risk: two-way · multi-cluster Apple Silicon Macs under fork/clone/exec workloads (runtime toggleable via NO_FORK_LOCAL in /sys/kernel/debug/sched/features).

Not yet: additional Mac generations beyond J775c at 3928d792a145.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 3.

  1. kernel/sched/fair.c:9989-10002: fork_local_idle_cpu() takes the first idle CPU in the creator's LLC and ignores CPU capacity. The path it short-circuits does not: update_sg_wakeup_stats() (:12720-12723) marks groups the task does not fit on SD_ASYM_CPUCAPACITY systems, and wake_short_local() in the same series checks task_fits_cpu() (:9969). On Apple Silicon every cluster is its own LLC, so a child forked from an E-core with an inherited uclamp_min now stays on E-cores. Skip i when sched_asym_cpucap_active() && !task_fits_cpu(p, i), as wake_short_local() does.
  2. kernel/sched/features.h (FORK_LOCAL, true) and fair.c:10078-10083: this changes fork placement by default for every architecture and topology. That includes multi-node NUMA, where the widest SD_BALANCE_FORK domain spans nodes, and threads, which get no exec balancing to correct them. On this tree the T6050 DT has no next-level-cache (t6050-base.dtsi: 0 hits), so the only machine measured gets no effect. Meanwhile T8103 and T8132 do describe per-cluster L2 (t8103.dtsi:87 onward, t8132.dtsi: 10 next-level-cache), so the feature is live there and untested. A throughput run is also needed, because this trades spreading for locality: a make -jN or a thread-pool start, on at least one other Mac. The known 12-16% posix_spawn regression is still unexplained. Either find its cause or keep the feature off by default until it is.
  3. Both commits carry Co-Authored-By: Claude Opus 5.5. Keep only the human Signed-off-by. The disclosure goes on the PR body's last line as Assisted-by: LLM (<Vendor>:<Model>), not "Generated with Claude Code".

HW row: this head on integration/aurora, built on its own, default command line, on J775c with the T6050 cache DT and on one M1 or M4 Mac. Same boot, FORK_LOCAL on/off: osbench fork/thread/spawn, a make -j$(nproc) kernel build wall time, and hackbench. The pass criteria are no throughput loss beyond noise and an explained or fixed posix_spawn cost, plus 0 failed units, 0 AVC and 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@satchlj

satchlj commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Codex GPT-6.2 Sol on @satchlj's behalf

The idle LLC scan now skips CPUs that cannot fit the child when asymmetric CPU capacity is active. FORK_LOCAL defaults off while the 12–16% posix_spawn regression and throughput across architectures are unresolved.

The PR now documents the T6050 dependency on the next-level-cache links in #2574 and the T8103/T8132 scope. Restacked both commits on the revised #2480, removed their co-author trailers, and updated the PR footer.

ARM64 kernel/sched/fair.o built with W=1. The revised head is untested on hardware. The J775c and M1/M4 latency and throughput comparisons and regression checks are pending.

@satchlj

satchlj commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Codex GPT-6.2 Sol on @satchlj's behalf

J775c same-boot A/B on exact 23e300314bbe, immediate parent 4d45f47255c8, both above #2480 c86e358c4a4c. The underlying integration ancestor 26294e82e9c87a0162a7973c5e23c599ceaea22f was 370 commits behind a84637dca209 on Nov 21. The stack's changed files merge cleanly in order in a text-only check against that tip. Runtime on the combined tip is untested.

The J775c carrier DTB included the exact #2574 cache properties. Cache records covered all 18 CPUs and the private P-core L2 size is unknown. The trial disabled PCI SDHCI and used arm64.nomte console=tty0 console=ttyDC0. FORK_LOCAL booted off and was restored to off. WAKE_SHORT_LOCAL stayed on. sched_energy_aware=1 read back, but the Energy Model debugfs directory was empty and the boot journal had no registration lines.

Three independent runs per state, in off/on/on/off/off/on order for each suite. Values are medians and ranges.

Workload FORK_LOCAL off FORK_LOCAL on
Thread create/join, µs 29.642 (27.116–30.379) 12.000 (11.712–12.246)
Fork/exit/wait, µs 144.358 (136.420–151.538) 68.087 (65.307–70.094)
posix_spawn true, µs 260.399 (249.892–268.636) 220.185 (219.822–228.213)
hackbench -p -g 8, s 0.016 (0.013–0.020) 0.020 (0.019–0.023)
Clean kernel Image.gz, -j18 wall s 108.91 (108.80–110.35) 108.95 (103.36–109.27)

The earlier posix_spawn slowdown did not reproduce in this row. Its cause remains open. hackbench's median rose with overlapping ranges and 1 ms output resolution. All six clean builds passed on the same source and config. Their wall-time ranges overlapped. Build start temperatures were 42.0–56.7 °C off and 51.2–60.5 °C on.

0 AVC denials, one failed unit (ac-power-mode.service) and three boot error lines absent from Aura (two for Gen4 SPMI IRQ rejection and one from AOP probe), also seen on #2480. Two other DCP errors were also present on Aura. Verified warm handback to the default kernel, original payload hashes, both selectors and spent markers, clean ext4 and journal, both ESPs passing offline and Thunderbolt peer 2/2. Non-T6050 hardware remains untested here.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of 23e3003: No blockers.

Points from the last review:

  1. Capacity fit: resolved. kernel/sched/fair.c:10017-10018 skips CPUs that fail task_fits_cpu() when sched_asym_cpucap_active(), which matches wake_short_local().
  2. Default-on for every topology: resolved. kernel/sched/features.h:109 is SCHED_FEAT(FORK_LOCAL, false), and the commit messages give the T6050 next-level-cache dependency (arm64: dts: apple: t6050: give each P core a private L2 in front of the cluster L3 #2574) and the T8103/T8132 scope.
  3. Co-author trailers: resolved. Both commits carry only the human Signed-off-by, and the body ends with the Assisted-by: line.

One new point:

  1. fair.c:10014-10021: fork_local_idle_cpu() returns the first idle CPU without sched_core_cookie_match(). The fork path it short-circuits, sched_balance_find_dst_group_cpu() (fair.c:8724), skips CPUs whose core runs a different cookie. With core scheduling on (SMT systems only, so not Apple Silicon), a child forked with a cookie can now land on a core whose sibling runs a different cookie, and that sibling is then forced idle. Add if (!sched_core_cookie_match(cpu_rq(i), p)) continue; next to the fit check.

The J775c same-boot row is useful: thread create/join 29.6 -> 12.0 us, fork/exit/wait 144 -> 68 us, the earlier posix_spawn slowdown did not reproduce (260 -> 220 us), and kernel build wall time did not change. hackbench rose from 0.016 to 0.020 s, but the ranges overlap at 1 ms output resolution. While the feature is off by default this code does nothing on a stock boot. Once the row below is in, turning it on here, or in a follow-up that cites it, is what makes the win reach users.

HW row: this stack merged onto the current integration/aurora tip on the default command line, on J775c with #2574 and on one M1 or M4 Mac (where per-cluster LLCs already exist), FORK_LOCAL on/off in the same boot: osbench thread/fork/spawn, hackbench -p -g 8 -l 10000, and make -j$(nproc) wall time. Pass criteria: no throughput loss beyond noise, 0 AVC, 0 failed units, 0 new kernel errors. The trial's ac-power-mode.service failure and its SPMI/AOP error lines should be gone on the tip.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-PR checklist review (§1–§6) on head 23e300314bbe05686f3455d32453ba97e6f20294 (stacked on #2480 c86e358c4a4c).

Blockers

  1. Core-scheduling cookie violation in fork_local_idle_cpu() (kernel/sched/fair.c) — Still unfixed on 23e300314bbe. The fork path bypassed here (sched_balance_find_dst_group_cpu()) checks if (!sched_core_cookie_match(rq, p)) continue; before choosing a CPU. fork_local_idle_cpu() returns the first idle CPU in sd_llc without checking sched_core_cookie_match(cpu_rq(i), p). On SMT systems with CONFIG_SCHED_CORE, a newly forked task carrying a cookie can land on a core whose sibling runs an incompatible cookie and force-idle that sibling.
  2. SD_BALANCE_FORK domain boundary not respected in fork_local_idle_cpu() (kernel/sched/fair.c) — select_task_rq_fair() enters this slow path with sd equal to the widest domain carrying SD_BALANCE_FORK, then fork_local_idle_cpu() unconditionally scans per_cpu(sd_llc, cpu) without checking sd_llc->flags & SD_BALANCE_FORK or intersecting with sched_domain_span(sd). If SD_BALANCE_FORK is cleared on sd_llc (or a cpuset/domain boundary restricts fork balancing below LLC), this heuristic violates the sched-domain flag.
  3. Missing CI (statusCheckRollup is empty) — Zero check runs have executed on 23e300314bbe because the PR base is satchlj/sched-brief-wake-20261119 (unmerged #2480, 370+ commits behind integration/aurora) rather than integration/aurora. Once #2480 lands, rebase/retarget onto integration/aurora so host-tests runs and passes.
  4. §2 (Default command line / production readiness) & §5 (Cross-Mac hardware evidence):
    • SCHED_FEAT(FORK_LOCAL, false) is currently default-off while the earlier 12–16% posix_spawn slowdown remains unexplained (note that glibc posix_spawn uses clone(CLONE_VM | CLONE_VFORK) and shares mm, so both commits affect it) and cross-architecture throughput is unqualified. Under §2, shipping a default-off heuristic that requires manual debugfs toggling is not a production-ready user-facing improvement.
    • The J775c A/B row (23e300314bbe) ran on a stale base (370 commits behind integration/aurora), with non-default cmdline/config (arm64.nomte console=tty0 console=ttyDC0, PCI SDHCI disabled, out-of-tree #2574 cache DT), and had 1 failed unit (ac-power-mode.service) and 3 new kernel error lines (Gen4 SPMI IRQ + AOP), which does not meet §2/§5.
    • hackbench -p -g 8 median regressed from 0.016 s to 0.020 s (+25%, at 1 ms resolution); this needs a longer run (e.g. hackbench -p -g 8 -l 10000) to distinguish noise from real contention.
    • Zero non-T6050 Mac testing: M1/M2/M3/M4 Macs already describe per-cluster next-level-cache LLCs and have asymmetric E/P clusters. Note that in wake_up_new_task(), select_task_rq() runs before post_init_entity_util_avg(p), so task_util_est(p) is 0 when task_fits_cpu(p, i) runs — meaning task_fits_cpu() enforces inherited uclamp_min / capacity pressure, while unclamped children forked from an E-core parent stay on the E-cluster until load balancing or misfit migration moves them. Cross-Mac A/B on at least one asymmetric Mac (M1/M2/M4) is essential.

Non-blocking Notes

  • fork_local_idle_cpu() returns the first idle CPU in wrap order (choose_idle_cpu()), bypassing sched_balance_find_dst_group_cpu()'s shallowest-idle-state / most-recently-idled (idle->exit_latency / rq->idle_stamp) selection; worth verifying on deeper idle states.

Checklist Summary

  • §1 No model gating: Pass (uses generic sd_llc).
  • §2 Production-ready / default cmdline: Fail (default-off feature with unexplained posix_spawn regression; J775c test used arm64.nomte + disabled PCI SDHCI).
  • §3 Safety: Pass.
  • §4 Clean-room & attribution: Pass (both commits have human author/committer + human Signed-off-by: only; PR body discloses Assisted-by:).
  • §5 Evidence: Fail (stale base, 1 failed unit + 3 kernel errors, no non-T6050 M1/M2/M4 row, unresolved hackbench/spawn questions).
  • §6 Naming: Pass.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Status check against integration/aurora 4a17f73: nothing equivalent is on the tip (no FORK_LOCAL in kernel/sched), and the stack of #2480 plus these two commits still merges cleanly; fair.c and features.h have not changed there since the stack's base. It still depends on #2480, and on #2574 for the T6050 cache topology; both are open. @satchlj, what is still open from the reviews on 23e3003: the sched_core_cookie_match() check and the SD_BALANCE_FORK domain bound in fork_local_idle_cpu(), a retarget onto integration/aurora once #2480 is in so CI runs, and an on/off row on one M1 or M4 Mac with a longer hackbench run.

Fork balancing starts a new task in the idlest group of the widest domain
with SD_BALANCE_FORK. With a creating thread busy in one cluster, that is
nearly always another cluster, often one that is idle and clocked down.

On an M5 Max (T6050, three six-core clusters), traced pthread_create() +
pthread_join() iterations take 11 us from the new thread's wake-up to its
creator running again when the thread starts in its creator's cluster,
and 16 us when it starts in another one (p50 of ~10k iterations): the
thread starts later and runs longer on a cold cache, and the wake-ups
between it and its creator cross clusters. The whole create+join loop
costs 25-32 us against 12 us on macOS.

Start a new thread, a task sharing its creator's mm, on an idle CPU in the
creating CPU's LLC domain when there is one, provided the LLC domain has
SD_BALANCE_FORK, the candidate CPU lies within the enclosing fork-balance
domain span, and its core-scheduling cookie matches. A thread that runs
for long is still spread by load balancing; most short-lived threads
finish before that. New processes keep the usual fork and exec balancing.

On asymmetric systems, skip CPUs that cannot fit the new task,
including its utilization clamps. Fall back to normal fork balancing
if no suitable local CPU is idle.

FORK_LOCAL is disabled by default pending throughput tests across
architectures. The heuristic follows the scheduler's LLC domains.
T6050 needs next-level-cache links to describe its per-cluster caches;
without those links this base groups the J775c CPUs into one LLC.
T8103 and T8132 already describe per-cluster L2 caches and need
hardware qualification when the feature is enabled.

Signed-off-by: Satya Benson <satya@benson.earth>
FORK_LOCAL starts a new thread on an idle CPU of its creator's LLC; a new
process still goes to the idlest group of the widest domain, on an M5 Max
(T6050) nearly always another cluster, often idle and clocked down. A
fork()+_exit()+waitpid() loop (osbench) takes 171-198 us that way on
J775c, and 39 us while one cluster other than the parent's is kept busy at
full clock: most of the cost is the child running on a cold cluster, and
the parent waking from it across clusters.

Most new processes exec at once, and exec balancing then places the program
in the idlest group as before; until then the child shares its parent's
pages and cache, as a thread does. Start new processes like new threads.
Both paths use the opt-in FORK_LOCAL feature. A same-boot J775c
comparison with the cache topology present found a 12-16% posix_spawn
slowdown with the feature enabled. Keep it disabled by default until
that cost is explained and throughput is qualified across architectures.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj
satchlj force-pushed the satchlj/sched-brief-wake-20261119 branch from c86e358 to 3133760 Compare November 24, 2026 01:53
@satchlj
satchlj force-pushed the satchlj/sched-fork-exec-llc-20261119 branch from 23e3003 to c412d8f Compare November 24, 2026 01:53
@satchlj

satchlj commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Gemini 4 Neon on @satchlj's behalf.

Rebased onto updated #2480 (3133760aed49) and pushed c412d8fd1519 addressing both code review blockers in fork_local_idle_cpu():

  1. Passed the enclosing fork-balance struct sched_domain *sd into fork_local_idle_cpu(), verified llc_sd && (llc_sd->flags & SD_BALANCE_FORK), and restricted candidates with cpumask_test_cpu(i, sched_domain_span(sd)).
  2. Added if (!sched_core_cookie_match(cpu_rq(i), p)) continue; to match sched_balance_find_dst_group_cpu().

Verified locally on c412d8fd1519:

  • scripts/checkpatch.pl --strict (2 commits): 0 errors, 0 warnings, 0 checks
  • kernel/sched/fair.o (W=1, CONFIG_SCHED_CORE=y): compiles with 0 warnings

Retarget onto integration/aurora (once #2480 merges) and cross-Mac on/off A/B rows remain.

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-PR re-review (§1–§6) at c412d8fd1519 (commits a052cab0076b and c412d8fd1519, stacked on #2480 3133760aed49): 0 code/policy/attribution/CI blockers at c412d8fd; ready to flip to APPROVE once #2480 merges, this PR retargets onto integration/aurora with green CI, and the exact-head §5 hardware row lands.

Prior Code Blockers Cleared

  1. Core-scheduling cookie check (kernel/sched/fair.c:10359-10360): Fixed — if (!sched_core_cookie_match(cpu_rq(i), p)) continue; added in fork_local_idle_cpu(), matching sched_balance_find_dst_group_cpu().
  2. SD_BALANCE_FORK domain boundary (kernel/sched/fair.c:10353-10358): Fixed — enclosing struct sched_domain *sd is passed in, llc_sd && (llc_sd->flags & SD_BALANCE_FORK) is checked, and candidates are constrained to sched_domain_span(sd) and p->cpus_ptr.

Checklist Summary (§1–§6 / CI)

  • §1 No model gating: Pass (uses generic sd_llc and task_fits_cpu() under sched_asym_cpucap_active()).
  • §2 Production-ready / §3 Safety: Code is clean; FORK_LOCAL remains default-off (false) pending cross-Mac qualification and decision on default enablement.
  • §4 Attribution: Pass (both commits a052cab0076b and c412d8fd1519 carry human author/committer + human Signed-off-by: only, zero AI commit trailers; PR body discloses Assisted-by:).
  • §6 Naming / CI: 0 check runs currently because base is stacked feature branch satchlj/sched-brief-wake-20261119 (#2480); retarget onto integration/aurora once #2480 merges so host-tests runs green.
  • §5 Evidence (remaining gate): Exact-head c412d8fd default-cmdline J775c (with #2574 cache DT) + M1/M4 on/off A/B rows (osbench thread/fork/spawn, longer hackbench, make -j$(nproc), 0 AVC denials, 0 failed units, 0 new kernel errors).

@satchlj

satchlj commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Gemini 4 Neon on @satchlj's behalf.

Hardware verification at c412d8fd1519 (stacked on #2480 3133760aed49) on J775c (same-boot A/B toggling NO_FORK_LOCAL vs FORK_LOCAL via /sys/kernel/debug/sched/features, 3 interleaved rounds):

  • Machine: lobata (Apple Mac Studio, M5 Max / T6050 / J775c)
  • Kernel & DT: integration/aurora (5746ef8a5) + #2574 (15e9687f1120), #2517 (6fcc45d80590), #2480 (3133760aed49), #2481 (c412d8fd1519), #2482 (78ebc6a42d17), #2479 (6810ea7b4a16), #2483 (d7e25fedf0e4) + flattened J775c board DTS (t6050-j775c.dtb SHA-256 d09dc6823eedb23b5e5a8427d16deb8a0d76f485ea5e646f113bf1639aad4cb9), Image.gz SHA-256 0052db5ea76f989f9cd7eb36e518576db7ced28eab27691840cbe88fada26fa9 (built with patched aurora-bindgen 0.73.2)
  • Boot: 7.3.0-posth4-b2+, boot_id f2f9d218-8991-4c40-86dd-95316c20dd88, default cmdline (rdinit=/init nr_cpus=18 maxcpus=18 root=UUID=3da7492b-6c5e-4e84-9eac-65b89fae44c6 arm64.nomte)
  • System health: SELinux N/A (Arch Linux, -SELINUX); systemctl --failed: 0 new failed units (only pre-existing ac-power-mode.service from baseline apple-spmi Gen4 -95); dmesg -l err,crit,alert,emerg: 0 new errors beyond baseline (apple-spmi Gen4 -95, apple_aop -61, apple-dcp set_active_lane_count / undeclared provider clock); 0 WARNING/BUG/Oops/Call Trace.

Results (2000 pthread_create+pthread_join / 400 fork+waitpid)

Round NO_FORK_LOCAL thread / fork FORK_LOCAL thread / fork
1 26.90 us / 125.15 us 10.49 us / 64.47 us
2 33.32 us / 154.25 us 12.05 us / 52.91 us
3 28.96 us / 145.92 us 11.14 us / 42.75 us
Median 28.96 us / 145.92 us 11.14 us / 52.91 us (2.6x / 2.8x faster)

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal §1–§6 pre-PR re-review at verified live head c412d8fd15192b84238f074d72756e283656fcc0 — holding APPROVE on stacked base retarget + green CI only.

Cleared (§1–§6 Code, Attribution & Exact-Head J775c §5 Row)

  • §1–§3 Code / Safety: Pass — fork_local_idle_cpu() cleanly enforces llc_sd->flags & SD_BALANCE_FORK, sched_domain_span(sd), p->cpus_ptr, sched_core_cookie_match(cpu_rq(i), p), and task_fits_cpu(p, i) under sched_asym_cpucap_active(); SCHED_FEAT(FORK_LOCAL, false) keeps stock behavior unchanged by default.
  • §4 Clean-room & attribution: Pass — both commits (a052cab0076b, c412d8fd1519) carry human author/committer (Satya Benson) and human Signed-off-by: only, zero AI commit trailers.
  • §5 Evidence (J775c): Exact-head c412d8fd1519 row (lobata, 7.3.0-posth4-b2+ with #2574 cache topology, 3 interleaved rounds) shows pthread_create+pthread_join median 28.96 µs -> 11.14 µs (2.6x faster) and fork+waitpid median 145.92 µs -> 52.91 µs (2.8x faster), with 0 new failed units, 0 new kernel errors beyond baseline, and 0 WARNING/BUG/Oops/Call Trace.
  • §6 Naming: Pass.

Remaining Merge Gate (Blocking APPROVE)

  1. Stacked base & 0 CI runs: Base branch is still satchlj/sched-brief-wake-20261119 (#2480, just approved, not yet merged), so statusCheckRollup has 0 check runs. Once #2480 merges, retarget #2481 onto integration/aurora so host-tests runs green — ready for immediate APPROVE once CI passes.

(Non-blocking note: cross-Mac M1/M4 + longer hackbench / make -j qualification remains needed before any follow-up proposing FORK_LOCAL default-on.)

@github-actions github-actions Bot added changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@DjDeveloperr
DjDeveloperr changed the base branch from satchlj/sched-brief-wake-20261119 to main November 24, 2026 18:47
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 24, 2026 18:48
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 3928d792: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 3928d792
Conflicts ok none
PR text ok Risk: two-way · multi-cluster Apple Silicon Macs under fork/clone/exec workloads (runtime toggleable via NOFORKLOCAL in /sys/kernel/debug/sched/features).

Areas: none matched in CODEOWNERS

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at c412d8fd1519

Blockers:

  1. kernel/sched/features.h: SCHED_FEAT(FORK_LOCAL, false) means the new placement only runs after someone writes to /sys/kernel/debug/sched/features. Merged features have to work on a default boot, with no manual step. Fix: turn it on by default, and add a same-boot spawn A/B at that head showing the posix_spawn slowdown from the 11-05 rows (+12–16 %) is gone or explained. Until then, keep the PR as a draft.

Checked: no Apple material, no gates. fork_local_idle_cpu() now respects SD_BALANCE_FORK and the domain span, cpus_ptr, the core-scheduling cookie and capacity fit on asymmetric systems. The J775c row at this head shows thread create+join 28.96 → 11.14 µs and fork+wait 145.92 → 52.91 µs, with 0 new failed units and 0 new kernel errors. #2480 is merged, so the branch is two commits on main. This replaces my earlier reviews: the code points they raised are fixed, and this is the only blocker left.

Evidence

Read a052cab0 and c412d8fd against main and the 11-24 J775c row (3 interleaved rounds, toggled through debugfs). Rows on an M1 or M4 Mac, kernel build time and hackbench are checks after the merge. They are not needed to merge.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 24, 2026 18:55

Superseded by the review at c412d8f

Scanning the local LLC round-robin from cpu + 1 spreads sequential
fork/exec loops across every core in a cluster, diluting per-CPU
PELT utilization under schedutil and dropping cluster frequency
during posix_spawn benchmarks. Scanning from the first CPU of the
LLC keeps a sequential parent/child pair warm on two cores while
still filling the remaining idle cores during concurrent fan-out.

Enable FORK_LOCAL by default so new threads and processes start in
the creator's LLC on a default boot without a debugfs toggle.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj satchlj changed the title sched/fair: start new threads and processes on an idle CPU of the creator's LLC (stacked on #2480) sched/fair: start new threads and processes on an idle CPU of the creator's LLC Nov 25, 2026
@satchlj
satchlj requested a review from a team as a code owner November 25, 2026 06:35
@satchlj

satchlj commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Addressed the blocker at head 3928d792a145 (forward-merged main, normal push):

  1. Root cause of the 11-05 posix_spawn +12-16% slowdown: fork_local_idle_cpu() scanned the local LLC round-robin with for_each_cpu_wrap(..., cpu + 1). In a sequential posix_spawn loop under default schedutil, that rotated each spawn across all 6 cores of the cluster, diluting per-CPU PELT utilization by 6x and dropping S-cluster frequency from 4.608 GHz to 2.292 GHz. Under performance governor, FORK_LOCAL was already faster on all three workloads (posix_spawn_true 78.83 -> 69.74 us, -11.5%).
  2. Fix & default-on (3928d792a145): Changed the scan in kernel/sched/fair.c to for_each_cpu(i, sched_domain_span(llc_sd)) (keeping sequential parent/child warm on two cores while still filling remaining idle cores on concurrent fan-out) and flipped SCHED_FEAT(FORK_LOCAL, true) in kernel/sched/features.h.
  3. Exact-head J775c verification (3928d792a145, default boot cmdline with MTE enabled, default schedutil, FORK_LOCAL active by default at boot, 3 interleaved same-boot rounds):
    • osbench thread_create_join: 18.560 us -> 8.529 us (-54.0%, 2.18x)
    • osbench fork_exit_wait: 95.961 us -> 29.604 us (-69.2%, 3.24x)
    • osbench posix_spawn_true: 130.003 us -> 85.227 us (-34.4%, 1.53x)
    • standalone posix_spawn (unpinned): 100.098 us -> 74.440 us (-25.6%)
    • standalone posix_spawn (pinned S-cluster 10-14,17): 54.600 us -> 54.091 us (-0.9%, 4.51-4.61 GHz held)
    • hb pipe (10 groups, 2000 loops): 0.301 s -> 0.356 s (ranges 0.300-0.371 s vs 0.331-0.373 s)
    • Health: 0 failed systemd units, 0 new kernel errors beyond baseline, 0 BUG/WARNING/Oops/Call Trace, W=1 kernel/sched/fair.o 0 warnings.

Ready for re-review at 3928d792a145 once CI finishes.

@satchlj
satchlj requested a review from DjDeveloperr November 25, 2026 06:35
@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Nov 25, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed updated diff at 3928d792a145: switching fork_local_idle_cpu() to for_each_cpu(i, sched_domain_span(llc_sd)) resolves the sequential posix_spawn PELT frequency-dilution regression under schedutil while enabling FORK_LOCAL by default, and exact-head J775c verification shows clean wins across all spawn/fork/thread workloads. Clearing the earlier changes-requested review; holding merge for a second-generation Mac exact-head row since this touches shared kernel/sched/fair.c.

@github-actions github-actions Bot added door:two-way Revertible or not, from Merge risk (bot) and removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 25, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

3928d792a145 (batched cleanly in J616s Batch #2 5b411e230229 over main 95a983c08be4, 0 merge-tree diffs across all 2 changed files) J616s (MacBook Pro 16" M4 Pro, T6040, Apple M4 Pro (G16S B1), macOS 26.6.2 fw, guarded one-shot 7.3.0-aurora-pr2905+, default cmdline, stock Stage 2 1.0.0b17, boot_id=de17fad3) PASS: 0 failed units, Enforcing, 0 new AVC (1 matching baseline), 0 GPU faults, 0 errors in this subsystem, real rtc1 s2idle 2/2 (success=2 fail=0), eDP connected pre/post-sleep, 406600000.sep + 514600000.mtp RTKit v12 (AppleMTPFirmwareMac-5340.61.4~502, HID keyboard/trackpad/accel/actuator/touch) clean, Borealis VK dEQP-VK.api.smoke.* 8/8 (pre & post-sleep) + glsl.loops.* 624/624, Wi-Fi 3/3 ping pre/post-sleep; stock 7.3.0-aurora-fleet89 restored & verified (b67edc6c).

@RyanTheTide
RyanTheTide merged commit 48edd88 into main Nov 26, 2026
5 of 8 checks passed
@RyanTheTide
RyanTheTide deleted the satchlj/sched-fork-exec-llc-20261119 branch November 27, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants