Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 340175b7 authored by Jiang Liu's avatar Jiang Liu Committed by Linus Torvalds
Browse files

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: default avatarJiang Liu <liuj97@gmail.com>
Signed-off-by: default avatarWei 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 08dff7b7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1331,6 +1331,7 @@ void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...);
extern void setup_per_cpu_pageset(void);

extern void zone_pcp_update(struct zone *zone);
extern void zone_pcp_reset(struct zone *zone);

/* nommu.c */
extern atomic_long_t mmap_pages_allocated;
+3 −0
Original line number Diff line number Diff line
@@ -966,6 +966,9 @@ static int __ref offline_pages(unsigned long start_pfn,

	init_per_zone_wmark_min();

	if (!populated_zone(zone))
		zone_pcp_reset(zone);

	if (!node_present_pages(node)) {
		node_clear_state(node, N_HIGH_MEMORY);
		kswapd_stop(node);
+13 −0
Original line number Diff line number Diff line
@@ -5894,6 +5894,19 @@ void free_contig_range(unsigned long pfn, unsigned nr_pages)
#endif

#ifdef CONFIG_MEMORY_HOTREMOVE
void zone_pcp_reset(struct zone *zone)
{
	unsigned long flags;

	/* avoid races with drain_pages()  */
	local_irq_save(flags);
	if (zone->pageset != &boot_pageset) {
		free_percpu(zone->pageset);
		zone->pageset = &boot_pageset;
	}
	local_irq_restore(flags);
}

/*
 * All pages in the range must be isolated before calling this.
 */