mm, compaction: simplify contended compaction handling
Subsystems (3)
[email protected]
maintainerPATCH 101/101 mm, compaction: simplify contended compaction handling
From: Vlastimil Babka <[email protected]>
Subject: mm, compaction: simplify contended compaction handling
Async compaction detects contention either due to failing trylock on zone->lock or lru_lock, or by need_resched(). Since 1f9efdef4f3f ("mm,
compaction: khugepaged should not give up due to need_resched()") the code got quite complicated to distinguish these two up to the __alloc_pages_slowpath() level, so different decisions could be taken for khugepaged allocations.
After the recent changes, khugepaged allocations don't check for contended compaction anymore, so we again don't need to distinguish lock and sched contention, and simplify the current convoluted code a lot.
However, I believe it's also possible to simplify even more and completely remove the check for contended compaction after the initial async compaction for costly orders, which was originally aimed at THP page fault allocations. There are several reasons why this can be done now:
- with the new defaults, THP page faults no longer do reclaim/compaction at all, unless the system admin has overridden the default, or application has indicated via madvise that it can benefit from THP's. In both cases, it means that the potential extra latency is expected and worth the benefits.
- even if reclaim/compaction proceeds after this patch where it previously wouldn't, the second compaction attempt is still async and will detect the contention and back off, if the contention persists
- there are still heuristics like deferred compaction and pageblock skip bits in place that prevent excessive THP page fault latencies
---
include/linux/compaction.h | 13 ------ mm/compaction.c | 72 ++++++----------------------------- mm/internal.h | 5 -- mm/page_alloc.c | 28 ------------- 4 files changed, 17 insertions(+), 101 deletions(-)
include/linux/compaction.h renamed from include/linux/compaction.h~mm-compaction-simplify-contended-compaction-handling +2 -11
@@ -55,14 +55,6 @@ enum compact_result { COMPACT_PARTIAL, }; -/* Used to signal whether compaction detected need_sched() or lock contention */ -/* No contention detected */ -#define COMPACT_CONTENDED_NONE 0 -/* Either need_sched() was true or fatal signal pending */ -#define COMPACT_CONTENDED_SCHED 1 -/* Zone lock or lru_lock was contended in async compaction */ -#define COMPACT_CONTENDED_LOCK 2 -struct alloc_context ;/* in mm/internal.h */ #ifdef CONFIG_COMPACTION
@@ -76,9 +68,8 @@ extern int sysctl_compact_unevictable_alextern int fragmentation_index (struct zone *zone,unsigned int order);extern enum compact_result try_to_compact_pages (gfp_t gfp_mask, -unsigned int order, -unsigned int alloc_flags,const struct alloc_context *ac, -enum compact_priority prio,int *contended); +unsigned int order,unsigned int alloc_flags, +const struct alloc_context *ac,enum compact_priority prio);extern void compact_pgdat (pg_data_t *pgdat,int order);extern void reset_isolation_suitable (pg_data_t *pgdat); extern enum compact_result compaction_suitable(struct zone *zone, int order,
mm/compaction.c renamed from mm/compaction.c~mm-compaction-simplify-contended-compaction-handling +13 -59
164 lines not on this page · raw message
mm/internal.h renamed from mm/internal.h~mm-compaction-simplify-contended-compaction-handling +1 -4
@@ -185,10 +185,7 @@ struct compact_control {const unsigned int alloc_flags;/* alloc flags of a direct compactor */ const int classzone_idx;/* zone index of a direct compactor */ struct zone *zone; -int contended;/* Signal need_sched() or lock -* contention detected during -* compaction -*/ +bool contended;/* Signal lock or sched contention */ };unsigned long
mm/page_alloc.c renamed from mm/page_alloc.c~mm-compaction-simplify-contended-compaction-handling +1 -25
@@ -3099,14 +3099,13 @@ __alloc_pages_direct_compact(gfp_t gfp_m enum compact_priority prio, enum compact_result *compact_result) { 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, - prio, &contended_compaction); + prio); current->flags &= ~PF_MEMALLOC ;if (*compact_result <=COMPACT_INACTIVE )
@@ -3135,24 +3134,6 @@ __alloc_pages_direct_compact(gfp_t gfp_m*/ count_vm_event (COMPACTFAIL ); -/* -* In all zones where compaction was attempted (and not -* deferred or skipped), lock contention has been detected. -* For THP allocation we do not want to disrupt the others -* so we fallback to base pages instead. -*/ -if (contended_compaction ==COMPACT_CONTENDED_LOCK ) - *compact_result =COMPACT_CONTENDED ; - -/* -* If compaction was aborted due to need_resched(), we do not -* want to further increase allocation latency, unless it is -* khugepaged trying to collapse. -*/ -if (contended_compaction ==COMPACT_CONTENDED_SCHED - && !(current->flags &PF_KTHREAD )) - *compact_result =COMPACT_CONTENDED ; -cond_resched ();return NULL ;
@@ -3548,13 +3529,6 @@ __alloc_pages_slowpath(gfp_t gfp_mask, u goto nopage;/* -* Compaction is contended so rather back off than cause -* excessive stalls. -*/ -if (compact_result ==COMPACT_CONTENDED ) - goto nopage;