From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 53C0DC98302 for ; Wed, 23 Sep 2026 17:20:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nN+B8a/AxCz9OoG3KR48abjGvqGGQmSYiVMln1NiHn8=; b=VQyzcjKSG+Deu7 Vgr7rh7WAapXE0+Ez2kP74FGQUVsxbWsHLCCGKcv8yj4NxKrQMh4R/ptPfKAmkU/+Yvg0mFViwWWd 0INCETA3L6GCQh61Ixo5u8y45OS1ixLRIQNIVMhnJMHrReDMZIqk3pJx+7N3av5zriITkfy5j0KuZ ipINAfRTs7VQUAyhgOUFOtcYlXFUzXMgkVEVMyQKu/KYq8miu8fRfoQjQxthwMUtunUzbD6gGp7Uh yur/iTM4F+U4gRRmpJaYPcp0Nw+6i/jC63i3sg5lyGwRuG/crLuh97GlEh7I4dhuun7psuhpSeua6 acmkwW0qjMwGviHsx0nA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x9Qdv-000000090Up-2zap; Wed, 23 Sep 2026 17:20:27 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x9Qdn-000000090Sb-3GAF; Wed, 23 Sep 2026 17:20:20 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 815B642E0C; Wed, 23 Sep 2026 17:20:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50FCE1F00893; Wed, 23 Sep 2026 17:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790184019; bh=+rwl1Zn9bU3CF5Lv6uJecPAyTurD5CJjPcxpUYcu/S0=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=mZ46Am8b6Wn9IMnH8S2ELNq04sKgdTBqXyocEc8OiLB0sIiwNs/r3xJS7H+Jps8UB Nr6oNJarDDpQaWtichSPBo6WiOxV2I/l6AUnAGHuHANUHxpuu2aHkDkf4NJ3FdIYPs LCw0TVk09iax4Vzz4tQdzXYTXcEPXUz34TFC+3lcSzfEhpFGFPbjAhQeHBqIQ/Dif8 ZFW0n3RzfA4QblsDN/VKZRAVIggc1iQPR5fT9pZ1lWsexJBduO/kql9jVY68tmvSvK U9JRqHbVg4kFTgLsFXUxkNb+L4jPIRFRUxVfE9wd2ZGBl0Y1yNn7XtyaJSKrxrB/bh 7+S3dv4tqFp+g== From: "Lorenzo Stoakes (ARM)" Date: Wed, 23 Sep 2026 18:17:58 +0100 Subject: [PATCH v4 09/22] kbuild: calculate list, composite object state per object MIME-Version: 1.0 Message-Id: <20260923-build-speedup-v4-9-73128809a4a4@kernel.org> References: <20260923-build-speedup-v4-0-73128809a4a4@kernel.org> In-Reply-To: <20260923-build-speedup-v4-0-73128809a4a4@kernel.org> To: Linus Torvalds , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Masahiro Yamada , Alexey Gladkov , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Arnd Bergmann , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Ilias Apalodimas , Josh Poimboeuf , Peter Zijlstra , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= , Jonathan Corbet , Randy Dunlap , Kees Cook , "Gustavo A. R. Silva" Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-doc@vger.kernel.org, Jens Axboe , linux-hardening@vger.kernel.org, Petr Pavlu , "Lorenzo Stoakes (ARM)" , Nicolas Schier X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3573; i=ljs@kernel.org; h=from:subject:message-id; bh=1tlfspzVyupWDtDIq9Xi6b2r8IeD5B+p03B8UkqK1dA=; b=owGbwMvMwCV2fu7ZrsZH9SKMp9WSGLK2cF6e9yE+QOQp734n36qPH5XC1tztqeaztH+w+1ud6 NnbN0xCO0pZGMS4GGTFFFmefxHfHyQSNq/zgr8bzBxWJpAhDFycAjARpuWMDD9uLjv/Tf5qzXuz +M+ue27qrjt6u2Xji/mi5iLfY+4//crH8E9zWuT8XfqLT783vWcXtMFMm4/zb/0vo393ec3/ZTG 5cLMCAA== X-Developer-Key: i=ljs@kernel.org; a=openpgp; fpr=E7F417BF5214569E89D04F46CF9DCD8A81E27F14 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org When each object's command line is expanded, kbuild has to figure out on multiple occasions whether it's built-in or part of a module and which composite object it belongs to. This causes the time spent on each directory in the kernel tree to grow O(n^2) with its object count, which is especially problematic for instance in drivers/gpu/drm/amd/amdgpu with 310 objects. No-op builds (i.e. make -j $(nproc) when nothing has changed) are particularly impacted by this. Fix the issue by calculating this data once and looking it up thereafter instead of recomputing it over and over again. This has a particularly large impact on allmodconfig builds. Whole build, 128-thread Threadripper 9980X, best of N runs: before after delta ------------------------------- x86 defconfig, no-op make, gcc 1.1s 1.1s -0.02s (-2%) x86 defconfig, no-op make, clang 1.3s 1.3s -0.01s (-1%) x86 allmodconfig, no-op make, gcc 15.3s 14.5s -0.83s (-5%) x86 allmodconfig, no-op make, clang 16.2s 15.5s -0.65s (-4%) x86 allmodconfig, touch mm/vma.c, gcc 35.0s 34.3s -0.77s (-2%) x86 allmodconfig, touch mm/vma.c, clang 33.7s 33.2s -0.51s (-2%) Assisted-by: LLM Reviewed-by: Nicolas Schier Reviewed-by: Kees Cook Signed-off-by: Lorenzo Stoakes (ARM) --- scripts/Makefile.build | 8 ++++++++ scripts/Makefile.lib | 7 +++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 4349108e75e1..2cabfe85b798 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -122,6 +122,14 @@ multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m)) subdir-ym := $(addprefix $(obj)/, $(subdir-ym)) endif +# Cache which list each object is in and which composite objects it belongs to, +# once per object for $(part-of-builtin), $(part-of-module) and $(modname-multi). +$(foreach o, $(real-obj-y) $(lib-y), $(eval part-of-builtin_$o := y)) +$(foreach o, $(real-obj-m), $(eval part-of-module_$o := y)) +$(foreach m, $(multi-obj-ym), \ + $(foreach o, $(call suffix-search, $m, .o, -objs -y -m), \ + $(eval modname-multi_$o += $(m:.o=)))) + ifndef obj $(warning kbuild: Makefile.build is included improperly) endif diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 0a4fdd8bd975..2f447bc25e7b 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -2,8 +2,7 @@ # Finds the multi-part object the current object will be linked into. # If the object belongs to two or more multi-part objects, list them all. -modname-multi = $(sort $(foreach m,$(multi-obj-ym),\ - $(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=)))) +modname-multi = $(sort $(modname-multi_$*.o)) __modname = $(or $(modname-multi),$(basetarget)) @@ -149,8 +148,8 @@ endif # If $(is-kernel-object) is 'y', this object will be linked to vmlinux or modules is-kernel-object = $(or $(part-of-builtin),$(part-of-module)) -part-of-builtin = $(if $(filter $(basename $@).o, $(real-obj-y) $(lib-y)),y) -part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y) +part-of-builtin = $(part-of-builtin_$(basename $@).o) +part-of-module = $(part-of-module_$(basename $@).o) quiet_modtag = $(if $(part-of-module),[M], ) modkern_cflags = \ -- 2.55.0 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv