Skip to content

Commit 769912d

Browse files
mjkravetzBrian Maly
authored andcommitted
mm: let page allocation slowpath retry 'order' times
In an effort to prevent premature page allocation failures, retry allocations in the slow path for up to 'order' times if retries are allowed. Orabug: 31295499 Signed-off-by: Mike Kravetz <[email protected]> Reviewed-by: Khalid Aziz <[email protected]> Signed-off-by: Brian Maly <[email protected]>
1 parent 2965ade commit 769912d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

mm/page_alloc.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,8 +2356,8 @@ void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...)
23562356

23572357
static inline int
23582358
should_alloc_retry(gfp_t gfp_mask, unsigned int order,
2359-
unsigned long did_some_progress,
2360-
unsigned long pages_reclaimed)
2359+
unsigned long did_some_progress,
2360+
unsigned long pages_reclaimed, int *alloc_retries)
23612361
{
23622362
/* Do not loop if specifically requested */
23632363
if (gfp_mask & __GFP_NORETRY)
@@ -2393,6 +2393,17 @@ should_alloc_retry(gfp_t gfp_mask, unsigned int order,
23932393
if (gfp_mask & __GFP_REPEAT && pages_reclaimed < (1 << order))
23942394
return 1;
23952395

2396+
/*
2397+
* We know __GFP_NORETRY is not set, so we are allowed to retry.
2398+
* As long as we are making progress, retry at least order times
2399+
* before giving up.
2400+
* NOTE - alloc_retries only comes into play in this 'last chance'
2401+
* retry scenario.
2402+
*/
2403+
(*alloc_retries)++;
2404+
if (did_some_progress && *alloc_retries <= order)
2405+
return 1;
2406+
23962407
return 0;
23972408
}
23982409

@@ -2686,6 +2697,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
26862697
enum migrate_mode migration_mode = MIGRATE_ASYNC;
26872698
bool deferred_compaction = false;
26882699
int contended_compaction = COMPACT_CONTENDED_NONE;
2700+
int alloc_retries = 0;
26892701

26902702
/*
26912703
* In the slowpath, we sanity check order to avoid ever trying to
@@ -2821,7 +2833,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
28212833
/* Check if we should retry the allocation */
28222834
pages_reclaimed += did_some_progress;
28232835
if (should_alloc_retry(gfp_mask, order, did_some_progress,
2824-
pages_reclaimed)) {
2836+
pages_reclaimed, &alloc_retries)) {
28252837
/*
28262838
* If we fail to make progress by freeing individual
28272839
* pages, but the allocation wants us to keep going,

0 commit comments

Comments
 (0)