[PATCH 2/2] crypto: deflate - use vmalloc() for stream workspaces
From: Usama Arif
Date: Wed Nov 11 2026 - 10:52:34 EST
The deflate acomp streams outlive the transforms that use them. One
stream is allocated during transform initialization; additional
per-CPU streams are allocated on demand. They are freed only when
the algorithm is unregistered.
In a 4 KiB-page x86-64 build, each stream requests 145,320 bytes.
If kvmalloc() succeeds via kmalloc(), it occupies an order-6 block
(256 KiB). vmalloc() needs 36 backing pages (144 KiB), 112 KiB fewer
per stream. Across 384 populated streams, that is 42 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, as the crypto lz4 implementations
already do. This uses vmalloc address space, page tables and
bookkeeping; the figures above compare workspace backing only.
Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
---
crypto/deflate.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/crypto/deflate.c b/crypto/deflate.c
index 710ebba7ce850..a8692532a65da 100644
--- a/crypto/deflate.c
+++ b/crypto/deflate.c
@@ -20,6 +20,7 @@
#include <linux/scatterlist.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
+#include <linux/vmalloc.h>
#include <linux/zlib.h>
#define DEFLATE_DEF_LEVEL Z_DEFAULT_COMPRESSION
@@ -40,7 +41,7 @@ static void *deflate_alloc_stream(void)
DEFLATE_DEF_MEMLEVEL));
struct deflate_stream *ctx;
- ctx = kvmalloc_flex(*ctx, workspace, size);
+ ctx = vmalloc(struct_size(ctx, workspace, size));
if (!ctx)
return ERR_PTR(-ENOMEM);
@@ -51,7 +52,7 @@ static void *deflate_alloc_stream(void)
static void deflate_free_stream(void *ctx)
{
- kvfree(ctx);
+ vfree(ctx);
}
static struct crypto_acomp_streams deflate_streams = {
--
2.53.0-Meta