Message ID | 20230717080739.1000460-1-wangkefeng.wang@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp977962vqt; Mon, 17 Jul 2023 01:30:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlHVXwujJK6LSVSZFTQ3YmsytTdO8TKyWXQLe0+kFV5a22GUt5RVtTRjhSj4IkorUWFOPRAt X-Received: by 2002:a05:6a20:8e0d:b0:129:b68b:92db with SMTP id y13-20020a056a208e0d00b00129b68b92dbmr12340632pzj.42.1689582603920; Mon, 17 Jul 2023 01:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689582603; cv=none; d=google.com; s=arc-20160816; b=NiobCd+MoYN2DUMg2Ks/pZpWdUK7ETQEblVNoCdQAWJbWVes509n6ulBPvPmcP1DJu RecAy9IF4bW0Mvh49id3J0dTSMVZ4Ad5VLMzp6RlJfYUDu/y7U0OPmVvWH/AN2TIDXTl 3S6iNU3i/96KN0ZDFKPu71UFObPNrp5WM8EUS6rG01ozESDZyt3tdyWnzgbLh0GW6oU4 V0XJnFJK46yh5Hqovx522F8+7mwpTYVjqHer/bCk1qQNMTLhYsIi7nZanYj66e3QgCJU gwdLbsxDVn81GyErqKxUejSO2oJIRB/LFZ2gNWjOZmokjlwBiuwiOSbEoEW+jWANn75d u6ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=4D+lSWSKrnTRvO0LKh0j6OjpMEGYwaapQpKLmzdhfBk=; fh=y+7ewH4c3E0JzpuDb9PdPVGIJ9FyRsSsBLy2rx1/08w=; b=e+1AJ/UqKTq9KQiytKZuRjvU+UOEzl3+IcKmZC0RIPG8S5sUF/5S22PJajhHPyWJ7A mfnwcXbGcfj8JMQVZN6L4A3QAKoptcQe9XJFC5RC192ktXTqd84JWax+8KX2BERiTSw/ qSUAhhtf4PkVzqxcIZGt+LLmOLvCgOLgc3ByfC4k9b3dYmBlx7ICnmLnogDk8ru6D7vU TYPKpRjxmQMiWJWKj5Di7IwAUsTQSNqfgzaJfVg1OIgMasNSX9DqjVX5RMUX5AzbXRY0 QdY1GopW0dEhMwJnoSYO3UjQ2PtF5n400vsauyeinf0cjjfegQbmgQMmd9ePP70K/sHs 0ZvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u188-20020a6279c5000000b006546d0d5832si11051391pfc.183.2023.07.17.01.29.50; Mon, 17 Jul 2023 01:30:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230109AbjGQIIx (ORCPT <rfc822;hadasmailinglist@gmail.com> + 99 others); Mon, 17 Jul 2023 04:08:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229608AbjGQIIw (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 17 Jul 2023 04:08:52 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9858A1FDB for <linux-kernel@vger.kernel.org>; Mon, 17 Jul 2023 01:08:28 -0700 (PDT) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4R4F424VsSzNmQS; Mon, 17 Jul 2023 16:04:50 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 17 Jul 2023 16:08:09 +0800 From: Kefeng Wang <wangkefeng.wang@huawei.com> To: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org> CC: <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org>, Kefeng Wang <wangkefeng.wang@huawei.com> Subject: [PATCH] arm64: enable dead code elimination Date: Mon, 17 Jul 2023 16:07:39 +0800 Message-ID: <20230717080739.1000460-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771655768392577960 X-GMAIL-MSGID: 1771655768392577960 |
Series |
arm64: enable dead code elimination
|
|
Commit Message
Kefeng Wang
July 17, 2023, 8:07 a.m. UTC
Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for arm64, allowing the
user to enable dead code elimination. In order for this to work, ensure
that we keep the necessary tables by annotating them with KEEP, also it
requires further changes to linker script to KEEP some tables and wildcard
compiler generated sections into the right place.
The following comparison is based 6.5-rc2 with defconfig,
$ ./scripts/bloat-o-meter vmlinux-base vmlinux-new
add/remove: 3/1106 grow/shrink: 4102/6964 up/down: 35704/-99980 (-64276)
Function old new delta
...
Total: Before=17888959, After=17824683, chg -0.36%
add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-44 (-44)
Data old new delta
...
Total: Before=4820808, After=4820764, chg -0.00%
add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-1096 (-1096)
RO Data old new delta
...
Total: Before=5179123, After=5178027, chg -0.02%
$ size vmlinux-base vmlinux
text data bss dec hex filename
25433734 15385766 630656 41450156 2787aac vmlinux-base
24756738 15360870 629888 40747496 26dc1e8 vmlinux-new
Memory available after booting, saving 704k on qemu,
base: 8084532K/8388608K
new: 8085236K/8388608K
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
arch/arm64/Kconfig | 1 +
arch/arm64/kernel/vmlinux.lds.S | 5 +++--
2 files changed, 4 insertions(+), 2 deletions(-)
Comments
On Mon, Jul 17, 2023 at 04:07:39PM +0800, Kefeng Wang wrote: > Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for arm64, allowing the > user to enable dead code elimination. In order for this to work, ensure > that we keep the necessary tables by annotating them with KEEP, also it > requires further changes to linker script to KEEP some tables and wildcard > compiler generated sections into the right place. > > The following comparison is based 6.5-rc2 with defconfig, > > $ ./scripts/bloat-o-meter vmlinux-base vmlinux-new > add/remove: 3/1106 grow/shrink: 4102/6964 up/down: 35704/-99980 (-64276) > Function old new delta > ... > Total: Before=17888959, After=17824683, chg -0.36% > > add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-44 (-44) > Data old new delta > ... > Total: Before=4820808, After=4820764, chg -0.00% > > add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-1096 (-1096) > RO Data old new delta > ... > Total: Before=5179123, After=5178027, chg -0.02% > > $ size vmlinux-base vmlinux > text data bss dec hex filename > 25433734 15385766 630656 41450156 2787aac vmlinux-base > 24756738 15360870 629888 40747496 26dc1e8 vmlinux-new > > Memory available after booting, saving 704k on qemu, > base: 8084532K/8388608K > new: 8085236K/8388608K Is that a 0.009% improvement? Is it really worth the hassle? x86 doesn't select this and risc-v had to turn it off for LLD, so it feels like we're just creating a rod for our own back by selecting it. Will > Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> > --- > arch/arm64/Kconfig | 1 + > arch/arm64/kernel/vmlinux.lds.S | 5 +++-- > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index a2511b30d0f6..73bb908ec62f 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -148,6 +148,7 @@ config ARM64 > select GENERIC_VDSO_TIME_NS > select HARDIRQS_SW_RESEND > select HAS_IOPORT > + select HAVE_LD_DEAD_CODE_DATA_ELIMINATION > select HAVE_MOVE_PMD > select HAVE_MOVE_PUD > select HAVE_PCI > diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S > index 3cd7e76cc562..bb4ce6cd6896 100644 > --- a/arch/arm64/kernel/vmlinux.lds.S > +++ b/arch/arm64/kernel/vmlinux.lds.S > @@ -238,7 +238,7 @@ SECTIONS > . = ALIGN(4); > .altinstructions : { > __alt_instructions = .; > - *(.altinstructions) > + KEEP(*(.altinstructions)) > __alt_instructions_end = .; > } > > @@ -258,8 +258,9 @@ SECTIONS > INIT_CALLS > CON_INITCALL > INIT_RAM_FS > - *(.init.altinstructions .init.bss) /* from the EFI stub */ > + KEEP(*(.init.altinstructions .init.bss*)) /* from the EFI stub */ > } > + > .exit.data : { > EXIT_DATA > } > -- > 2.27.0 >
On 2023-07-17 09:07, Kefeng Wang wrote: > Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for arm64, allowing > the > user to enable dead code elimination. In order for this to work, ensure > that we keep the necessary tables by annotating them with KEEP, also it > requires further changes to linker script to KEEP some tables and > wildcard > compiler generated sections into the right place. > > The following comparison is based 6.5-rc2 with defconfig, > > $ ./scripts/bloat-o-meter vmlinux-base vmlinux-new > add/remove: 3/1106 grow/shrink: 4102/6964 up/down: 35704/-99980 > (-64276) > Function old new delta > ... > Total: Before=17888959, After=17824683, chg -0.36% > > add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-44 (-44) > Data old new delta > ... > Total: Before=4820808, After=4820764, chg -0.00% > > add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-1096 (-1096) > RO Data old new delta > ... > Total: Before=5179123, After=5178027, chg -0.02% > > $ size vmlinux-base vmlinux > text data bss dec hex filename > 25433734 15385766 630656 41450156 2787aac vmlinux-base > 24756738 15360870 629888 40747496 26dc1e8 vmlinux-new > > Memory available after booting, saving 704k on qemu, > base: 8084532K/8388608K > new: 8085236K/8388608K > > Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> I took this patch for a spin in my tree, and ended up with: CC .vmlinux.export.o UPD include/generated/utsversion.h CC init/version-timestamp.o LD .tmp_vmlinux.kallsyms1 ld: init/main.o(__patchable_function_entries): error: need linked-to section for --gc-sections make[2]: *** [scripts/Makefile.vmlinux:36: vmlinux] Error 1 make[1]: *** [/home/maz/hot-poop/arm-platforms/Makefile:1238: vmlinux] Error 2 make: *** [Makefile:234: __sub-make] Error 2 so it's probably not ready for prime time. M.
On 2023/7/17 17:24, Will Deacon wrote: > On Mon, Jul 17, 2023 at 04:07:39PM +0800, Kefeng Wang wrote: >> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for arm64, allowing the >> user to enable dead code elimination. In order for this to work, ensure >> that we keep the necessary tables by annotating them with KEEP, also it >> requires further changes to linker script to KEEP some tables and wildcard >> compiler generated sections into the right place. >> >> The following comparison is based 6.5-rc2 with defconfig, >> >> $ ./scripts/bloat-o-meter vmlinux-base vmlinux-new >> add/remove: 3/1106 grow/shrink: 4102/6964 up/down: 35704/-99980 (-64276) >> Function old new delta >> ... >> Total: Before=17888959, After=17824683, chg -0.36% >> >> add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-44 (-44) >> Data old new delta >> ... >> Total: Before=4820808, After=4820764, chg -0.00% >> >> add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-1096 (-1096) >> RO Data old new delta >> ... >> Total: Before=5179123, After=5178027, chg -0.02% >> >> $ size vmlinux-base vmlinux >> text data bss dec hex filename >> 25433734 15385766 630656 41450156 2787aac vmlinux-base >> 24756738 15360870 629888 40747496 26dc1e8 vmlinux-new >> >> Memory available after booting, saving 704k on qemu, >> base: 8084532K/8388608K >> new: 8085236K/8388608K > > Is that a 0.009% improvement? Is it really worth the hassle? > > x86 doesn't select this and risc-v had to turn it off for LLD, so it feels > like we're just creating a rod for our own back by selecting it. The LD_DEAD_CODE_DATA_ELIMINATION is particularly used for small configs on small systems, risc-v is aimed to resource limited board platforms, maybe x86 has no strong requirement, and we will try to use it on some embedded board, if no one try it, this feature will never become stable :) > > Will >
On 2023/7/17 17:42, Marc Zyngier wrote: > On 2023-07-17 09:07, Kefeng Wang wrote: >> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for arm64, allowing the >> user to enable dead code elimination. In order for this to work, ensure >> that we keep the necessary tables by annotating them with KEEP, also it >> requires further changes to linker script to KEEP some tables and >> wildcard >> compiler generated sections into the right place. >> >> The following comparison is based 6.5-rc2 with defconfig, >> >> $ ./scripts/bloat-o-meter vmlinux-base vmlinux-new >> add/remove: 3/1106 grow/shrink: 4102/6964 up/down: 35704/-99980 (-64276) >> Function old new delta >> ... >> Total: Before=17888959, After=17824683, chg -0.36% >> >> add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-44 (-44) >> Data old new delta >> ... >> Total: Before=4820808, After=4820764, chg -0.00% >> >> add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-1096 (-1096) >> RO Data old new delta >> ... >> Total: Before=5179123, After=5178027, chg -0.02% >> >> $ size vmlinux-base vmlinux >> text data bss dec hex filename >> 25433734 15385766 630656 41450156 2787aac vmlinux-base >> 24756738 15360870 629888 40747496 26dc1e8 vmlinux-new >> >> Memory available after booting, saving 704k on qemu, >> base: 8084532K/8388608K >> new: 8085236K/8388608K >> >> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> > > I took this patch for a spin in my tree, and ended up with: > > CC .vmlinux.export.o > UPD include/generated/utsversion.h > CC init/version-timestamp.o > LD .tmp_vmlinux.kallsyms1 > ld: init/main.o(__patchable_function_entries): error: need linked-to > section for --gc-sections > make[2]: *** [scripts/Makefile.vmlinux:36: vmlinux] Error 1 > make[1]: *** [/home/maz/hot-poop/arm-platforms/Makefile:1238: vmlinux] > Error 2 > make: *** [Makefile:234: __sub-make] Error 2 I don't find this error with CONFIG_FTRACE_MCOUNT_RECORD or allyesconfig, does it need special config or gcc version? > > so it's probably not ready for prime time. > > M.
On Mon, 17 Jul 2023 12:56:39 +0100, Kefeng Wang <wangkefeng.wang@huawei.com> wrote: > > > > On 2023/7/17 17:42, Marc Zyngier wrote: > > On 2023-07-17 09:07, Kefeng Wang wrote: > >> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for arm64, allowing the > >> user to enable dead code elimination. In order for this to work, ensure > >> that we keep the necessary tables by annotating them with KEEP, also it > >> requires further changes to linker script to KEEP some tables and > >> wildcard > >> compiler generated sections into the right place. > >> > >> The following comparison is based 6.5-rc2 with defconfig, > >> > >> $ ./scripts/bloat-o-meter vmlinux-base vmlinux-new > >> add/remove: 3/1106 grow/shrink: 4102/6964 up/down: 35704/-99980 (-64276) > >> Function old new delta > >> ... > >> Total: Before=17888959, After=17824683, chg -0.36% > >> > >> add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-44 (-44) > >> Data old new delta > >> ... > >> Total: Before=4820808, After=4820764, chg -0.00% > >> > >> add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-1096 (-1096) > >> RO Data old new delta > >> ... > >> Total: Before=5179123, After=5178027, chg -0.02% > >> > >> $ size vmlinux-base vmlinux > >> text data bss dec hex filename > >> 25433734 15385766 630656 41450156 2787aac vmlinux-base > >> 24756738 15360870 629888 40747496 26dc1e8 vmlinux-new > >> > >> Memory available after booting, saving 704k on qemu, > >> base: 8084532K/8388608K > >> new: 8085236K/8388608K > >> > >> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> > > > > I took this patch for a spin in my tree, and ended up with: > > > > CC .vmlinux.export.o > > UPD include/generated/utsversion.h > > CC init/version-timestamp.o > > LD .tmp_vmlinux.kallsyms1 > > ld: init/main.o(__patchable_function_entries): error: need linked-to > > section for --gc-sections > > make[2]: *** [scripts/Makefile.vmlinux:36: vmlinux] Error 1 > > make[1]: *** [/home/maz/hot-poop/arm-platforms/Makefile:1238: > > vmlinux] Error 2 > > make: *** [Makefile:234: __sub-make] Error 2 > > I don't find this error with CONFIG_FTRACE_MCOUNT_RECORD or > allyesconfig, does it need special config or gcc version? You tell me! gcc (Debian 10.2.1-6) 10.2.1 20210110 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. so hardly something special. This is built with the current state of my NV tree, available here[1] As for the configuration, have a look here[2]. M. [1] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/log/?h=kvm-arm64/nv-6.6-WIP [2] https://paste.debian.net/1286106/
On 2023/7/17 20:15, Marc Zyngier wrote: > On Mon, 17 Jul 2023 12:56:39 +0100, > Kefeng Wang <wangkefeng.wang@huawei.com> wrote: >> >> >> >> On 2023/7/17 17:42, Marc Zyngier wrote: >>> On 2023-07-17 09:07, Kefeng Wang wrote: >>>> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for arm64, allowing the >>>> user to enable dead code elimination. In order for this to work, ensure >>>> that we keep the necessary tables by annotating them with KEEP, also it >>>> requires further changes to linker script to KEEP some tables and >>>> wildcard >>>> compiler generated sections into the right place. >>>> >>>> The following comparison is based 6.5-rc2 with defconfig, >>>> ... >>> >>> I took this patch for a spin in my tree, and ended up with: >>> >>> CC .vmlinux.export.o >>> UPD include/generated/utsversion.h >>> CC init/version-timestamp.o >>> LD .tmp_vmlinux.kallsyms1 >>> ld: init/main.o(__patchable_function_entries): error: need linked-to >>> section for --gc-sections >>> make[2]: *** [scripts/Makefile.vmlinux:36: vmlinux] Error 1 >>> make[1]: *** [/home/maz/hot-poop/arm-platforms/Makefile:1238: >>> vmlinux] Error 2 >>> make: *** [Makefile:234: __sub-make] Error 2 >> >> I don't find this error with CONFIG_FTRACE_MCOUNT_RECORD or >> allyesconfig, does it need special config or gcc version? > > You tell me! > > gcc (Debian 10.2.1-6) 10.2.1 20210110 > Copyright (C) 2020 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > so hardly something special. This is built with the current state of > my NV tree, available here[1] As for the configuration, have a look > here[2]. 1) With gcc 10.3.1/ld (GNU Binutils) 2.37, it could be reproduced, but there is no issue for cross-compiler gcc 9.3/ld (GNU Binutils for Ubuntu) 2.34. 2) There is same issue like commit f7584322e4fe ("riscv: disable HAVE_LD_DEAD_CODE_DATA_ELIMINATION for LLD") said with allyesconfig on arm64, it takes too long in bfd_flavour_name() Samples: 257K of event 'cycles', Event count (approx.): 203974259359 Overhead Shared Object Symbol IPC [IPC Coverage] - 61.11% libbfd-2.34-arm64.so [.] bfd_flavour_name - - bfd_flavour_name - 6.55% libbfd-2.34-arm64.so [.] bfd_hash_traverse - - Just like you said, it is not ready for prime time, so please ignore this patch :( > > M. > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/log/?h=kvm-arm64/nv-6.6-WIP > [2] https://paste.debian.net/1286106/ >
On 2023/7/17 17:24, Will Deacon wrote: > On Mon, Jul 17, 2023 at 04:07:39PM +0800, Kefeng Wang wrote: >> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for arm64, allowing the >> user to enable dead code elimination. In order for this to work, ensure >> that we keep the necessary tables by annotating them with KEEP, also it >> requires further changes to linker script to KEEP some tables and wildcard >> compiler generated sections into the right place. >> >> The following comparison is based 6.5-rc2 with defconfig, >> >> $ ./scripts/bloat-o-meter vmlinux-base vmlinux-new >> add/remove: 3/1106 grow/shrink: 4102/6964 up/down: 35704/-99980 (-64276) >> Function old new delta >> ... >> Total: Before=17888959, After=17824683, chg -0.36% >> >> add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-44 (-44) >> Data old new delta >> ... >> Total: Before=4820808, After=4820764, chg -0.00% >> >> add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-1096 (-1096) >> RO Data old new delta >> ... >> Total: Before=5179123, After=5178027, chg -0.02% >> >> $ size vmlinux-base vmlinux >> text data bss dec hex filename >> 25433734 15385766 630656 41450156 2787aac vmlinux-base >> 24756738 15360870 629888 40747496 26dc1e8 vmlinux-new >> >> Memory available after booting, saving 704k on qemu, >> base: 8084532K/8388608K >> new: 8085236K/8388608K > > Is that a 0.009% improvement? Is it really worth the hassle? > > x86 doesn't select this and risc-v had to turn it off for LLD, so it feels > like we're just creating a rod for our own back by selecting it. I tested this patch and found that, the smaller the config file,the more significant the reduction in file size of the builds. This may be useful in scenarios such as embedded systems where size is particularly critical. Just like Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, this boots well on qemu, with defconfig, it shrinks their builds by ~1.6%, and with tinyconfig it shrinks their builds by ~18.7%. defconfig: text data bss dec hex 26839348 16695234 629456 44164038 2a1e3c6 before 26140556 16667058 628880 43436494 296c9ce after tinyconfig: text data bss dec hex 1259568 272100 104312 1635980 18f68c before 967056 258716 103824 1329596 1449bc after | tinyconfig | defconfig --------|------------------------|--------------------- No DCE | 1635980 | 44164038 DCE | 1329596 | 43436494 Shrink | 306384 (~18.7%) | 727544 (~1.6%) > > Will >
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index a2511b30d0f6..73bb908ec62f 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -148,6 +148,7 @@ config ARM64 select GENERIC_VDSO_TIME_NS select HARDIRQS_SW_RESEND select HAS_IOPORT + select HAVE_LD_DEAD_CODE_DATA_ELIMINATION select HAVE_MOVE_PMD select HAVE_MOVE_PUD select HAVE_PCI diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 3cd7e76cc562..bb4ce6cd6896 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -238,7 +238,7 @@ SECTIONS . = ALIGN(4); .altinstructions : { __alt_instructions = .; - *(.altinstructions) + KEEP(*(.altinstructions)) __alt_instructions_end = .; } @@ -258,8 +258,9 @@ SECTIONS INIT_CALLS CON_INITCALL INIT_RAM_FS - *(.init.altinstructions .init.bss) /* from the EFI stub */ + KEEP(*(.init.altinstructions .init.bss*)) /* from the EFI stub */ } + .exit.data : { EXIT_DATA }