Skip to content

Commit 340175b

Browse files
Jiang Liutorvalds
authored andcommitted
mm/hotplug: free zone->pageset when a zone becomes empty
When a zone becomes empty after memory offlining, free zone->pageset. Otherwise it will cause memory leak when adding memory to the empty zone again because build_all_zonelists() will allocate zone->pageset for an empty zone. Signed-off-by: Jiang Liu <liuj97@gmail.com> Signed-off-by: Wei Wang <Bessel.Wang@huawei.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Michal Hocko <mhocko@suse.cz> Cc: Minchan Kim <minchan@kernel.org> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Yinghai Lu <yinghai@kernel.org> Cc: Tony Luck <tony.luck@intel.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: David Rientjes <rientjes@google.com> Cc: Keping Chen <chenkeping@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 08dff7b commit 340175b

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

include/linux/mm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...);
13311331
extern void setup_per_cpu_pageset(void);
13321332

13331333
extern void zone_pcp_update(struct zone *zone);
1334+
extern void zone_pcp_reset(struct zone *zone);
13341335

13351336
/* nommu.c */
13361337
extern atomic_long_t mmap_pages_allocated;

mm/memory_hotplug.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,9 @@ static int __ref offline_pages(unsigned long start_pfn,
966966

967967
init_per_zone_wmark_min();
968968

969+
if (!populated_zone(zone))
970+
zone_pcp_reset(zone);
971+
969972
if (!node_present_pages(node)) {
970973
node_clear_state(node, N_HIGH_MEMORY);
971974
kswapd_stop(node);

mm/page_alloc.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5894,6 +5894,19 @@ void free_contig_range(unsigned long pfn, unsigned nr_pages)
58945894
#endif
58955895

58965896
#ifdef CONFIG_MEMORY_HOTREMOVE
5897+
void zone_pcp_reset(struct zone *zone)
5898+
{
5899+
unsigned long flags;
5900+
5901+
/* avoid races with drain_pages() */
5902+
local_irq_save(flags);
5903+
if (zone->pageset != &boot_pageset) {
5904+
free_percpu(zone->pageset);
5905+
zone->pageset = &boot_pageset;
5906+
}
5907+
local_irq_restore(flags);
5908+
}
5909+
58975910
/*
58985911
* All pages in the range must be isolated before calling this.
58995912
*/

0 commit comments

Comments
 (0)