From: Usama Arif <usama.arif@linux.dev>
To: Herbert Xu <herbert@gondor.apana.org.au>,
davem@davemloft.net, terrelln@fb.com, dsterba@suse.com,
hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com,
chengming.zhou@linux.dev,
Andrew Morton <akpm@linux-foundation.org>,
linux-crypto@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, riel@surriel.com,
shakeel.butt@linux.dev, kernel-team@meta.com
Cc: Usama Arif <usama.arif@linux.dev>
Subject: [PATCH 1/2] crypto: zstd - use vmalloc() for stream workspaces
Date: Wed, 11 Nov 2026 07:07:39 -0800 [thread overview]
Message-ID: <20261111153532.1036709-2-usama.arif@linux.dev> (raw)
In-Reply-To: <20261111153532.1036709-1-usama.arif@linux.dev>
The zstd acomp streams retain their workspaces after the last transform
has been freed. The first is allocated during transform initialization;
additional per-CPU streams are allocated on demand. They are released
when the algorithm is unregistered.
In a 4 KiB-page x86-64 build, each stream requests 1,566,281 bytes.
If kvmalloc() succeeds via kmalloc(), it occupies an order-9 block
(2 MiB). vmalloc() needs 383 backing pages (1,532 KiB), 516 KiB fewer
per stream. Across 384 populated streams, that is 193.5 MiB less
workspace backing if all would have used kmalloc(). There is no such
gain when kvmalloc() already falls back to vmalloc().
Use vmalloc() and vfree() directly to avoid the high-order allocation.
This uses vmalloc address space, page tables and bookkeeping; the
figures above compare workspace backing only.
Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
crypto/zstd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/crypto/zstd.c b/crypto/zstd.c
index 76bdaca327330..f012293919368 100644
--- a/crypto/zstd.c
+++ b/crypto/zstd.c
@@ -44,7 +44,7 @@ static void *zstd_alloc_stream(void)
if (!wksp_size)
return ERR_PTR(-EINVAL);
- ctx = kvmalloc_flex(*ctx, wksp, wksp_size);
+ ctx = vmalloc(struct_size(ctx, wksp, wksp_size));
if (!ctx)
return ERR_PTR(-ENOMEM);
@@ -56,7 +56,7 @@ static void *zstd_alloc_stream(void)
static void zstd_free_stream(void *ctx)
{
- kvfree(ctx);
+ vfree(ctx);
}
static struct crypto_acomp_streams zstd_streams = {
--
2.53.0-Meta
next prev parent reply other threads:[~2026-11-11 15:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 15:07 [PATCH 0/2] crypto: use vmalloc() for large " Usama Arif
2026-11-11 15:07 ` Usama Arif [this message]
2026-11-11 15:43 ` [PATCH 1/2] crypto: zstd - use vmalloc() for " Rik van Riel
2026-11-11 15:07 ` [PATCH 2/2] crypto: deflate " Usama Arif
2026-11-11 15:44 ` Rik van Riel
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=20261111153532.1036709-2-usama.arif@linux.dev \
--to=usama.arif@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=davem@davemloft.net \
--cc=dsterba@suse.com \
--cc=hannes@cmpxchg.org \
--cc=herbert@gondor.apana.org.au \
--cc=kernel-team@meta.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=riel@surriel.com \
--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®