Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5961531ybi; Tue, 4 Jun 2019 15:43:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyEY3WaDe1L+DjYerrZ8pZWdsajpbJj5KwVnnOy+AICF26WRzn4Rx90THm4DYERdsoNfxHh X-Received: by 2002:a63:5211:: with SMTP id g17mr188695pgb.405.1559688235315; Tue, 04 Jun 2019 15:43:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559688235; cv=none; d=google.com; s=arc-20160816; b=bHSXIjn8ZviZjY7L48L7o7jNUgHyBTfjIneOW97y6R2QVJjAIziv0VxfCRIzR0FNd6 vRcS5Ilgt7f42a3Z+VMMlxj/ca/GLIAWmVfOWtoZKaNmWfpXsM5a42Sj5AznrwJyUUAg DJPqEEw9YyLxdHwOvMdr+t23TVDIAHM+Fmw5lYvvXaauE5j71Svs3+VPuFmaQvfJ7qds mDPOVfnnXY+yx1JaY2VVTgsiF9NunVMP3FSAjnZ+HahZGQe0lg0aps7pMpLuhXibidky Vvrx/cSPOv+A1C+OsWFdbmIQzqGgo94VUsyJhHwY02Qc+kNXp/2z2Ag7NWTQYLaTyJY4 ySTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=QUEHZyFvG5iuF+EVhEeyZ851KxEqIiUTh7g5c/1yeII=; b=ERu0XhhzZPBOv8aJh8s+nSbpnbBmXSbPgYyWB+aY8bYQ8HjT13L8IjY0Vurw475EIS +Iqlui+f2ozCmD1dSjiVhNjVhF8lnpksAf3LWG793NkacYUG6KblsqkvNe58ac8Ae5gl QV3g4R6B63mIvZdwUkiHX3czrLS4JnirK1GopYg2YZsetO3WzWLmOZLf8fDTEAjJu2t/ lRako3T2pm46GRJ7wYpVArsldF11D+fBChEpGlxtWgt6hi4gvShigSXvJP8t71geRBpo a9+GZomSGXl4f6rJ/vKD5LZVzKyXCQhzQWSpBa/JjFGmtsQfXptrQegUwx6Txndhu4p8 vycw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iMpvIC1K; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s68si26465249pfb.39.2019.06.04.15.43.31; Tue, 04 Jun 2019 15:43:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iMpvIC1K; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726293AbfFDWn2 (ORCPT + 99 others); Tue, 4 Jun 2019 18:43:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:44768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726179AbfFDWn2 (ORCPT ); Tue, 4 Jun 2019 18:43:28 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 92F10206B8; Tue, 4 Jun 2019 22:43:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559688207; bh=McnH01l012LgpITPnazCqRJYDfp8SFNlTpLeOyd0rDk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=iMpvIC1KpLUBc26GINzifM0DVnm8whlDtaLjgjFzkGsUuxLi4URKQ7Kz86LO1axJb ROYDLOE5iJKCfO3e/mDuVFq36lJWgmDFCC1r7h0nwP2pLpHpITo/a8kmnu+8Xlf8E5 EsXgRa+o7Hse3+A4mDjXy7HiDjwS37jUW3oVHF+8= Date: Tue, 4 Jun 2019 15:43:26 -0700 From: Andrew Morton To: Maninder Singh Cc: herbert@gondor.apana.org.au, davem@davemloft.net, keescook@chromium.org, gustavo@embeddedor.com, joe@perches.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, a.sahrawat@samsung.com, pankaj.m@samsung.com, v.narang@samsung.com, Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Subject: Re: [PATCH 1/4] zstd: pass pointer rathen than structure to functions Message-Id: <20190604154326.8868a10f896c148a0ce804d1@linux-foundation.org> In-Reply-To: <1559552526-4317-2-git-send-email-maninder1.s@samsung.com> References: <1559552526-4317-1-git-send-email-maninder1.s@samsung.com> <1559552526-4317-2-git-send-email-maninder1.s@samsung.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Mon, 3 Jun 2019 14:32:03 +0530 Maninder Singh 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 > .... > > Signed-off-by: Maninder Singh > Signed-off-by: Vaneet Narang > You missed btrfs. This needs review, please - particularly the kernel-wide static ZSTD_parameters in zstd_get_btrfs_parameters(). The base patch is here: http://lkml.kernel.org/r/1559552526-4317-2-git-send-email-maninder1.s@samsung.com --- a/fs/btrfs/zstd.c~zstd-pass-pointer-rathen-than-structure-to-functions-fix +++ a/fs/btrfs/zstd.c @@ -27,15 +27,17 @@ /* 307s to avoid pathologically clashing with transaction commit */ #define ZSTD_BTRFS_RECLAIM_JIFFIES (307 * HZ) -static ZSTD_parameters zstd_get_btrfs_parameters(unsigned int level, +static ZSTD_parameters *zstd_get_btrfs_parameters(unsigned int level, size_t src_len) { - ZSTD_parameters params = ZSTD_getParams(level, src_len, 0); + static ZSTD_parameters params; + + params = ZSTD_getParams(level, src_len, 0); if (params.cParams.windowLog > ZSTD_BTRFS_MAX_WINDOWLOG) params.cParams.windowLog = ZSTD_BTRFS_MAX_WINDOWLOG; WARN_ON(src_len > ZSTD_BTRFS_MAX_INPUT); - return params; + return ¶ms; } struct workspace { @@ -155,11 +157,12 @@ static void zstd_calc_ws_mem_sizes(void) unsigned int level; for (level = 1; level <= ZSTD_BTRFS_MAX_LEVEL; level++) { - ZSTD_parameters params = - zstd_get_btrfs_parameters(level, ZSTD_BTRFS_MAX_INPUT); - size_t level_size = - max_t(size_t, - ZSTD_CStreamWorkspaceBound(params.cParams), + ZSTD_parameters *params; + size_t level_size; + + params = zstd_get_btrfs_parameters(level, ZSTD_BTRFS_MAX_INPUT); + level_size = max_t(size_t, + ZSTD_CStreamWorkspaceBound(params->cParams), ZSTD_DStreamWorkspaceBound(ZSTD_BTRFS_MAX_INPUT)); max_size = max_t(size_t, max_size, level_size); @@ -385,8 +388,9 @@ static int zstd_compress_pages(struct li unsigned long len = *total_out; const unsigned long nr_dest_pages = *out_pages; unsigned long max_out = nr_dest_pages * PAGE_SIZE; - ZSTD_parameters params = zstd_get_btrfs_parameters(workspace->req_level, - len); + ZSTD_parameters *params; + + params = zstd_get_btrfs_parameters(workspace->req_level, len); *out_pages = 0; *total_out = 0; _