diff options
Diffstat (limited to 'mm/page_alloc.c')
-rw-r--r-- | mm/page_alloc.c | 108 |
1 files changed, 89 insertions, 19 deletions
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2bc2ac63f41e..d79b92580561 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #include <linux/page_cgroup.h> | 48 | #include <linux/page_cgroup.h> |
49 | #include <linux/debugobjects.h> | 49 | #include <linux/debugobjects.h> |
50 | #include <linux/kmemleak.h> | 50 | #include <linux/kmemleak.h> |
51 | #include <linux/memory.h> | ||
51 | #include <trace/events/kmem.h> | 52 | #include <trace/events/kmem.h> |
52 | 53 | ||
53 | #include <asm/tlbflush.h> | 54 | #include <asm/tlbflush.h> |
@@ -486,7 +487,6 @@ static inline void __free_one_page(struct page *page, | |||
486 | zone->free_area[order].nr_free++; | 487 | zone->free_area[order].nr_free++; |
487 | } | 488 | } |
488 | 489 | ||
489 | #ifdef CONFIG_HAVE_MLOCKED_PAGE_BIT | ||
490 | /* | 490 | /* |
491 | * free_page_mlock() -- clean up attempts to free and mlocked() page. | 491 | * free_page_mlock() -- clean up attempts to free and mlocked() page. |
492 | * Page should not be on lru, so no need to fix that up. | 492 | * Page should not be on lru, so no need to fix that up. |
@@ -497,9 +497,6 @@ static inline void free_page_mlock(struct page *page) | |||
497 | __dec_zone_page_state(page, NR_MLOCK); | 497 | __dec_zone_page_state(page, NR_MLOCK); |
498 | __count_vm_event(UNEVICTABLE_MLOCKFREED); | 498 | __count_vm_event(UNEVICTABLE_MLOCKFREED); |
499 | } | 499 | } |
500 | #else | ||
501 | static void free_page_mlock(struct page *page) { } | ||
502 | #endif | ||
503 | 500 | ||
504 | static inline int free_pages_check(struct page *page) | 501 | static inline int free_pages_check(struct page *page) |
505 | { | 502 | { |
@@ -1658,12 +1655,22 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order, | |||
1658 | if (page) | 1655 | if (page) |
1659 | goto out; | 1656 | goto out; |
1660 | 1657 | ||
1661 | /* The OOM killer will not help higher order allocs */ | 1658 | if (!(gfp_mask & __GFP_NOFAIL)) { |
1662 | if (order > PAGE_ALLOC_COSTLY_ORDER && !(gfp_mask & __GFP_NOFAIL)) | 1659 | /* The OOM killer will not help higher order allocs */ |
1663 | goto out; | 1660 | if (order > PAGE_ALLOC_COSTLY_ORDER) |
1664 | 1661 | goto out; | |
1662 | /* | ||
1663 | * GFP_THISNODE contains __GFP_NORETRY and we never hit this. | ||
1664 | * Sanity check for bare calls of __GFP_THISNODE, not real OOM. | ||
1665 | * The caller should handle page allocation failure by itself if | ||
1666 | * it specifies __GFP_THISNODE. | ||
1667 | * Note: Hugepage uses it but will hit PAGE_ALLOC_COSTLY_ORDER. | ||
1668 | */ | ||
1669 | if (gfp_mask & __GFP_THISNODE) | ||
1670 | goto out; | ||
1671 | } | ||
1665 | /* Exhausted what can be done so it's blamo time */ | 1672 | /* Exhausted what can be done so it's blamo time */ |
1666 | out_of_memory(zonelist, gfp_mask, order); | 1673 | out_of_memory(zonelist, gfp_mask, order, nodemask); |
1667 | 1674 | ||
1668 | out: | 1675 | out: |
1669 | clear_zonelist_oom(zonelist, gfp_mask); | 1676 | clear_zonelist_oom(zonelist, gfp_mask); |
@@ -3127,7 +3134,7 @@ static int __cpuinit process_zones(int cpu) | |||
3127 | 3134 | ||
3128 | if (percpu_pagelist_fraction) | 3135 | if (percpu_pagelist_fraction) |
3129 | setup_pagelist_highmark(zone_pcp(zone, cpu), | 3136 | setup_pagelist_highmark(zone_pcp(zone, cpu), |
3130 | (zone->present_pages / percpu_pagelist_fraction)); | 3137 | (zone->present_pages / percpu_pagelist_fraction)); |
3131 | } | 3138 | } |
3132 | 3139 | ||
3133 | return 0; | 3140 | return 0; |
@@ -3573,7 +3580,7 @@ static unsigned long __meminit zone_spanned_pages_in_node(int nid, | |||
3573 | * Return the number of holes in a range on a node. If nid is MAX_NUMNODES, | 3580 | * Return the number of holes in a range on a node. If nid is MAX_NUMNODES, |
3574 | * then all holes in the requested range will be accounted for. | 3581 | * then all holes in the requested range will be accounted for. |
3575 | */ | 3582 | */ |
3576 | static unsigned long __meminit __absent_pages_in_range(int nid, | 3583 | unsigned long __meminit __absent_pages_in_range(int nid, |
3577 | unsigned long range_start_pfn, | 3584 | unsigned long range_start_pfn, |
3578 | unsigned long range_end_pfn) | 3585 | unsigned long range_end_pfn) |
3579 | { | 3586 | { |
@@ -4102,7 +4109,7 @@ static int __init cmp_node_active_region(const void *a, const void *b) | |||
4102 | } | 4109 | } |
4103 | 4110 | ||
4104 | /* sort the node_map by start_pfn */ | 4111 | /* sort the node_map by start_pfn */ |
4105 | static void __init sort_node_map(void) | 4112 | void __init sort_node_map(void) |
4106 | { | 4113 | { |
4107 | sort(early_node_map, (size_t)nr_nodemap_entries, | 4114 | sort(early_node_map, (size_t)nr_nodemap_entries, |
4108 | sizeof(struct node_active_region), | 4115 | sizeof(struct node_active_region), |
@@ -5002,23 +5009,65 @@ void set_pageblock_flags_group(struct page *page, unsigned long flags, | |||
5002 | int set_migratetype_isolate(struct page *page) | 5009 | int set_migratetype_isolate(struct page *page) |
5003 | { | 5010 | { |
5004 | struct zone *zone; | 5011 | struct zone *zone; |
5005 | unsigned long flags; | 5012 | struct page *curr_page; |
5013 | unsigned long flags, pfn, iter; | ||
5014 | unsigned long immobile = 0; | ||
5015 | struct memory_isolate_notify arg; | ||
5016 | int notifier_ret; | ||
5006 | int ret = -EBUSY; | 5017 | int ret = -EBUSY; |
5007 | int zone_idx; | 5018 | int zone_idx; |
5008 | 5019 | ||
5009 | zone = page_zone(page); | 5020 | zone = page_zone(page); |
5010 | zone_idx = zone_idx(zone); | 5021 | zone_idx = zone_idx(zone); |
5022 | |||
5011 | spin_lock_irqsave(&zone->lock, flags); | 5023 | spin_lock_irqsave(&zone->lock, flags); |
5024 | if (get_pageblock_migratetype(page) == MIGRATE_MOVABLE || | ||
5025 | zone_idx == ZONE_MOVABLE) { | ||
5026 | ret = 0; | ||
5027 | goto out; | ||
5028 | } | ||
5029 | |||
5030 | pfn = page_to_pfn(page); | ||
5031 | arg.start_pfn = pfn; | ||
5032 | arg.nr_pages = pageblock_nr_pages; | ||
5033 | arg.pages_found = 0; | ||
5034 | |||
5012 | /* | 5035 | /* |
5013 | * In future, more migrate types will be able to be isolation target. | 5036 | * It may be possible to isolate a pageblock even if the |
5037 | * migratetype is not MIGRATE_MOVABLE. The memory isolation | ||
5038 | * notifier chain is used by balloon drivers to return the | ||
5039 | * number of pages in a range that are held by the balloon | ||
5040 | * driver to shrink memory. If all the pages are accounted for | ||
5041 | * by balloons, are free, or on the LRU, isolation can continue. | ||
5042 | * Later, for example, when memory hotplug notifier runs, these | ||
5043 | * pages reported as "can be isolated" should be isolated(freed) | ||
5044 | * by the balloon driver through the memory notifier chain. | ||
5014 | */ | 5045 | */ |
5015 | if (get_pageblock_migratetype(page) != MIGRATE_MOVABLE && | 5046 | notifier_ret = memory_isolate_notify(MEM_ISOLATE_COUNT, &arg); |
5016 | zone_idx != ZONE_MOVABLE) | 5047 | notifier_ret = notifier_to_errno(notifier_ret); |
5048 | if (notifier_ret || !arg.pages_found) | ||
5017 | goto out; | 5049 | goto out; |
5018 | set_pageblock_migratetype(page, MIGRATE_ISOLATE); | 5050 | |
5019 | move_freepages_block(zone, page, MIGRATE_ISOLATE); | 5051 | for (iter = pfn; iter < (pfn + pageblock_nr_pages); iter++) { |
5020 | ret = 0; | 5052 | if (!pfn_valid_within(pfn)) |
5053 | continue; | ||
5054 | |||
5055 | curr_page = pfn_to_page(iter); | ||
5056 | if (!page_count(curr_page) || PageLRU(curr_page)) | ||
5057 | continue; | ||
5058 | |||
5059 | immobile++; | ||
5060 | } | ||
5061 | |||
5062 | if (arg.pages_found == immobile) | ||
5063 | ret = 0; | ||
5064 | |||
5021 | out: | 5065 | out: |
5066 | if (!ret) { | ||
5067 | set_pageblock_migratetype(page, MIGRATE_ISOLATE); | ||
5068 | move_freepages_block(zone, page, MIGRATE_ISOLATE); | ||
5069 | } | ||
5070 | |||
5022 | spin_unlock_irqrestore(&zone->lock, flags); | 5071 | spin_unlock_irqrestore(&zone->lock, flags); |
5023 | if (!ret) | 5072 | if (!ret) |
5024 | drain_all_pages(); | 5073 | drain_all_pages(); |
@@ -5085,3 +5134,24 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) | |||
5085 | spin_unlock_irqrestore(&zone->lock, flags); | 5134 | spin_unlock_irqrestore(&zone->lock, flags); |
5086 | } | 5135 | } |
5087 | #endif | 5136 | #endif |
5137 | |||
5138 | #ifdef CONFIG_MEMORY_FAILURE | ||
5139 | bool is_free_buddy_page(struct page *page) | ||
5140 | { | ||
5141 | struct zone *zone = page_zone(page); | ||
5142 | unsigned long pfn = page_to_pfn(page); | ||
5143 | unsigned long flags; | ||
5144 | int order; | ||
5145 | |||
5146 | spin_lock_irqsave(&zone->lock, flags); | ||
5147 | for (order = 0; order < MAX_ORDER; order++) { | ||
5148 | struct page *page_head = page - (pfn & ((1 << order) - 1)); | ||
5149 | |||
5150 | if (PageBuddy(page_head) && page_order(page_head) >= order) | ||
5151 | break; | ||
5152 | } | ||
5153 | spin_unlock_irqrestore(&zone->lock, flags); | ||
5154 | |||
5155 | return order < MAX_ORDER; | ||
5156 | } | ||
5157 | #endif | ||