diff options
author | Jianguo Wu <wujianguo@huawei.com> | 2012-10-08 19:33:06 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-09 03:22:54 -0400 |
commit | 7f1290f2f2a4d2c3f1b7ce8e87256e052ca23125 (patch) | |
tree | 10328fcb468647ba678e022911d5c2005080f309 /mm/page_alloc.c | |
parent | 05106e6a54aed321191b4bb5c9ee09538cbad3b1 (diff) |
mm: fix-up zone present pages
I think zone->present_pages indicates pages that buddy system can management,
it should be:
zone->present_pages = spanned pages - absent pages - bootmem pages,
but is now:
zone->present_pages = spanned pages - absent pages - memmap pages.
spanned pages: total size, including holes.
absent pages: holes.
bootmem pages: pages used in system boot, managed by bootmem allocator.
memmap pages: pages used by page structs.
This may cause zone->present_pages less than it should be. For example,
numa node 1 has ZONE_NORMAL and ZONE_MOVABLE, it's memmap and other
bootmem will be allocated from ZONE_MOVABLE, so ZONE_NORMAL's
present_pages should be spanned pages - absent pages, but now it also
minus memmap pages(free_area_init_core), which are actually allocated from
ZONE_MOVABLE. When offlining all memory of a zone, this will cause
zone->present_pages less than 0, because present_pages is unsigned long
type, it is actually a very large integer, it indirectly caused
zone->watermark[WMARK_MIN] becomes a large
integer(setup_per_zone_wmarks()), than cause totalreserve_pages become a
large integer(calculate_totalreserve_pages()), and finally cause memory
allocating failure when fork process(__vm_enough_memory()).
[root@localhost ~]# dmesg
-bash: fork: Cannot allocate memory
I think the bug described in
http://marc.info/?l=linux-mm&m=134502182714186&w=2
is also caused by wrong zone present pages.
This patch intends to fix-up zone->present_pages when memory are freed to
buddy system on x86_64 and IA64 platforms.
Signed-off-by: Jianguo Wu <wujianguo@huawei.com>
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Reported-by: Petr Tesarik <ptesarik@suse.cz>
Tested-by: Petr Tesarik <ptesarik@suse.cz>
Cc: "Luck, Tony" <tony.luck@intel.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Minchan Kim <minchan.kim@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/page_alloc.c')
-rw-r--r-- | mm/page_alloc.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 8ac593893e6e..00750bc08a3a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c | |||
@@ -6087,3 +6087,37 @@ void dump_page(struct page *page) | |||
6087 | dump_page_flags(page->flags); | 6087 | dump_page_flags(page->flags); |
6088 | mem_cgroup_print_bad_page(page); | 6088 | mem_cgroup_print_bad_page(page); |
6089 | } | 6089 | } |
6090 | |||
6091 | /* reset zone->present_pages */ | ||
6092 | void reset_zone_present_pages(void) | ||
6093 | { | ||
6094 | struct zone *z; | ||
6095 | int i, nid; | ||
6096 | |||
6097 | for_each_node_state(nid, N_HIGH_MEMORY) { | ||
6098 | for (i = 0; i < MAX_NR_ZONES; i++) { | ||
6099 | z = NODE_DATA(nid)->node_zones + i; | ||
6100 | z->present_pages = 0; | ||
6101 | } | ||
6102 | } | ||
6103 | } | ||
6104 | |||
6105 | /* calculate zone's present pages in buddy system */ | ||
6106 | void fixup_zone_present_pages(int nid, unsigned long start_pfn, | ||
6107 | unsigned long end_pfn) | ||
6108 | { | ||
6109 | struct zone *z; | ||
6110 | unsigned long zone_start_pfn, zone_end_pfn; | ||
6111 | int i; | ||
6112 | |||
6113 | for (i = 0; i < MAX_NR_ZONES; i++) { | ||
6114 | z = NODE_DATA(nid)->node_zones + i; | ||
6115 | zone_start_pfn = z->zone_start_pfn; | ||
6116 | zone_end_pfn = zone_start_pfn + z->spanned_pages; | ||
6117 | |||
6118 | /* if the two regions intersect */ | ||
6119 | if (!(zone_start_pfn >= end_pfn || zone_end_pfn <= start_pfn)) | ||
6120 | z->present_pages += min(end_pfn, zone_end_pfn) - | ||
6121 | max(start_pfn, zone_start_pfn); | ||
6122 | } | ||
6123 | } | ||