Skip to content

Commit c5d01d0

Browse files
Michal Hockotorvalds
authored andcommitted
mm, compaction: simplify __alloc_pages_direct_compact feedback interface
__alloc_pages_direct_compact communicates potential back off by two variables: - deferred_compaction tells that the compaction returned COMPACT_DEFERRED - contended_compaction is set when there is a contention on zone->lock resp. zone->lru_lock locks __alloc_pages_slowpath then backs of for THP allocation requests to prevent from long stalls. This is rather messy and it would be much cleaner to return a single compact result value and hide all the nasty details into __alloc_pages_direct_compact. This patch shouldn't introduce any functional changes. Signed-off-by: Michal Hocko <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Acked-by: Hillf Danton <[email protected]> Cc: David Rientjes <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Tetsuo Handa <[email protected]> Cc: Vladimir Davydov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 4f9a358 commit c5d01d0

File tree

1 file changed

+31
-36
lines changed

1 file changed

+31
-36
lines changed

mm/page_alloc.c

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,29 +3185,21 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
31853185
static struct page *
31863186
__alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
31873187
unsigned int alloc_flags, const struct alloc_context *ac,
3188-
enum migrate_mode mode, int *contended_compaction,
3189-
bool *deferred_compaction)
3188+
enum migrate_mode mode, enum compact_result *compact_result)
31903189
{
3191-
enum compact_result compact_result;
31923190
struct page *page;
3191+
int contended_compaction;
31933192

31943193
if (!order)
31953194
return NULL;
31963195

31973196
current->flags |= PF_MEMALLOC;
3198-
compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac,
3199-
mode, contended_compaction);
3197+
*compact_result = try_to_compact_pages(gfp_mask, order, alloc_flags, ac,
3198+
mode, &contended_compaction);
32003199
current->flags &= ~PF_MEMALLOC;
32013200

3202-
switch (compact_result) {
3203-
case COMPACT_DEFERRED:
3204-
*deferred_compaction = true;
3205-
/* fall-through */
3206-
case COMPACT_SKIPPED:
3201+
if (*compact_result <= COMPACT_INACTIVE)
32073202
return NULL;
3208-
default:
3209-
break;
3210-
}
32113203

32123204
/*
32133205
* At least in one zone compaction wasn't deferred or skipped, so let's
@@ -3233,6 +3225,24 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
32333225
*/
32343226
count_vm_event(COMPACTFAIL);
32353227

3228+
/*
3229+
* In all zones where compaction was attempted (and not
3230+
* deferred or skipped), lock contention has been detected.
3231+
* For THP allocation we do not want to disrupt the others
3232+
* so we fallback to base pages instead.
3233+
*/
3234+
if (contended_compaction == COMPACT_CONTENDED_LOCK)
3235+
*compact_result = COMPACT_CONTENDED;
3236+
3237+
/*
3238+
* If compaction was aborted due to need_resched(), we do not
3239+
* want to further increase allocation latency, unless it is
3240+
* khugepaged trying to collapse.
3241+
*/
3242+
if (contended_compaction == COMPACT_CONTENDED_SCHED
3243+
&& !(current->flags & PF_KTHREAD))
3244+
*compact_result = COMPACT_CONTENDED;
3245+
32363246
cond_resched();
32373247

32383248
return NULL;
@@ -3241,8 +3251,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
32413251
static inline struct page *
32423252
__alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
32433253
unsigned int alloc_flags, const struct alloc_context *ac,
3244-
enum migrate_mode mode, int *contended_compaction,
3245-
bool *deferred_compaction)
3254+
enum migrate_mode mode, enum compact_result *compact_result)
32463255
{
32473256
return NULL;
32483257
}
@@ -3387,8 +3396,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
33873396
unsigned long pages_reclaimed = 0;
33883397
unsigned long did_some_progress;
33893398
enum migrate_mode migration_mode = MIGRATE_ASYNC;
3390-
bool deferred_compaction = false;
3391-
int contended_compaction = COMPACT_CONTENDED_NONE;
3399+
enum compact_result compact_result;
33923400

33933401
/*
33943402
* In the slowpath, we sanity check order to avoid ever trying to
@@ -3475,8 +3483,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
34753483
*/
34763484
page = __alloc_pages_direct_compact(gfp_mask, order, alloc_flags, ac,
34773485
migration_mode,
3478-
&contended_compaction,
3479-
&deferred_compaction);
3486+
&compact_result);
34803487
if (page)
34813488
goto got_pg;
34823489

@@ -3489,25 +3496,14 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
34893496
* to heavily disrupt the system, so we fail the allocation
34903497
* instead of entering direct reclaim.
34913498
*/
3492-
if (deferred_compaction)
3493-
goto nopage;
3494-
3495-
/*
3496-
* In all zones where compaction was attempted (and not
3497-
* deferred or skipped), lock contention has been detected.
3498-
* For THP allocation we do not want to disrupt the others
3499-
* so we fallback to base pages instead.
3500-
*/
3501-
if (contended_compaction == COMPACT_CONTENDED_LOCK)
3499+
if (compact_result == COMPACT_DEFERRED)
35023500
goto nopage;
35033501

35043502
/*
3505-
* If compaction was aborted due to need_resched(), we do not
3506-
* want to further increase allocation latency, unless it is
3507-
* khugepaged trying to collapse.
3503+
* Compaction is contended so rather back off than cause
3504+
* excessive stalls.
35083505
*/
3509-
if (contended_compaction == COMPACT_CONTENDED_SCHED
3510-
&& !(current->flags & PF_KTHREAD))
3506+
if(compact_result == COMPACT_CONTENDED)
35113507
goto nopage;
35123508
}
35133509

@@ -3555,8 +3551,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
35553551
*/
35563552
page = __alloc_pages_direct_compact(gfp_mask, order, alloc_flags,
35573553
ac, migration_mode,
3558-
&contended_compaction,
3559-
&deferred_compaction);
3554+
&compact_result);
35603555
if (page)
35613556
goto got_pg;
35623557
nopage:

0 commit comments

Comments
 (0)