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

From: Sergey Senozhatsky

Date: Sun Oct 11 2026 - 00:28:20 EST


On (26/10/09 16:11), Sergey Senozhatsky wrote:
> Currently, per-CPU decompression streams use a mutex, so there is
> a chance for priority inversion - a low priority Reader can get
> preempted by a higher priority Reader, which simply will get
> blocked on the stream mutex.
>
> Switch zcomp_dstrm lock from mutex to rw_semaphore to permit parallel
> usage. However, things are not completely straightforward. Many
> backends have stateless decompression and don't modify decompression
> context, so those can be used concurrently. But then there are backends
> that do modify decompression context. We also can have compressed
> object span across physical pages, which zcomp linearises using stream's
> ->local_copy buffer before decompression. That buffer, clearly, cannot
> be used concurrently.
>
> When the backend has no per-stream decompression context (stateless)
> and zsmalloc object fits in a single page (ZCOMP_DECOMP_INPLACE), take
> the stream lock in shared mode (read). Otherwise, when ->local_copy
> is needed (ZCOMP_DECOMP_BOUNCE) or the backend has a decompression
> context (zstd, deflate), take the lock in exclusive mode (write).
>
> A quick synthetic fio test on 24 CPUs (preempt=full, lz4, 48 low
> priority (nice 19) readers, 24 normal priority (nice 0) CPU hogs
> and 24 high priority (nice -19) readers):
>
> Metric Base Patched
> ----------------------------------------------------------
> Read IOPS 473k 680k (+43.8%)
> Read clat avg 35.98 us 21.28 us (-40.9%)
> Read clat p99.95 55.55 us 20.86 us (-2.7x)
> Read clat p99.99 6,717 us 2,834 us (-2.4x)
> Read clat max 2,005,100 us 1,614,300 us (-19.5%)
>
> Suggested-by: Brian Geffon <bgeffon@xxxxxxxxxx>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>

JFI
I have completely reworked this patch. Will run tests and then
send out v3.