diff options
author | Jiang Liu <liuj97@gmail.com> | 2012-12-12 16:52:12 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-12 20:38:34 -0500 |
commit | 9feedc9d831e18ae6d0d15aa562e5e46ba53647b (patch) | |
tree | cb26ff54b0f02c4905772288b27f99b8b384ad6d /mm/nobootmem.c | |
parent | c2d23f919bafcbc2259f5257d9a7d729802f0e3a (diff) |
mm: introduce new field "managed_pages" to struct zone
Currently a zone's present_pages is calcuated as below, which is
inaccurate and may cause trouble to memory hotplug.
spanned_pages - absent_pages - memmap_pages - dma_reserve.
During fixing bugs caused by inaccurate zone->present_pages, we found
zone->present_pages has been abused. The field zone->present_pages may
have different meanings in different contexts:
1) pages existing in a zone.
2) pages managed by the buddy system.
For more discussions about the issue, please refer to:
http://lkml.org/lkml/2012/11/5/866
https://patchwork.kernel.org/patch/1346751/
This patchset tries to introduce a new field named "managed_pages" to
struct zone, which counts "pages managed by the buddy system". And revert
zone->present_pages to count "physical pages existing in a zone", which
also keep in consistence with pgdat->node_present_pages.
We will set an initial value for zone->managed_pages in function
free_area_init_core() and will adjust it later if the initial value is
inaccurate.
For DMA/normal zones, the initial value is set to:
(spanned_pages - absent_pages - memmap_pages - dma_reserve)
Later zone->managed_pages will be adjusted to the accurate value when the
bootmem allocator frees all free pages to the buddy system in function
free_all_bootmem_node() and free_all_bootmem().
The bootmem allocator doesn't touch highmem pages, so highmem zones'
managed_pages is set to the accurate value "spanned_pages - absent_pages"
in function free_area_init_core() and won't be updated anymore.
This patch also adds a new field "managed_pages" to /proc/zoneinfo
and sysrq showmem.
[akpm@linux-foundation.org: small comment tweaks]
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: Wen Congyang <wency@cn.fujitsu.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Maciej Rutecki <maciej.rutecki@gmail.com>
Tested-by: Chris Clayton <chris2553@googlemail.com>
Cc: "Rafael J . Wysocki" <rjw@sisk.pl>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Minchan Kim <minchan@kernel.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Jianguo Wu <wujianguo@huawei.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/nobootmem.c')
-rw-r--r-- | mm/nobootmem.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/mm/nobootmem.c b/mm/nobootmem.c index bd82f6b31411..b8294fc03df8 100644 --- a/mm/nobootmem.c +++ b/mm/nobootmem.c | |||
@@ -137,6 +137,22 @@ unsigned long __init free_low_memory_core_early(int nodeid) | |||
137 | return count; | 137 | return count; |
138 | } | 138 | } |
139 | 139 | ||
140 | static void reset_node_lowmem_managed_pages(pg_data_t *pgdat) | ||
141 | { | ||
142 | struct zone *z; | ||
143 | |||
144 | /* | ||
145 | * In free_area_init_core(), highmem zone's managed_pages is set to | ||
146 | * present_pages, and bootmem allocator doesn't allocate from highmem | ||
147 | * zones. So there's no need to recalculate managed_pages because all | ||
148 | * highmem pages will be managed by the buddy system. Here highmem | ||
149 | * zone also includes highmem movable zone. | ||
150 | */ | ||
151 | for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++) | ||
152 | if (!is_highmem(z)) | ||
153 | z->managed_pages = 0; | ||
154 | } | ||
155 | |||
140 | /** | 156 | /** |
141 | * free_all_bootmem_node - release a node's free pages to the buddy allocator | 157 | * free_all_bootmem_node - release a node's free pages to the buddy allocator |
142 | * @pgdat: node to be released | 158 | * @pgdat: node to be released |
@@ -146,6 +162,7 @@ unsigned long __init free_low_memory_core_early(int nodeid) | |||
146 | unsigned long __init free_all_bootmem_node(pg_data_t *pgdat) | 162 | unsigned long __init free_all_bootmem_node(pg_data_t *pgdat) |
147 | { | 163 | { |
148 | register_page_bootmem_info_node(pgdat); | 164 | register_page_bootmem_info_node(pgdat); |
165 | reset_node_lowmem_managed_pages(pgdat); | ||
149 | 166 | ||
150 | /* free_low_memory_core_early(MAX_NUMNODES) will be called later */ | 167 | /* free_low_memory_core_early(MAX_NUMNODES) will be called later */ |
151 | return 0; | 168 | return 0; |
@@ -158,6 +175,11 @@ unsigned long __init free_all_bootmem_node(pg_data_t *pgdat) | |||
158 | */ | 175 | */ |
159 | unsigned long __init free_all_bootmem(void) | 176 | unsigned long __init free_all_bootmem(void) |
160 | { | 177 | { |
178 | struct pglist_data *pgdat; | ||
179 | |||
180 | for_each_online_pgdat(pgdat) | ||
181 | reset_node_lowmem_managed_pages(pgdat); | ||
182 | |||
161 | /* | 183 | /* |
162 | * We need to use MAX_NUMNODES instead of NODE_DATA(0)->node_id | 184 | * We need to use MAX_NUMNODES instead of NODE_DATA(0)->node_id |
163 | * because in some case like Node0 doesn't have RAM installed | 185 | * because in some case like Node0 doesn't have RAM installed |