Skip to content

zram: use a 4 KiB LZ4 hash table for independent pages - #503

Merged
dormancygrace merged 3 commits into
mainfrom
codex/lz4-zram-table4k
Oct 27, 2026
Merged

dormancygrace merged 3 commits into
mainfrom
codex/lz4-zram-table4k

Conversation

@dormancygrace

@dormancygrace dormancygrace commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Depends on #501. This PR contains only the small-table specialization and its zram integration.

Use a 4 KiB hash table for independent blocks up to 4096 bytes. On 4 KiB-page kernels, the zram backend uses a 4,128-byte workspace instead of 16,416 bytes when no dictionary is configured. On 4 KiB-page kernels, vmalloc backs these workspace requests with 8 KiB and 20 KiB respectively: 12 KiB less per no-dictionary context, excluding allocation metadata and virtual guard pages. This is workspace memory, not compressed zsmalloc savings. Generic callers, dictionary mode, and larger-page kernels retain the original table. The block format and decoder are unchanged.

The dedicated C906 object adds 1,940 bytes of text/readonly data; the generic compressor machine code is byte-identical to #501. On 1,413 synthetic and target-ELF pages, compressed bytes change from 2,901,428 to 2,909,962 (+0.294%); the largest per-page increase is 51 bytes. This corpus is not an observed swap distribution or a measurement of zsmalloc memory.

Validation:

  • All input lengths from 0 through 4096, unaligned inputs/output, guard pages, bounded output, acceleration extremes, and oversized-input rejection; normal and ASan/UBSan runs. The test rejects a negative control with the input-size guard removed.
  • Actual patched zram backend exercised with native kernel-allocation shims at 4 KiB, 8 KiB and 64 KiB page sizes, including dictionary mode, existing kernel decoder, and allocation failure; ASan/UBSan.
  • Linux 7.3 compressor module and zram backend cross-compiled with production C906 flags; both patches apply without fuzz.
  • New guarded-buffer test added to CI.

Kernel microbenchmarks of the exact PR501 and PR503 implementations now pass on C906. The initial comparison favors the 4 KiB path, but an identical-code placement effect means its timing percentage remains preliminary. Real swap-pressure qualification and zsmalloc memory savings remain unmeasured. All 15 CI checks, including the full firmware build, pass.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Build outputs

Compared with the build of main at 2571baa; codex/lz4-compressor-110 is at d12e7d7, so outputs changed since then are listed too.

4 changed, 0 added, 0 removed of 570 outputs.

directory files
changed lib lib/modules/7.3.0-nanokvm-os-r3/kernel/drivers/block/zram/zram.ko
lib/modules/7.3.0-nanokvm-os-r3/kernel/lib/lz4/lz4_compress.ko
lib/modules/7.3.0-nanokvm-os-r3/modules.symbols
lib/modules/7.3.0-nanokvm-os-r3/modules.symbols.bin
Hashes: outputs-sha256 artifact of this run.

@dormancygrace dormancygrace left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

  • The 4 KiB table produces ordinary LZ4 block output.
  • The small-table test passes, including round-trips for every length 0–4096, guard pages, bounded output and oversize rejection.
  • Workspace alignment is enforced by the static_assert.
  • Dictionary mode and larger pages keep the old path.

Two small notes:

Comment thread platform/kernel/0053-lz4-zram-small-table.patch Outdated
Comment thread platform/kernel/0055-lz4-zram-small-table.patch

@dormancygrace dormancygrace left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed at e6825cb. Corrected a NULL dereference for NULL/misaligned small-table workspace and integrated the matching #501 API correction. The zram page-size/dictionary selection and bounded compression paths were independently checked. All 0..4096 lengths, guarded/unaligned buffers, bounded output, acceleration extremes and invalid workspaces pass normally and under ASan/UBSan; the complete LZ4 and zram patch stack applies to Linux 7.3 with exact context. Platform configuration/build tests pass. The runtime correction is substantive; this PR remains open.

Base automatically changed from codex/lz4-compressor-110 to main October 27, 2026 00:21

@dormancygrace dormancygrace left a comment •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final review at ccdfe3e: the small-table patch is now 0055-lz4-zram-small-table.patch after compressor patch 0054, with both test references updated. The patch blob is byte-for-byte identical to the previously reviewed fix. Current main and the renumbered #501 are integrated without changing the small-table runtime. Clean Linux 7.3 patch/Kconfig and guarded 0..4096-byte small-table tests pass normally and under ASan/UBSan. All 15 head checks pass, and the prepared main merge tree exactly matches the tested head. No unresolved findings.

@dormancygrace
dormancygrace merged commit 93e133c into main Oct 27, 2026
15 checks passed
@dormancygrace
dormancygrace deleted the codex/lz4-zram-table4k branch October 27, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant