Skip to contentSkip to conversation

memory-hotplug: fix zone stat mismatch

PATCH In review Minchan Kim 3 participants 5 messages Sep 20, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 memory-hotplug: fix zone stat mismatch

During memory-hotplug, I found NR_ISOLATED_[ANON|FILE] are increasing so that kernel are hang out.

The cause is that when we do memory-hotadd after memory-remove, __zone_pcp_update clear out zone's ZONE_STAT_ITEMS in setup_pageset although vm_stat_diff of all CPU still have value.

In addtion, when we offline all pages of the zone, we reset them in zone_pcp_reset without drain so that we lost zone stat item.

This patch fixes it.

* from v2
* Add Reviewed-by - Wen

* from v1
* drain offline patch - KOSAKI, Wen

Cc Kamezawa Hiroyuki <[email protected]>
Cc Yasuaki Ishimatsu <[email protected]>
Cc KOSAKI Motohiro <[email protected]>
---
 include/linux/vmstat.h |    4 ++++
 mm/page_alloc.c        |    7 +++++++
 mm/vmstat.c            |   12 ++++++++++++
 3 files changed, 23 insertions(+)
include/linux/vmstat.h +4 -0
index ad2cfd5..5d31876 100644
@@ -198,6 +198,8 @@ extern void __dec_zone_state(struct zone *, enum zone_stat_item);
 void refresh_cpu_vm_stats(int);
 void refresh_zone_stat_thresholds(void);
 
+void drain_zonestat(struct zone *zone, struct per_cpu_pageset *);
+
 int calculate_pressure_threshold(struct zone *zone);
 int calculate_normal_threshold(struct zone *zone);
 void set_pgdat_percpu_threshold(pg_data_t *pgdat,
@@ -251,6 +253,8 @@ static inline void __dec_zone_page_state(struct page *page,
 static inline void refresh_cpu_vm_stats(int cpu) { }
 static inline void refresh_zone_stat_thresholds(void) { }
 
+static inline void drain_zonestat(struct zone *zone,
+			struct per_cpu_pageset *pset) { }
 #endif		/* CONFIG_SMP */
 
 extern const char * const vmstat_text[];
mm/page_alloc.c +7 -0
index ab58346..980f2e7 100644
@@ -5904,6 +5904,7 @@ static int __meminit __zone_pcp_update(void *data)
 		local_irq_save(flags);
 		if (pcp->count > 0)
 			free_pcppages_bulk(zone, pcp->count, pcp);
+		drain_zonestat(zone, pset);
 		setup_pageset(pset, batch);
 		local_irq_restore(flags);
 	}
@@ -5920,10 +5921,16 @@ void __meminit zone_pcp_update(struct zone *zone)
 void zone_pcp_reset(struct zone *zone)
 {
 	unsigned long flags;
+	int cpu;
+	struct per_cpu_pageset *pset;
 
 	/* avoid races with drain_pages()  */
 	local_irq_save(flags);
 	if (zone->pageset != &boot_pageset) {
+		for_each_online_cpu(cpu) {
+			pset = per_cpu_ptr(zone->pageset, cpu);
+			drain_zonestat(zone, pset);
+		}
 		free_percpu(zone->pageset);
 		zone->pageset = &boot_pageset;
 	}
mm/vmstat.c +12 -0
index b3e3b9d..d4cc1c2 100644
@@ -495,6 +495,18 @@ void refresh_cpu_vm_stats(int cpu)
 			atomic_long_add(global_diff[i], &vm_stat[i]);
 }
 
+void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
+{
+	int i;
+
+	for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
+		if (pset->vm_stat_diff[i]) {
+			int v = pset->vm_stat_diff[i];
+			pset->vm_stat_diff[i] = 0;
+			atomic_long_add(v, &zone->vm_stat[i]);
+			atomic_long_add(v, &vm_stat[i]);
+		}
+}
 #endif
 
 #ifdef CONFIG_NUMA
Signature · 7 lines
1.7.9.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

Hi Minchan,

Sorry for late reply.

Quoted 2 lines · Minchan Kim

During memory-hotplug, I found NR_ISOLATED_[ANON|FILE] are increasing so that kernel are hang out.

Why does your system hang out by increasing NR_ISOLATED_[ANON|FILE]? I cannot understand what has happened by your system.

Thanks,
Yasuaki Ishimatsu

Quoted 92 lines

The cause is that when we do memory-hotadd after memory-remove, __zone_pcp_update clear out zone's ZONE_STAT_ITEMS in setup_pageset although vm_stat_diff of all CPU still have value.

In addtion, when we offline all pages of the zone, we reset them in zone_pcp_reset without drain so that we lost zone stat item.

This patch fixes it.

* from v2
* Add Reviewed-by - Wen

* from v1
* drain offline patch - KOSAKI, Wen

Cc Kamezawa Hiroyuki <[email protected]>
Cc Yasuaki Ishimatsu <[email protected]>
Cc KOSAKI Motohiro <[email protected]>
---
  include/linux/vmstat.h |    4 ++++
  mm/page_alloc.c        |    7 +++++++
  mm/vmstat.c            |   12 ++++++++++++
  3 files changed, 23 insertions(+)
include/linux/vmstat.h +4 -0
index ad2cfd5..5d31876 100644
@@ -198,6 +198,8 @@ extern void __dec_zone_state(struct zone *, enum zone_stat_item);
  void refresh_cpu_vm_stats(int);
  void refresh_zone_stat_thresholds(void);
 
+void drain_zonestat(struct zone *zone, struct per_cpu_pageset *);
+
  int calculate_pressure_threshold(struct zone *zone);
  int calculate_normal_threshold(struct zone *zone);
  void set_pgdat_percpu_threshold(pg_data_t *pgdat,
@@ -251,6 +253,8 @@ static inline void __dec_zone_page_state(struct page *page,
  static inline void refresh_cpu_vm_stats(int cpu) { }
  static inline void refresh_zone_stat_thresholds(void) { }
 
+static inline void drain_zonestat(struct zone *zone,
+			struct per_cpu_pageset *pset) { }
  #endif		/* CONFIG_SMP */
 
  extern const char * const vmstat_text[];
mm/page_alloc.c +7 -0
index ab58346..980f2e7 100644
@@ -5904,6 +5904,7 @@ static int __meminit __zone_pcp_update(void *data)
  		local_irq_save(flags);
  		if (pcp->count > 0)
  			free_pcppages_bulk(zone, pcp->count, pcp);
+		drain_zonestat(zone, pset);
  		setup_pageset(pset, batch);
  		local_irq_restore(flags);
  	}
@@ -5920,10 +5921,16 @@ void __meminit zone_pcp_update(struct zone *zone)
  void zone_pcp_reset(struct zone *zone)
  {
  	unsigned long flags;
+	int cpu;
+	struct per_cpu_pageset *pset;
 
  	/* avoid races with drain_pages()  */
  	local_irq_save(flags);
  	if (zone->pageset != &boot_pageset) {
+		for_each_online_cpu(cpu) {
+			pset = per_cpu_ptr(zone->pageset, cpu);
+			drain_zonestat(zone, pset);
+		}
  		free_percpu(zone->pageset);
  		zone->pageset = &boot_pageset;
  	}
mm/vmstat.c +5 -0
index b3e3b9d..d4cc1c2 100644
@@ -495,6 +495,18 @@ void refresh_cpu_vm_stats(int cpu)
  			atomic_long_add(global_diff[i], &vm_stat[i]);
  }
 
+void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
+{
+	int i;
+
+	for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)

mm/vmstat.c void refresh_cpu_vm_stats(int cpu) · line 512

Quoted 10 lines
mm/vmstat.c +7 -0
+		if (pset->vm_stat_diff[i]) {
+			int v = pset->vm_stat_diff[i];
+			pset->vm_stat_diff[i] = 0;
+			atomic_long_add(v, &zone->vm_stat[i]);
+			atomic_long_add(v, &vm_stat[i]);
+		}
+}
  #endif
 
  #ifdef CONFIG_NUMA

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

Hi Yasuaki,

Quoted 10 lines · Yasuaki Ishimatsu

Hi Minchan,

Sorry for late reply.

Quoted 2 lines · Minchan Kim

During memory-hotplug, I found NR_ISOLATED_[ANON|FILE] are increasing so that kernel are hang out.

Why does your system hang out by increasing NR_ISOLATED_[ANON|FILE]? I cannot understand what has happened by your system.

If system doesn't have enough free page, it goes reclaim path and never reclaim any pages by too_many_isolated and loop forever.

--
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#3 lore raw
In reply to Minchan Kim
Quoted 10 lines · On Thu, 20 Sep 2012 15:43:25 +0900 Minchan Kim <[email protected]> wrote:

During memory-hotplug, I found NR_ISOLATED_[ANON|FILE] are increasing so that kernel are hang out.

The cause is that when we do memory-hotadd after memory-remove, __zone_pcp_update clear out zone's ZONE_STAT_ITEMS in setup_pageset although vm_stat_diff of all CPU still have value.

In addtion, when we offline all pages of the zone, we reset them in zone_pcp_reset without drain so that we lost zone stat item.

Here's what I ended up with for a changelog:

: During memory-hotplug, I found NR_ISOLATED_[ANON|FILE] are increasing, : causing the kernel to hang. When the system doesn't have enough free : pages, it enters reclaim but never reclaim any pages due to : too_many_isolated()==true and loops forever.
:
: The cause is that when we do memory-hotadd after memory-remove, : __zone_pcp_update() clears a zone's ZONE_STAT_ITEMS in setup_pageset() : although the vm_stat_diff of all CPUs still have values.
:
: In addtion, when we offline all pages of the zone, we reset them in : zone_pcp_reset without draining so we loss some zone stat item.

As memory hotplug seems fairly immature and broken, I'm thinking there's no point in backporting this into -stable. And I don't *think* we really need it in 3.6 either? (It doesn't apply cleanly to current mainline anyway - I didn't check why).

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 16 lines · Andrew Morton
Quoted 10 lines · On Thu, 20 Sep 2012 15:43:25 +0900 Minchan Kim <[email protected]> wrote:

During memory-hotplug, I found NR_ISOLATED_[ANON|FILE] are increasing so that kernel are hang out.

The cause is that when we do memory-hotadd after memory-remove, __zone_pcp_update clear out zone's ZONE_STAT_ITEMS in setup_pageset although vm_stat_diff of all CPU still have value.

In addtion, when we offline all pages of the zone, we reset them in zone_pcp_reset without drain so that we lost zone stat item.

Here's what I ended up with for a changelog:

Quoted 12 lines

: During memory-hotplug, I found NR_ISOLATED_[ANON|FILE] are increasing, : causing the kernel to hang. When the system doesn't have enough free : pages, it enters reclaim but never reclaim any pages due to : too_many_isolated()==true and loops forever.
:
: The cause is that when we do memory-hotadd after memory-remove, : __zone_pcp_update() clears a zone's ZONE_STAT_ITEMS in setup_pageset() : although the vm_stat_diff of all CPUs still have values.
:
: In addtion, when we offline all pages of the zone, we reset them in : zone_pcp_reset without draining so we loss some zone stat item.

Thanks for clarifying the description, Andrew!

Quoted 3 lines

As memory hotplug seems fairly immature and broken, I'm thinking there's no point in backporting this into -stable. And I don't *think*

I have no idea usecase of memory-hotplug in real practice. If they do a ton of memory-hotadd/delete without rebooting zone stat could be wrong. And it could turn for the worse in case of using many CPUs.

Other zone stat items are not critical other than NR_ISOLATED which could make system hang when VM start to reclaim heavily. Anyway, If fujitsu guys don't yell, I'm okay. :)

Quoted 2 lines

we really need it in 3.6 either? (It doesn't apply cleanly to current mainline anyway - I didn't check why).

At least, it works in my side.

barrios@bbox:~/linux-2.6$ git log -n 1
commit c46de2263f42fb4bbde411b9126f471e9343cb22
Merge: 077fee0 2453f5f
Author: Linus Torvalds <[email protected]>
Date:   Wed Sep 19 11:04:34 2012 -0700

Merge branch 'for-linus' of git://git.kernel.dk/linux-block

Pull block fixes from Jens Axboe:
"A small collection of driver fixes/updates and a core fix for 3.6. It
contains:

- Bug fixes for mtip32xx, and support for new hardware (just addition of IDs). They have been queued up for 3.7 for a few weeks as well.

- rate-limit a failing command error message in block core.

- A fix for an old cciss bug from Stephen.

- Prevent overflow of partition count from Alan."

* 'for-linus' of git://git.kernel.dk/linux-block:
cciss: fix handling of protocol error
blk: add an upper sanity check on partition adding
mtip32xx: fix user_buffer check in exec_drive_command
mtip32xx: Remove dead code
mtip32xx: Change printk to pr_xxxx
mtip32xx: Proper reporting of write protect status on big-endian
mtip32xx: Increase timeout for standby command
mtip32xx: Handle NCQ commands during the security locked state
mtip32xx: Add support for new devices
block: rate-limit the error message from failing commands

barrios@bbox:~/linux-2.6$ patch -p1 < ../linux-mmotm/0001-memory-hotplug-fix-zone-stat-mismatch.patch --dry-run
patching file include/linux/vmstat.h
patching file mm/page_alloc.c
Hunk #1 succeeded at 5874 (offset -30 lines).
Hunk #2 succeeded at 5891 (offset -30 lines).
patching file mm/vmstat.c
Quoted 7 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>