[GH-ISSUE #13] Linux: CPU pool spawns ~16k workers and hangs at start (dangling else in pool.cpp, root cause of #11) #9

Closed
opened 2026-11-04 01:38:57 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Vistawizard on GitHub (Sep 26, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/13

Summary

On Linux, the engine hangs right after loading: the CPU expert pool is created with thousands of workers instead of one per core. This is the root cause of #11 (closed with the --pool-workers 6 workaround), and it affects every Linux machine where the process affinity mask doesn't cover all 1024 CPU_SETSIZE slots, i.e. basically all of them.

Symptoms

strata generate: 16143 expert-pool workers + the host thread
strata generate: session is up; locating the head

Load average climbs past 10 000, all cores at 100%, and the server never becomes ready. #11 shows the same thing on Debian 14.

Root cause

A dangling else in src/kernels/cpu/pool.cpp, Linux branch of physical_cores():

if (sched_getaffinity(0, sizeof set, &set) == 0)
    for (int i = 0; i < CPU_SETSIZE; ++i)
        if (CPU_ISSET(i, &set)) cores.push_back(i);
else   // binds to `if (CPU_ISSET…)`, not to the sched_getaffinity check
    for (unsigned i = 0; i < std::thread::hardware_concurrency(); ++i) cores.push_back((int) i);

Without braces, the else belongs to the inner if (CPU_ISSET(i, &set)). So for every CPU id that is not in the affinity mask, all hardware_concurrency() ids are appended again. On my 16-CPU Proxmox LXC: (1024 − 16) × 16 + 16 − 1 (skip_first) = 16 143, exactly the number in the log. Windows uses a different branch, which is why it doesn't show up there.

Fix

Add braces so the else belongs to the sched_getaffinity check (PR incoming):

-    if (sched_getaffinity(0, sizeof set, &set) == 0)
+    if (sched_getaffinity(0, sizeof set, &set) == 0) {
         for (int i = 0; i < CPU_SETSIZE; ++i)
             if (CPU_ISSET(i, &set)) cores.push_back(i);
-    else
+    } else {
         for (unsigned i = 0; i < std::thread::hardware_concurrency(); ++i) cores.push_back((int) i);
+    }

Verified

With the fix, on Debian 13 (Proxmox LXC, 16 CPUs), RTX 3060 12 GB, Ryzen 9 5950X (AVX2), DDR4-3200, IQ2_XS, 32K context:

  • 15 expert-pool workers + the host thread; server ready in 48 s
  • decode ~40.5 tok/s, prefill 421 tok/s on a 16.5K-token prompt
  • same model/files on llama.cpp b11146 (CUDA, --n-cpu-moe 40): ~10.9 tok/s decode, 227 tok/s prefill

Thanks for Strata, it's a great piece of work.

Originally created by @Vistawizard on GitHub (Sep 26, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/13 ## Summary On Linux, the engine hangs right after loading: the CPU expert pool is created with thousands of workers instead of one per core. This is the root cause of #11 (closed with the `--pool-workers 6` workaround), and it affects every Linux machine where the process affinity mask doesn't cover all 1024 `CPU_SETSIZE` slots, i.e. basically all of them. ## Symptoms ``` strata generate: 16143 expert-pool workers + the host thread strata generate: session is up; locating the head ``` Load average climbs past 10 000, all cores at 100%, and the server never becomes ready. #11 shows the same thing on Debian 14. ## Root cause A dangling `else` in `src/kernels/cpu/pool.cpp`, Linux branch of `physical_cores()`: ```cpp if (sched_getaffinity(0, sizeof set, &set) == 0) for (int i = 0; i < CPU_SETSIZE; ++i) if (CPU_ISSET(i, &set)) cores.push_back(i); else // binds to `if (CPU_ISSET…)`, not to the sched_getaffinity check for (unsigned i = 0; i < std::thread::hardware_concurrency(); ++i) cores.push_back((int) i); ``` Without braces, the `else` belongs to the inner `if (CPU_ISSET(i, &set))`. So for every CPU id that is **not** in the affinity mask, all `hardware_concurrency()` ids are appended again. On my 16-CPU Proxmox LXC: (1024 − 16) × 16 + 16 − 1 (`skip_first`) = **16 143**, exactly the number in the log. Windows uses a different branch, which is why it doesn't show up there. ## Fix Add braces so the `else` belongs to the `sched_getaffinity` check (PR incoming): ```diff - if (sched_getaffinity(0, sizeof set, &set) == 0) + if (sched_getaffinity(0, sizeof set, &set) == 0) { for (int i = 0; i < CPU_SETSIZE; ++i) if (CPU_ISSET(i, &set)) cores.push_back(i); - else + } else { for (unsigned i = 0; i < std::thread::hardware_concurrency(); ++i) cores.push_back((int) i); + } ``` ## Verified With the fix, on Debian 13 (Proxmox LXC, 16 CPUs), RTX 3060 12 GB, Ryzen 9 5950X (AVX2), DDR4-3200, IQ2_XS, 32K context: - `15 expert-pool workers + the host thread`; server ready in 48 s - decode ~40.5 tok/s, prefill 421 tok/s on a 16.5K-token prompt - same model/files on llama.cpp b11146 (CUDA, `--n-cpu-moe 40`): ~10.9 tok/s decode, 227 tok/s prefill Thanks for Strata, it's a great piece of work.
Author
Owner

@Niko1221 commented on GitHub (Sep 26, 2026):

Fixed by #14, thanks for tracking it down! Pull main and rerun ./setup.sh, and you won't need --pool-workers anymore.

<!-- gh-comment-id:5849626503 --> @Niko1221 commented on GitHub (Sep 26, 2026): Fixed by #14, thanks for tracking it down! Pull main and rerun ./setup.sh, and you won't need --pool-workers anymore.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#9
No description provided.