linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Build performance regressions originating from min()/max() macros
@ 2024-07-23 21:59 Lorenzo Stoakes
  2024-07-24  8:14 ` Jürgen Groß
  2024-07-24  8:44 ` Lorenzo Stoakes
  0 siblings, 2 replies; 10+ messages in thread
From: Lorenzo Stoakes @ 2024-07-23 21:59 UTC (permalink / raw)
  To: Andrew Morton, david.laight
  Cc: Arnd Bergmann, willy, torvalds, Jason, hch, andriy.shevchenko,
	pedro.falcato, Mateusz Guzik, linux-mm, linux-kernel

Arnd reported a significant build slowdown [0], which was bisected to the
series spanning commit 80fcac55385c ("minmax: relax check to allow
comparison between unsigned arguments and signed constants") to commit
867046cc70277 ("minmax: relax check to allow comparison between unsigned
arguments and signed constants"), originating from the series "minmax:
Relax type checks in min() and max()." [1].

I have reproduced this locally, reverting this series and manually fixing
up all call sites that invoke min()/max() for a simple x86-64 defconfig (+
some other debug flags I use for debug kernels, I can provide the .config
if needed).

Arnd noted that the arch/x86/xen/setup.c file was particularly problematic,
taking 15 (!) seconds to pre-process on his machine, so I also enabled
CONFIG_XEN to test this and obtained performance numbers with this set/not
set.

I was able to reproduce this very significant pre-processor time on this
file, noting that with the series reverted compile time for the file is
0.79s, with it in place, it takes 6.90s for a 873.4% slowdown.

I also checked total build times (32-core intel i9-14900KF box):

## With CONFIG_XEN

### Reverted minmax code

make 1588.46s user 92.33s system 2430% cpu 1:09.16 total
make 1598.57s user 93.49s system 2419% cpu 1:09.94 total
make 1598.99s user 92.49s system 2419% cpu 1:09.91 total

### Not reverted

make 1639.25s user 96.34s system 2433% cpu 1:11.32 total
make 1640.34s user 96.01s system 2427% cpu 1:11.54 total
make 1639.98s user 96.76s system 2436% cpu 1:11.27 total

## Without CONFIG_XEN

### Reverted minmax code

make 1524.97s user 89.84s system 2399% cpu 1:07.31 total
make 1521.01s user 88.99s system 2391% cpu 1:07.32 total
make 1530.75s user 89.65s system 2389% cpu 1:07.83 total

### Not reverted

make 1570.64s user 94.09s system 2398% cpu 1:09.41 total
make 1571.25s user 94.36s system 2401% cpu 1:09.36 total
make 1568.25s user 93.83s system 2396% cpu 1:09.35 total

Which suggests a worryingly significant slowdown of ~45s with CONFIG_XEN
enabled and ~35s even without it.

The underlying problems seems to be very large macro expansions, which Arnd
noted in the xen case originated from the line:

extra_pages = min3(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)),
		extra_pages, max_pages - max_pfn);

And resulted in the generation of 47 MB (!) of pre-processor output.

It seems a lot of code now relies on the relaxed conditions of the newly
changed min/max() macros, so the question is - what can we do to address
these regressions?

[0]:https://social.kernel.org/notice/AkDuGHsn0WuA1g1uD2
[1]:https://lore.kernel.org/all/b97faef60ad24922b530241c5d7c933c@AcuMS.aculab.com/


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-07-24 14:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-23 21:59 Build performance regressions originating from min()/max() macros Lorenzo Stoakes
2024-07-24  8:14 ` Jürgen Groß
2024-07-24  8:31   ` Lorenzo Stoakes
2024-07-24  9:40     ` Jürgen Groß
2024-07-24  9:43       ` Lorenzo Stoakes
2024-07-24 14:47       ` David Laight
2024-07-24  8:34   ` David Laight
2024-07-24  8:50   ` Arnd Bergmann
2024-07-24  8:44 ` Lorenzo Stoakes
2024-07-24 11:05   ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox