Skip to content

Commit d2ebd0f

Browse files
Alex,Shitorvalds
authored andcommitted
kswapd: avoid unnecessary rebalance after an unsuccessful balancing
In commit 215ddd6 ("mm: vmscan: only read new_classzone_idx from pgdat when reclaiming successfully") , Mel Gorman said kswapd is better to sleep after a unsuccessful balancing if there is tighter reclaim request pending in the balancing. But in the following scenario, kswapd do something that is not matched our expectation. The patch fixes this issue. 1, Read pgdat request A (classzone_idx, order = 3) 2, balance_pgdat() 3, During pgdat, a new pgdat request B (classzone_idx, order = 5) is placed 4, balance_pgdat() returns but failed since returned order = 0 5, pgdat of request A assigned to balance_pgdat(), and do balancing again. While the expectation behavior of kswapd should try to sleep. Signed-off-by: Alex Shi <alex.shi@intel.com> Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com> Acked-by: Mel Gorman <mgorman@suse.de> Tested-by: Pádraig Brady <P@draigBrady.com> Cc: Rik van Riel <riel@redhat.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 64212ec commit d2ebd0f

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎mm/vmscan.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,7 +2823,9 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order, int classzone_idx)
28232823
static int kswapd(void *p)
28242824
{
28252825
unsigned long order, new_order;
2826+
unsigned balanced_order;
28262827
int classzone_idx, new_classzone_idx;
2828+
int balanced_classzone_idx;
28272829
pg_data_t *pgdat = (pg_data_t*)p;
28282830
struct task_struct *tsk = current;
28292831

@@ -2854,7 +2856,9 @@ static int kswapd(void *p)
28542856
set_freezable();
28552857

28562858
order = new_order = 0;
2859+
balanced_order = 0;
28572860
classzone_idx = new_classzone_idx = pgdat->nr_zones - 1;
2861+
balanced_classzone_idx = classzone_idx;
28582862
for ( ; ; ) {
28592863
int ret;
28602864

@@ -2863,7 +2867,8 @@ static int kswapd(void *p)
28632867
* new request of a similar or harder type will succeed soon
28642868
* so consider going to sleep on the basis we reclaimed at
28652869
*/
2866-
if (classzone_idx >= new_classzone_idx && order == new_order) {
2870+
if (balanced_classzone_idx >= new_classzone_idx &&
2871+
balanced_order == new_order) {
28672872
new_order = pgdat->kswapd_max_order;
28682873
new_classzone_idx = pgdat->classzone_idx;
28692874
pgdat->kswapd_max_order = 0;
@@ -2878,7 +2883,8 @@ static int kswapd(void *p)
28782883
order = new_order;
28792884
classzone_idx = new_classzone_idx;
28802885
} else {
2881-
kswapd_try_to_sleep(pgdat, order, classzone_idx);
2886+
kswapd_try_to_sleep(pgdat, balanced_order,
2887+
balanced_classzone_idx);
28822888
order = pgdat->kswapd_max_order;
28832889
classzone_idx = pgdat->classzone_idx;
28842890
pgdat->kswapd_max_order = 0;
@@ -2895,7 +2901,9 @@ static int kswapd(void *p)
28952901
*/
28962902
if (!ret) {
28972903
trace_mm_vmscan_kswapd_wake(pgdat->node_id, order);
2898-
order = balance_pgdat(pgdat, order, &classzone_idx);
2904+
balanced_classzone_idx = classzone_idx;
2905+
balanced_order = balance_pgdat(pgdat, order,
2906+
&balanced_classzone_idx);
28992907
}
29002908
}
29012909
return 0;

0 commit comments

Comments
 (0)