Repository navigation
7z LZMA2 threads: blocks reach idle workers early; parallel budget scales with memory (2x on -mmt archives) - #318
Conversation
…udget scales with memory The 7z extractor already decoded LZMA2 dictionary-reset blocks on several threads (#235), but on 7-Zip -mmt archives with 64-128 MiB blocks it ran at about 1.8 cores whatever the thread count: - The 256 MiB budget held about one and a half 64 MiB blocks in flight. The default is now an eighth of physical memory, 256 MiB to 2 GiB (1 GiB where memory can't be read). - Reading ahead to find the next block was bounded by the output so far, so the second block was found half way through the first, and stored (random-data) blocks were read 256 KiB at a time, so LZMA blocks after them reached the workers late. Now, while a worker waits with no piece, only the budget bounds reading ahead; before the workers start the lookahead may reach four dictionary windows (one 7-Zip block). Output order, CRC checks and error placement are unchanged. Tests: BCJ and Delta after a multi-block LZMA2 coder, damage in the middle, shuffled block layouts, idle-worker read-ahead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6a47b24dbf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let (pages, page) = unsafe { (libc::sysconf(libc::_SC_PHYS_PAGES), libc::sysconf(libc::_SC_PAGESIZE)) }; | ||
| let pages = u64::try_from(pages).ok().filter(|&n| n > 0)?; | ||
| let page = u64::try_from(page).ok().filter(|&n| n > 0)?; | ||
| pages.checked_mul(page) |
There was a problem hiding this comment.
Account for the container memory limit when sizing the budget
On Linux containers with a memory limit below the host's RAM, _SC_PHYS_PAGES reports host memory rather than the cgroup allowance. For example, a 512 MiB container on a host with at least 16 GiB now gets a 2 GiB parallel budget instead of the previous 256 MiB. This can cause an OOM kill during multi-block extraction: lzma2_par::plan permits additional workers and decoded blocks accumulate behind the head up to this budget. The normal extraction paths in src/extract.rs construct SevenZipLimits::default() directly, so they inherit this regression. Bound the detected memory by the effective cgroup memory limit before calculating the default.
Useful? React with 👍 / 👎.
|
Local CI ( |
Prybar's benchmark found that
extract::runon a 7-Zip-mmtLZMA2 archive ran at about 1.8 cores and that--threadsmade no difference. zipfast already decodes dictionary-reset blocks in parallel (#235). This PR removes the two things that kept those threads idle.What limited it
A per-piece trace of the pipeline on the x86 set (20 blocks of 64 MiB) showed:
lzma2_parallel_bytesdefaulted to 256 MiB. That holds about 1.5 decoded 64 MiB blocks waiting for in-order write-out, so only about 2 blocks were ever in flight.Change
SevenZipLimits::lzma2_parallel_bytesnow defaults to an eighth of physical memory, clamped to 256 MiB–2 GiB. It is read withsysconfon Linux, macOS and FreeBSD; elsewhere it is 1 GiB. It is still a cap, not an allocation: memory is taken only as blocks decode ahead of the one being written.Parallel::room: while a worker is idle (more idle workers than queued pieces), only the budget bounds read-ahead. Before the workers start, the lookahead may reach four dictionary windows (one 7-Zip block), so the second piece is found while the first is still decoding. A one-block stream still reads little ahead.Benchmarks
Data: 1.28 GB mixed (6 × 100 MB text, 6 × 100 MB random, 40 × 2 MB short-run data),
7z a -m0=lzma2 -mx5 -mmt. Extracted withzipfast x -mtNto local disk; wall-clock seconds.x86, rustyget-x86-a (Xeon Platinum 8581C, 32 vCPU, Linux). Archive from 7z 23.01
-mmt=32: 20 blocks of 64 MiB. Median of 3. The host was shared, with load 5–88 during the runs, but spread within a row stayed under 3%.An earlier quieter run on the same host gave mt8 5.47 → 2.65 and mt32 5.50 → 2.27, with 7zz mt32 at 4.10.
Apple M5 (this Mac, 10 cores). Archive from 7zz 26.06
-mmt=10: 10 blocks of 128 MiB. The host was loaded (load 5–9), so these are the median of 5 interleaved rounds:LzmaReader); the 1-thread differences are noise.Tests
tests/sevenzip_lzma2_threads.rs:lzma2_parunit testidle_workers_get_the_pieces_after_stored_ones_early: every piece reaches a thread before the first is handed out. It fails on main (4 of 7).🤖 Generated with Claude Code
https://claude.ai/code/session_01LG44gZ63jJDJGeNcamsGrj