linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org, jpoimboe@redhat.com, jbaron@akamai.com,
	rostedt@goodmis.org, ardb@kernel.org,
	linux-kernel@vger.kernel.org, samitolvanen@google.com,
	ndesaulniers@google.com, clang-built-linux@googlegroups.com
Subject: Re: [PATCH 01/13] objtool: Rewrite hashtable sizing
Date: Thu, 10 Jun 2021 11:14:51 -0700	[thread overview]
Message-ID: <YMJWmzXgSipOqXAf@DESKTOP-1V8MEUQ.localdomain> (raw)
In-Reply-To: <20210506194157.452881700@infradead.org>

Hi Peter,

On Thu, May 06, 2021 at 09:33:53PM +0200, Peter Zijlstra wrote:
> Currently objtool has 5 hashtables and sizes them 16 or 20 bits
> depending on the --vmlinux argument.
> 
> However, a single side doesn't really work well for the 5 tables,
> which among them, cover 3 different uses. Also, while vmlinux is
> larger, there is still a very wide difference between a defconfig and
> allyesconfig build, which again isn't optimally covered by a single
> size.
> 
> Another aspect is the cost of elf_hash_init(), which for large tables
> dominates the runtime for small input files. It turns out that all it
> does it assign NULL, something that is required when using malloc().
> However, when we allocate memory using mmap(), we're guaranteed to get
> zero filled pages.
> 
> Therefore, rewrite the whole thing to:
> 
>  1) use more dynamic sized tables, depending on the input file,
>  2) avoid the need for elf_hash_init() entirely by using mmap().
> 
> This speeds up a regular kernel build (100s to 98s for
> x86_64-defconfig), and potentially dramatically speeds up vmlinux
> processing.
> 
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

This patch as commit 25cf0d8aa2a3 ("objtool: Rewrite hashtable sizing")
in -tip causes a massive compile time regression with allmodconfig +
ThinLTO.

At v5.13-rc1, the performance penalty is only about 23%, as measured with
hyperfine for two runs [1]:

Benchmark #1: allmodconfig
  Time (mean ± σ):     625.173 s ±  2.198 s    [User: 35120.895 s, System: 2176.868 s]
  Range (min … max):   623.619 s … 626.727 s    2 runs

Benchmark #2: allmodconfig with ThinLTO
  Time (mean ± σ):     771.034 s ±  0.369 s    [User: 39706.084 s, System: 2326.166 s]
  Range (min … max):   770.773 s … 771.295 s    2 runs

Summary
  'allmodconfig' ran
    1.23 ± 0.00 times faster than 'allmodconfig with ThinLTO'

However, at 25cf0d8aa2a3, it is almost 150% on a 64-core server.

Benchmark #1: allmodconfig
  Time (mean ± σ):     624.759 s ±  2.153 s    [User: 35114.379 s, System: 2145.456 s]
  Range (min … max):   623.237 s … 626.281 s    2 runs

Benchmark #2: allmodconfig with ThinLTO
  Time (mean ± σ):     1555.377 s ± 12.806 s    [User: 40558.463 s, System: 2310.139 s]
  Range (min … max):   1546.321 s … 1564.432 s    2 runs

Summary
  'allmodconfig' ran
    2.49 ± 0.02 times faster than 'allmodconfig with ThinLTO'

Adding Sami because I am not sure why this patch would have much of an impact
in relation to LTO. https://git.kernel.org/tip/25cf0d8aa2a3 is the patch in
question.

If I can provide any further information or help debug, please let me know.

If you are interested in reproducing this locally, you will need a
fairly recent LLVM stack (I used the stable release/12.x branch) and to
cherry-pick commit 976aac5f8829 ("kcsan: Fix debugfs initcall return
type") to fix an unrelated build failure. My script [2] can build a
self-contained toolchain fairly quickly if you cannot get one from your
package manager. A command like below will speed up the build a bit:

$ ./build-llvm.py \
    --branch "release/12.x" \
    --build-stage1-only \
    --install-stage1-only \
    --projects "clang;lld" \
    --targets X86

After adding the "install/bin" directory to PATH:

$ echo "CONFIG_GCOV_KERNEL=n
CONFIG_KASAN=n
CONFIG_LTO_CLANG_THIN=y" >allmod.config

$ make -skj"$(nproc)" LLVM=1 LLVM_IAS=1 allmodconfig all

[1]: https://github.com/sharkdp/hyperfine
[2]: https://github.com/ClangBuiltLinux/tc-build

Cheers,
Nathan

  parent reply	other threads:[~2021-06-10 18:14 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-06 19:33 [PATCH 00/13] jump_label: Yet another attempt at variable sized jump_labels Peter Zijlstra
2021-05-06 19:33 ` [PATCH 01/13] objtool: Rewrite hashtable sizing Peter Zijlstra
2021-05-12 10:41   ` Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-06-10 18:14   ` Nathan Chancellor [this message]
2021-06-10 18:43     ` [PATCH 01/13] " Peter Zijlstra
2021-06-10 18:54       ` Nathan Chancellor
2021-06-10 18:50     ` Sami Tolvanen
2021-06-10 19:33       ` Peter Zijlstra
2021-06-10 19:43         ` Sami Tolvanen
2021-06-10 20:59         ` Nathan Chancellor
2021-06-14 13:19         ` [tip: objtool/core] objtool: Improve reloc hash size guestimate tip-bot2 for Peter Zijlstra
2021-05-06 19:33 ` [PATCH 02/13] x86,objtool: Dont exclude arch/x86/realmode/ Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] x86, objtool: " tip-bot2 for Peter Zijlstra
2021-05-06 19:33 ` [PATCH 03/13] jump_label, x86: Strip ASM jump_label support Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-05-06 19:33 ` [PATCH 04/13] jump_label, x86: Factor out the __jump_table generation Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-05-06 19:33 ` [PATCH 05/13] jump_label, x86: Improve error when we fail expected text Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-05-06 19:33 ` [PATCH 06/13] jump_label, x86: Introduce jump_entry_size() Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-05-06 19:33 ` [PATCH 07/13] jump_label, x86: Add variable length patching support Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-05-13 14:16   ` [PATCH 07.5/13] jump_label,x86: Remove unused JUMP_LABEL_NOP_SIZE Peter Zijlstra
2021-05-14  7:01     ` [tip: objtool/core] jump_label/x86: " tip-bot2 for Peter Zijlstra
2021-05-06 19:34 ` [PATCH 08/13] jump_label: Free jump_entry::key bit1 for build use Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-05-06 19:34 ` [PATCH 09/13] jump_label,x86: Emit short JMP Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] jump_label, x86: " tip-bot2 for Peter Zijlstra
2021-05-06 19:34 ` [PATCH 10/13] objtool: Decode jump_entry::key addend Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-05-06 19:34 ` [PATCH 11/13] objtool: Rewrite jump_label instructions Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-05-06 19:34 ` [PATCH 12/13] objtool: Provide stats for jump_labels Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-05-13 14:15   ` [PATCH 12.5/13] objtool: Reflow handle_jump_alt() Peter Zijlstra
2021-05-06 19:34 ` [PATCH 13/13] jump_label,x86: Allow short NOPs Peter Zijlstra
2021-05-06 19:49   ` Peter Zijlstra
2021-05-12 13:19   ` [tip: objtool/core] jump_label, x86: " tip-bot2 for Peter Zijlstra
2021-05-18 19:50     ` Peter Zijlstra
2021-05-18 20:24       ` Peter Zijlstra
2021-05-19  0:44         ` Josh Poimboeuf
2021-05-19  6:56           ` Peter Zijlstra
2021-06-29 20:00             ` Matthew Wilcox
2021-06-29 20:35               ` Matthew Wilcox
2021-06-30  7:07                 ` Peter Zijlstra
2021-06-30  7:38                   ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YMJWmzXgSipOqXAf@DESKTOP-1V8MEUQ.localdomain \
    --to=nathan@kernel.org \
    --cc=ardb@kernel.org \
    --cc=clang-built-linux@googlegroups.com \
    --cc=jbaron@akamai.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).