linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 mm-hotfixes] mm/zsmalloc: do not pass __GFP_MOVABLE if CONFIG_COMPACTION=n
@ 2025-07-04 10:30 Harry Yoo
  2025-07-04 10:38 ` Harry Yoo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Harry Yoo @ 2025-07-04 10:30 UTC (permalink / raw)
  To: akpm, Minchan Kim, Sergey Senozhatsky
  Cc: David Hildenbrand, linux-mm, Harry Yoo, stable

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).

Cc: stable@vger.kernel.org
Fixes: 48b4800a1c6a ("zsmalloc: page migration support")
Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
---
 mm/zsmalloc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 999b513c7fdf..f3e2215f95eb 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -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;
-- 
2.43.0



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

* Re: [PATCH v1 mm-hotfixes] mm/zsmalloc: do not pass __GFP_MOVABLE if CONFIG_COMPACTION=n
  2025-07-04 10:30 [PATCH v1 mm-hotfixes] mm/zsmalloc: do not pass __GFP_MOVABLE if CONFIG_COMPACTION=n Harry Yoo
@ 2025-07-04 10:38 ` Harry Yoo
  2025-07-04 10:42 ` David Hildenbrand
  2025-07-07  7:58 ` Sergey Senozhatsky
  2 siblings, 0 replies; 4+ messages in thread
From: Harry Yoo @ 2025-07-04 10:38 UTC (permalink / raw)
  To: akpm, Minchan Kim, Sergey Senozhatsky; +Cc: David Hildenbrand, linux-mm, stable

On Fri, Jul 04, 2025 at 07:30:53PM +0900, Harry Yoo wrote:
> 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).
> 
> Cc: stable@vger.kernel.org
> Fixes: 48b4800a1c6a ("zsmalloc: page migration support")
> Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
> ---

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 :(

>  mm/zsmalloc.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index 999b513c7fdf..f3e2215f95eb 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -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;
> -- 
> 2.43.0
> 

-- 
Cheers,
Harry / Hyeonggon


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

* Re: [PATCH v1 mm-hotfixes] mm/zsmalloc: do not pass __GFP_MOVABLE if CONFIG_COMPACTION=n
  2025-07-04 10:30 [PATCH v1 mm-hotfixes] mm/zsmalloc: do not pass __GFP_MOVABLE if CONFIG_COMPACTION=n Harry Yoo
  2025-07-04 10:38 ` Harry Yoo
@ 2025-07-04 10:42 ` David Hildenbrand
  2025-07-07  7:58 ` Sergey Senozhatsky
  2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2025-07-04 10:42 UTC (permalink / raw)
  To: Harry Yoo, akpm, Minchan Kim, Sergey Senozhatsky; +Cc: linux-mm, stable

On 04.07.25 12:30, Harry Yoo wrote:
> 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).
> 
> Cc: stable@vger.kernel.org
> Fixes: 48b4800a1c6a ("zsmalloc: page migration support")
> Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
> ---
>   mm/zsmalloc.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index 999b513c7fdf..f3e2215f95eb 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -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.

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



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

* Re: [PATCH v1 mm-hotfixes] mm/zsmalloc: do not pass __GFP_MOVABLE if CONFIG_COMPACTION=n
  2025-07-04 10:30 [PATCH v1 mm-hotfixes] mm/zsmalloc: do not pass __GFP_MOVABLE if CONFIG_COMPACTION=n Harry Yoo
  2025-07-04 10:38 ` Harry Yoo
  2025-07-04 10:42 ` David Hildenbrand
@ 2025-07-07  7:58 ` Sergey Senozhatsky
  2 siblings, 0 replies; 4+ messages in thread
From: Sergey Senozhatsky @ 2025-07-07  7:58 UTC (permalink / raw)
  To: Harry Yoo
  Cc: akpm, Minchan Kim, Sergey Senozhatsky, David Hildenbrand,
	linux-mm, stable

On (25/07/04 19:30), Harry Yoo wrote:
> 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).
> 
> Cc: stable@vger.kernel.org
> Fixes: 48b4800a1c6a ("zsmalloc: page migration support")
> Signed-off-by: Harry Yoo <harry.yoo@oracle.com>

Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>


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

end of thread, other threads:[~2025-07-07  7:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-04 10:30 [PATCH v1 mm-hotfixes] mm/zsmalloc: do not pass __GFP_MOVABLE if CONFIG_COMPACTION=n Harry Yoo
2025-07-04 10:38 ` Harry Yoo
2025-07-04 10:42 ` David Hildenbrand
2025-07-07  7:58 ` Sergey Senozhatsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).