Skip to contentSkip to conversation

memory-hotplug: fix zone stat mismatch

PATCH Superseded Minchan Kim 3 participants 11 messages Sep 19, 2012 – Sep 20, 2012

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

During memory-hotplug stress test, 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 without draining vm_stat_diff of all CPU.

This patch fixes it.

Cc Kamezawa Hiroyuki <[email protected]>
Cc Yasuaki Ishimatsu <[email protected]>
Cc Wen Congyang <[email protected]>
Cc Shaohua Li <[email protected]>

---
Andrew, I think it's a candidate of stable but didn't Cced stable.
Please send this patch to stable if reviewer couldn't find any fault when you merge.

Thanks.

 include/linux/vmstat.h |    4 ++++
 mm/page_alloc.c        |    1 +
 mm/vmstat.c            |   12 ++++++++++++
 3 files changed, 17 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 +1 -0
index ab58346..5d005c8 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);
 	}
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
Quoted 8 lines · Minchan Kim

During memory-hotplug stress test, 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 without draining vm_stat_diff of all CPU.

This patch fixes it.

zone_pcp_update() is called from online pages path. but IMHO, the statistics should be drained offline path. isn't it?

thanks.

--
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 KOSAKI,

Quoted 4 lines · KOSAKI Motohiro
Quoted 3 lines · Minchan Kim

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

Quoted 8 lines
Quoted 5 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 without draining vm_stat_diff of all CPU.

This patch fixes it.

zone_pcp_update() is called from online pages path. but IMHO, the statistics should be drained offline path. isn't it?

It isn't necessary because statistics is right until we reset it to zero in online path.
Do you have something on your mind that we have to drain it in offline path?

Quoted 2 lines

thanks.

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>
#3 lore raw

At 09/20/2012 04:17 AM, Minchan Kim Wrote:

Quoted 11 lines

Hi KOSAKI,

Quoted 8 lines · KOSAKI Motohiro
Quoted 7 lines · Minchan Kim

During memory-hotplug stress test, 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 without draining vm_stat_diff of all CPU.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

This patch fixes it.

zone_pcp_update() is called from online pages path. but IMHO, the statistics should be drained offline path. isn't it?

It isn't necessary because statistics is right until we reset it to zero in online path.
Do you have something on your mind that we have to drain it in offline path?

When a node is offlined and onlined again. We create node_data[i] in the function hotadd_new_pgdat(), and we will lost the statistics stored in zone->pageset. So we should drain it in offline path.

Thanks
Wen Congyang

Quoted 4 lines
Quoted 3 lines

thanks.

--
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 14 lines · Wen Congyang

At 09/20/2012 04:17 AM, Minchan Kim Wrote:

Quoted 13 lines

Hi KOSAKI,

Quoted 10 lines · KOSAKI Motohiro
Quoted 8 lines · Minchan Kim

During memory-hotplug stress test, 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 without draining vm_stat_diff of all CPU.

This patch fixes it.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

zone_pcp_update() is called from online pages path. but IMHO, the statistics should be drained offline path. isn't it?

It isn't necessary because statistics is right until we reset it to zero in online path.
Do you have something on your mind that we have to drain it in offline path?

When a node is offlined and onlined again. We create node_data[i] in the

I would like to clarify your word.
Create or recreate?
Why I have a question is as I look over the source code, hotadd_new_pgdat seem to be called if we do hotadd *new* memory. It's not the case for offline and online again you mentioned. If you're right, I should find arch_free_nodedata to free pgdat when node is disappear but I can't find it. Do I miss something?

Quoted 2 lines

function hotadd_new_pgdat(), and we will lost the statistics stored in zone->pageset. So we should drain it in offline path.

Even we drain in offline patch, it still has a problem.

1. offline
2. drain -> OKAY
3. schedule
4. Process A increase zone stat
5. Process B increase zone stat
6. online
7. reset it -> we ends up lost zone stat counter which is modified between 2-6

Quoted 14 lines

Thanks
Wen Congyang

Quoted 4 lines
Quoted 3 lines

thanks.

--
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>
#5 lore raw

At 09/20/2012 10:30 AM, Minchan Kim Wrote:

Quoted 24 lines · Wen Congyang
Quoted 14 lines

At 09/20/2012 04:17 AM, Minchan Kim Wrote:

Quoted 13 lines

Hi KOSAKI,

Quoted 10 lines · KOSAKI Motohiro
Quoted 8 lines · Minchan Kim

During memory-hotplug stress test, 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 without draining vm_stat_diff of all CPU.

This patch fixes it.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

zone_pcp_update() is called from online pages path. but IMHO, the statistics should be drained offline path. isn't it?

It isn't necessary because statistics is right until we reset it to zero in online path.
Do you have something on your mind that we have to drain it in offline path?

When a node is offlined and onlined again. We create node_data[i] in the

Quoted 7 lines

I would like to clarify your word.
Create or recreate?
Why I have a question is as I look over the source code, hotadd_new_pgdat seem to be called if we do hotadd *new* memory. It's not the case for offline and online again you mentioned. If you're right, I should find arch_free_nodedata to free pgdat when node is disappear but I can't find it. Do I miss something?

Hmm, when a memory is removed, we don't do cleanup now. We(Fujitsu) posted a patchset to do this:
https://lkml.org/lkml/2012/9/5/201

We don't free pgdat in this patchset now. We have two choice:
1. free pgdat
2. don't free it, and reuse it when it is onlined again

I'm not sure which choice is better.

Quoted 7 lines
Quoted 4 lines

function hotadd_new_pgdat(), and we will lost the statistics stored in zone->pageset. So we should drain it in offline path.

Even we drain in offline patch, it still has a problem.

Quoted 8 lines

1. offline
2. drain -> OKAY
3. schedule
4. Process A increase zone stat
5. Process B increase zone stat
6. online
7. reset it -> we ends up lost zone stat counter which is modified between 2-6

I understand why you drain it in online path now. But it still should drain it in offline path because if all pages in this zone are offlined, we will call zone_pcp_reset() to reset zone's pcp. We should also drop it in the function zone_pcp_reset().

Thanks
Wen Congyang

Quoted 7 lines
Quoted 7 lines

Thanks
Wen Congyang

Quoted 2 lines
Quoted 2 lines
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
Quoted 1 line

thanks.

--
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>

--
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>

#6 lore raw
Quoted 37 lines · Wen Congyang

At 09/20/2012 10:30 AM, Minchan Kim Wrote:

Quoted 24 lines · Wen Congyang
Quoted 14 lines

At 09/20/2012 04:17 AM, Minchan Kim Wrote:

Quoted 13 lines

Hi KOSAKI,

Quoted 10 lines · KOSAKI Motohiro
Quoted 8 lines · Minchan Kim

During memory-hotplug stress test, 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 without draining vm_stat_diff of all CPU.

This patch fixes it.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

zone_pcp_update() is called from online pages path. but IMHO, the statistics should be drained offline path. isn't it?

It isn't necessary because statistics is right until we reset it to zero in online path.
Do you have something on your mind that we have to drain it in offline path?

When a node is offlined and onlined again. We create node_data[i] in the

Quoted 7 lines

I would like to clarify your word.
Create or recreate?
Why I have a question is as I look over the source code, hotadd_new_pgdat seem to be called if we do hotadd *new* memory. It's not the case for offline and online again you mentioned. If you're right, I should find arch_free_nodedata to free pgdat when node is disappear but I can't find it. Do I miss something?

Hmm, when a memory is removed, we don't do cleanup now. We(Fujitsu) posted a patchset to do this:
https://lkml.org/lkml/2012/9/5/201

Quoted 5 lines

We don't free pgdat in this patchset now. We have two choice:
1. free pgdat
2. don't free it, and reuse it when it is onlined again

I'm not sure which choice is better.

I have no idea because I don't know how you guys uses. If there is use case that sometime you ues many node burstly but ues a few node in most time, 1) would be good POV memory efficiency although it makes code rather complicated.

Anyway, it's another story with this patch because it's not merged yet.

Quoted 17 lines
Quoted 8 lines
Quoted 5 lines

function hotadd_new_pgdat(), and we will lost the statistics stored in zone->pageset. So we should drain it in offline path.

Even we drain in offline patch, it still has a problem.

Quoted 8 lines

1. offline
2. drain -> OKAY
3. schedule
4. Process A increase zone stat
5. Process B increase zone stat
6. online
7. reset it -> we ends up lost zone stat counter which is modified between 2-6

Quoted 4 lines

I understand why you drain it in online path now. But it still should drain it in offline path because if all pages in this zone are offlined, we will call zone_pcp_reset() to reset zone's pcp. We should also drop it in the function zone_pcp_reset().

Good point.
How about this?

#7 lore raw

At 09/20/2012 01:16 PM, Minchan Kim Wrote:

Quoted 42 lines · Wen Congyang
Quoted 41 lines

At 09/20/2012 10:30 AM, Minchan Kim Wrote:

Quoted 24 lines · Wen Congyang
Quoted 14 lines

At 09/20/2012 04:17 AM, Minchan Kim Wrote:

Quoted 13 lines

Hi KOSAKI,

Quoted 10 lines · KOSAKI Motohiro
Quoted 8 lines · Minchan Kim

During memory-hotplug stress test, 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 without draining vm_stat_diff of all CPU.

This patch fixes it.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

zone_pcp_update() is called from online pages path. but IMHO, the statistics should be drained offline path. isn't it?

It isn't necessary because statistics is right until we reset it to zero in online path.
Do you have something on your mind that we have to drain it in offline path?

When a node is offlined and onlined again. We create node_data[i] in the

Quoted 7 lines

I would like to clarify your word.
Create or recreate?
Why I have a question is as I look over the source code, hotadd_new_pgdat seem to be called if we do hotadd *new* memory. It's not the case for offline and online again you mentioned. If you're right, I should find arch_free_nodedata to free pgdat when node is disappear but I can't find it. Do I miss something?

Hmm, when a memory is removed, we don't do cleanup now. We(Fujitsu) posted a patchset to do this:
https://lkml.org/lkml/2012/9/5/201

We don't free pgdat in this patchset now. We have two choice:
1. free pgdat
2. don't free it, and reuse it when it is onlined again

Quoted 8 lines
Quoted 1 line

I'm not sure which choice is better.

I have no idea because I don't know how you guys uses. If there is use case that sometime you ues many node burstly but ues a few node in most time, 1) would be good POV memory efficiency although it makes code rather complicated.

Anyway, it's another story with this patch because it's not merged yet.

Yes, it is another story.

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 6 lines

function hotadd_new_pgdat(), and we will lost the statistics stored in zone->pageset. So we should drain it in offline path.

Even we drain in offline patch, it still has a problem.

1. offline
2. drain -> OKAY
3. schedule
4. Process A increase zone stat
5. Process B increase zone stat
6. online
7. reset it -> we ends up lost zone stat counter which is modified between 2-6

Quoted 7 lines
Quoted 4 lines

I understand why you drain it in online path now. But it still should drain it in offline path because if all pages in this zone are offlined, we will call zone_pcp_reset() to reset zone's pcp. We should also drop it in the function zone_pcp_reset().

Good point.
How about this?

It looks fine to me now.

Thanks
Wen Congyang

Quoted 106 lines
Quoted 2 lines

From e92bf3e96720c89cb18ec32c5db095a27ad4133c Mon Sep 17 00:00:00 2001

From: Minchan Kim <[email protected]>
Date: Thu, 20 Sep 2012 14:11:49 +0900
Subject: [PATCH v2] 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 v1
* drain offline patch - KOSAKI, Wen

Cc Kamezawa Hiroyuki <[email protected]>
Cc Yasuaki Ishimatsu <[email protected]>
Cc Wen Congyang <[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
#8 lore raw
In reply to Minchan Kim

At 09/20/2012 01:16 PM, Minchan Kim Wrote:

Quoted 142 lines · Wen Congyang
Quoted 37 lines

At 09/20/2012 10:30 AM, Minchan Kim Wrote:

Quoted 24 lines · Wen Congyang
Quoted 14 lines

At 09/20/2012 04:17 AM, Minchan Kim Wrote:

Quoted 13 lines

Hi KOSAKI,

Quoted 10 lines · KOSAKI Motohiro
Quoted 8 lines · Minchan Kim

During memory-hotplug stress test, 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 without draining vm_stat_diff of all CPU.

This patch fixes it.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

zone_pcp_update() is called from online pages path. but IMHO, the statistics should be drained offline path. isn't it?

It isn't necessary because statistics is right until we reset it to zero in online path.
Do you have something on your mind that we have to drain it in offline path?

When a node is offlined and onlined again. We create node_data[i] in the

Quoted 7 lines

I would like to clarify your word.
Create or recreate?
Why I have a question is as I look over the source code, hotadd_new_pgdat seem to be called if we do hotadd *new* memory. It's not the case for offline and online again you mentioned. If you're right, I should find arch_free_nodedata to free pgdat when node is disappear but I can't find it. Do I miss something?

Hmm, when a memory is removed, we don't do cleanup now. We(Fujitsu) posted a patchset to do this:
https://lkml.org/lkml/2012/9/5/201

Quoted 5 lines

We don't free pgdat in this patchset now. We have two choice:
1. free pgdat
2. don't free it, and reuse it when it is onlined again

I'm not sure which choice is better.

I have no idea because I don't know how you guys uses. If there is use case that sometime you ues many node burstly but ues a few node in most time, 1) would be good POV memory efficiency although it makes code rather complicated.

Anyway, it's another story with this patch because it's not merged yet.

Quoted 17 lines
Quoted 8 lines
Quoted 5 lines

function hotadd_new_pgdat(), and we will lost the statistics stored in zone->pageset. So we should drain it in offline path.

Even we drain in offline patch, it still has a problem.

Quoted 8 lines

1. offline
2. drain -> OKAY
3. schedule
4. Process A increase zone stat
5. Process B increase zone stat
6. online
7. reset it -> we ends up lost zone stat counter which is modified between 2-6

Quoted 4 lines

I understand why you drain it in online path now. But it still should drain it in offline path because if all pages in this zone are offlined, we will call zone_pcp_reset() to reset zone's pcp. We should also drop it in the function zone_pcp_reset().

Good point.
How about this?

Quoted 1 line

From e92bf3e96720c89cb18ec32c5db095a27ad4133c Mon Sep 17 00:00:00 2001

From: Minchan Kim <[email protected]>
Date: Thu, 20 Sep 2012 14:11:49 +0900
Subject: [PATCH v2] 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 v1
* drain offline patch - KOSAKI, Wen

Cc Kamezawa Hiroyuki <[email protected]>
Cc Yasuaki Ishimatsu <[email protected]>
Cc Wen Congyang <[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 +1 -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);
 	}

mm/page_alloc.c void __meminit zone_pcp_update(struct zone *zone) · line 5930

Quoted 10 lines
mm/page_alloc.c +3 -0
@@ -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) {

A cpu can be offlined before the pages in the zone are offlined. So I think you should drain it on all possible cpu, not online cpu.

Thanks
Wen Congyang

Quoted 19 lines
mm/page_alloc.c +3 -0
+			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>

#9 lore raw
Quoted 149 lines · Wen Congyang

At 09/20/2012 01:16 PM, Minchan Kim Wrote:

Quoted 148 lines · Wen Congyang
Quoted 37 lines

At 09/20/2012 10:30 AM, Minchan Kim Wrote:

Quoted 24 lines · Wen Congyang
Quoted 14 lines

At 09/20/2012 04:17 AM, Minchan Kim Wrote:

Quoted 13 lines

Hi KOSAKI,

Quoted 10 lines · KOSAKI Motohiro
Quoted 8 lines · Minchan Kim

During memory-hotplug stress test, 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 without draining vm_stat_diff of all CPU.

This patch fixes it.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

zone_pcp_update() is called from online pages path. but IMHO, the statistics should be drained offline path. isn't it?

It isn't necessary because statistics is right until we reset it to zero in online path.
Do you have something on your mind that we have to drain it in offline path?

When a node is offlined and onlined again. We create node_data[i] in the

Quoted 7 lines

I would like to clarify your word.
Create or recreate?
Why I have a question is as I look over the source code, hotadd_new_pgdat seem to be called if we do hotadd *new* memory. It's not the case for offline and online again you mentioned. If you're right, I should find arch_free_nodedata to free pgdat when node is disappear but I can't find it. Do I miss something?

Hmm, when a memory is removed, we don't do cleanup now. We(Fujitsu) posted a patchset to do this:
https://lkml.org/lkml/2012/9/5/201

Quoted 5 lines

We don't free pgdat in this patchset now. We have two choice:
1. free pgdat
2. don't free it, and reuse it when it is onlined again

I'm not sure which choice is better.

I have no idea because I don't know how you guys uses. If there is use case that sometime you ues many node burstly but ues a few node in most time, 1) would be good POV memory efficiency although it makes code rather complicated.

Anyway, it's another story with this patch because it's not merged yet.

Quoted 17 lines
Quoted 8 lines
Quoted 5 lines

function hotadd_new_pgdat(), and we will lost the statistics stored in zone->pageset. So we should drain it in offline path.

Even we drain in offline patch, it still has a problem.

Quoted 8 lines

1. offline
2. drain -> OKAY
3. schedule
4. Process A increase zone stat
5. Process B increase zone stat
6. online
7. reset it -> we ends up lost zone stat counter which is modified between 2-6

Quoted 4 lines

I understand why you drain it in online path now. But it still should drain it in offline path because if all pages in this zone are offlined, we will call zone_pcp_reset() to reset zone's pcp. We should also drop it in the function zone_pcp_reset().

Good point.
How about this?

Quoted 1 line

From e92bf3e96720c89cb18ec32c5db095a27ad4133c Mon Sep 17 00:00:00 2001

From: Minchan Kim <[email protected]>
Date: Thu, 20 Sep 2012 14:11:49 +0900
Subject: [PATCH v2] 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 v1
* drain offline patch - KOSAKI, Wen

Cc Kamezawa Hiroyuki <[email protected]>
Cc Yasuaki Ishimatsu <[email protected]>
Cc Wen Congyang <[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 +3 -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;
 
Quoted 8 lines

mm/page_alloc.c void __meminit zone_pcp_update(struct zone *zone) · line 5930

Quoted 4 lines
mm/page_alloc.c +1 -0
 	/* avoid races with drain_pages()  */
 	local_irq_save(flags);
 	if (zone->pageset != &boot_pageset) {
+		for_each_online_cpu(cpu) {

A cpu can be offlined before the pages in the zone are offlined. So I think you should drain it on all possible cpu, not online cpu.

I'm not CPU hotplug expert but IMHO, it should be handled by vmstat_cpuup_callback when the CPU is down. Otherwise, it should never drain until zone is empty by memory-hotplug.

And if it is, it should be another patch.

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>
#10 lore raw

At 09/20/2012 01:55 PM, Minchan Kim Wrote:

Quoted 159 lines · Wen Congyang
Quoted 149 lines

At 09/20/2012 01:16 PM, Minchan Kim Wrote:

Quoted 148 lines · Wen Congyang
Quoted 37 lines

At 09/20/2012 10:30 AM, Minchan Kim Wrote:

Quoted 24 lines · Wen Congyang
Quoted 14 lines

At 09/20/2012 04:17 AM, Minchan Kim Wrote:

Quoted 13 lines

Hi KOSAKI,

Quoted 10 lines · KOSAKI Motohiro
Quoted 8 lines · Minchan Kim

During memory-hotplug stress test, 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 without draining vm_stat_diff of all CPU.

This patch fixes it.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

zone_pcp_update() is called from online pages path. but IMHO, the statistics should be drained offline path. isn't it?

It isn't necessary because statistics is right until we reset it to zero in online path.
Do you have something on your mind that we have to drain it in offline path?

When a node is offlined and onlined again. We create node_data[i] in the

Quoted 7 lines

I would like to clarify your word.
Create or recreate?
Why I have a question is as I look over the source code, hotadd_new_pgdat seem to be called if we do hotadd *new* memory. It's not the case for offline and online again you mentioned. If you're right, I should find arch_free_nodedata to free pgdat when node is disappear but I can't find it. Do I miss something?

Hmm, when a memory is removed, we don't do cleanup now. We(Fujitsu) posted a patchset to do this:
https://lkml.org/lkml/2012/9/5/201

Quoted 5 lines

We don't free pgdat in this patchset now. We have two choice:
1. free pgdat
2. don't free it, and reuse it when it is onlined again

I'm not sure which choice is better.

I have no idea because I don't know how you guys uses. If there is use case that sometime you ues many node burstly but ues a few node in most time, 1) would be good POV memory efficiency although it makes code rather complicated.

Anyway, it's another story with this patch because it's not merged yet.

Quoted 17 lines
Quoted 8 lines
Quoted 5 lines

function hotadd_new_pgdat(), and we will lost the statistics stored in zone->pageset. So we should drain it in offline path.

Even we drain in offline patch, it still has a problem.

Quoted 8 lines

1. offline
2. drain -> OKAY
3. schedule
4. Process A increase zone stat
5. Process B increase zone stat
6. online
7. reset it -> we ends up lost zone stat counter which is modified between 2-6

Quoted 4 lines

I understand why you drain it in online path now. But it still should drain it in offline path because if all pages in this zone are offlined, we will call zone_pcp_reset() to reset zone's pcp. We should also drop it in the function zone_pcp_reset().

Good point.
How about this?

Quoted 1 line

From e92bf3e96720c89cb18ec32c5db095a27ad4133c Mon Sep 17 00:00:00 2001

From: Minchan Kim <[email protected]>
Date: Thu, 20 Sep 2012 14:11:49 +0900
Subject: [PATCH v2] 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 v1
* drain offline patch - KOSAKI, Wen

Cc Kamezawa Hiroyuki <[email protected]>
Cc Yasuaki Ishimatsu <[email protected]>
Cc Wen Congyang <[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 +3 -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;
 
Quoted 8 lines

mm/page_alloc.c void __meminit zone_pcp_update(struct zone *zone) · line 5930

Quoted 4 lines
mm/page_alloc.c +1 -0
 	/* avoid races with drain_pages()  */
 	local_irq_save(flags);
 	if (zone->pageset != &boot_pageset) {
+		for_each_online_cpu(cpu) {

A cpu can be offlined before the pages in the zone are offlined. So I think you should drain it on all possible cpu, not online cpu.

Quoted 5 lines

I'm not CPU hotplug expert but IMHO, it should be handled by vmstat_cpuup_callback when the CPU is down. Otherwise, it should never drain until zone is empty by memory-hotplug.

And if it is, it should be another patch.

It has been done in page_alloc_cpu_notify(). Your patch is OK to me now.

Thanks
Wen Congyang

--
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>