Skip to contentSkip to conversation

mm/slub: clamp slab_min_order to MAX_PAGE_ORDER

PATCH Superseded Sang-Heon Jeon 2 participants 3 messages Oct 7 – Oct 8

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/slub: clamp slab_min_order to MAX_PAGE_ORDER

setup_slub_max_order() clamps slab_max_order to MAX_PAGE_ORDER, but setup_slub_min_order() has no such clamp.

The buddy allocator cannot allocate more than 2^MAX_PAGE_ORDER pages at once, so slab_min_order above it makes no sense.

If slab_min_order is set above MAX_PAGE_ORDER, it can even panic at boot or invoke undefined behavior in order_objects().

So clamp slab_min_order to MAX_PAGE_ORDER as well.

Fixes 818cf5909701 ("slub: enforce MAX_ORDER")

---
QEMU-based test results

- Booted with "slab_min_order=20"

1) AS-IS (before fix)

[    0.094926] mem auto-init: stack:all(zero), heap alloc:off, heap free:off
[    0.097776] Kernel panic - not syncing: Creation of kmalloc slab kmem_cache_node size=64 failed. Reason -22
[    0.099542] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 7.2.0 #1 PREEMPT(undef) 
[    0.100903] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[    0.102607] Call Trace:
[    0.103040]  <TASK>
[    0.103417]  vpanic+0x32a/0x4b0
[    0.103976]  panic+0x5e/0x60
[    0.104491]  create_boot_cache+0xe3/0xf0
[    0.105194]  kmem_cache_init+0x12d/0x410
[    0.105890]  ? mem_init+0x1fc/0x210
[    0.106521]  mm_core_init+0xba/0x140
[    0.107153]  start_kernel+0x441/0x8b0
[    0.107814]  x86_64_start_reservations+0x18/0x30
[    0.108638]  x86_64_start_kernel+0x10c/0x120
[    0.109401]  common_startup_64+0x13e/0x158
[    0.110145]  </TASK>
[    0.110584] ---[ end Kernel panic - not syncing: Creation of kmalloc slab kmem_cache_node size=64 failed. Reason -22 ]---

2) TO-BE (after fix)

[    0.008976] mem auto-init: stack:all(zero), heap alloc:off, heap free:off
[    0.011366] SLUB: HWalign=64, Order=10-10, MinObjects=0, CPUs=4, Nodes=1

Also, I'm not sure about the Fixes commit. Please change it if you know a better one.

---
 mm/slub.c | 2 ++
 1 file changed, 2 insertions(+)
mm/slub.c +2 -0
index 1559cbace469..8400df7c222e 100644
@@ -8354,6 +8354,8 @@ static int __init setup_slub_min_order(const char *str, const struct kernel_para
 	if (ret)
 		return ret;
 
+	slub_min_order = min_t(unsigned int, slub_min_order, MAX_PAGE_ORDER);
+
 	if (slub_min_order > slub_max_order)
 		slub_max_order = slub_min_order;
 

base-commit: d755441b7672c74f29d1241ffdd2b067ecab1ca0

Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 6 lines · Sang-Heon Jeon

setup_slub_max_order() clamps slab_max_order to MAX_PAGE_ORDER, but setup_slub_min_order() has no such clamp.

The buddy allocator cannot allocate more than 2^MAX_PAGE_ORDER pages at once, so slab_min_order above it makes no sense.

Quoted 6 lines

If slab_min_order is set above MAX_PAGE_ORDER, it can even panic at boot or invoke undefined behavior in order_objects().

So clamp slab_min_order to MAX_PAGE_ORDER as well.

Fixes 818cf5909701 ("slub: enforce MAX_ORDER")

I think Fixes: should be the commit that introduced slub_min_order.

Quoted 1 line

And no need for Cc: stable? It's been there for decades and people should realize the kernel parameter is broken when it doesn't boot.

Otherwise looks good to me.

Quoted 55 lines

---
QEMU-based test results

- Booted with "slab_min_order=20"

1) AS-IS (before fix)

[    0.094926] mem auto-init: stack:all(zero), heap alloc:off, heap free:off
[    0.097776] Kernel panic - not syncing: Creation of kmalloc slab kmem_cache_node size=64 failed. Reason -22
[    0.099542] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 7.2.0 #1 PREEMPT(undef) 
[    0.100903] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[    0.102607] Call Trace:
[    0.103040]  <TASK>
[    0.103417]  vpanic+0x32a/0x4b0
[    0.103976]  panic+0x5e/0x60
[    0.104491]  create_boot_cache+0xe3/0xf0
[    0.105194]  kmem_cache_init+0x12d/0x410
[    0.105890]  ? mem_init+0x1fc/0x210
[    0.106521]  mm_core_init+0xba/0x140
[    0.107153]  start_kernel+0x441/0x8b0
[    0.107814]  x86_64_start_reservations+0x18/0x30
[    0.108638]  x86_64_start_kernel+0x10c/0x120
[    0.109401]  common_startup_64+0x13e/0x158
[    0.110145]  </TASK>
[    0.110584] ---[ end Kernel panic - not syncing: Creation of kmalloc slab kmem_cache_node size=64 failed. Reason -22 ]---

2) TO-BE (after fix)

[    0.008976] mem auto-init: stack:all(zero), heap alloc:off, heap free:off
[    0.011366] SLUB: HWalign=64, Order=10-10, MinObjects=0, CPUs=4, Nodes=1

Also, I'm not sure about the Fixes commit. Please change it if you know a better one.

---
 mm/slub.c | 2 ++
 1 file changed, 2 insertions(+)
mm/slub.c +2 -0
index 1559cbace469..8400df7c222e 100644
@@ -8354,6 +8354,8 @@ static int __init setup_slub_min_order(const char *str, const struct kernel_para
 	if (ret)
 		return ret;
 
+	slub_min_order = min_t(unsigned int, slub_min_order, MAX_PAGE_ORDER);
+
 	if (slub_min_order > slub_max_order)
 		slub_max_order = slub_min_order;
 

base-commit: d755441b7672c74f29d1241ffdd2b067ecab1ca0

Signature · 1 line
2.43.0
Signature · 2 lines
Cheers,
Harry / Hyeonggon
#2 lore raw

Hi, Harry

2026년 10월 8일 (목) 오전 2:47, Harry Yoo <[email protected]>님이 작성:

Quoted 8 lines · Sang-Heon Jeon
Quoted 6 lines

setup_slub_max_order() clamps slab_max_order to MAX_PAGE_ORDER, but setup_slub_min_order() has no such clamp.

The buddy allocator cannot allocate more than 2^MAX_PAGE_ORDER pages at once, so slab_min_order above it makes no sense.

Quoted 8 lines
Quoted 6 lines

If slab_min_order is set above MAX_PAGE_ORDER, it can even panic at boot or invoke undefined behavior in order_objects().

So clamp slab_min_order to MAX_PAGE_ORDER as well.

Fixes 818cf5909701 ("slub: enforce MAX_ORDER")

I think Fixes: should be the commit that introduced slub_min_order.

Thanks for your guidance. I'll switch this to 81819f0fc828 ("SLUB core") in v2.

Quoted 4 lines
Quoted 1 line

And no need for Cc: stable? It's been there for decades and people should realize the kernel parameter is broken when it doesn't boot.

Okay, I'll remove it in v2.

Quoted 1 line

Otherwise looks good to me.

Thanks for the review :)

Quoted 51 lines
Quoted 51 lines

---
QEMU-based test results

- Booted with "slab_min_order=20"

1) AS-IS (before fix)

[    0.094926] mem auto-init: stack:all(zero), heap alloc:off, heap free:off
[    0.097776] Kernel panic - not syncing: Creation of kmalloc slab kmem_cache_node size=64 failed. Reason -22
[    0.099542] CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 7.2.0 #1 PREEMPT(undef)
[    0.100903] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[    0.102607] Call Trace:
[    0.103040]  <TASK>
[    0.103417]  vpanic+0x32a/0x4b0
[    0.103976]  panic+0x5e/0x60
[    0.104491]  create_boot_cache+0xe3/0xf0
[    0.105194]  kmem_cache_init+0x12d/0x410
[    0.105890]  ? mem_init+0x1fc/0x210
[    0.106521]  mm_core_init+0xba/0x140
[    0.107153]  start_kernel+0x441/0x8b0
[    0.107814]  x86_64_start_reservations+0x18/0x30
[    0.108638]  x86_64_start_kernel+0x10c/0x120
[    0.109401]  common_startup_64+0x13e/0x158
[    0.110145]  </TASK>
[    0.110584] ---[ end Kernel panic - not syncing: Creation of kmalloc slab kmem_cache_node size=64 failed. Reason -22 ]---

2) TO-BE (after fix)

[    0.008976] mem auto-init: stack:all(zero), heap alloc:off, heap free:off
[    0.011366] SLUB: HWalign=64, Order=10-10, MinObjects=0, CPUs=4, Nodes=1

Also, I'm not sure about the Fixes commit. Please change it if you know a better one.

---
 mm/slub.c | 2 ++
 1 file changed, 2 insertions(+)
mm/slub.c +2 -0
index 1559cbace469..8400df7c222e 100644
@@ -8354,6 +8354,8 @@ static int __init setup_slub_min_order(const char *str, const struct kernel_para
      if (ret)
              return ret;
 
+     slub_min_order = min_t(unsigned int, slub_min_order, MAX_PAGE_ORDER);
+
      if (slub_min_order > slub_max_order)
              slub_max_order = slub_min_order;
 
Quoted 8 lines
Quoted 4 lines

base-commit: d755441b7672c74f29d1241ffdd2b067ecab1ca0 --
2.43.0

--
Cheers,
Harry / Hyeonggon

Best regards,
Sang-Heon Jeon