Repository navigation
Optimize scalar LZ4 compression and decompression on C906 - #505
Conversation
Build outputsCompared with the build of main at 2571baa; codex/lz4-zram-table4k is at ccdfe3e, so outputs changed since then are listed too. 17 changed, 0 added, 0 removed of 570 outputs.
|
There was a problem hiding this comment.
The new code is correct.
- Differential: I compared the old and new decoders on 309,540 constructed cases (offsets 0–16, match lengths 4–70, 0–20 trailing literals, with the safe, fast and partial APIs) and on 300,000 bit-flipped or truncated streams under ASan. The results were identical.
- bswap+clz: it is only reached with a non-zero
diff, and the kernel build always enables XTheadBb.
Removing 0039 is fine with the kernel built with -mno-strict-align (see the corrected inline comment); only the bench docs still point at it.
dormancygrace
left a comment
There was a problem hiding this comment.
Review completed at 5f35ef5. No new production-code defect found in the scalar byte-count or overlap-copy changes. Expanded near-end and malformed-block tests pass with the actual patched Linux 7.3 decoder, normally and under ASan/UBSan; compressor and small-table contracts pass in both modes. Full LZ4 patch application, platform configuration and C906 flag checks pass. Historical benchmark documentation and the full/partial decode comment are corrected. This branch includes the substantive #501/#503 workspace corrections and remains open with its dependencies.
dormancygrace
left a comment
There was a problem hiding this comment.
Final review at 1046bfc: scalar LZ4 paths are now patch 0056, following compressor 0054 and small-table 0055. All test paths and the current benchmark README reference are updated; the patch contents are unchanged. Both decoder and C906 memory/usercopy documentation sections are preserved when integrating current main. Clean Linux 7.3 patch/Kconfig, compressor and small-table contracts, and the actual patched decoder in normal and ASan/UBSan modes pass. The prepared main merge tree exactly matches the validated head. No unresolved findings.
C906 spends avoidable instructions in LZ4 byte counting and match copies. Use byte reversal plus CLZ in the compressor, initialize the decoder overlap buffer only for offsets below eight, and remove the old aligned-copy dispatch and its kernel option. Public APIs, bounds checks and compressed output are preserved.
Measured with the actual kernel code on C906, using 1,413 identical 4 KiB pages and matched code placement:
These are codec measurements, not end-to-end zram gains. Decoder inputs were produced by the exact compressor in #503. Each comparison used bracketing baselines, three rounds and two layouts; decoder candidate order was rotated. All device runs passed, with unchanged output.
Validation: normal and ASan/UBSan compressor, small-table and decoder contracts; guarded buffers and malformed input; overlap distances, partial decoding, dictionaries, safe/fast streaming and in-place decompression. A negative control confirms that the decoder test detects missing zero-offset initialization. Final C906 machine code matches the measured prototypes; patch application, platform tests and kernel configuration checks pass. The decoder contract now runs against the actual patched kernel source in firmware CI.
Stacked on #503; compressor update #501 and table-size change #503 remain separate.