From: Usama Arif <usama.arif@linux.dev>
To: Nhat Pham <nphamcs@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
chengming.zhou@linux.dev, dsterba@suse.com, hannes@cmpxchg.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
terrelln@fb.com, yosry@kernel.org, riel@surriel.com,
shakeel.butt@linux.dev, alex@ghiti.fr, senozhatsky@chromium.org,
kernel-team@meta.com
Subject: Re: [PATCH 1/2] mm: zswap: use separate compression and decompression requests
Date: Wed, 7 Oct 2026 13:02:25 +0200 [thread overview]
Message-ID: <65503b6e-5038-4709-8f16-cd7922286963@linux.dev> (raw)
In-Reply-To: <CAKEwX=O=QNWUCTn9kcCwu9V3pTrSwTj8SMCMS6Z-8fwhGjrkdA@mail.gmail.com>
On 06/10/2026 11:47, Nhat Pham wrote:
> On Tue, Oct 6, 2026 at 2:23 AM Usama Arif <usama.arif@linux.dev> wrote:
>>
>> Stores and loads serialize on the same per-CPU acomp request and mutex.
>> A low-priority store can be preempted as soon as the compressor drops
>> its stream lock, while it still holds the mutex. A higher-priority load
>> on that CPU then waits until the store runs again, which can take a
>> long time when other tasks are runnable.
>>
>> Give compression and decompression their own request, completion wait
>> and mutex. Since commit e2c3b6b21c77f ("mm: zswap: use SG list
>> decompression APIs from zsmalloc"), the per-CPU buffer is only used for
>> compression. The two requests can share the per-CPU transform: no
>> in-tree implementation modifies transform state while (de)compressing,
>> and shared codec state has its own locking. Loads can still wait for
>> each other on the decompression mutex, and stores still serialize on
>> the compression mutex.
>>
>> This follows the proposal from Sergey Senozhatsky for the same split
>> for zram [1].
>
> Thanks, zram peeps :P
>
>>
>> [1] https://lore.kernel.org/all/20261005122036.718976-10-senozhatsky@chromium.org/
>>
>> Signed-off-by: Usama Arif <usama.arif@linux.dev>
>
> Code mostly LGTM. Just one question:
>
> [...]
>
>> - * If there was an error in allocating @acomp_ctx->req, it
>> - * would be set to NULL.
>> - */
>> - if (acomp_ctx->req)
>> - acomp_request_free(acomp_ctx->req);
>> -
>> - acomp_ctx->req = NULL;
>> + acomp_request_free(acomp_ctx->comp.req);
>> + acomp_ctx->comp.req = NULL;
>> + acomp_request_free(acomp_ctx->decomp.req);
>> + acomp_ctx->decomp.req = NULL;
>
> Hmm do we not have to null check here anymore? Does
> acomp_request_free() handle NULL itself too?
Yes, since v6.15 it starts with "if (!req || ...) return;", so the
check in acomp_ctx_free() was redundant.
>
> For instance, taking the code blob below:
>
>> - /* acomp_request_alloc() returns NULL in case of an error. */
>> - acomp_ctx->req = acomp_request_alloc(acomp_ctx->acomp);
>> - if (!acomp_ctx->req) {
>> + if (zswap_acomp_req_init(&acomp_ctx->comp, acomp_ctx->acomp) ||
>> + zswap_acomp_req_init(&acomp_ctx->decomp, acomp_ctx->acomp)) {
>> pr_err("could not alloc crypto acomp_request %s\n",
>> pool->tfm_name);
>
> Here, we can success with the comp's req but fail with the decomp's req, right?
Right. decomp.req is then NULL, as zswap_acomp_req_init() stores what
acomp_request_alloc() returned, and acomp_ctx_free() frees comp.req
and skips decomp.req. After patch 2, decomp.req also stays NULL for
synchronous algorithms, since the per-CPU contexts are zeroed, and
acomp_ctx_free() relies on the same NULL handling.
next prev parent reply other threads:[~2026-10-07 11:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 0:22 [PATCH 0/2] mm: zswap: reduce request contention on loads Usama Arif
2026-10-06 0:22 ` [PATCH 1/2] mm: zswap: use separate compression and decompression requests Usama Arif
2026-10-06 9:47 ` Nhat Pham
2026-10-06 9:52 ` Sergey Senozhatsky
2026-10-07 11:02 ` Usama Arif [this message]
2026-10-06 0:22 ` [PATCH 2/2] mm: zswap: use stack requests for synchronous decompression Usama Arif
2026-10-07 5:46 ` Nhat Pham
2026-10-06 9:18 ` [PATCH 0/2] mm: zswap: reduce request contention on loads Usama Arif
2026-10-06 9:35 ` Nhat Pham
2026-10-07 10:56 ` Usama Arif
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=65503b6e-5038-4709-8f16-cd7922286963@linux.dev \
--to=usama.arif@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=chengming.zhou@linux.dev \
--cc=dsterba@suse.com \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=riel@surriel.com \
--cc=senozhatsky@chromium.org \
--cc=shakeel.butt@linux.dev \
--cc=terrelln@fb.com \
--cc=yosry@kernel.org \
/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
all inboxes | Powered by JetHome®