Skip to contentSkip to conversation

mm:kswapd: clean up the kswapd

PATCH Superseded Chen Yucong 2 participants 3 messages Jun 23, 2014 – Jun 24, 2014

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

PATCH 1/1 mm:kswapd: clean up the kswapd

According to the commit 215ddd66 (mm: vmscan: only read new_classzone_idx from pgdat when reclaiming successfully) and the commit d2ebd0f6b (kswapd: avoid unnecessary rebalance after an unsuccessful balancing), we can use a boolean variable for replace balanced_* variables, which makes the kswapd more clarify.

---
 mm/vmscan.c |   29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
mm/vmscan.c +16 -13
index a8ffe4e..b0a75d1 100644
@@ -3332,10 +3332,9 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order, int classzone_idx)
  */
 static int kswapd(void *p)
 {
+	bool balance_is_successful;
 	unsigned long order, new_order;
-	unsigned balanced_order;
 	int classzone_idx, new_classzone_idx;
-	int balanced_classzone_idx;
 	pg_data_t *pgdat = (pg_data_t*)p;
 	struct task_struct *tsk = current;
 
@@ -3366,9 +3365,7 @@ static int kswapd(void *p)
 	set_freezable();
 
 	order = new_order = 0;
-	balanced_order = 0;
 	classzone_idx = new_classzone_idx = pgdat->nr_zones - 1;
-	balanced_classzone_idx = classzone_idx;
 	for ( ; ; ) {
 		bool ret;
 
@@ -3377,24 +3374,32 @@ static int kswapd(void *p)
 		 * new request of a similar or harder type will succeed soon
 		 * so consider going to sleep on the basis we reclaimed at
 		 */
-		if (balanced_classzone_idx >= new_classzone_idx &&
-					balanced_order == new_order) {
+		balance_is_successful = false;
+		if (classzone_idx >= new_classzone_idx && order == new_order) {
+			/*
+			 * After the last balance_pgdat, if the `order' stays
+			 * constant and the scanned zones are not less than
+			 * specified by original classzone_idx, then the last
+			 * balance_pgdat was successful.
+			 */
 			new_order = pgdat->kswapd_max_order;
 			new_classzone_idx = pgdat->classzone_idx;
 			pgdat->kswapd_max_order =  0;
 			pgdat->classzone_idx = pgdat->nr_zones - 1;
+			balance_is_successful = true;
 		}
 
-		if (order < new_order || classzone_idx > new_classzone_idx) {
+		if (balance_is_successful && (order < new_order ||
+					classzone_idx > new_classzone_idx)) {
 			/*
 			 * Don't sleep if someone wants a larger 'order'
-			 * allocation or has tigher zone constraints
+			 * allocation or has tighter zone constraints on the
+			 * premise of the last balance_pgdat was successful.
 			 */
 			order = new_order;
 			classzone_idx = new_classzone_idx;
 		} else {
-			kswapd_try_to_sleep(pgdat, balanced_order,
-						balanced_classzone_idx);
+			kswapd_try_to_sleep(pgdat, order, classzone_idx);
 			order = pgdat->kswapd_max_order;
 			classzone_idx = pgdat->classzone_idx;
 			new_order = order;
@@ -3413,9 +3418,7 @@ static int kswapd(void *p)
 		 */
 		if (!ret) {
 			trace_mm_vmscan_kswapd_wake(pgdat->node_id, order);
-			balanced_classzone_idx = classzone_idx;
-			balanced_order = balance_pgdat(pgdat, order,
-						&balanced_classzone_idx);
+			order = balance_pgdat(pgdat, order, &classzone_idx);
 		}
 	}
 
Signature · 7 lines
1.7.10.4

--
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 6 lines · Chen Yucong

According to the commit 215ddd66 (mm: vmscan: only read new_classzone_idx from pgdat when reclaiming successfully) and the commit d2ebd0f6b (kswapd: avoid unnecessary rebalance after an unsuccessful balancing), we can use a boolean variable for replace balanced_* variables, which makes the kswapd more clarify.

I think this is just churning code for the sake of it. It's not any easier to understand as a result of the modification and does not appear to be a preparation for a follow-on patch that addresses a bug.

Signature · 2 lines
Mel Gorman
SUSE Labs
#2 lore raw
Quoted 6 lines · Mel Gorman
Quoted 5 lines · Chen Yucong

According to the commit 215ddd66 (mm: vmscan: only read new_classzone_idx from pgdat when reclaiming successfully) and the commit d2ebd0f6b (kswapd: avoid unnecessary rebalance after an unsuccessful balancing), we can use a boolean variable for replace balanced_* variables, which makes the kswapd more clarify.

Quoted 6 lines
Quoted 1 line

I think this is just churning code for the sake of it. It's not any easier to understand as a result of the modification and does not appear to be a preparation for a follow-on patch that addresses a bug.

Anyway, there are some palaces that still need to be cleaned in `kswapd'.

thx!
cyc

Subject: [PATCH] mm:kswapd: clean up the kswapd

The type of variables(order, new_order, and balanced_order) has some flaws.
According to the `order' argument for kswapd_try_to_sleep() and balance_pgdat(),
they should be defined as int' rather than unsigned long' or `unsigned'.
This patch also does minimal cleanup, which makes the kswapd more clarify.

---
 mm/vmscan.c |   33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)
mm/vmscan.c +0 -0
index a8ffe4e..1b2576d 100644
@@ -3332,8 +3332,8 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat,

int order, int classzone_idx)
*/
static int kswapd(void *p)
{
- unsigned long order, new_order;
- unsigned balanced_order;
+ int order, new_order;
+ int balanced_order;
int classzone_idx, new_classzone_idx; int balanced_classzone_idx; pg_data_t *pgdat = (pg_data_t*)p;
@@ -3371,34 +3371,37 @@ static int kswapd(void *p)
balanced_classzone_idx = classzone_idx; for ( ; ; ) {
bool ret;
+ bool sleep = true;

/*
* If the last balance_pgdat was unsuccessful it's unlikely a
* new request of a similar or harder type will succeed soon
* so consider going to sleep on the basis we reclaimed at */
- if (balanced_classzone_idx >= new_classzone_idx &&
- balanced_order == new_order) {
+ if (balanced_classzone_idx >= classzone_idx &&
+ balanced_order == order) {
new_order = pgdat->kswapd_max_order; new_classzone_idx = pgdat->classzone_idx;
- pgdat->kswapd_max_order = 0;
+ pgdat->kswapd_max_order = 0;
pgdat->classzone_idx = pgdat->nr_zones - 1;
+
+ if (order < new_order ||
+ classzone_idx > new_classzone_idx) {
+ /*
+ * Don't sleep if someone wants a larger 'order'
+ * allocation or has tighter zone constraints
+ */
+ order = new_order;
+ classzone_idx = new_classzone_idx;
+ sleep = false;
+ }
}

- if (order < new_order || classzone_idx > new_classzone_idx) {
- /*
- * Don't sleep if someone wants a larger 'order'
- * allocation or has tigher zone constraints
- */
- order = new_order;
- classzone_idx = new_classzone_idx;
- } else {
+ if (sleep) {
kswapd_try_to_sleep(pgdat, balanced_order,
balanced_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 · 9 lines
1.7.10.4

  

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