Re: [PATCH 1/2] crypto: zstd - use vmalloc() for stream workspaces
From: Johannes Weiner
Date: Thu Nov 12 2026 - 12:23:03 EST
On Wed, Nov 11, 2026 at 07:07:39AM -0800, Usama Arif wrote:
> 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@xxxxxxxxx>
Nice catch. Given the lifetime of these streams, there really isn't
enough turnover to justify the kmalloc optimization to begin with.
Reviewed-by: Johannes Weiner <hannes@xxxxxxxxxxx>