Skip to contentSkip to conversation

kswapd: assign new_order and new_classzone_idx after wakeup in sleeping

PATCH In review Alex Shi 2 participants 5 messages Jul 28, 2011 – Jul 29, 2011

Subsystems (3)
lore
Share & tools
lore

Alex Shi

author
#0 lore raw

PATCH 1/1 kswapd: assign new_order and new_classzone_idx after wakeup in sleeping

There 2 place to read pgdat in kswapd. One is return from a successful balance, another is waked up from sleeping. But the new_order and new_classzone_idx are not assigned after kswapd_try_to_sleep(), that will cause a bug in the following scenario.

After the last time successful balance, kswapd goes to sleep. So the new_order and new_classzone_idx were assigned to 0 and MAX-1 since there is no new wakeup during last time balancing. Now, a new wakeup came and finish balancing successful with order > 0. But since new_order is still 0, this time successful balancing were judged as a failed balance. so, if there is another new wakeup coming during balancing, kswapd cann't read this and still want to try to sleep. And if the new wakeup is a tighter request, kswapd may goes to sleep, not to do balancing. That is incorrect.

So, to avoid above problem, the new_order and new_classzone_idx need to be assigned for later successful comparison.

---
 mm/vmscan.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
mm/vmscan.c +2 -0
index 7ef6912..eb7bcce 100644
@@ -2850,6 +2850,8 @@ static int kswapd(void *p)
 			kswapd_try_to_sleep(pgdat, order, classzone_idx);
 			order = pgdat->kswapd_max_order;
 			classzone_idx = pgdat->classzone_idx;
+			new_order = order;
+			new_classzone_idx = classzone_idx;
 			pgdat->kswapd_max_order = 0;
 			pgdat->classzone_idx = pgdat->nr_zones - 1;
 		}
Signature · 1 line
1.6.3.3
Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · Alex Shi

There 2 place to read pgdat in kswapd. One is return from a successful balance, another is waked up from sleeping. But the new_order and new_classzone_idx are not assigned after kswapd_try_to_sleep(), that will cause a bug in the following scenario.

After the last time successful balance, kswapd goes to sleep. So the new_order and new_classzone_idx were assigned to 0 and MAX-1 since there is no new wakeup during last time balancing. Now, a new wakeup came and finish balancing successful with order > 0. But since new_order is still 0, this time successful balancing were judged as a failed balance. so, if there is another new wakeup coming during balancing, kswapd cann't read this and still want to try to sleep. And if the new wakeup is a tighter request, kswapd may goes to sleep, not to do balancing. That is incorrect.

Quoted 3 lines

So, to avoid above problem, the new_order and new_classzone_idx need to be assigned for later successful comparison.

Other than a different changelog, this is identical to
https://lkml.org/lkml/2011/6/30/157 so

It won't be merged to -stable until it goes to mainline though so minimally you need to post this to linux-mm.

For -stable, you should explain why it is a candidate. I didn't push the patch at the time because user problems were already resolved and I wanted the merged for 3.0 before revisiting it. What problem did you observe without this patch? With the lack of reference to the other thread or the previous patch, I'm assuming you found and solved the problem independently and I'd like to add a test case.

Thanks.

Signature · 2 lines
Mel Gorman
SUSE Labs
author
#2 lore raw
Quoted 16 lines · Mel Gorman
Quoted 15 lines · Alex Shi

There 2 place to read pgdat in kswapd. One is return from a successful balance, another is waked up from sleeping. But the new_order and new_classzone_idx are not assigned after kswapd_try_to_sleep(), that will cause a bug in the following scenario.

After the last time successful balance, kswapd goes to sleep. So the new_order and new_classzone_idx were assigned to 0 and MAX-1 since there is no new wakeup during last time balancing. Now, a new wakeup came and finish balancing successful with order > 0. But since new_order is still 0, this time successful balancing were judged as a failed balance. so, if there is another new wakeup coming during balancing, kswapd cann't read this and still want to try to sleep. And if the new wakeup is a tighter request, kswapd may goes to sleep, not to do balancing. That is incorrect.

Quoted 6 lines
Quoted 3 lines

So, to avoid above problem, the new_order and new_classzone_idx need to be assigned for later successful comparison.

Other than a different changelog, this is identical to
https://lkml.org/lkml/2011/6/30/157 so

Oops, I didn't aware this, otherwise it will save me several hours to explain what the problem in current code to Shaohua and others. :) In fact, I still hold another patch of kswapd and some idea of how to kswapd working that want to talk with you.

Quoted 6 lines

It won't be merged to -stable until it goes to mainline though so minimally you need to post this to linux-mm.

Quoted 6 lines

For -stable, you should explain why it is a candidate. I didn't push the patch at the time because user problems were already resolved and I wanted the merged for 3.0 before revisiting it. What problem did you observe without this patch? With the lack of reference to the other thread or the previous patch, I'm assuming you found and solved the problem independently and I'd like to add a test case.

Actually, our LKP testing didn't find this problem on this point. Even with the patch, performance has no change on our machines. I just find this by my eyes.

BTW, I have tracked our benchmarks for their hot path in kernel. The most exercised benchmark on kswapd is no more than 5% of system load. that is fio mmap rand write or randrw.

Do you have some benchmark can use kswapd much?

BTW, our project http://kernel-perf.sourceforge.net/

Quoted 3 lines

Thanks.

#3 lore raw
Quoted 21 lines · Alex,Shi
Quoted 20 lines · Mel Gorman
Quoted 18 lines · Alex Shi

There 2 place to read pgdat in kswapd. One is return from a successful balance, another is waked up from sleeping. But the new_order and new_classzone_idx are not assigned after kswapd_try_to_sleep(), that will cause a bug in the following scenario.

After the last time successful balance, kswapd goes to sleep. So the new_order and new_classzone_idx were assigned to 0 and MAX-1 since there is no new wakeup during last time balancing. Now, a new wakeup came and finish balancing successful with order > 0. But since new_order is still 0, this time successful balancing were judged as a failed balance. so, if there is another new wakeup coming during balancing, kswapd cann't read this and still want to try to sleep. And if the new wakeup is a tighter request, kswapd may goes to sleep, not to do balancing. That is incorrect.

So, to avoid above problem, the new_order and new_classzone_idx need to be assigned for later successful comparison.

Quoted 5 lines
Quoted 2 lines

Other than a different changelog, this is identical to
https://lkml.org/lkml/2011/6/30/157 so

Oops, I didn't aware this, otherwise it will save me several hours to explain what the problem in current code to Shaohua and others. :)

Sorry for wasting your time.

Quoted 3 lines

In fact, I still hold another patch of kswapd and some idea of how to kswapd working that want to talk with you.

Post to linux-mm, cc me.

Quoted 12 lines
Quoted 11 lines

It won't be merged to -stable until it goes to mainline though so minimally you need to post this to linux-mm.

For -stable, you should explain why it is a candidate. I didn't push the patch at the time because user problems were already resolved and I wanted the merged for 3.0 before revisiting it. What problem did you observe without this patch? With the lack of reference to the other thread or the previous patch, I'm assuming you found and solved the problem independently and I'd like to add a test case.

Quoted 4 lines

Actually, our LKP testing didn't find this problem on this point. Even with the patch, performance has no change on our machines. I just find this by my eyes.

Dang. I figured all right that it was unlikely the patch would actually fix any problem but it looks correct and shouldnt' cause a regression. You should resend the patch to Andrew cc'ing the people in the old thread and linux-mm and ask Padraig Brady to test the patch to confirm his problem does not reappear. When it gets into mainline, try for -stable but I think there is very little motivation for merging it there.

Quoted 6 lines

BTW, I have tracked our benchmarks for their hot path in kernel. The most exercised benchmark on kswapd is no more than 5% of system load. that is fio mmap rand write or randrw.

Do you have some benchmark can use kswapd much?

Not excessively. Except in cases where kswapd is buggy, I don't remember many cases where it gets very far over 9% . I'll dig through old results later today or tomorrow and double check.

Quoted 1 line

BTW, our project http://kernel-perf.sourceforge.net/

Thanks.

Signature · 2 lines
Mel Gorman
SUSE Labs
author
#4 lore raw
Quoted 20 lines

Post to linux-mm, cc me.

Quoted 12 lines
Quoted 11 lines

It won't be merged to -stable until it goes to mainline though so minimally you need to post this to linux-mm.

For -stable, you should explain why it is a candidate. I didn't push the patch at the time because user problems were already resolved and I wanted the merged for 3.0 before revisiting it. What problem did you observe without this patch? With the lack of reference to the other thread or the previous patch, I'm assuming you found and solved the problem independently and I'd like to add a test case.

Quoted 4 lines

Actually, our LKP testing didn't find this problem on this point. Even with the patch, performance has no change on our machines. I just find this by my eyes.

Quoted 7 lines

Dang. I figured all right that it was unlikely the patch would actually fix any problem but it looks correct and shouldnt' cause a regression. You should resend the patch to Andrew cc'ing the people in the old thread and linux-mm and ask Padraig Brady to test the patch to confirm his problem does not reappear. When it gets into mainline, try for -stable but I think there is very little motivation for merging it there.

Thanks a lot for the suggestions. I will do them.