Repository navigation
Conversation
|
nice finding! |
|
Added |
Merging this PR will not alter performance1 warning, 1 note
Comparing Footnotes
|
|
The CodSpeed regression was from my change: The same commit fixes the wasi lint (the field was unused there). The stty clippy and OpenBSD failures happen on main too. |
I am more interested in the fix :) |
Under a cgroup pids limit (for example TasksMax in a systemd unit), the sorter thread could not be spawned and sort panicked with "failed to spawn thread". Sort the chunks on the reading thread in that case. If rayon's global pool cannot be created either, rayon never gets one, so sort chunks without it instead of panicking on the first large one.
RLIMIT_NPROC set to 1 stops an unprivileged process from creating any thread, like a cgroup pids limit. Check a small input and one large enough for the parallel sort.
build_global() also fails when the pool is already initialized, which happens whenever sort runs again in the same process, as in the benchmarks. That was taken to mean there is no pool, so those runs sorted sequentially. Only an I/O error means no thread could be created; decide once per process. Also only define the parallel field where it is read, so the wasi builds do not warn about a dead field.
|
Rebased on main so the lint job picks up the stty clippy fix. |
ab83b45 to
354e856
Compare
|
GNU testsuite comparison: |
Ubuntu's
openvpn-client@.servicesetsTasksMax=20, andupdate-resolv-confpipes throughsort, so on a 16-CPU machinesortpanics withfailed to spawn threadand openvpn fails to bring the connection up (LP: #2172214). GNU sort keeps working with fewer threads.Two places needed a fallback:
ext_sort: if it can't be spawned, the chunks go back to the reading thread and are sorted there.build_globalfails, rayon can't create one later either, so chunks are sorted without it instead of panicking on the first one large enough forpar_sortto use the pool.I tested it on a 2-CPU runner with
systemd-run --scope -p TasksMax=N. Main panics at TasksMax 1-3 forprintf 'b\na\n' | sort, and at 2-3 for 300k shuffled numbers with-n. With this change both work at every limit and give the same output as GNU. Thesorttests pass, and clippy and the wasi check are clean.Not covered here: when the input spills to temporary files (or with
-m/-c), the merge and check paths start their own reader thread and still panic under the same limits (-S 1Mwith TasksMax 2-3). That needs a bigger change to the merger, so I'd rather do it separately.(#13806 adds a compile-time no-thread variant for WASI. This one is the runtime case, when the OS refuses a thread on Linux.)