Skip to contentSkip to conversation

mm/compaction: remove unnecessary order check in direct compact path

PATCH In review Ganesh Mahendran 3 participants 3 messages Jun 16, 2016 – Jun 21, 2016

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

PATCH v3 1/1 mm/compaction: remove unnecessary order check in direct compact path

In direct compact path, both __alloc_pages_direct_compact and try_to_compact_pages check (order == 0).

This patch removes the check in __alloc_pages_direct_compact() and move the modifying of current->flags to the entry point of direct page compaction where we really do the compaction.

---
v2:
remove the check in __alloc_pages_direct_compact - Anshuman Khandual
v3:
remove check in __alloc_pages_direct_compact and move current->flags modifying to try_to_compact_pages

---
 mm/compaction.c | 7 ++++++-
 mm/page_alloc.c | 5 -----
 2 files changed, 6 insertions(+), 6 deletions(-)
mm/compaction.c +6 -1
index fbb7b38..dcfaf57 100644
@@ -1686,12 +1686,16 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
 
 	*contended = COMPACT_CONTENDED_NONE;
 
-	/* Check if the GFP flags allow compaction */
+	/*
+	 * Check if this is an order-0 request and
+	 * if the GFP flags allow compaction.
+	 */
 	if (!order || !may_enter_fs || !may_perform_io)
 		return COMPACT_SKIPPED;
 
 	trace_mm_compaction_try_to_compact_pages(order, gfp_mask, mode);
 
+	current->flags |= PF_MEMALLOC;
 	/* Compact each zone in the list */
 	for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, ac->high_zoneidx,
 								ac->nodemask) {
@@ -1768,6 +1772,7 @@ break_loop:
 		all_zones_contended = 0;
 		break;
 	}
+	current->flags &= ~PF_MEMALLOC;
 
 	/*
 	 * If at least one zone wasn't deferred or skipped, we report if all
mm/page_alloc.c +0 -5
index b9ea618..dd3a2b6 100644
@@ -3173,13 +3173,8 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
 	struct page *page;
 	int contended_compaction;
 
-	if (!order)
-		return NULL;
-
-	current->flags |= PF_MEMALLOC;
 	*compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac,
 						mode, &contended_compaction);
-	current->flags &= ~PF_MEMALLOC;
 
 	if (*compact_result <= COMPACT_INACTIVE)
 		return NULL;
Signature · 7 lines
1.9.1

--
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>
#1 lore raw
Quoted 6 lines · Ganesh Mahendran

In direct compact path, both __alloc_pages_direct_compact and try_to_compact_pages check (order == 0).

This patch removes the check in __alloc_pages_direct_compact() and move the modifying of current->flags to the entry point of direct page compaction where we really do the compaction.

I do not have strong opinion on whether the order should be checked at try_to_compact_pages or __alloc_pages_direct_compact. The later one sounds more suitable because no further steps are really appropriate for order == 0. try_to_compact_pages is not used anywhere else to be order aware (maybe it will in future, who knows). But this all is a matter of taste.

[...]

mm/compaction.c enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order, · line 1692

Quoted 13 lines
mm/compaction.c +4 -1
index fbb7b38..dcfaf57 100644
@@ -1686,12 +1686,16 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
 
 	*contended = COMPACT_CONTENDED_NONE;
 
-	/* Check if the GFP flags allow compaction */
+	/*
+	 * Check if this is an order-0 request and
+	 * if the GFP flags allow compaction.
+	 */

If you are touching this comment then it would be appropriate to change it from "what is checked" into "why it is checked" because that is far from obvious from this context. Especially !fs/io part.

mm/compaction.c enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order, · line 1695

Quoted 3 lines
mm/compaction.c +0 -0
 	if (!order || !may_enter_fs || !may_perform_io)
 		return COMPACT_SKIPPED;
 

That being said, I am not really sure the patch is an improvement. If anything I would much rather see the above comment updated.

Thanks!

Signature · 2 lines
Michal Hocko
SUSE Labs
#2 lore raw
In reply to Ganesh Mahendran

mm/compaction.c enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order, · line 1692

Quoted 13 lines · Ganesh Mahendran
mm/compaction.c +4 -1
index fbb7b38..dcfaf57 100644
@@ -1686,12 +1686,16 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
 
 	*contended = COMPACT_CONTENDED_NONE;
 
-	/* Check if the GFP flags allow compaction */
+	/*
+	 * Check if this is an order-0 request and
+	 * if the GFP flags allow compaction.
+	 */

This seems obvious.

Quoted 10 lines
mm/compaction.c +1 -0
 	if (!order || !may_enter_fs || !may_perform_io)
 		return COMPACT_SKIPPED;
 
 	trace_mm_compaction_try_to_compact_pages(order, gfp_mask, mode);
 
+	current->flags |= PF_MEMALLOC;
 	/* Compact each zone in the list */
 	for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, ac->high_zoneidx,
 								ac->nodemask) {

mm/compaction.c break_loop: · line 1778

Quoted 7 lines
mm/compaction.c +1 -0
@@ -1768,6 +1772,7 @@ break_loop:
 		all_zones_contended = 0;
 		break;
 	}
+	current->flags &= ~PF_MEMALLOC;
 
 	/*
 	 * If at least one zone wasn't deferred or skipped, we report if all

Compaction don't touch task_struct flags and PF_MEMALLOC is flag used primarily by the page allocator, moving this to try_to_compact_pages() doesn't make sense.

You could remove the !order check in try_to_compact_pages(), but I don't think it offers anything substantial.

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