xz: Compress with -9 -T0 for Small Artifacts
xz compresses files to .xz using LZMA2, giving the best ratio of the common CLIs, with -T0 to use every core for speed.
xz is what you use when artifact size matters more than compress time (release tarballs, kernel sources). Multi-threading with -T0 makes -9 tolerable in CI.
What it does
xz compresses each file with LZMA2, appends .xz, and removes the source unless -k is given. unxz or xz -d reverses it. -T0 enables multi-threaded compression across all cores, at a small cost to ratio.
Common usage
xz -9 -T0 release.tar # best ratio, all cores
xz -k -6 build.log # keep source, default-ish level
tar cf - src/ | xz -9 > src.tar.xz
xz -d package.tar.xz # decompressOptions
| Flag | What it does |
|---|---|
| -9 | Maximum compression (large dictionary) |
| -T0 / --threads=0 | Use all available cores (0 = auto) |
| -e / --extreme | Extra effort at a given level for a bit more ratio |
| -k / --keep | Keep the input file |
| -c / --stdout | Write to stdout |
| -d / --decompress | Decompress (like unxz) |
In CI
Add -T0 so xz -9 uses every core; without it xz is single-threaded and slow. Multi-threaded compression splits into blocks, which very slightly reduces ratio but is worth it in a pipeline. Install with apt-get install -y xz-utils or apk add xz.
Common errors in CI
"xz: (stdin): File format not recognized" on decompress means the input is not xz (often gzip or zstd); check with file. "xz: Cannot allocate memory" at -9 on small runners is real: -9 needs roughly 700 MB per thread, so lower the level or thread count. "xz: command not found" means xz-utils is not installed.