← Back to Pull requests

Compress the file data of images with lz4 #16

Closed
unknown closed this pull request without merging on Nov 19, 2026 18:16 UTC
View on GitHub
unknown unknown commented on Nov 19, 2026 15:31 UTC
Author

Give -zlz4 to mkfs.erofs, so every input image holds its file data compressed. That covers store closures, --root trees and root tars. The guest kernel already has CONFIG_EROFS_FS_ZIP, and it decompresses a block only when the guest reads it.

The images directory is now 3, so Rewind does not reuse an uncompressed image from before.

Size

An image is about 56 percent of its closure. With #15, peak disk while building falls from about 3.2x the closure to about 1.6x.

Why lz4 and not lz4hc

lz4hc at its default level costs ten times the CPU for an image about 10 percent smaller. On the 433 MB input closure of hello:

| Mode | CPU to build | Image |
|---|---|---|
| none | 0.03 s | 433 MB |
| lz4 | 0.9 s | 246 MB |
| lz4hc,3 | 5.0 s | 224 MB |
| lz4hc (level 9) | 8.7 s | 221 MB |

Single-threaded, lz4hc runs at about 46 MB/s. mkfs pays that on every new closure. mkfs memory also grows with the worker count, which follows the CPU count: about 1 GB at 16 workers on a 3.5 GB closure, and more on a many-core builder.

Determinism

The image must be a function of its files alone. mkfs.erofs compresses in fixed 16 MiB segments and merges them in order, whatever the number of workers. With lz4, a 171 MB tree gave the same image with 1 worker, 16 workers and the default. With lz4hc, a 3.5 GB closure gave the same image with 1 worker, 16 workers and taskset -c 0, and the release's static mkfs.erofs gave the same image as the dynamic one. A mkfs.erofs built without threads (--workers=0) lays the data out differently. The release ships its own threaded mkfs.erofs.

Guest cost

Measured with lz4hc; lz4 decompresses faster.

The guest mounts erofs without DAX, so file data already went through the guest page cache. Compression gives up no fast path. For rewind nix of hello:

| | Uncompressed | Compressed |
|---|---|---|
| Steps (3 runs) | 123389–123410 | 123384–123648 |
| Virtual time | 11.579 s | 11.579 s |
| Guest MemFree at step 120000 | 880.7 MB | 871.4 MB |
| Host rewind RSS | 430 MB | 326 MB |

The page store grew 6.5 percent. Reading every file of a 436 MB image used 26 MB more guest memory and took 2 more steps.

The image hash is part of the run id, so this changes every run id.

Tests

an_image_holds_its_file_data_compressed packs a 1 MiB file of one repeated line and checks that the image is under half its size. It fails if -z is dropped. docs/design.md describes the compression and names images/3.

Tested: the Fediversity checks build in Rewind with lz4hc.

Assisted-by: Claude:claude-fable-5-2

Diff: 321 lines (+240 / -81) across 4 files Reviewer: fzakaria Review duration: 164m
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 321 lines diff across 4 files
0.42
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.345
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #16"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 41.9% (MEDIUM) · Higher = larger blast radius
41.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 16.6% · Safe to merge
16.6%