diff mbox series

[01/16] mm/page_alloc: ensure kswapd doesn't accidentally go to sleep

Message ID 20220909092451.24883-2-linmiaohe@huawei.com (mailing list archive)
State New
Headers show
Series A few cleanup patches for mm | expand

Commit Message

Miaohe Lin Sept. 9, 2022, 9:24 a.m. UTC
If ALLOC_KSWAPD is set, wake_all_kswapds() will be called to ensure
kswapd doesn't accidentally go to sleep. But when reserve_flags is
set, alloc_flags will be overwritten and ALLOC_KSWAPD is thus lost.
Preserve the ALLOC_KSWAPD flag in alloc_flags to ensure kswapd won't
go to sleep accidentally.

Fixes: 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/page_alloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

David Hildenbrand Sept. 9, 2022, 11:39 a.m. UTC | #1
On 09.09.22 11:24, Miaohe Lin wrote:
> If ALLOC_KSWAPD is set, wake_all_kswapds() will be called to ensure
> kswapd doesn't accidentally go to sleep. But when reserve_flags is
> set, alloc_flags will be overwritten and ALLOC_KSWAPD is thus lost.
> Preserve the ALLOC_KSWAPD flag in alloc_flags to ensure kswapd won't
> go to sleep accidentally.
> 
> Fixes: 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>   mm/page_alloc.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index ba5c9402a5cb..4b97a03fa2dd 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5147,7 +5147,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
>   
>   	reserve_flags = __gfp_pfmemalloc_flags(gfp_mask);
>   	if (reserve_flags)
> -		alloc_flags = gfp_to_alloc_flags_cma(gfp_mask, reserve_flags);
> +		alloc_flags = gfp_to_alloc_flags_cma(gfp_mask, reserve_flags) |
> +					  (alloc_flags & ALLOC_KSWAPD);
>   
>   	/*
>   	 * Reset the nodemask and zonelist iterators if memory policies can be

Acked-by: David Hildenbrand <david@redhat.com>
Anshuman Khandual Sept. 13, 2022, 7:02 a.m. UTC | #2
On 9/9/22 14:54, Miaohe Lin wrote:
> If ALLOC_KSWAPD is set, wake_all_kswapds() will be called to ensure
> kswapd doesn't accidentally go to sleep. But when reserve_flags is
> set, alloc_flags will be overwritten and ALLOC_KSWAPD is thus lost.
> Preserve the ALLOC_KSWAPD flag in alloc_flags to ensure kswapd won't
> go to sleep accidentally.

Currently wake_all_kswapds() gets skipped subsequently if ALLOC_KSWAPD
is lost, but this only happens when the 'retry:' loops is taken ?

> 
> Fixes: 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  mm/page_alloc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index ba5c9402a5cb..4b97a03fa2dd 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5147,7 +5147,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
>  
>  	reserve_flags = __gfp_pfmemalloc_flags(gfp_mask);
>  	if (reserve_flags)
> -		alloc_flags = gfp_to_alloc_flags_cma(gfp_mask, reserve_flags);
> +		alloc_flags = gfp_to_alloc_flags_cma(gfp_mask, reserve_flags) |
> +					  (alloc_flags & ALLOC_KSWAPD);
>  
>  	/*
>  	 * Reset the nodemask and zonelist iterators if memory policies can be
Matthew Wilcox Sept. 13, 2022, 7:58 a.m. UTC | #3
On Tue, Sep 13, 2022 at 12:32:50PM +0530, Anshuman Khandual wrote:
> 
> 
> On 9/9/22 14:54, Miaohe Lin wrote:
> > If ALLOC_KSWAPD is set, wake_all_kswapds() will be called to ensure
> > kswapd doesn't accidentally go to sleep. But when reserve_flags is
> > set, alloc_flags will be overwritten and ALLOC_KSWAPD is thus lost.
> > Preserve the ALLOC_KSWAPD flag in alloc_flags to ensure kswapd won't
> > go to sleep accidentally.
> 
> Currently wake_all_kswapds() gets skipped subsequently if ALLOC_KSWAPD
> is lost, but this only happens when the 'retry:' loops is taken ?

Right, but see the comment:

        /* Ensure kswapd doesn't accidentally go to sleep as long as we loop */

and that is not currently true.  I think that was an inadvertent change.
Particularly since the changelog for 0a79cdad5eb2 says "No functional
change".

> > 
> > Fixes: 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
> > Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> > ---
> >  mm/page_alloc.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> > index ba5c9402a5cb..4b97a03fa2dd 100644
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -5147,7 +5147,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
> >  
> >  	reserve_flags = __gfp_pfmemalloc_flags(gfp_mask);
> >  	if (reserve_flags)
> > -		alloc_flags = gfp_to_alloc_flags_cma(gfp_mask, reserve_flags);
> > +		alloc_flags = gfp_to_alloc_flags_cma(gfp_mask, reserve_flags) |
> > +					  (alloc_flags & ALLOC_KSWAPD);
> >  
> >  	/*
> >  	 * Reset the nodemask and zonelist iterators if memory policies can be
>
Anshuman Khandual Sept. 13, 2022, 11:23 a.m. UTC | #4
On 9/13/22 13:28, Matthew Wilcox wrote:
> On Tue, Sep 13, 2022 at 12:32:50PM +0530, Anshuman Khandual wrote:
>>
>> On 9/9/22 14:54, Miaohe Lin wrote:
>>> If ALLOC_KSWAPD is set, wake_all_kswapds() will be called to ensure
>>> kswapd doesn't accidentally go to sleep. But when reserve_flags is
>>> set, alloc_flags will be overwritten and ALLOC_KSWAPD is thus lost.
>>> Preserve the ALLOC_KSWAPD flag in alloc_flags to ensure kswapd won't
>>> go to sleep accidentally.
>> Currently wake_all_kswapds() gets skipped subsequently if ALLOC_KSWAPD
>> is lost, but this only happens when the 'retry:' loops is taken ?
> Right, but see the comment:
> 
>         /* Ensure kswapd doesn't accidentally go to sleep as long as we loop */
> 
> and that is not currently true.  I think that was an inadvertent change.
> Particularly since the changelog for 0a79cdad5eb2 says "No functional
> change".

Got it, thanks for the explanation.
Oscar Salvador Sept. 15, 2022, 4:34 a.m. UTC | #5
On Fri, Sep 09, 2022 at 05:24:36PM +0800, Miaohe Lin wrote:
> If ALLOC_KSWAPD is set, wake_all_kswapds() will be called to ensure
> kswapd doesn't accidentally go to sleep. But when reserve_flags is
> set, alloc_flags will be overwritten and ALLOC_KSWAPD is thus lost.
> Preserve the ALLOC_KSWAPD flag in alloc_flags to ensure kswapd won't
> go to sleep accidentally.
> 
> Fixes: 0a79cdad5eb2 ("mm: use alloc_flags to record if kswapd can wake")
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>

Reviewed-by: Oscar Salvador <osalvador@suse.de>

> ---
>  mm/page_alloc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index ba5c9402a5cb..4b97a03fa2dd 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5147,7 +5147,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
>  
>  	reserve_flags = __gfp_pfmemalloc_flags(gfp_mask);
>  	if (reserve_flags)
> -		alloc_flags = gfp_to_alloc_flags_cma(gfp_mask, reserve_flags);
> +		alloc_flags = gfp_to_alloc_flags_cma(gfp_mask, reserve_flags) |
> +					  (alloc_flags & ALLOC_KSWAPD);
>  
>  	/*
>  	 * Reset the nodemask and zonelist iterators if memory policies can be
> -- 
> 2.23.0
>
diff mbox series

Patch

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index ba5c9402a5cb..4b97a03fa2dd 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5147,7 +5147,8 @@  __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
 
 	reserve_flags = __gfp_pfmemalloc_flags(gfp_mask);
 	if (reserve_flags)
-		alloc_flags = gfp_to_alloc_flags_cma(gfp_mask, reserve_flags);
+		alloc_flags = gfp_to_alloc_flags_cma(gfp_mask, reserve_flags) |
+					  (alloc_flags & ALLOC_KSWAPD);
 
 	/*
 	 * Reset the nodemask and zonelist iterators if memory policies can be