Skip to contentSkip to conversation

mm/page_alloc.c: avoid inheritting current's flags when invoked in interrupt

PATCH In review [email protected] 2 participants 3 messages Sep 15, 2020 – Sep 16, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/page_alloc.c: avoid inheritting current's flags when invoked in interrupt

From: Yanfei Xu <[email protected]>

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

---
 mm/page_alloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
index fab5e97dc9ca..388b587b35a8 100644
@@ -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;
 
 	/*
Signature · 1 line
2.18.2
maintainer
#1 lore raw
Quoted 10 lines · On Tue, 15 Sep 2020 15:56:35 +0800 <[email protected]> wrote:

From: Yanfei Xu <[email protected]>

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

...

mm/page_alloc.c __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid, · line 4896

Quoted 9 lines
mm/page_alloc.c +2 -1
@@ -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.

author
#2 lore raw
Quoted 20 lines · Andrew Morton
Quoted 18 lines · On Tue, 15 Sep 2020 15:56:35 +0800 <[email protected]> wrote:

From: Yanfei Xu <[email protected]>

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

...

mm/page_alloc.c +2 -1
@@ -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;
 
Quoted 8 lines

mm/page_alloc.c __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid, · line 4896

Quoted 1 line
mm/page_alloc.c +0 -0
  	/*

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