RFC zram: Allow zcomps to manage their own streams
Get series with b4
b4 am [email protected] change-id 20260202-b4_zcomp_stream-7e9f7884e128Versions newest first
- v2 RFC Latest5 patches 5 repliesIn review
- v1 RFC3 patches 0 repliesSuperseded
Changes in v2 from the cover letter
- Decouple locking from per-CPU streams by introducing struct
percpu_zstrm (PATCH 2/5)
- Refactor zcomp-managed streams to use struct managed_zstrm (PATCH 3/5)
- Add PoC zcomp-managed streams for lz4 backend (PATCH 5/5, only for demonstration)
- Rebase to v7.0-rc2
- Link to v1: https://lore.kernel.org/r/[email protected]
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/5 | zram: Rename zcomp_strm_{init, free}()drivers/ | +5 | 0 replies | |
| 2/5 | zram: Separate the lock from zcomp_strmdrivers/ drivers/ | +32 | 0 replies | |
| 3/5 | zram: Introduce zcomp-managed streamsdrivers/ drivers/ drivers/ | +72 | 3 replies | |
| 4/5 | zram: Use zcomp-managed streams for async write requestsdrivers/ | +17 | 0 replies | |
| 5/5 | zram: Add lz4 PoC for zcomp-managed streamsdrivers/ | +442 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.
Cover letter [PATCH RFC v2 0/5] zram: Allow zcomps to manage their own streams
Hi all,
This RFC series introduces a new interface to allow zram compression backends to manage their own streams, in addition to the existing per-CPU stream model.
Currently, zram manages compression contexts via preemptive per-CPU streams, which strictly limits concurrency to the number of online CPUs. In contrast, hardware accelerators specialized for page compression generally process PAGE_SIZE payloads (e.g. 4K) using standard algorithms. These devices expose the limitations of the current model due to the following features:
- These devices utilize a hardware queue to batch requests. A typical queue depth (e.g., 256) far exceeds the number of available CPUs.
- These devices are asymmetric. Submission is generally fast and asynchronous, but completion implies latency.
- Some devices only support compression requests, leaving decompression to be handled by software.
The current "one-size-fits-all" design lacks the flexibility to support these devices, preventing effective offloading of compression work.
This series proposes a hybrid approach. While maintaining full backward compatibility with existing backends, this series introduces a new set of operations, op->{get, put}_stream(), for backends that wish to manage their own streams. This allows the backend to handle contention internally and dynamically select an execution path for the acquired streams. A new flag is also introduced to indicate this capability at runtime. zram_write_page() now prefers streams managed by the backend if a bio is considered asynchronous.
Some design decisions are as follows.
1. The proposed get_stream() does not take gfp_t flags to keep the interface minimal. By design, backends are fully responsible for allocation safety.
2. The default per-cpu streams now also imply a synchronous path for the backends.
3. The recompression path currently relies on the default per-cpu streams. This is a trade-off, since recompression is primarily for memory saving, and hardware accelerators typically prioritize throughput over compression ratio.
4. Backends must implement internal locking if required.
This RFC series focuses on the stream management interface required for accelerator backends, laying the groundwork for batched asynchronous operations in zram. Since I cannot verify this on specific accelerators at this moment, a PoC patch that simulates this behavior in software is included to verify new stream operations without requiring specific accelerators. The next step would be to add a non-blocking interface to fully utilize their concurrency, and allow backends to be built as separate modules. Any feedback would be greatly appreciated.
---
Changes in v2:
- Decouple locking from per-CPU streams by introducing struct
percpu_zstrm (PATCH 2/5)
- Refactor zcomp-managed streams to use struct managed_zstrm (PATCH 3/5)
- Add PoC zcomp-managed streams for lz4 backend (PATCH 5/5, only for demonstration)
- Rebase to v7.0-rc2
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Jihan LIN (5):
zram: Rename zcomp_strm_{init, free}()
zram: Separate the lock from zcomp_strm
zram: Introduce zcomp-managed streams
zram: Use zcomp-managed streams for async write requests
zram: Add lz4 PoC for zcomp-managed streams
drivers/block/zram/backend_lz4.c | 464 +++++++++++++++++++++++++++++++++++++-- drivers/block/zram/zcomp.c | 85 +++++-- drivers/block/zram/zcomp.h | 35 ++- drivers/block/zram/zram_drv.c | 29 ++- 4 files changed, 562 insertions(+), 51 deletions(-)
---
base-commit: 11439c4635edd669ae435eec308f4ab8a0804808
change-id: 20260202-b4_zcomp_stream-7e9f7884e128
Best regards,
Signature · 1 line
Jihan LIN <[email protected]>