Skip to contentSkip to conversation

mm, page_alloc: don't check cpuset allowed twice in fast-path

PATCH In review Vlastimil Babka 3 participants 4 messages Jan 6, 2017 – Jan 16, 2017

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

PATCH 1/1 mm, page_alloc: don't check cpuset allowed twice in fast-path

Since commit 682a3385e773 ("mm, page_alloc: inline the fast path of the zonelist iterator") we replace a NULL nodemask with cpuset_current_mems_allowed in the fast path, so that get_page_from_freelist() filters nodes allowed by the cpuset via for_next_zone_zonelist_nodemask(). In that case it's pointless to also check __cpuset_zone_allowed(), which we can avoid by not using ALLOC_CPUSET in that scenario.

---
 mm/page_alloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
index 2c6d5f64feca..3d86fbe2f4f4 100644
@@ -3754,9 +3754,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
 
 	if (cpusets_enabled()) {
 		alloc_mask |= __GFP_HARDWALL;
-		alloc_flags |= ALLOC_CPUSET;
 		if (!ac.nodemask)
 			ac.nodemask = &cpuset_current_mems_allowed;
+		else
+			alloc_flags |= ALLOC_CPUSET;
 	}
 
 	gfp_mask &= gfp_allowed_mask;
Signature · 7 lines
2.11.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Vlastimil Babka

Since commit 682a3385e773 ("mm, page_alloc: inline the fast path of the zonelist iterator") we replace a NULL nodemask with cpuset_current_mems_allowed in the fast path, so that get_page_from_freelist() filters nodes allowed by the cpuset via for_next_zone_zonelist_nodemask(). In that case it's pointless to also check __cpuset_zone_allowed(), which we can avoid by not using ALLOC_CPUSET in that scenario.

OK, this seems to be really worth it as most allocations go via __alloc_pages so we can save __cpuset_zone_allowed in the fast path.

I was about to object how fragile this might be wrt. other ALLOC_CPUSET checks but then I've realized this is only for the hotpath as the slowpath goes through gfp_to_alloc_flags() which sets it back on.

Maybe all that could be added to the changelog?

Quoted 1 line
Quoted 28 lines
---
 mm/page_alloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
index 2c6d5f64feca..3d86fbe2f4f4 100644
@@ -3754,9 +3754,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
 
 	if (cpusets_enabled()) {
 		alloc_mask |= __GFP_HARDWALL;
-		alloc_flags |= ALLOC_CPUSET;
 		if (!ac.nodemask)
 			ac.nodemask = &cpuset_current_mems_allowed;
+		else
+			alloc_flags |= ALLOC_CPUSET;
 	}
 
 	gfp_mask &= gfp_allowed_mask;
Signature · 7 lines
2.11.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
Quoted 10 lines · Michal Hocko
Quoted 6 lines · Vlastimil Babka

Since commit 682a3385e773 ("mm, page_alloc: inline the fast path of the zonelist iterator") we replace a NULL nodemask with cpuset_current_mems_allowed in the fast path, so that get_page_from_freelist() filters nodes allowed by the cpuset via for_next_zone_zonelist_nodemask(). In that case it's pointless to also check __cpuset_zone_allowed(), which we can avoid by not using ALLOC_CPUSET in that scenario.

OK, this seems to be really worth it as most allocations go via __alloc_pages so we can save __cpuset_zone_allowed in the fast path.

Well the "really fast path" assumes that there are no cpusets (except the root one), which is done using static key check in cpusets_enabled(). But we can still do better even if they are enabled.

Quoted 5 lines

I was about to object how fragile this might be wrt. other ALLOC_CPUSET checks but then I've realized this is only for the hotpath as the slowpath goes through gfp_to_alloc_flags() which sets it back on.

Maybe all that could be added to the changelog?

OK, will do after collecting more feedback.

Quoted 4 lines
Quoted 2 lines

Thanks!

Quoted 24 lines
Quoted 24 lines
---
 mm/page_alloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
index 2c6d5f64feca..3d86fbe2f4f4 100644
@@ -3754,9 +3754,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
 
 	if (cpusets_enabled()) {
 		alloc_mask |= __GFP_HARDWALL;
-		alloc_flags |= ALLOC_CPUSET;
 		if (!ac.nodemask)
 			ac.nodemask = &cpuset_current_mems_allowed;
+		else
+			alloc_flags |= ALLOC_CPUSET;
 	}
 
 	gfp_mask &= gfp_allowed_mask;
Signature · 1 line
2.11.0
Quoted 6 lines
Quoted 5 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Reviewed-by
#3 lore raw
In reply to Michal Hocko
Quoted 8 lines · Michal Hocko
Quoted 6 lines · Vlastimil Babka

Since commit 682a3385e773 ("mm, page_alloc: inline the fast path of the zonelist iterator") we replace a NULL nodemask with cpuset_current_mems_allowed in the fast path, so that get_page_from_freelist() filters nodes allowed by the cpuset via for_next_zone_zonelist_nodemask(). In that case it's pointless to also check __cpuset_zone_allowed(), which we can avoid by not using ALLOC_CPUSET in that scenario.

Quoted 8 lines

OK, this seems to be really worth it as most allocations go via __alloc_pages so we can save __cpuset_zone_allowed in the fast path.

I was about to object how fragile this might be wrt. other ALLOC_CPUSET checks but then I've realized this is only for the hotpath as the slowpath goes through gfp_to_alloc_flags() which sets it back on.

Maybe all that could be added to the changelog?

Agreed, all these should be added into the change log as the effect of cpuset based nodemask during fast path and slow path is little bit confusing.

Quoted 4 lines
Quoted 2 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>