Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Bo Zhang <zhangbo0325@gmail.com>
Cc: senozhatsky@chromium.org, akpm@linux-foundation.org,
	baohua@kernel.org,  bgeffon@google.com, minchan@kernel.org,
	richardycc@google.com,  linux-kernel@vger.kernel.org,
	linux-block@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v3 10/11] zram: use rw_semaphore for decompression streams
Date: Fri, 16 Oct 2026 11:50:55 +0900	[thread overview]
Message-ID: <atGPwJL6XzlRaMva@google.com> (raw)
In-Reply-To: <20261015112440.1491168-1-zhangbo56@xiaomi.com>

On (26/10/15 19:24), Bo Zhang wrote:
> On Thu, 15 Oct 2026 12:19:49 +0900 Sergey Senozhatsky <senozhatsky@chromium.org> wrote:
> > Or perhaps we can avoid vm_map/unmap.  A slightly different approach.
> > kmalloc on fast path + memcpy (zsmalloc objects are strictly less than
> > PAGE_SIZE bytes)
> 
> I applied the kmalloc+memcpy variant on-device and re-ran the same
> Android A/B. It removes the exclusive path entirely in our workload.
> 
>                       9+10       9+10 + kmalloc fastpath
>   read contended      ~1,959     0
>   read wait_ns total  ~12 s      0
>   read wait_ns max    72-96 ms   0
>   shared              76.7%      100%
>   exclusive           23.3%      0%
>   dpin_contended      0          0
> 
> Every decompression now takes the shared (down_read) path, including the
> cross-page objects that previously had to go exclusive. The ~1,959
> residual contentions on the exclusive path are gone, and pin contention
> stays at zero, so the full read side runs concurrently with no stream
> contention.
> 
> Read-side contention end to end:
> 
>                  baseline   9+10      9+10 + kmalloc
>   read contended 24,749     ~1,959    0
>   shared         0%         76.7%     100%

Thank you.  I'll include kmalloc patch to v4 of the series.

> This is a stateless-backend result (lzo-rle). zstd/deflate have
> create_dctx and stay exclusive, so they don't benefit from shared reads
> at all - which, as you noted, is the sad part about zstd on that list.
> 
> For those backends the serialization is unavoidable, but the actual
> root cause of the long waits is still the holder being preempted or
> migrated while holding the stream. So on top of 9+10+kmalloc I tried
> a quick-and-dirty preempt-disable for synchronous backends. Allocation
> can no longer sleep under the stream, so a two-stage zram_zs_malloc()
> does a non-sleeping attempt first and, on failure, bounces into a kmalloc()
> buffer, drops the stream and retries with a sleeping GFP_NOIO.
> 
> zstd backend, same A/B workload, on top of 9+10+kmalloc:
> 
>                        9+10+kmalloc   + preempt-disable
>   cwrite_contended     14,880         48          (-99.7%)
>   cwrite_wait_ns_total 137 s          0.32 s      (-99.8%)
>   cwrite_wait_ns_max   243 ms         43 ms       (-82%)
>   dexcl_contended      15,919         54          (-99.7%)
>   dexcl_wait_ns_total  109.6 s        0.68 s      (-99.4%)
>   dexcl_wait_ns_max    145 ms         34.6 ms     (-76%)
> 
> zstd stays 100% exclusive either way; the win comes purely from the
> holder no longer being preempted/migrated, so the hold time stays short.
> It's the same mechanism that took lzo-rle read contention from 24,749 to
> 406 earlier. So the two are complementary: shared reads remove
> reader-vs-reader queuing for stateless backends, and preempt-disable
> covers the exclusive/write serialization that stateful backends can't
> avoid.
> 
> Quick and dirty, for discussion only - Patch below.

Yeah... I need to think about it, before I can join discussions
in a meaningful way.


  reply	other threads:[~2026-10-16  2:51 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13  3:50 [PATCH v3 00/11] zram: redesign zcomp and rework backends Sergey Senozhatsky
2026-10-13  3:50 ` [PATCH v3 01/11] zram: prefix backends printk-s Sergey Senozhatsky
2026-10-13  3:50 ` [PATCH v3 02/11] zram: remove debugfs entry on init failure Sergey Senozhatsky
2026-10-13  3:50 ` [PATCH v3 03/11] zram: zstd: do not allocate empty C/D-dictionaries Sergey Senozhatsky
2026-10-13  3:50 ` [PATCH v3 04/11] zram: lz4hc: pre-initialize dictionary stream in setup_params Sergey Senozhatsky
2026-10-13  3:50 ` [PATCH v3 05/11] zram: lz4: use LZ4_decompress_safe_usingDict() Sergey Senozhatsky
2026-10-13  3:50 ` [PATCH v3 06/11] zram: lz4hc: " Sergey Senozhatsky
2026-10-13  3:50 ` [PATCH v3 07/11] zram: zstd: do not use kvzalloc() for zstd allocations Sergey Senozhatsky
2026-10-13  3:50 ` [PATCH v3 08/11] zram: reset writeback state in zram_reset_device() Sergey Senozhatsky
2026-10-13  3:50 ` [PATCH v3 09/11] zram: split zcomp into separate R/W streams Sergey Senozhatsky
2026-10-13  3:50 ` [PATCH v3 10/11] zram: use rw_semaphore for decompression streams Sergey Senozhatsky
2026-10-14 15:36   ` Bo Zhang
2026-10-14 20:46     ` Barry Song
2026-10-15  2:04       ` Sergey Senozhatsky
2026-10-15  3:19       ` Bo Zhang
2026-10-15  3:24         ` Sergey Senozhatsky
2026-10-15  1:41     ` Sergey Senozhatsky
2026-10-15  2:11       ` Sergey Senozhatsky
2026-10-15  3:19       ` Sergey Senozhatsky
2026-10-15  5:18         ` Sergey Senozhatsky
2026-10-15 11:24           ` Bo Zhang
2026-10-16  2:50             ` Sergey Senozhatsky [this message]
2026-10-16  3:10               ` Barry Song
2026-10-16  3:13                 ` Sergey Senozhatsky
2026-10-16  8:54               ` Sergey Senozhatsky
2026-10-16 13:48                 ` Bo Zhang
2026-10-13  3:50 ` [PATCH v3 11/11] zram: use a singleton compression context for recompression Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=atGPwJL6XzlRaMva@google.com \
    --to=senozhatsky@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=bgeffon@google.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=richardycc@google.com \
    --cc=zhangbo0325@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox