kbuild: Give jobserver-exec recipes the jobserver
Subsystems (19)
v2 cover kbuild: Give jobserver-exec recipes the jobserver
Hi!
Paul reported a build failure on CentOS Stream 9 with linux-next[1]: the kernel builds, but scripts/jobserver-exec prints
WARNING: Unable to reopen jobserver read-side pipe: FileNotFoundError(2, 'No such file or directory')
and rcutorture's build check counts the "Error" in that line. CentOS's make 4.3 carries a backport of the fix for GNU Make bug 58232, so sub-makes, like the top-level make, give the jobserver pipe only to recipes marked recursive, while MAKEFLAGS still names it. The new pigz steps (1/2), for the kernel image, the built-in initramfs, and the other gzip rules, and the older Clang LTO initcall ordering step (2/2) run jobserver-exec from recipes without "+", so pigz gets one thread and the initcall script caps its children at the CPU count instead of the free job slots. Mark these recipes recursive, as was done for rustc.
Thanks!
-Kees
v2:
- 1/2: also mark the gzip rules that choose gzip through a variable,
including the built-in initramfs in usr/Makefile, which rcutorture's
kvm.sh builds and v1 missed (Paul)
- 1/2: update the gzip entry in Documentation/kbuild/makefiles.rst
(Nicolas)
- 2/2: cite Masahiro's earlier version of this change and say when the
script gets more than one archive (Nicolas)
- v1..v2 diff: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/diff/?id=dev/next-20261001/pigz-recursive/v2&id2=dev/next-20261001/pigz-recursive/v1
v1: https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/0ddb5e5e-f801-444c-aa98-0cfe814a3026@paulmck-laptop/
Kees Cook (2):
kbuild: Mark the gzip recipes as recursive
kbuild: Mark the initcall ordering recipe as recursive
arch/alpha/boot/Makefile | 4 ++-- arch/arc/boot/Makefile | 2 +- arch/arm/boot/compressed/Makefile | 2 +- arch/arm64/boot/Makefile | 2 +- arch/csky/boot/Makefile | 2 +- arch/microblaze/boot/Makefile | 2 +- arch/mips/boot/Makefile | 2 +- arch/mips/boot/compressed/Makefile | 2 +- arch/nios2/boot/Makefile | 2 +- arch/parisc/boot/compressed/Makefile | 2 +- arch/riscv/boot/Makefile | 2 +- arch/s390/boot/Makefile | 2 +- arch/sh/boot/Makefile | 2 +- arch/sh/boot/compressed/Makefile | 2 +- arch/sparc/boot/Makefile | 4 ++-- arch/x86/boot/compressed/Makefile | 2 +- arch/xtensa/boot/Makefile | 2 +- usr/Makefile | 2 +- drivers/firmware/efi/libstub/Makefile.zboot | 2 +- scripts/Makefile.vmlinux_o | 2 +- Documentation/kbuild/makefiles.rst | 7 +++++-- 21 files changed, 27 insertions(+), 24 deletions(-)
Signature · 1 line
2.55.0
PATCH v2 1/2 kbuild: Mark the gzip recipes as recursive
Since commit 48ebe1cbbeb51 ("kbuild: compress the kernel with pigz if available"), cmd_gzip runs pigz through scripts/jobserver-exec, which takes the job slots make has free. GNU Make passes the jobserver pipe only to recipes it treats as recursive, but leaves --jobserver-auth in MAKEFLAGS for all of them. The make 4.3 in CentOS Stream 9 also hides the pipe in sub-makes (a backport of the fix for GNU Make bug 58232), so jobserver-exec cannot open it, runs pigz on one thread, and prints:
WARNING: Unable to reopen jobserver read-side pipe: FileNotFoundError(2, 'No such file or directory')
Mark every recipe that can run cmd_gzip as recursive with "+", as commit ecab4115c44cc ("kbuild: mark rustc (and others) invocations as recursive") did for rustc. Besides the $(call if_changed,gzip) rules, this covers those that choose gzip through a variable: the built-in initramfs in usr/Makefile (which rcutorture's kvm.sh builds), the EFI zboot image, and the arm, csky, and mips compressed images. As with rustc, "make -n" now runs these recipes, including those that choose through a variable when they select another compressor. Also update the gzip entry in Documentation/kbuild/makefiles.rst, as suggested in review.
Tested with GNU Make 4.3 plus CentOS Stream 9's make-4.3-cloexec.patch, GCC 16.2.0, and -j64, on ARCH=x86_64, arm64, and arm defconfig, and ARCH=x86_64 defconfig with a built-in initramfs: none of them prints the warning, and pigz gets the free job slots (-p 54, 64, and 50 for the kernel image). Without this change, the x86_64 builds print it for the kernel image and for the initramfs.
--- arch/alpha/boot/Makefile | 4 ++-- arch/arc/boot/Makefile | 2 +- arch/arm/boot/compressed/Makefile | 2 +- arch/arm64/boot/Makefile | 2 +- arch/csky/boot/Makefile | 2 +- arch/microblaze/boot/Makefile | 2 +- arch/mips/boot/Makefile | 2 +- arch/mips/boot/compressed/Makefile | 2 +- arch/nios2/boot/Makefile | 2 +- arch/parisc/boot/compressed/Makefile | 2 +- arch/riscv/boot/Makefile | 2 +- arch/s390/boot/Makefile | 2 +- arch/sh/boot/Makefile | 2 +- arch/sh/boot/compressed/Makefile | 2 +- arch/sparc/boot/Makefile | 4 ++-- arch/x86/boot/compressed/Makefile | 2 +- arch/xtensa/boot/Makefile | 2 +- usr/Makefile | 2 +- drivers/firmware/efi/libstub/Makefile.zboot | 2 +- Documentation/kbuild/makefiles.rst | 7 +++++-- 20 files changed, 26 insertions(+), 23 deletions(-)
arch/alpha/boot/Makefile +2 -2
@@ -40,7 +40,7 @@ endif # Compressed kernel image $(obj)/vmlinux.gz: $(obj)/vmlinux FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) @echo ' Kernel $@ is ready' $(obj)/main.o: $(obj)/ksize.h
@@ -85,7 +85,7 @@ $(obj)/vmlinux.nh: vmlinux $(OBJSTRIP) FORCE $(call if_changed,objstrip) $(obj)/vmlinux.nh.gz: $(obj)/vmlinux.nh FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) $(obj)/tools/lxboot: $(obj)/bootloader $(OBJSTRIP) FORCE $(call if_changed,objstrip)
arch/arc/boot/Makefile +1 -1
@@ -23,7 +23,7 @@ $(obj)/vmlinux.bin: vmlinux FORCE $(call if_changed,objcopy) $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) $(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE $(call if_changed,lzma)
arch/arm/boot/compressed/Makefile +1 -1
@@ -153,7 +153,7 @@ $(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.o \ @$(check_for_bad_syms) $(obj)/piggy_data: $(obj)/../Image FORCE - $(call if_changed,$(compress-y)) + +$(call if_changed,$(compress-y)) $(obj)/piggy.o: $(obj)/piggy_data
arch/arm64/boot/Makefile +1 -1
@@ -26,7 +26,7 @@ $(obj)/Image.bz2: $(obj)/Image FORCE $(call if_changed,bzip2) $(obj)/Image.gz: $(obj)/Image FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) $(obj)/Image.lz4: $(obj)/Image FORCE $(call if_changed,lz4)
arch/csky/boot/Makefile +1 -1
@@ -12,7 +12,7 @@ compress-$(CONFIG_KERNEL_XZ) = xzkern compress-$(CONFIG_KERNEL_LZ4) = lz4 $(obj)/zImage: $(obj)/Image FORCE - $(call if_changed,$(compress-y)) + +$(call if_changed,$(compress-y)) @echo ' Kernel: $@ is ready' UIMAGE_ARCH = sandbox
arch/microblaze/boot/Makefile +1 -1
@@ -14,7 +14,7 @@ $(obj)/linux.bin.ub: $(obj)/linux.bin FORCE $(call if_changed,uimage) $(obj)/linux.bin.gz: $(obj)/linux.bin FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) quiet_cmd_strip = STRIP $< $@$2 cmd_strip = $(STRIP) -K microblaze_start -K _end -K __log_buf \
arch/mips/boot/Makefile +1 -1
@@ -63,7 +63,7 @@ $(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE $(call if_changed,bzip2) $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) $(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE $(call if_changed,lzma)
arch/mips/boot/compressed/Makefile +1 -1
@@ -69,7 +69,7 @@ tool_$(CONFIG_KERNEL_ZSTD) = zstd22_with_size targets += vmlinux.bin.z $(obj)/vmlinux.bin.z: $(obj)/vmlinux.bin FORCE - $(call if_changed,$(tool_y)) + +$(call if_changed,$(tool_y)) targets += piggy.o dummy.o
arch/nios2/boot/Makefile +1 -1
@@ -18,7 +18,7 @@ $(obj)/vmlinux.bin: vmlinux FORCE $(call if_changed,objcopy) $(obj)/vmlinux.gz: $(obj)/vmlinux.bin FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) $(obj)/vmImage: $(obj)/vmlinux.gz FORCE $(call if_changed,uimage)
arch/parisc/boot/compressed/Makefile +1 -1
@@ -55,7 +55,7 @@ suffix-$(CONFIG_KERNEL_LZO) := lzo suffix-$(CONFIG_KERNEL_XZ) := xz $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) $(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE $(call if_changed,bzip2_with_size) $(obj)/vmlinux.bin.lz4: $(obj)/vmlinux.bin FORCE
arch/riscv/boot/Makefile +1 -1
@@ -23,7 +23,7 @@ $(obj)/Image: vmlinux FORCE $(call if_changed,objcopy) $(obj)/Image.gz: $(obj)/Image FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) $(obj)/loader.o: $(src)/loader.S $(obj)/Image
arch/s390/boot/Makefile +1 -1
@@ -117,7 +117,7 @@ suffix-$(CONFIG_KERNEL_XZ) := .xz suffix-$(CONFIG_KERNEL_ZSTD) := .zst $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) $(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE $(call if_changed,bzip2_with_size) $(obj)/vmlinux.bin.lz4: $(obj)/vmlinux.bin FORCE
arch/sh/boot/Makefile +1 -1
@@ -66,7 +66,7 @@ $(obj)/vmlinux.bin: vmlinux FORCE $(call if_changed,objcopy) $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) $(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE $(call if_changed,bzip2)
arch/sh/boot/compressed/Makefile +1 -1
@@ -39,7 +39,7 @@ $(obj)/vmlinux.bin: vmlinux FORCE $(call if_changed,objcopy) $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) $(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE $(call if_changed,bzip2_with_size) $(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
arch/sparc/boot/Makefile +2 -2
@@ -23,7 +23,7 @@ ifeq ($(CONFIG_SPARC64),y) # Actual linking $(obj)/zImage: $(obj)/image FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) @$(kecho) 'Kernel: $@ is ready' '(#'$(or $(KBUILD_BUILD_VERSION),`cat .version`)')' $(obj)/vmlinux.aout: vmlinux FORCE
@@ -45,7 +45,7 @@ $(obj)/image.bin: $(obj)/image FORCE $(call if_changed,objcopy) $(obj)/image.gz: $(obj)/image.bin FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) UIMAGE_LOADADDR = $(CONFIG_UBOOT_LOAD_ADDR) UIMAGE_ENTRYADDR = $(CONFIG_UBOOT_ENTRY_ADDR)
arch/x86/boot/compressed/Makefile +1 -1
@@ -133,7 +133,7 @@ vmlinux.bin.all-y := $(obj)/vmlinux.bin vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) += $(obj)/vmlinux.relocs $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE $(call if_changed,bzip2_with_size) $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
arch/xtensa/boot/Makefile +1 -1
@@ -36,7 +36,7 @@ $(obj)/vmlinux.bin: vmlinux FORCE $(call if_changed,objcopy) $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) boot-elf: $(obj)/vmlinux.bin boot-redboot: $(obj)/vmlinux.bin.gz
usr/Makefile +1 -1
@@ -76,7 +76,7 @@ $(obj)/initramfs_data.cpio: $(srctree)/scripts/gen_initramfs.sh scripts/gen_init endif $(obj)/initramfs_inc_data: $(cpio-data) FORCE - $(call if_changed,$(compress-y)) + +$(call if_changed,$(compress-y)) targets += initramfs_data.cpio initramfs_inc_data
drivers/firmware/efi/libstub/Makefile.zboot +1 -1
@@ -24,7 +24,7 @@ zboot-method-$(CONFIG_KERNEL_ZSTD) := zstd22_with_size zboot-size-len-$(CONFIG_KERNEL_ZSTD) := 4 $(obj)/vmlinuz: $(obj)/vmlinux.bin FORCE - $(call if_changed,$(zboot-method-y)) + +$(call if_changed,$(zboot-method-y)) # avoid eager evaluation to prevent references to non-existent build artifacts OBJCOPYFLAGS_vmlinuz.o = -I binary -O $(EFI_ZBOOT_BFD_TARGET) $(EFI_ZBOOT_OBJCOPY_FLAGS) \
Documentation/kbuild/makefiles.rst +5 -2
@@ -1452,13 +1452,16 @@ objcopy OBJCOPYFLAGS_$@ may be used to set additional options. gzip - Compress target. Use maximum compression to compress target. + Compress target. Use maximum compression to compress target. Prefix the + recipe line with '+' so that GNU Make passes it the jobserver, which + scripts/jobserver-exec needs to run pigz (if available) on the free job + slots. Example:: #arch/x86/boot/compressed/Makefile $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE - $(call if_changed,gzip) + +$(call if_changed,gzip) dtc Create flattened device tree blob object suitable for linking
Signature · 1 line
2.55.0
PATCH v2 2/2 kbuild: Mark the initcall ordering recipe as recursive
In reply to Kees Cookgenerate_initcall_order.pl, which orders initcalls for Clang LTO, forks a child per input file, up to the job count scripts/jobserver-exec passes it in PARALLELISM. It used to run from link-vmlinux.sh, which the top-level Makefile invokes as a recursive recipe, but commit 5d45950dfbb15 ("kbuild: move vmlinux.o link to scripts/Makefile.vmlinux_o") moved it into a recipe without "+".
GNU Make passes the jobserver pipe only to recipes it treats as recursive, and the make 4.3 in CentOS Stream 9 also hides it in sub-makes (a backport of the fix for GNU Make bug 58232), so jobserver-exec cannot open it and prints:
WARNING: Unable to reopen jobserver read-side pipe: FileNotFoundError(2, 'No such file or directory')
PARALLELISM is then left unset, and the script caps its children at the number of online CPUs instead of the free job slots.
Mark the recipe as recursive again (this makes "make -n" runs the script again too, as it did from link-vmlinux.sh). Masahiro posted the same change and withdrew it because the script was given only vmlinux.a, and so never ran more than one child [1]. But on arm64, LoongArch, and RISC-V with CONFIG_EFI_STUB, KBUILD_VMLINUX_LIBS also gives it the EFI stub's lib.a. Either way, the warning is silenced.
Tested ARCH=x86_64 defconfig with CONFIG_LTO_CLANG_THIN=y, LLVM=1 (Clang 24.0.0git), and GNU Make 4.3 plus CentOS Stream 9's make-4.3-cloexec.patch.
--- scripts/Makefile.vmlinux_o | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Makefile.vmlinux_o +1 -1
@@ -19,7 +19,7 @@ quiet_cmd_gen_initcalls_lds = GEN $@ .tmp_initcalls.lds: $(srctree)/scripts/generate_initcall_order.pl \ vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE - $(call if_changed,gen_initcalls_lds) + +$(call if_changed,gen_initcalls_lds) targets := .tmp_initcalls.lds
Signature · 1 line
2.55.0
Nathan Chancellor
maintainerQuoted 32 lines · Kees Cook
Hi!
Paul reported a build failure on CentOS Stream 9 with linux-next[1]: the kernel builds, but
scripts/jobserver-execprintsWARNING: Unable to reopen jobserver read-side pipe:
FileNotFoundError(2, 'No such file or directory')and rcutorture's build check counts the "Error" in that line. CentOS's make 4.3 carries a backport of the fix for GNU Make bug 58232, so sub-makes, like the top-level make, give the jobserver pipe only to recipes marked recursive, while MAKEFLAGS still names it. The new pigz steps (1/2), for the kernel image, the built-in initramfs, and the other gzip rules, and the older Clang LTO initcall ordering step (2/2) run jobserver-exec from recipes without "+", so pigz gets one thread and the initcall script caps its children at the CPU count instead of the free job slots. Mark these recipes recursive, as was done for rustc.
Thanks!
-Kees
v2:
- 1/2: also mark the gzip rules that choose gzip through a variable,
including the built-in initramfs in usr/Makefile, which rcutorture's
kvm.shbuilds and v1 missed (Paul)
- 1/2: update the gzip entry inDocumentation/kbuild/makefiles.rst
(Nicolas)
- 2/2: cite Masahiro's earlier version of this change and say when the
script gets more than one archive (Nicolas)
- v1..v2 diff: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/diff/?id=dev/next-20261001/pigz-recursive/v2&id2=dev/next-20261001/pigz-recursive/v1
v1: https://lore.kernel.org/all/[email protected]/
Quoted 5 lines
[1] https://lore.kernel.org/all/0ddb5e5e-f801-444c-aa98-0cfe814a3026@paulmck-laptop/
Kees Cook (2):
kbuild: Mark the gzip recipes as recursive
kbuild: Mark the initcall ordering recipe as recursive
I've kicked these into -next, I will formally apply them to kbuild-next-speedups once Paul can confirm that it resolves his regression. Thanks a lot for the assist here!
Signature · 2 lines
Cheers, Nathan
Paul E. McKenney
Tested-byQuoted 35 lines · Nathan Chancellor
Quoted 34 lines · Kees Cook
Hi!
Paul reported a build failure on CentOS Stream 9 with linux-next[1]: the kernel builds, but
scripts/jobserver-execprintsWARNING: Unable to reopen jobserver read-side pipe:
FileNotFoundError(2, 'No such file or directory')and rcutorture's build check counts the "Error" in that line. CentOS's make 4.3 carries a backport of the fix for GNU Make bug 58232, so sub-makes, like the top-level make, give the jobserver pipe only to recipes marked recursive, while MAKEFLAGS still names it. The new pigz steps (1/2), for the kernel image, the built-in initramfs, and the other gzip rules, and the older Clang LTO initcall ordering step (2/2) run jobserver-exec from recipes without "+", so pigz gets one thread and the initcall script caps its children at the CPU count instead of the free job slots. Mark these recipes recursive, as was done for rustc.
Thanks!
-Kees
v2:
- 1/2: also mark the gzip rules that choose gzip through a variable,
including the built-in initramfs in usr/Makefile, which rcutorture's
kvm.shbuilds and v1 missed (Paul)
- 1/2: update the gzip entry inDocumentation/kbuild/makefiles.rst
(Nicolas)
- 2/2: cite Masahiro's earlier version of this change and say when the
script gets more than one archive (Nicolas)
- v1..v2 diff: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/diff/?id=dev/next-20261001/pigz-recursive/v2&id2=dev/next-20261001/pigz-recursive/v1
v1: https://lore.kernel.org/all/[email protected]/[1] https://lore.kernel.org/all/0ddb5e5e-f801-444c-aa98-0cfe814a3026@paulmck-laptop/
Quoted 7 lines
Quoted 3 lines
Kees Cook (2):
kbuild: Mark the gzip recipes as recursive
kbuild: Mark the initcall ordering recipe as recursiveI've kicked these into -next, I will formally apply them to kbuild-next-speedups once Paul can confirm that it resolves his regression. Thanks a lot for the assist here!
And it works!!! ;-)
Nathan Chancellor
maintainerQuoted 8 lines · Kees Cook
kbuild: Give jobserver-exec recipes the jobserver
Hi!
Paul reported a build failure on CentOS Stream 9 with linux-next[1]: the kernel builds, but
scripts/jobserver-execprints[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux.git kbuild-next-speedups
Thanks!
[1/2] kbuild: Mark the gzip recipes as recursive
https://git.kernel.org/kbuild/c/0d4d70da348b0 [2/2] kbuild: Mark the initcall ordering recipe as recursive https://git.kernel.org/kbuild/c/ae5f6044c4cdf
Please look out for regression or issue reports or other follow up comments, as they may result in the patch/series getting dropped or reverted. Patches applied to an "unstable" branch are accepted pending wider testing in -next and any post-commit review; they will generally be moved to the main branch in a week if no issues are found.
Best regards,
Signature · 2 lines
Cheers, Nathan
Sorry I meant to review this but my inbox is as usual a disasterzone.
So instead I'll just say thank you for it :)
--
Cheers, Lorenzo