[PATCH] mm/compaction: fix the total_isolated in strict mode

Qiang Liu posted 1 patch 3 weeks ago
mm/compaction.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] mm/compaction: fix the total_isolated in strict mode
Posted by Qiang Liu 3 weeks ago
If the last cycle reads bogus compound_order() and blockpfn > end_pfn occurs,
it is possible that total_isolated will be less than nr_scanned. In this case,
strict mode should return 0, but the “if (strict && blockpfn < end_pfn)”
statement cannot recognize this situation

Signed-off-by: Qiang Liu <liuq131@chinatelecom.cn>
---
 mm/compaction.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index a2b16b08cbbf..6009f5d1021a 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -699,7 +699,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
 	 * pages requested were isolated. If there were any failures, 0 is
 	 * returned and CMA will fail.
 	 */
-	if (strict && blockpfn < end_pfn)
+	if (strict && (blockpfn < end_pfn || total_isolated != nr_scanned))
 		total_isolated = 0;
 
 	cc->total_free_scanned += nr_scanned;
-- 
2.27.0

Re: [PATCH] mm/compaction: fix the total_isolated in strict mode
Posted by Baolin Wang 1 week, 5 days ago

On 2024/11/3 04:16, Qiang Liu wrote:
> If the last cycle reads bogus compound_order() and blockpfn > end_pfn occurs,

if blockpfn > end_pfn occurs, we will reset the blockpfn, right?

	/*
	 * Be careful to not go outside of the pageblock.
	 */
	if (unlikely(blockpfn > end_pfn))
		blockpfn = end_pfn;

So how this can happen?

> it is possible that total_isolated will be less than nr_scanned. In this case,
> strict mode should return 0, but the “if (strict && blockpfn < end_pfn)”
> statement cannot recognize this situation
> 
> Signed-off-by: Qiang Liu <liuq131@chinatelecom.cn>
> ---
>   mm/compaction.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/compaction.c b/mm/compaction.c
> index a2b16b08cbbf..6009f5d1021a 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -699,7 +699,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
>   	 * pages requested were isolated. If there were any failures, 0 is
>   	 * returned and CMA will fail.
>   	 */
> -	if (strict && blockpfn < end_pfn)
> +	if (strict && (blockpfn < end_pfn || total_isolated != nr_scanned))
>   		total_isolated = 0;
>   
>   	cc->total_free_scanned += nr_scanned;
Re: [PATCH] mm/compaction: fix the total_isolated in strict mode
Posted by Andrew Morton 1 week, 5 days ago
On Sat,  2 Nov 2024 20:16:21 +0000 Qiang Liu <liuq131@chinatelecom.cn> wrote:

> If the last cycle reads bogus compound_order() and blockpfn > end_pfn occurs,
> it is possible that total_isolated will be less than nr_scanned. In this case,
> strict mode should return 0, but the “if (strict && blockpfn < end_pfn)”
> statement cannot recognize this situation
> 
> ...
>
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -699,7 +699,7 @@ static unsigned long isolate_freepages_block(struct compact_control *cc,
>  	 * pages requested were isolated. If there were any failures, 0 is
>  	 * returned and CMA will fail.
>  	 */
> -	if (strict && blockpfn < end_pfn)
> +	if (strict && (blockpfn < end_pfn || total_isolated != nr_scanned))
>  		total_isolated = 0;
>  
>  	cc->total_free_scanned += nr_scanned;

That's really old code.  What userspace-visible effects might this
have?  Is this from code inspection, or was some misbehaviour observed?

Thanks.