Re: [PATCH v3 10/11] zram: use rw_semaphore for decompression streams

From: Bo Zhang

Date: Wed Oct 14 2026 - 11:45:26 EST


Following up on the RFC thread [1]: Sergey pointed me at this series as
the reworked version of the by-direction split I had tested, so I applied
patches 9 and 10 and re-ran the same A/B. Big improvement.

[1] https://lore.kernel.org/lkml/20261012123328.1138059-1-zhangbo56@xxxxxxxxxx

Setup as before: real Android device (MemTotal ~7.7GB, zram ~8GB), cycle
20 apps through fg/bg to force swap-out/in, 8 rounds, reboot before each.
Same trylock instrumentation on the stream locks across all builds. For
patch 10, "read contended" = dpin_contended + dexcl_contended. Decompress
("read") is the swap-in path, which is what matters for us.

I use decompress acquire count (swapped-in pages) as the comparability anchor
instead of swap volume, which stays within ~20% across builds.

baseline preempt-disable 9 + 10
read contended 24,749 406 1,959
read wait_ns total 239.8 s 3.78 s ~12 s
read wait_ns max 757 ms 51.7 ms 72-96 ms
read acquire 3,948,150 4,305,078 3,510,610

Decompression on 9+10 splits into:
shared (stateless backend, single-page): 76.7% -> down_read never
blocked (dpin_contended = 0)
exclusive (cross-page object): 23.3% -> excl_lock, ~1,959 contended

- 9+10: read contention -92%, total wait ~-95%, worst case 757ms -> ~90ms.
The rwsem does the heavy lifting: ~77% of swap-in decompressions now run
concurrently with zero pin contention - exactly the reader-vs-reader
queuing we were hitting. Clear win over the two-mutex split.
- Residual contention is all on the exclusive path, mostly cross-page
objects (which need the ->local_copy bounce), not a specific backend -
lzo-rle single-page objects all go shared.
- preempt-disable still shows the lowest read contention (406). It covers
the other half of the root cause (holder preempted/migrated while
holding the stream), so the two are complementary rather than
competing: 9+10 removes reader-vs-reader queuing structurally, and the
~90ms tail that remains on 9+10 is the preempt/migrate effect.

Happy to share scripts and raw numbers on request.

Thanks,
Bo