Skip to content

Commit 974a786

Browse files
gormanmtorvalds
authored andcommitted
mm, page_alloc: remove MIGRATE_RESERVE
MIGRATE_RESERVE preserves an old property of the buddy allocator that existed prior to fragmentation avoidance -- min_free_kbytes worth of pages tended to remain contiguous until the only alternative was to fail the allocation. At the time it was discovered that high-order atomic allocations relied on this property so MIGRATE_RESERVE was introduced. A later patch will introduce an alternative MIGRATE_HIGHATOMIC so this patch deletes MIGRATE_RESERVE and supporting code so it'll be easier to review. Note that this patch in isolation may look like a false regression if someone was bisecting high-order atomic allocation failures. Signed-off-by: Mel Gorman <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: David Rientjes <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Vitaly Wool <[email protected]> Cc: Rik van Riel <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent f77cf4e commit 974a786

File tree

4 files changed

+11
-150
lines changed

4 files changed

+11
-150
lines changed

include/linux/mmzone.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ enum {
3939
MIGRATE_UNMOVABLE,
4040
MIGRATE_MOVABLE,
4141
MIGRATE_RECLAIMABLE,
42-
MIGRATE_PCPTYPES, /* the number of types on the pcp lists */
43-
MIGRATE_RESERVE = MIGRATE_PCPTYPES,
4442
#ifdef CONFIG_CMA
4543
/*
4644
* MIGRATE_CMA migration type is designed to mimic the way
@@ -63,6 +61,8 @@ enum {
6361
MIGRATE_TYPES
6462
};
6563

64+
#define MIGRATE_PCPTYPES (MIGRATE_RECLAIMABLE+1)
65+
6666
#ifdef CONFIG_CMA
6767
# define is_migrate_cma(migratetype) unlikely((migratetype) == MIGRATE_CMA)
6868
#else
@@ -429,12 +429,6 @@ struct zone {
429429

430430
const char *name;
431431

432-
/*
433-
* Number of MIGRATE_RESERVE page block. To maintain for just
434-
* optimization. Protected by zone->lock.
435-
*/
436-
int nr_migrate_reserve_block;
437-
438432
#ifdef CONFIG_MEMORY_ISOLATION
439433
/*
440434
* Number of isolated pageblock. It is used to solve incorrect

mm/huge_memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static void set_recommended_min_free_kbytes(void)
116116
for_each_populated_zone(zone)
117117
nr_zones++;
118118

119-
/* Make sure at least 2 hugepages are free for MIGRATE_RESERVE */
119+
/* Ensure 2 pageblocks are free to assist fragmentation avoidance */
120120
recommended_min = pageblock_nr_pages * nr_zones * 2;
121121

122122
/*

mm/page_alloc.c

Lines changed: 8 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ static void free_pcppages_bulk(struct zone *zone, int count,
817817
if (unlikely(has_isolate_pageblock(zone)))
818818
mt = get_pageblock_migratetype(page);
819819

820-
/* MIGRATE_MOVABLE list may include MIGRATE_RESERVEs */
821820
__free_one_page(page, page_to_pfn(page), zone, 0, mt);
822821
trace_mm_page_pcpu_drain(page, 0, mt);
823822
} while (--to_free && --batch_free && !list_empty(list));
@@ -1417,15 +1416,14 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order,
14171416
* the free lists for the desirable migrate type are depleted
14181417
*/
14191418
static int fallbacks[MIGRATE_TYPES][4] = {
1420-
[MIGRATE_UNMOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_MOVABLE, MIGRATE_RESERVE },
1421-
[MIGRATE_RECLAIMABLE] = { MIGRATE_UNMOVABLE, MIGRATE_MOVABLE, MIGRATE_RESERVE },
1422-
[MIGRATE_MOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_UNMOVABLE, MIGRATE_RESERVE },
1419+
[MIGRATE_UNMOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_MOVABLE, MIGRATE_TYPES },
1420+
[MIGRATE_RECLAIMABLE] = { MIGRATE_UNMOVABLE, MIGRATE_MOVABLE, MIGRATE_TYPES },
1421+
[MIGRATE_MOVABLE] = { MIGRATE_RECLAIMABLE, MIGRATE_UNMOVABLE, MIGRATE_TYPES },
14231422
#ifdef CONFIG_CMA
1424-
[MIGRATE_CMA] = { MIGRATE_RESERVE }, /* Never used */
1423+
[MIGRATE_CMA] = { MIGRATE_TYPES }, /* Never used */
14251424
#endif
1426-
[MIGRATE_RESERVE] = { MIGRATE_RESERVE }, /* Never used */
14271425
#ifdef CONFIG_MEMORY_ISOLATION
1428-
[MIGRATE_ISOLATE] = { MIGRATE_RESERVE }, /* Never used */
1426+
[MIGRATE_ISOLATE] = { MIGRATE_TYPES }, /* Never used */
14291427
#endif
14301428
};
14311429

@@ -1598,7 +1596,7 @@ int find_suitable_fallback(struct free_area *area, unsigned int order,
15981596
*can_steal = false;
15991597
for (i = 0;; i++) {
16001598
fallback_mt = fallbacks[migratetype][i];
1601-
if (fallback_mt == MIGRATE_RESERVE)
1599+
if (fallback_mt == MIGRATE_TYPES)
16021600
break;
16031601

16041602
if (list_empty(&area->free_list[fallback_mt]))
@@ -1676,25 +1674,13 @@ static struct page *__rmqueue(struct zone *zone, unsigned int order,
16761674
{
16771675
struct page *page;
16781676

1679-
retry_reserve:
16801677
page = __rmqueue_smallest(zone, order, migratetype);
1681-
1682-
if (unlikely(!page) && migratetype != MIGRATE_RESERVE) {
1678+
if (unlikely(!page)) {
16831679
if (migratetype == MIGRATE_MOVABLE)
16841680
page = __rmqueue_cma_fallback(zone, order);
16851681

16861682
if (!page)
16871683
page = __rmqueue_fallback(zone, order, migratetype);
1688-
1689-
/*
1690-
* Use MIGRATE_RESERVE rather than fail an allocation. goto
1691-
* is used because __rmqueue_smallest is an inline function
1692-
* and we want just one call site
1693-
*/
1694-
if (!page) {
1695-
migratetype = MIGRATE_RESERVE;
1696-
goto retry_reserve;
1697-
}
16981684
}
16991685

17001686
trace_mm_page_alloc_zone_locked(page, order, migratetype);
@@ -3492,7 +3478,6 @@ static void show_migration_types(unsigned char type)
34923478
[MIGRATE_UNMOVABLE] = 'U',
34933479
[MIGRATE_RECLAIMABLE] = 'E',
34943480
[MIGRATE_MOVABLE] = 'M',
3495-
[MIGRATE_RESERVE] = 'R',
34963481
#ifdef CONFIG_CMA
34973482
[MIGRATE_CMA] = 'C',
34983483
#endif
@@ -4302,120 +4287,6 @@ static inline unsigned long wait_table_bits(unsigned long size)
43024287
return ffz(~size);
43034288
}
43044289

4305-
/*
4306-
* Check if a pageblock contains reserved pages
4307-
*/
4308-
static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
4309-
{
4310-
unsigned long pfn;
4311-
4312-
for (pfn = start_pfn; pfn < end_pfn; pfn++) {
4313-
if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
4314-
return 1;
4315-
}
4316-
return 0;
4317-
}
4318-
4319-
/*
4320-
* Mark a number of pageblocks as MIGRATE_RESERVE. The number
4321-
* of blocks reserved is based on min_wmark_pages(zone). The memory within
4322-
* the reserve will tend to store contiguous free pages. Setting min_free_kbytes
4323-
* higher will lead to a bigger reserve which will get freed as contiguous
4324-
* blocks as reclaim kicks in
4325-
*/
4326-
static void setup_zone_migrate_reserve(struct zone *zone)
4327-
{
4328-
unsigned long start_pfn, pfn, end_pfn, block_end_pfn;
4329-
struct page *page;
4330-
unsigned long block_migratetype;
4331-
int reserve;
4332-
int old_reserve;
4333-
4334-
/*
4335-
* Get the start pfn, end pfn and the number of blocks to reserve
4336-
* We have to be careful to be aligned to pageblock_nr_pages to
4337-
* make sure that we always check pfn_valid for the first page in
4338-
* the block.
4339-
*/
4340-
start_pfn = zone->zone_start_pfn;
4341-
end_pfn = zone_end_pfn(zone);
4342-
start_pfn = roundup(start_pfn, pageblock_nr_pages);
4343-
reserve = roundup(min_wmark_pages(zone), pageblock_nr_pages) >>
4344-
pageblock_order;
4345-
4346-
/*
4347-
* Reserve blocks are generally in place to help high-order atomic
4348-
* allocations that are short-lived. A min_free_kbytes value that
4349-
* would result in more than 2 reserve blocks for atomic allocations
4350-
* is assumed to be in place to help anti-fragmentation for the
4351-
* future allocation of hugepages at runtime.
4352-
*/
4353-
reserve = min(2, reserve);
4354-
old_reserve = zone->nr_migrate_reserve_block;
4355-
4356-
/* When memory hot-add, we almost always need to do nothing */
4357-
if (reserve == old_reserve)
4358-
return;
4359-
zone->nr_migrate_reserve_block = reserve;
4360-
4361-
for (pfn = start_pfn; pfn < end_pfn; pfn += pageblock_nr_pages) {
4362-
if (!early_page_nid_uninitialised(pfn, zone_to_nid(zone)))
4363-
return;
4364-
4365-
if (!pfn_valid(pfn))
4366-
continue;
4367-
page = pfn_to_page(pfn);
4368-
4369-
/* Watch out for overlapping nodes */
4370-
if (page_to_nid(page) != zone_to_nid(zone))
4371-
continue;
4372-
4373-
block_migratetype = get_pageblock_migratetype(page);
4374-
4375-
/* Only test what is necessary when the reserves are not met */
4376-
if (reserve > 0) {
4377-
/*
4378-
* Blocks with reserved pages will never free, skip
4379-
* them.
4380-
*/
4381-
block_end_pfn = min(pfn + pageblock_nr_pages, end_pfn);
4382-
if (pageblock_is_reserved(pfn, block_end_pfn))
4383-
continue;
4384-
4385-
/* If this block is reserved, account for it */
4386-
if (block_migratetype == MIGRATE_RESERVE) {
4387-
reserve--;
4388-
continue;
4389-
}
4390-
4391-
/* Suitable for reserving if this block is movable */
4392-
if (block_migratetype == MIGRATE_MOVABLE) {
4393-
set_pageblock_migratetype(page,
4394-
MIGRATE_RESERVE);
4395-
move_freepages_block(zone, page,
4396-
MIGRATE_RESERVE);
4397-
reserve--;
4398-
continue;
4399-
}
4400-
} else if (!old_reserve) {
4401-
/*
4402-
* At boot time we don't need to scan the whole zone
4403-
* for turning off MIGRATE_RESERVE.
4404-
*/
4405-
break;
4406-
}
4407-
4408-
/*
4409-
* If the reserve is met and this is a previous reserved block,
4410-
* take it back
4411-
*/
4412-
if (block_migratetype == MIGRATE_RESERVE) {
4413-
set_pageblock_migratetype(page, MIGRATE_MOVABLE);
4414-
move_freepages_block(zone, page, MIGRATE_MOVABLE);
4415-
}
4416-
}
4417-
}
4418-
44194290
/*
44204291
* Initially all pages are reserved - free ones are freed
44214292
* up by free_all_bootmem() once the early boot process is
@@ -4455,9 +4326,7 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone,
44554326
* movable at startup. This will force kernel allocations
44564327
* to reserve their blocks rather than leaking throughout
44574328
* the address space during boot when many long-lived
4458-
* kernel allocations are made. Later some blocks near
4459-
* the start are marked MIGRATE_RESERVE by
4460-
* setup_zone_migrate_reserve()
4329+
* kernel allocations are made.
44614330
*
44624331
* bitmap is created for zone's valid pfn range. but memmap
44634332
* can be created for invalid pages (for alignment)
@@ -6018,7 +5887,6 @@ static void __setup_per_zone_wmarks(void)
60185887
high_wmark_pages(zone) - low_wmark_pages(zone) -
60195888
atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
60205889

6021-
setup_zone_migrate_reserve(zone);
60225890
spin_unlock_irqrestore(&zone->lock, flags);
60235891
}
60245892

mm/vmstat.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,6 @@ static char * const migratetype_names[MIGRATE_TYPES] = {
923923
"Unmovable",
924924
"Reclaimable",
925925
"Movable",
926-
"Reserve",
927926
#ifdef CONFIG_CMA
928927
"CMA",
929928
#endif

0 commit comments

Comments
 (0)