Commit 23baf831 authored by Kirill A. Shutemov's avatar Kirill A. Shutemov Committed by Andrew Morton
Browse files

mm, treewide: redefine MAX_ORDER sanely

MAX_ORDER currently defined as number of orders page allocator supports:
user can ask buddy allocator for page order between 0 and MAX_ORDER-1.

This definition is counter-intuitive and lead to number of bugs all over
the kernel.

Change the definition of MAX_ORDER to be inclusive: the range of orders
user can ask from buddy allocator is 0..MAX_ORDER now.

[kirill@shutemov.name: fix min() warning]
  Link: https://lkml.kernel.org/r/20230315153800.32wib3n5rickolvh@box
[akpm@linux-foundation.org: fix another min_t warning]
[kirill@shutemov.name: fixups per Zi Yan]
  Link: https://lkml.kernel.org/r/20230316232144.b7ic4cif4kjiabws@box.shutemov.name
[akpm@linux-foundation.org: fix underlining in docs]
  Link: https://lore.kernel.org/oe-kbuild-all/202303191025.VRCTk6mP-lkp@intel.com/
Link: https://lkml.kernel.org/r/20230315113133.11326-11-kirill.shutemov@linux.intel.com


Signed-off-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reviewed-by: Michael Ellerman <mpe@ellerman.id.au>	[powerpc]
Cc: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 61883d3c
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -172,7 +172,7 @@ variables.
Offset of the free_list's member. This value is used to compute the number
Offset of the free_list's member. This value is used to compute the number
of free pages.
of free pages.


Each zone has a free_area structure array called free_area[MAX_ORDER].
Each zone has a free_area structure array called free_area[MAX_ORDER + 1].
The free_list represents a linked list of free page blocks.
The free_list represents a linked list of free page blocks.


(list_head, next|prev)
(list_head, next|prev)
@@ -189,8 +189,8 @@ Offsets of the vmap_area's members. They carry vmalloc-specific
information. Makedumpfile gets the start address of the vmalloc region
information. Makedumpfile gets the start address of the vmalloc region
from this.
from this.


(zone.free_area, MAX_ORDER)
(zone.free_area, MAX_ORDER + 1)
---------------------------
-------------------------------


Free areas descriptor. User-space tools use this value to iterate the
Free areas descriptor. User-space tools use this value to iterate the
free_area ranges. MAX_ORDER is used by the zone buddy allocator.
free_area ranges. MAX_ORDER is used by the zone buddy allocator.
+1 −1
Original line number Original line Diff line number Diff line
@@ -3969,7 +3969,7 @@
			[KNL] Minimal page reporting order
			[KNL] Minimal page reporting order
			Format: <integer>
			Format: <integer>
			Adjust the minimal page reporting order. The page
			Adjust the minimal page reporting order. The page
			reporting is disabled when it exceeds (MAX_ORDER-1).
			reporting is disabled when it exceeds MAX_ORDER.


	panic=		[KNL] Kernel behaviour on panic: delay <timeout>
	panic=		[KNL] Kernel behaviour on panic: delay <timeout>
			timeout > 0: seconds before rebooting
			timeout > 0: seconds before rebooting
+2 −2
Original line number Original line Diff line number Diff line
@@ -556,7 +556,7 @@ endmenu # "ARC Architecture Configuration"


config ARCH_FORCE_MAX_ORDER
config ARCH_FORCE_MAX_ORDER
	int "Maximum zone order"
	int "Maximum zone order"
	default "12" if ARC_HUGEPAGE_16M
	default "11" if ARC_HUGEPAGE_16M
	default "11"
	default "10"


source "kernel/power/Kconfig"
source "kernel/power/Kconfig"
+3 −6
Original line number Original line Diff line number Diff line
@@ -1355,9 +1355,9 @@ config ARM_MODULE_PLTS


config ARCH_FORCE_MAX_ORDER
config ARCH_FORCE_MAX_ORDER
	int "Maximum zone order"
	int "Maximum zone order"
	default "12" if SOC_AM33XX
	default "11" if SOC_AM33XX
	default "9" if SA1111
	default "8" if SA1111
	default "11"
	default "10"
	help
	help
	  The kernel memory allocator divides physically contiguous memory
	  The kernel memory allocator divides physically contiguous memory
	  blocks into "zones", where each zone is a power of two number of
	  blocks into "zones", where each zone is a power of two number of
@@ -1366,9 +1366,6 @@ config ARCH_FORCE_MAX_ORDER
	  blocks of physically contiguous memory, then you may need to
	  blocks of physically contiguous memory, then you may need to
	  increase this value.
	  increase this value.


	  This config option is actually maximum order plus one. For example,
	  a value of 11 means that the largest free memory block is 2^10 pages.

config ALIGNMENT_TRAP
config ALIGNMENT_TRAP
	def_bool CPU_CP15_MMU
	def_bool CPU_CP15_MMU
	select HAVE_PROC_CPU if PROC_FS
	select HAVE_PROC_CPU if PROC_FS
+1 −1
Original line number Original line Diff line number Diff line
@@ -31,7 +31,7 @@ CONFIG_SOC_VF610=y
CONFIG_SMP=y
CONFIG_SMP=y
CONFIG_ARM_PSCI=y
CONFIG_ARM_PSCI=y
CONFIG_HIGHMEM=y
CONFIG_HIGHMEM=y
CONFIG_ARCH_FORCE_MAX_ORDER=14
CONFIG_ARCH_FORCE_MAX_ORDER=13
CONFIG_CMDLINE="noinitrd console=ttymxc0,115200"
CONFIG_CMDLINE="noinitrd console=ttymxc0,115200"
CONFIG_KEXEC=y
CONFIG_KEXEC=y
CONFIG_CPU_FREQ=y
CONFIG_CPU_FREQ=y
Loading