* [RFC PATCH] x86/boot: use zstd -19 if building for 32-bit
@ 2026-07-28 14:31 Mingcong Bai
2026-07-28 14:42 ` Xi Ruoyao
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Mingcong Bai @ 2026-07-28 14:31 UTC (permalink / raw)
To: linux-kernel
Cc: Kexy Biscuit, Xi Ruoyao, Mingcong Bai, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
Nathan Chancellor, Nicolas Schier, Nick Terrell, David Sterba,
Ard Biesheuvel, Jan Stancek, Josh Poimboeuf, Petr Mladek,
Peter Zijlstra (Intel),
Thomas Weißschuh, Simon Glass, Marco Elver, linux-kbuild
When using native build environments (that is, 32-bit x86 chroot/container
as build environment for 32-bit x86 binaries), `zstd -22' requests more
virtual memory than that could be allowed on 32-bit hosts.
Introduce `cmd_zstd_with_size' for CONFIG_X86_32 builds.
This is quite possibly just stupid... But there doesn't seem to be a way
to detect the host environment. So I'm sending this patch as a means to
ask for your opinions.
Any help would be greated appreciated.
Signed-off-by: Mingcong Bai <jeffbai@aosc.io>
---
arch/x86/boot/compressed/Makefile | 5 +++++
scripts/Makefile.lib | 3 +++
2 files changed, 8 insertions(+)
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 07e0e64b9a98..2261fb0d4d1d 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -143,8 +143,13 @@ $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
$(call if_changed,lzo_with_size)
$(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
$(call if_changed,lz4_with_size)
+ifdef CONFIG_X86_32
+$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
+ $(call if_changed,zstd_with_size)
+else
$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
$(call if_changed,zstd22_with_size)
+endif
suffix-$(CONFIG_KERNEL_GZIP) := gz
suffix-$(CONFIG_KERNEL_BZIP2) := bz2
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 0718e39cedda..09910dc57af3 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -464,6 +464,9 @@ quiet_cmd_xzmisc = XZMISC $@
quiet_cmd_zstd = ZSTD $@
cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@
+quiet_cmd_zstd = ZSTD $@
+ cmd_zstd_with_size = { cat $(real-prereqs) | $(ZSTD) -19; $(size_append); } > $@
+
quiet_cmd_zstd22 = ZSTD22 $@
cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] x86/boot: use zstd -19 if building for 32-bit
2026-07-28 14:31 [RFC PATCH] x86/boot: use zstd -19 if building for 32-bit Mingcong Bai
@ 2026-07-28 14:42 ` Xi Ruoyao
2026-07-28 15:58 ` Ard Biesheuvel
2026-07-28 16:05 ` H. Peter Anvin
2 siblings, 0 replies; 5+ messages in thread
From: Xi Ruoyao @ 2026-07-28 14:42 UTC (permalink / raw)
To: Mingcong Bai, linux-kernel
Cc: Kexy Biscuit, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, Nathan Chancellor,
Nicolas Schier, Nick Terrell, David Sterba, Ard Biesheuvel,
Jan Stancek, Josh Poimboeuf, Petr Mladek, Peter Zijlstra (Intel),
Thomas Weißschuh, Simon Glass, Marco Elver, linux-kbuild
On Tue, 2026-07-28 at 22:31 +0800, Mingcong Bai wrote:
> When using native build environments (that is, 32-bit x86 chroot/container
> as build environment for 32-bit x86 binaries), `zstd -22' requests more
> virtual memory than that could be allowed on 32-bit hosts.
>
> Introduce `cmd_zstd_with_size' for CONFIG_X86_32 builds.
>
> This is quite possibly just stupid... But there doesn't seem to be a way
> to detect the host environment. So I'm sending this patch as a means to
> ask for your opinions.
"readelf -d $(which zstd) -h | grep ELF64" ?
But it's also stupid, if someone is using a script wrapping the actual
zstd executable or cross-compiling from a non-ELF platform things will
still blow up.
--
Xi Ruoyao <xry111@xry111.site>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] x86/boot: use zstd -19 if building for 32-bit
2026-07-28 14:31 [RFC PATCH] x86/boot: use zstd -19 if building for 32-bit Mingcong Bai
2026-07-28 14:42 ` Xi Ruoyao
@ 2026-07-28 15:58 ` Ard Biesheuvel
2026-07-29 1:44 ` Mingcong Bai
2026-07-28 16:05 ` H. Peter Anvin
2 siblings, 1 reply; 5+ messages in thread
From: Ard Biesheuvel @ 2026-07-28 15:58 UTC (permalink / raw)
To: Mingcong Bai, linux-kernel
Cc: Kexy Biscuit, Xi Ruoyao, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H . Peter Anvin,
Nathan Chancellor, Nicolas Schier, Nick Terrell, David Sterba,
Jan Stancek, Josh Poimboeuf, Petr Mladek, Peter Zijlstra,
Thomas Weißschuh, Simon Glass, Marco Elver, linux-kbuild
On Tue, 28 Jul 2026, at 17:31, Mingcong Bai wrote:
> When using native build environments (that is, 32-bit x86 chroot/container
> as build environment for 32-bit x86 binaries), `zstd -22' requests more
> virtual memory than that could be allowed on 32-bit hosts.
>
> Introduce `cmd_zstd_with_size' for CONFIG_X86_32 builds.
>
> This is quite possibly just stupid... But there doesn't seem to be a way
> to detect the host environment. So I'm sending this patch as a means to
> ask for your opinions.
>
> Any help would be greated appreciated.
>
> Signed-off-by: Mingcong Bai <jeffbai@aosc.io>
> ---
> arch/x86/boot/compressed/Makefile | 5 +++++
> scripts/Makefile.lib | 3 +++
> 2 files changed, 8 insertions(+)
>
Doesn't this mean ZSTD -22 is generally broken on 32-bit? How is this
specific to the kernel?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] x86/boot: use zstd -19 if building for 32-bit
2026-07-28 14:31 [RFC PATCH] x86/boot: use zstd -19 if building for 32-bit Mingcong Bai
2026-07-28 14:42 ` Xi Ruoyao
2026-07-28 15:58 ` Ard Biesheuvel
@ 2026-07-28 16:05 ` H. Peter Anvin
2 siblings, 0 replies; 5+ messages in thread
From: H. Peter Anvin @ 2026-07-28 16:05 UTC (permalink / raw)
To: Mingcong Bai, linux-kernel
Cc: Kexy Biscuit, Xi Ruoyao, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, Nathan Chancellor,
Nicolas Schier, Nick Terrell, David Sterba, Ard Biesheuvel,
Jan Stancek, Josh Poimboeuf, Petr Mladek, Peter Zijlstra (Intel),
Thomas Weißschuh, Simon Glass, Marco Elver, linux-kbuild
On July 28, 2026 7:31:35 AM PDT, Mingcong Bai <jeffbai@aosc.io> wrote:
>When using native build environments (that is, 32-bit x86 chroot/container
>as build environment for 32-bit x86 binaries), `zstd -22' requests more
>virtual memory than that could be allowed on 32-bit hosts.
>
>Introduce `cmd_zstd_with_size' for CONFIG_X86_32 builds.
>
>This is quite possibly just stupid... But there doesn't seem to be a way
>to detect the host environment. So I'm sending this patch as a means to
>ask for your opinions.
>
>Any help would be greated appreciated.
>
>Signed-off-by: Mingcong Bai <jeffbai@aosc.io>
>---
> arch/x86/boot/compressed/Makefile | 5 +++++
> scripts/Makefile.lib | 3 +++
> 2 files changed, 8 insertions(+)
>
>diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
>index 07e0e64b9a98..2261fb0d4d1d 100644
>--- a/arch/x86/boot/compressed/Makefile
>+++ b/arch/x86/boot/compressed/Makefile
>@@ -143,8 +143,13 @@ $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y) FORCE
> $(call if_changed,lzo_with_size)
> $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y) FORCE
> $(call if_changed,lz4_with_size)
>+ifdef CONFIG_X86_32
>+$(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
>+ $(call if_changed,zstd_with_size)
>+else
> $(obj)/vmlinux.bin.zst: $(vmlinux.bin.all-y) FORCE
> $(call if_changed,zstd22_with_size)
>+endif
>
> suffix-$(CONFIG_KERNEL_GZIP) := gz
> suffix-$(CONFIG_KERNEL_BZIP2) := bz2
>diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
>index 0718e39cedda..09910dc57af3 100644
>--- a/scripts/Makefile.lib
>+++ b/scripts/Makefile.lib
>@@ -464,6 +464,9 @@ quiet_cmd_xzmisc = XZMISC $@
> quiet_cmd_zstd = ZSTD $@
> cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@
>
>+quiet_cmd_zstd = ZSTD $@
>+ cmd_zstd_with_size = { cat $(real-prereqs) | $(ZSTD) -19; $(size_append); } > $@
>+
> quiet_cmd_zstd22 = ZSTD22 $@
> cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@
>
This is really just stupid. Basing it on the config setting is just plain wrong.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] x86/boot: use zstd -19 if building for 32-bit
2026-07-28 15:58 ` Ard Biesheuvel
@ 2026-07-29 1:44 ` Mingcong Bai
0 siblings, 0 replies; 5+ messages in thread
From: Mingcong Bai @ 2026-07-29 1:44 UTC (permalink / raw)
To: Ard Biesheuvel, linux-kernel
Cc: Kexy Biscuit, Xi Ruoyao, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H . Peter Anvin,
Nathan Chancellor, Nicolas Schier, Nick Terrell, David Sterba,
Jan Stancek, Josh Poimboeuf, Petr Mladek, Peter Zijlstra,
Thomas Weißschuh, Simon Glass, Marco Elver, linux-kbuild
Hi Ard,
在 2026/7/28 23:58, Ard Biesheuvel 写道:
>
>
> On Tue, 28 Jul 2026, at 17:31, Mingcong Bai wrote:
>> When using native build environments (that is, 32-bit x86 chroot/container
>> as build environment for 32-bit x86 binaries), `zstd -22' requests more
>> virtual memory than that could be allowed on 32-bit hosts.
>>
>> Introduce `cmd_zstd_with_size' for CONFIG_X86_32 builds.
>>
>> This is quite possibly just stupid... But there doesn't seem to be a way
>> to detect the host environment. So I'm sending this patch as a means to
>> ask for your opinions.
>>
>> Any help would be greated appreciated.
>>
>> Signed-off-by: Mingcong Bai <jeffbai@aosc.io>
>> ---
>> arch/x86/boot/compressed/Makefile | 5 +++++
>> scripts/Makefile.lib | 3 +++
>> 2 files changed, 8 insertions(+)
>>
>
> Doesn't this mean ZSTD -22 is generally broken on 32-bit? How is this
> specific to the kernel?
It's not (and remains unresolved)[1] - as I mentioned in the email, I
sent this patch out as a means to spark some discussion on how to
approach this problem.
Nick Terrel mentioned in commit 48f7ddf785af ("init: Add support for
zstd compressed kernel") that "zstd22 is used for kernel compression
because it is decompressed in a single pass, so zstd doesn't need to
allocate a window buffer." But I wonder if it resulted in tangible
change in compression ratio - but I can do more testing.
[1]: https://github.com/facebook/zstd/issues/1964
Best Regards,
Mingcong Bai
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-29 1:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-28 14:31 [RFC PATCH] x86/boot: use zstd -19 if building for 32-bit Mingcong Bai
2026-07-28 14:42 ` Xi Ruoyao
2026-07-28 15:58 ` Ard Biesheuvel
2026-07-29 1:44 ` Mingcong Bai
2026-07-28 16:05 ` H. Peter Anvin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®