mm/page_alloc: skip setting nodemask when we are in interrupt
Subsystems (2)
PATCH RESEND 1/1 mm/page_alloc: skip setting nodemask when we are in interrupt
When we are in the interrupt context, it is irrelevant to the current task context. If we use current task's mems_allowed, we can fair to alloc pages in the fast path and fall back to slow path memory allocation when the current node(which is the current task mems_allowed) does not have enough memory to allocate. In this case, it slows down the memory allocation speed of interrupt context. So we can skip setting the nodemask to allow any node to allocate memory, so that fast path allocation can success.
--- mm/page_alloc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
mm/page_alloc.c +5 -3
@@ -4726,10 +4726,12 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,if (cpusets_enabled ()) { *alloc_mask |= __GFP_HARDWALL; -if (!ac->nodemask) - ac->nodemask = &cpuset_current_mems_allowed; -else +if (!ac->nodemask) { +if (!in_interrupt ()) + ac->nodemask = &cpuset_current_mems_allowed; + }else { *alloc_flags |=ALLOC_CPUSET ; + } }fs_reclaim_acquire (gfp_mask);
Signature · 1 line
2.11.0
Quoted 20 lines · Muchun Song
When we are in the interrupt context, it is irrelevant to the current task context. If we use current task's
mems_allowed, we can fair to alloc pages in the fast path and fall back to slow path memory allocation when the currentnode(which is the current task mems_allowed)does not have enough memory to allocate. In this case, it slows down the memory allocation speed of interrupt context. So we can skip setting the nodemask to allow any node to allocate memory, so that fast path allocation can success.Signed-off-by Muchun Song <[email protected]>--- mm/page_alloc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)mm/page_alloc.c +0
-0
mm/page_alloc.c static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, · line 4731
Quoted 9 lines
mm/page_alloc.c +3
-3@@ -4726,10 +4726,12 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,if (cpusets_enabled ()) { *alloc_mask |= __GFP_HARDWALL; -if (!ac->nodemask) - ac->nodemask = &cpuset_current_mems_allowed; -else +if (!ac->nodemask) { +if (!in_interrupt ()) + ac->nodemask = &cpuset_current_mems_allowed;
If !ac->nodemask and in_interrupt() the ALLOC_CPUSET flag is not set, which by-passes the __cpuset_zone_allowed() check for allocations. This works fine because in the case if in_interrupt() the function allows allocation on any zone/node.
mm/page_alloc.c static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, · line 4735
Quoted 4 lines
mm/page_alloc.c +2
-0+ }else { *alloc_flags |=ALLOC_CPUSET ; + } }
However, if you write the condition as follows:
if (cpusets_enabled()) {
*alloc_mask |= __GFP_HARDWALL;
if (!in_interrupt() && !ac->nodemask)
ac->nodemask = &cpuset_current_mems_allowed;
else
*alloc_flags |= ALLOC_CPUSET;
}then the code is future-proof in case of __cpuset_zone_allowed() is one day extended to support IRQ context too (it probably should eventually respect IRQ SMP affinity).
Quoted 6 lines
mm/page_alloc.c +0
-1fs_reclaim_acquire (gfp_mask); --2.11.0
Quoted 43 lines · Pekka Enberg
Quoted 20 lines · Muchun Song
When we are in the interrupt context, it is irrelevant to the current task context. If we use current task's
mems_allowed, we can fair to alloc pages in the fast path and fall back to slow path memory allocation when the currentnode(which is the current task mems_allowed)does not have enough memory to allocate. In this case, it slows down the memory allocation speed of interrupt context. So we can skip setting the nodemask to allow any node to allocate memory, so that fast path allocation can success.Signed-off-by Muchun Song <[email protected]>--- mm/page_alloc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)mm/page_alloc.c +0
-0mm/page_alloc.c static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, · line 4731
Quoted 9 lines
mm/page_alloc.c +3
-3@@ -4726,10 +4726,12 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,if (cpusets_enabled ()) { *alloc_mask |= __GFP_HARDWALL; -if (!ac->nodemask) - ac->nodemask = &cpuset_current_mems_allowed; -else +if (!ac->nodemask) { +if (!in_interrupt ()) + ac->nodemask = &cpuset_current_mems_allowed;If !ac->nodemask and
in_interrupt()theALLOC_CPUSETflag is not set, which by-passes the__cpuset_zone_allowed()check for allocations. This works fine because in the case ifin_interrupt()the function allows allocation on any zone/node.mm/page_alloc.c static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, · line 4735
Quoted 4 lines
mm/page_alloc.c +2
-0+ }else { *alloc_flags |=ALLOC_CPUSET ; + } }However, if you write the condition as follows:
Quoted 7 lines
if (cpusets_enabled()) {
*alloc_mask |= __GFP_HARDWALL;
if (!in_interrupt() && !ac->nodemask)
ac->nodemask = &cpuset_current_mems_allowed;
else
*alloc_flags |= ALLOC_CPUSET;
}^ looks much cleaner as well. Do we want to add a summarizing comment?
Quoted 4 lines
then the code is future-proof in case of
__cpuset_zone_allowed()is one day extended to support IRQ context too (it probably should eventually respect IRQ SMP affinity).
Signature · 3 lines
Thanks, David / dhildenb
Quoted 7 lines · Pekka Enberg
Quoted 7 lines
if (cpusets_enabled()) { *alloc_mask |= __GFP_HARDWALL; if (!in_interrupt() && !ac->nodemask) ac->nodemask = &cpuset_current_mems_allowed; else *alloc_flags |= ALLOC_CPUSET; }
Quoted 1 line · David Hildenbrand
^ looks much cleaner as well. Do we want to add a summarizing comment?
I see no harm in adding one. I'm sure the next person starting a journey in the maze some call the page allocator will appreciate it.
- Pekka