Skip to contentSkip to conversation

mm/zsmalloc: do not pass __GFP_MOVABLE if CONFIG_COMPACTION=n

PATCH Applied Harry Yoo 3 participants 4 messages Jul 4, 2025 – Jul 7, 2025

Subsystems (3)
lore
Share & tools
lore

Harry Yoo

author
#0 lore raw

PATCH 1/1 mm/zsmalloc: do not pass __GFP_MOVABLE if CONFIG_COMPACTION=n

Commit 48b4800a1c6a ("zsmalloc: page migration support") added support for migrating zsmalloc pages using the movable_operations migration framework. However, the commit did not take into account that zsmalloc supports migration only when CONFIG_COMPACTION is enabled. Tracing shows that zsmalloc was still passing the __GFP_MOVABLE flag even when compaction is not supported.

This can result in unmovable pages being allocated from movable page blocks (even without stealing page blocks), ZONE_MOVABLE and CMA area.

Clear the __GFP_MOVABLE flag when !IS_ENABLED(CONFIG_COMPACTION).

Fixes 48b4800a1c6a ("zsmalloc: page migration support")
---
 mm/zsmalloc.c | 3 +++
 1 file changed, 3 insertions(+)
mm/zsmalloc.c +3 -0
index 999b513c7fdf..f3e2215f95eb 100644
@@ -1043,6 +1043,9 @@ static struct zspage *alloc_zspage(struct zs_pool *pool,
 	if (!zspage)
 		return NULL;
 
+	if (!IS_ENABLED(CONFIG_COMPACTION))
+		gfp &= ~__GFP_MOVABLE;
+
 	zspage->magic = ZSPAGE_MAGIC;
 	zspage->pool = pool;
 	zspage->class = class->index;
Signature · 1 line
2.43.0
author
#1 lore raw
Quoted 10 lines · Harry Yoo

Commit 48b4800a1c6a ("zsmalloc: page migration support") added support for migrating zsmalloc pages using the movable_operations migration framework. However, the commit did not take into account that zsmalloc supports migration only when CONFIG_COMPACTION is enabled. Tracing shows that zsmalloc was still passing the __GFP_MOVABLE flag even when compaction is not supported.

This can result in unmovable pages being allocated from movable page blocks (even without stealing page blocks), ZONE_MOVABLE and CMA area.

Quoted 6 lines

Clear the __GFP_MOVABLE flag when !IS_ENABLED(CONFIG_COMPACTION).

Fixes 48b4800a1c6a ("zsmalloc: page migration support")

---

Possible user visible effects:
- Some ZONE_MOVABLE memory can be not actually movable
- CMA allocation can fail because of this
- Increased memory fragmentation due to ignoring the page mobility grouping feature

I'm not really sure who uses kernels without compaction support, though :(

Quoted 20 lines
 mm/zsmalloc.c | 3 +++
 1 file changed, 3 insertions(+)
mm/zsmalloc.c +3 -0
index 999b513c7fdf..f3e2215f95eb 100644
@@ -1043,6 +1043,9 @@ static struct zspage *alloc_zspage(struct zs_pool *pool,
 	if (!zspage)
 		return NULL;
 
+	if (!IS_ENABLED(CONFIG_COMPACTION))
+		gfp &= ~__GFP_MOVABLE;
+
 	zspage->magic = ZSPAGE_MAGIC;
 	zspage->pool = pool;
 	zspage->class = class->index;
Signature · 1 line
2.43.0
Signature · 2 lines
Cheers,
Harry / Hyeonggon
Acked-by on v1 1/1
#2 lore raw
In reply to Harry Yoo
Quoted 24 lines · Harry Yoo

Commit 48b4800a1c6a ("zsmalloc: page migration support") added support for migrating zsmalloc pages using the movable_operations migration framework. However, the commit did not take into account that zsmalloc supports migration only when CONFIG_COMPACTION is enabled. Tracing shows that zsmalloc was still passing the __GFP_MOVABLE flag even when compaction is not supported.

This can result in unmovable pages being allocated from movable page blocks (even without stealing page blocks), ZONE_MOVABLE and CMA area.

Clear the __GFP_MOVABLE flag when !IS_ENABLED(CONFIG_COMPACTION).

Fixes 48b4800a1c6a ("zsmalloc: page migration support")
---
  mm/zsmalloc.c | 3 +++
  1 file changed, 3 insertions(+)
mm/zsmalloc.c +0 -0
index 999b513c7fdf..f3e2215f95eb 100644

mm/zsmalloc.c static struct zspage *alloc_zspage(struct zs_pool *pool, · line 1051

Quoted 9 lines
mm/zsmalloc.c +3 -0
@@ -1043,6 +1043,9 @@ static struct zspage *alloc_zspage(struct zs_pool *pool,
  	if (!zspage)
  		return NULL;
 
+	if (!IS_ENABLED(CONFIG_COMPACTION))
+		gfp &= ~__GFP_MOVABLE;
+
  	zspage->magic = ZSPAGE_MAGIC;
  	zspage->pool = pool;
  	zspage->class = class->index;

IIUC, the real problem was exposed once zsmalloc allocation users started passing __GFP_MOVABLE.

Probably zpool_malloc_support_movable() was used for determining that at some point.

Signature · 3 lines
Cheers,

David / dhildenb
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Harry Yoo
Quoted 7 lines · Harry Yoo

Commit 48b4800a1c6a ("zsmalloc: page migration support") added support for migrating zsmalloc pages using the movable_operations migration framework. However, the commit did not take into account that zsmalloc supports migration only when CONFIG_COMPACTION is enabled. Tracing shows that zsmalloc was still passing the __GFP_MOVABLE flag even when compaction is not supported.

Quoted 8 lines

This can result in unmovable pages being allocated from movable page blocks (even without stealing page blocks), ZONE_MOVABLE and CMA area.

Clear the __GFP_MOVABLE flag when !IS_ENABLED(CONFIG_COMPACTION).

Fixes 48b4800a1c6a ("zsmalloc: page migration support")