Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FE8AC433F5 for ; Wed, 24 Nov 2021 15:30:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240458AbhKXPeC (ORCPT ); Wed, 24 Nov 2021 10:34:02 -0500 Received: from sonic310-21.consmr.mail.gq1.yahoo.com ([98.137.69.147]:46346 "EHLO sonic310-21.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236235AbhKXPd7 (ORCPT ); Wed, 24 Nov 2021 10:33:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.ca; s=s2048; t=1637767849; bh=sZfrWG5Xvk1chzVi4S16DUIyfYrQAOBdWOyCjDnxAs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=I5Z7WOXDusts6iVDUN8wxnh2N0zM4DHk0f5EcG6aNH957XxwtolvQ8KkMC7z7szTzV0j49+6SLRgFLRMCNV9Yor+StDnZg4HGlbiJuBwOnAc+ameVxAiqvKSNqdeoJ3KLFmOOQp4iT3s7wyxjQzCykLrV7FcbICkrUzYgaCp9pxb/eN6ddcNvRCQynIabIks0judljqNLDoNKtZ6wAXHB4KXH2+FCRGG+C7wb962T/u0EZtWUah2wP+IBtYUD2OLmcdQKe9+nNBNsuhoXzhutgfpsr0JFCqd09CZ91bdlvjGq2KrwXk2YZWTr+VNeTXDIzIN3w6BejAi4mW6nCZAbA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1637767849; bh=2MLcPnpndP6JxWngdhJ2fz3QQCi0VBWOA3SQ1tdekOY=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=BUS+imbxef+7ojjge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Xaf_Y4ihvhIeoAS_EE7MewUZpCNlJYq6SKVQZxyldjcowAwWmFsQFPYLSFEEGUWehTPo7 JrC.KmmIx.ITwxpfA5JGX7dvG2g_uokMmfffToGx8gZjYH6prZa1V6PrYvizQCV.jL2Xv1LGWheR qYKJ3FPKBddc1g.WThejQNoMV9I3.olpOGoVQAdTlHxPsIJcqhKJVwfaYCkClXAjZrG0dfDDbaXC 8Rf052pMC8xuI94vU6DbqUx.5VODycTB922x0kil8Hv6KCYd7vPWROepYbUH.0SQwkUgST0kE2Uc rW9IDkTYr3Q2PCrSdFeyIReNtWmyajwMVe056iBCXe9q.wQTtUYhqQ6qpCsybghhepXbNpRovDCG C9JVy0sh_2wQXiqul2ji.yxTgJgUqEY0gITSgOlyoJKNnGb4PTBAqeXdF0Z9qSJznbUn6CfGwE58 8w1AXIDxc1.G5j.1irPRplK0wG51DpaZN3bHoBE9YmfciUmgbITti6BnxvRwU9hZOiatAXxpkLHg fXYlB4qY- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.gq1.yahoo.com with HTTP; Wed, 24 Nov 2021 15:30:49 +0000 Received: by kubenode520.mail-prod1.omega.bf1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID a9ce41034f328ae2261d33f37437d315; Wed, 24 Nov 2021 15:30:46 +0000 (UTC) From: "Alex Xu (Hello71)" To: Michael Forney , Masahiro Yamada , Michal Marek , Nick Desaulniers , Nick Terrell , Ingo Molnar , Sedat Dilek , Kees Cook , linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Cc: "Alex Xu (Hello71)" Subject: [PATCH v2 2/2] kbuild: pass --stream-size --no-content-size to zstd Date: Wed, 24 Nov 2021 10:31:05 -0500 Message-Id: <20211124153105.155739-2-alex_y_xu@yahoo.ca> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124153105.155739-1-alex_y_xu@yahoo.ca> References: <20211124153105.155739-1-alex_y_xu@yahoo.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Otherwise, it allocates 2 GB of memory at once. Even though the majority of this memory is never touched, the default heuristic overcommit refuses this request if less than 2 GB of RAM+swap is currently available. This results in "zstd: error 11 : Allocation error : not enough memory" and the kernel failing to build. When the size is specified, zstd will reduce the memory request appropriately. For typical kernel sizes of ~32 MB, the largest mmap request will be reduced to 512 MB, which will succeed on all but the smallest devices. For inputs around this size, --stream-size --no-content-size may slightly decrease the compressed size, or slightly increase it: https://github.com/facebook/zstd/issues/2848. Signed-off-by: Alex Xu (Hello71) --- scripts/Makefile.lib | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index ca901814986a..c98a82ca38e6 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -466,12 +466,20 @@ quiet_cmd_xzmisc = XZMISC $@ # single pass, so zstd doesn't need to allocate a window buffer. When streaming # decompression is used, like initramfs decompression, zstd22 should likely not # be used because it would require zstd to allocate a 128 MB buffer. +# +# --stream-size to reduce zstd memory usage (otherwise zstd -22 --ultra +# allocates, but does not use, 2 GB) and potentially improve compression. +# +# --no-content-size to save three bytes which we do not use (we use size_append). + +# zstd --stream-size is only supported since 1.4.4 +zstd_stream_size = $(shell $(ZSTD) -1c --stream-size=0 --no-content-size /dev/null 2>&1 && printf '%s' '--stream-size=$(total_size) --no-content-size') quiet_cmd_zstd = ZSTD $@ - cmd_zstd = { cat $(real-prereqs) | $(ZSTD) -19; $(size_append); } > $@ + cmd_zstd = { cat $(real-prereqs) | $(ZSTD) $(zstd_stream_size) -19; $(size_append); } > $@ quiet_cmd_zstd22 = ZSTD22 $@ - cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@ + cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) $(zstd_stream_size) -22 --ultra; $(size_append); } > $@ # ASM offsets # --------------------------------------------------------------------------- -- 2.34.0