linux/include
Linus Torvalds 3a7e02c040 minmax: avoid overly complicated constant expressions in VM code
The minmax infrastructure is overkill for simple constants, and can
cause huge expansions because those simple constants are then used by
other things.

For example, 'pageblock_order' is a core VM constant, but because it was
implemented using 'min_t()' and all the type-checking that involves, it
actually expanded to something like 2.5kB of preprocessor noise.

And when that simple constant was then used inside other expansions:

  #define pageblock_nr_pages      (1UL << pageblock_order)
  #define pageblock_start_pfn(pfn)  ALIGN_DOWN((pfn), pageblock_nr_pages)

and we then use that inside a 'max()' macro:

	case ISOLATE_SUCCESS:
		update_cached = false;
		last_migrated_pfn = max(cc->zone->zone_start_pfn,
			pageblock_start_pfn(cc->migrate_pfn - 1));

the end result was that one statement expanding to 253kB in size.

There are probably other cases of this, but this one case certainly
stood out.

I've added 'MIN_T()' and 'MAX_T()' macros for this kind of "core simple
constant with specific type" use.  These macros skip the type checking,
and as such need to be very sparingly used only for obvious cases that
have active issues like this.

Reported-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/all/36aa2cad-1db1-4abf-8dd2-fb20484aabc3@lucifer.local/
Cc: David Laight <David.Laight@aculab.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2024-07-26 15:32:27 -07:00
..
acpi Driver core changes for 6.11-rc1 2024-07-25 10:42:22 -07:00
asm-generic Kbuild updates for v6.11 2024-07-23 14:32:21 -07:00
clocksource
crypto
drm Merge tag 'drm-intel-next-2024-06-28' of https://gitlab.freedesktop.org/drm/i915/kernel into drm-next 2024-07-10 10:36:47 +02:00
dt-bindings Char/Misc and other driver changes for 6.11-rc1 2024-07-19 15:55:08 -07:00
keys
kunit kunit: Introduce KUNIT_ASSERT_MEMEQ and KUNIT_ASSERT_MEMNEQ macros 2024-07-12 10:12:11 -06:00
kvm
linux minmax: avoid overly complicated constant expressions in VM code 2024-07-26 15:32:27 -07:00
math-emu
media
memory
misc
net sysctl: treewide: constify the ctl_table argument of proc_handlers 2024-07-24 20:59:29 +02:00
pcmcia
ras mm/memory-failure: remove obsolete MF_MSG_DIFFERENT_COMPOUND 2024-07-12 15:52:22 -07:00
rdma RDMA/core: Introduce "name_assign_type" for an IB device 2024-07-04 07:59:53 +03:00
rv
scsi Driver core changes for 6.11-rc1 2024-07-25 10:42:22 -07:00
soc sound updates for 6.11-rc1 2024-07-19 12:39:34 -07:00
sound sound fixes for 6.11-rc1 2024-07-26 11:01:31 -07:00
target
trace Random number generator updates for Linux 6.11-rc1. 2024-07-24 10:29:50 -07:00
uapi A lot of networking people were at a conference last week, busy 2024-07-25 13:32:25 -07:00
ufs Merge patch series "Basic inline encryption support for ufs-exynos" 2024-07-10 22:33:34 -04:00
vdso Random number generator updates for Linux 6.11-rc1. 2024-07-24 10:29:50 -07:00
video
xen Driver core changes for 6.11-rc1 2024-07-25 10:42:22 -07:00