linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/page_alloc.c: avoid inheritting current's flags when invoked in interrupt
@ 2020-09-15  7:56 yanfei.xu
  2020-09-16  1:17 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: yanfei.xu @ 2020-09-15  7:56 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel

From: Yanfei Xu <yanfei.xu@windriver.com>

alloc_mask shouldn't inherit the current task's flags when
__alloc_pages_nodemask is invoked in interrupt.

Signed-off-by: Yanfei Xu <yanfei.xu@windriver.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 fab5e97dc9ca..388b587b35a8 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4889,7 +4889,8 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid,
 	 * from a particular context which has been marked by
 	 * memalloc_no{fs,io}_{save,restore}.
 	 */
-	alloc_mask = current_gfp_context(gfp_mask);
+	if (!in_interrupt())
+		alloc_mask = current_gfp_context(gfp_mask);
 	ac.spread_dirty_pages = false;
 
 	/*
-- 
2.18.2



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

* Re: [PATCH] mm/page_alloc.c: avoid inheritting current's flags when invoked in interrupt
  2020-09-15  7:56 [PATCH] mm/page_alloc.c: avoid inheritting current's flags when invoked in interrupt yanfei.xu
@ 2020-09-16  1:17 ` Andrew Morton
  2020-09-16  3:47   ` Xu, Yanfei
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2020-09-16  1:17 UTC (permalink / raw)
  To: yanfei.xu; +Cc: linux-mm, linux-kernel

On Tue, 15 Sep 2020 15:56:35 +0800 <yanfei.xu@windriver.com> wrote:

> From: Yanfei Xu <yanfei.xu@windriver.com>
> 
> alloc_mask shouldn't inherit the current task's flags when
> __alloc_pages_nodemask is invoked in interrupt.
> 
> ...
>
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -4889,7 +4889,8 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid,
>  	 * from a particular context which has been marked by
>  	 * memalloc_no{fs,io}_{save,restore}.
>  	 */
> -	alloc_mask = current_gfp_context(gfp_mask);
> +	if (!in_interrupt())
> +		alloc_mask = current_gfp_context(gfp_mask);
>  	ac.spread_dirty_pages = false;
>  
>  	/*

hm, yes, and perhaps other callsites in page_alloc.c.

I assume this doesn't actually make any runtime difference?  Because
gfp_mask in interrupt contexts isn't going to have __GFP_IO or __GFP_FS
anyway.


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

* Re: [PATCH] mm/page_alloc.c: avoid inheritting current's flags when invoked in interrupt
  2020-09-16  1:17 ` Andrew Morton
@ 2020-09-16  3:47   ` Xu, Yanfei
  0 siblings, 0 replies; 3+ messages in thread
From: Xu, Yanfei @ 2020-09-16  3:47 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel



On 9/16/20 9:17 AM, Andrew Morton wrote:
> On Tue, 15 Sep 2020 15:56:35 +0800 <yanfei.xu@windriver.com> wrote:
> 
>> From: Yanfei Xu <yanfei.xu@windriver.com>
>>
>> alloc_mask shouldn't inherit the current task's flags when
>> __alloc_pages_nodemask is invoked in interrupt.
>>
>> ...
>>
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -4889,7 +4889,8 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid,
>>   	 * from a particular context which has been marked by
>>   	 * memalloc_no{fs,io}_{save,restore}.
>>   	 */
>> -	alloc_mask = current_gfp_context(gfp_mask);
>> +	if (!in_interrupt())
>> +		alloc_mask = current_gfp_context(gfp_mask);
>>   	ac.spread_dirty_pages = false;
>>   
>>   	/*
> 
> hm, yes, and perhaps other callsites in page_alloc.c.
> 
> I assume this doesn't actually make any runtime difference?  Because
> gfp_mask in interrupt contexts isn't going to have __GFP_IO or __GFP_FS
> anyway.
> 
Thanks for your reply!

Yes, It doesn't make any runtime difference. Theoretically, GPF_ATOMIC 
or GFP_NOWAIT should be used in interrupt context for allocate pages, so
that gfp_mask isn't going to have __GFP_IO or __GFP_FS.

But if somebody use wrong gfp_masks, __GFP_IO or __GFP_FS will be 
introduced, with the process interrupted has PF_MEMALLOC_NOIO or 
PF_MEMALLOC_NOFS, current_gfp_context may help to hide these wrong 
usages. I don't think it is the original purpose of that piece of
codes.

And how about add BUG_ON or WARN_ON to figure out the situation which
introduce __GFP_IO or __GFP_FS in interrupt context?

Regards,
Yanfei


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

end of thread, other threads:[~2020-09-16  3:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-15  7:56 [PATCH] mm/page_alloc.c: avoid inheritting current's flags when invoked in interrupt yanfei.xu
2020-09-16  1:17 ` Andrew Morton
2020-09-16  3:47   ` Xu, Yanfei

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