Re: [PATCH 1/4] zstd: pass pointer rathen than structure to functions
From: Andrew Morton
Date: Mon Jun 03 2019 - 17:51:18 EST
On Mon, 3 Jun 2019 14:32:03 +0530 Maninder Singh <maninder1.s@xxxxxxxxxxx> wrote:
> currently params structure is passed in all functions, which increases
> stack usage in all the function and lead to stack overflow on target like
> ARM with kernel stack size of 8 KB so better to pass pointer.
>
> Checked for ARM:
>
> Original Patched
> Call FLow Size: 1264 1040
> ....
> (HUF_sort) -> 296
> (HUF_buildCTable_wksp) -> 144
> (HUF_compress4X_repeat) -> 88
> (ZSTD_compressBlock_internal) -> 200
> (ZSTD_compressContinue_internal)-> 136 -> 88
> (ZSTD_compressCCtx) -> 192 -> 64
> (zstd_compress) -> 144 -> 96
> (crypto_compress) -> 32
> (zcomp_compress) -> 32
> ....
>
> ...
>
> --- a/crypto/zstd.c
> +++ b/crypto/zstd.c
> @@ -162,7 +162,7 @@ static int __zstd_compress(const u8 *src, unsigned int slen,
> struct zstd_ctx *zctx = ctx;
> const ZSTD_parameters params = zstd_params();
>
> - out_len = ZSTD_compressCCtx(zctx->cctx, dst, *dlen, src, slen, params);
> + out_len = ZSTD_compressCCtx(zctx->cctx, dst, *dlen, src, slen, ¶ms);
> if (ZSTD_isError(out_len))
> return -EINVAL;
> *dlen = out_len;
> diff --git a/include/linux/zstd.h b/include/linux/zstd.h
> index 249575e..5103efa 100644
> --- a/include/linux/zstd.h
> +++ b/include/linux/zstd.h
> @@ -254,7 +254,7 @@ ZSTD_CCtx *ZSTD_initCCtx(void *workspace, size_t workspaceSize);
> * ZSTD_isError().
> */
> size_t ZSTD_compressCCtx(ZSTD_CCtx *ctx, void *dst, size_t dstCapacity,
> - const void *src, size_t srcSize, ZSTD_parameters params);
> + const void *src, size_t srcSize, const ZSTD_parameters *params);
Making the params poniter const made review a lot easier ;)
But struct ZSTD_CCtx_s.params is still a copied structure. Could we
make it `const ZSTD_parameters *params'? Probably not, due to lifetime
issues?