RE:(2) [PATCH 1/4] zstd: pass pointer rathen than structure to functions

From: Vaneet Narang
Date: Thu Jun 06 2019 - 10:26:49 EST


Hi Andrew / David,

Â
>>Â>Â>Â-ÂÂÂÂÂÂÂÂZSTD_parametersÂparamsÂ=ÂZSTD_getParams(level,Âsrc_len,Â0);
>>Â>Â>Â+ÂÂÂÂÂÂÂÂstaticÂZSTD_parametersÂparams;
>>Â>Â
>>Â>Â>Â+
>>Â>Â>Â+ÂÂÂÂÂÂÂÂparamsÂ=ÂZSTD_getParams(level,Âsrc_len,Â0);
>>Â>Â
>>Â>ÂNoÂthats'Âbroken,ÂtheÂparamsÂcan'tÂbeÂstaticÂasÂitÂdependsÂonÂlevelÂand
>>Â>Âsrc_len.ÂWhatÂhappensÂifÂthereÂareÂseveralÂrequestsÂinÂparallelÂwith
>>Â>Âeg.ÂdifferentÂlevels?

There is no need to make static for btrfs. We can keep it as a stack variable.
This patch set focussed on reducing stack usage of zstd compression when triggered
through zram. ZRAM internally uses crypto and currently crpto uses fixed level and also
not dependent upon source length.

crypto/zstd.c:
static ZSTD_parameters zstd_params(void)
{
return ZSTD_getParams(ZSTD_DEF_LEVEL, 0, 0);
}


Actually high stack usage problem with zstd compression patch gets exploited more incase of
shrink path which gets triggered randomly from any call flow in case of low memory and adds overhead
of more than 2000 byte of stack and results in stack overflow.

Stack usage of alloc_page in case of low memory

72 HUF_compressWeights_wksp+0x140/0x200
64 HUF_writeCTable_wksp+0xdc/0x1c8
88 HUF_compress4X_repeat+0x214/0x450
208 ZSTD_compressBlock_internal+0x224/0x137c
136 ZSTD_compressContinue_internal+0x210/0x3b0
192 ZSTD_compressCCtx+0x6c/0x144
144 zstd_compress+0x40/0x58
32 crypto_compress+0x2c/0x34
32 zcomp_compress+0x3c/0x44
80 zram_bvec_rw+0x2f8/0xa7c
64 zram_rw_page+0x104/0x170
48 bdev_write_page+0x80/0xb4
112 __swap_writepage+0x160/0x29c
24 swap_writepage+0x3c/0x58
160 shrink_page_list+0x788/0xae0
128 shrink_inactive_list+0x210/0x4a8
184 shrink_zone+0x53c/0x7c0
160 try_to_free_pages+0x2fc/0x7cc
80 __alloc_pages_nodemask+0x534/0x91c

Thanks & Regards,
Vaneet NarangÂ
Â