Skip to contentSkip to conversation

Remove pointless next_mz nullification in mem_cgroup_soft_limit_reclaim

PATCH Superseded Michal Hocko 3 participants 8 messages Mar 29, 2011 – Mar 30, 2011

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

PATCH 1/1 Remove pointless next_mz nullification in mem_cgroup_soft_limit_reclaim

Hi,
while reading the code I have encountered the following thing. It is no biggie but...
---
From: Michal Hocko <[email protected]>
Subject: Remove pointless next_mz nullification in mem_cgroup_soft_limit_reclaim

next_mz is assigned to NULL if __mem_cgroup_largest_soft_limit_node selects the same mz. This doesn't make much sense as we assign to the variable right in the next loop.

Compiler will probably optimize this out but it is little bit confusing for the code reading.

mm/memcontrol.c +0 -1
Index: linux-2.6.38-rc8/mm/memcontrol.c
===================================================================
@@ -3349,7 +3349,6 @@ unsigned long mem_cgroup_soft_limit_recl
 				__mem_cgroup_largest_soft_limit_node(mctz);
 				if (next_mz == mz) {
 					css_put(&next_mz->mem->css);
-					next_mz = NULL;
 				} else /* next_mz == NULL or other memcg */
 					break;
 			} while (1);
Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

Michal,
IIUC it's to prevent the infinite loop, as in the end of the do-while there's
if (!nr_reclaimed &&

    (next_mz == NULL ||
    loop > MEM_CGROUP_MAX_SOFT_LIMIT_RECLAIM_LOOPS))
		break;

so the loop will break earlier if all groups are iterated once and no pages are freed.

Thanks,
Zhu Yanhai

2011/3/29 Michal Hocko <[email protected]>:

Quoted 36 lines

Hi,
while reading the code I have encountered the following thing. It is no biggie but...
---
From: Michal Hocko <[email protected]>
Subject: Remove pointless next_mz nullification in mem_cgroup_soft_limit_reclaim

next_mz is assigned to NULL if __mem_cgroup_largest_soft_limit_node selects the same mz. This doesn't make much sense as we assign to the variable right in the next loop.

Compiler will probably optimize this out but it is little bit confusing for the code reading.

Index: linux-2.6.38-rc8/mm/memcontrol.c
===================================================================

mm/memcontrol.c    2011-03-29 15:24:08.000000000 +0200 renamed from mm/memcontrol.c       2011-03-28 11:25:14.000000000 +0200 +0 -2
@@ -3349,7 +3349,6 @@ unsigned long mem_cgroup_soft_limit_recl
                                __mem_cgroup_largest_soft_limit_node(mctz);
                                if (next_mz == mz) {
                                        css_put(&next_mz->mem->css);
-                                       next_mz = NULL;
                                } else /* next_mz == NULL or other memcg */
                                        break;
                        } while (1);
--

Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9
Czech Republic

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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 10 lines · Zhu Yanhai

Michal,
IIUC it's to prevent the infinite loop, as in the end of the do-while there's
if (!nr_reclaimed &&

    (next_mz == NULL ||
    loop > MEM_CGROUP_MAX_SOFT_LIMIT_RECLAIM_LOOPS))
		break;

so the loop will break earlier if all groups are iterated once and no pages are freed.

The code (in mmotm 2011-03-10-16-42) reads:

			do {
				[skipped comments]
                                next_mz =
                                __mem_cgroup_largest_soft_limit_node(mctz);
                                if (next_mz == mz) {
                                        css_put(&next_mz->mem->css);
					next_mz = NULL;
                                } else /* next_mz == NULL or other memcg */
                                        break;
                        } while (1);

So we do not break out of the loop and start a new iteration if next_mz == mz and assign next_mz again.
Am I missing something?

Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

R290IGl0LiBTb3JyeSwgbXkgZmF1bHQgOikKCi16eWgKCjIwMTEvMy8yOSBNaWNoYWwgSG9ja28g PG1ob2Nrb0BzdXNlLmN6PjoKPiBPbiBUdWUgMjktMDMtMTEgMjE6NDA6MTMsIFpodSBZYW5oYWkg d3JvdGU6Cj4+IE1pY2hhbCwKPj4gSUlVQyBpdCdzIHRvIHByZXZlbnQgdGhlIGluZmluaXRlIGxv b3AsIGFzIGluIHRoZSBlbmQgb2YgdGhlIGRvLXdoaWxlCj4+IHRoZXJlJ3MKPj4gaWYgKCFucl9y ZWNsYWltZWQgJiYKPj4gwqAgwqAgKG5leHRfbXogPT0gTlVMTCB8fAo+PiDCoCDCoCBsb29wID4g TUVNX0NHUk9VUF9NQVhfU09GVF9MSU1JVF9SRUNMQUlNX0xPT1BTKSkKPj4gwqAgwqAgwqAgwqAg wqAgwqAgwqAgYnJlYWs7Cj4KPj4gc28gdGhlIGxvb3Agd2lsbCBicmVhayBlYXJsaWVyIGlmIGFs bCBncm91cHMgYXJlIGl0ZXJhdGVkIG9uY2UgYW5kIG5vCj4+IHBhZ2VzIGFyZSBmcmVlZC4KPgo+ IFRoZSBjb2RlIChpbiBtbW90bSAyMDExLTAzLTEwLTE2LTQyKSByZWFkczoKPiDCoCDCoCDCoCDC oCDCoCDCoCDCoCDCoCDCoCDCoCDCoCDCoGRvIHsKPiDCoCDCoCDCoCDCoCDCoCDCoCDCoCDCoCDC oCDCoCDCoCDCoCDCoCDCoCDCoCDCoFtza2lwcGVkIGNvbW1lbnRzXQo+IMKgIMKgIMKgIMKgIM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rYSAxMDYwLzEyCj4gMTkw IDAwIFByYWhhIDkKPiBDemVjaCBSZXB1YmxpYwo+Cg==

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
In reply to Michal Hocko
Quoted 21 lines · On Tue, 29 Mar 2011 15:28:00 +0200 Michal Hocko <[email protected]> wrote:

Hi,
while reading the code I have encountered the following thing. It is no biggie but...
---
From: Michal Hocko <[email protected]>
Subject: Remove pointless next_mz nullification in mem_cgroup_soft_limit_reclaim

next_mz is assigned to NULL if __mem_cgroup_largest_soft_limit_node selects the same mz. This doesn't make much sense as we assign to the variable right in the next loop.

Compiler will probably optimize this out but it is little bit confusing for the code reading.

Index: linux-2.6.38-rc8/mm/memcontrol.c
===================================================================

mm/memcontrol.c unsigned long mem_cgroup_soft_limit_recl · line 3354

Quoted 7 lines
mm/memcontrol.c +0 -1
@@ -3349,7 +3349,6 @@ unsigned long mem_cgroup_soft_limit_recl
 				__mem_cgroup_largest_soft_limit_node(mctz);
 				if (next_mz == mz) {
 					css_put(&next_mz->mem->css);
-					next_mz = NULL;
 				} else /* next_mz == NULL or other memcg */
 					break;
 			} while (1);

hmm, make sense.

Can you remove the braces of the if-else statement too ?

Thanks,
Daisuke Nishimura.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

PATCH v2 1/1 Remove pointless next_mz nullification in mem_cgroup_soft_limit_reclaim

On Wed 30-03-11 11:09:53, Daisuke Nishimura wrote:
[...]

Quoted 14 lines

mm/memcontrol.c unsigned long mem_cgroup_soft_limit_recl · line 3354

Quoted 12 lines

Index: linux-2.6.38-rc8/mm/memcontrol.c
===================================================================

mm/memcontrol.c +0 -1
@@ -3349,7 +3349,6 @@ unsigned long mem_cgroup_soft_limit_recl
 				__mem_cgroup_largest_soft_limit_node(mctz);
 				if (next_mz == mz) {
 					css_put(&next_mz->mem->css);
-					next_mz = NULL;
 				} else /* next_mz == NULL or other memcg */
 					break;
 			} while (1);

hmm, make sense.

Quoted 1 line

Can you remove the braces of the if-else statement too ?

Sure, makes sense and the diff is even nicer because now we can see that nezt_mz is assigned right before.
Thanks
---
From: Michal Hocko <[email protected]>
Subject: Remove pointless next_mz nullification in mem_cgroup_soft_limit_reclaim

next_mz is assigned to NULL if __mem_cgroup_largest_soft_limit_node selects the same mz. This doesn't make much sense as we assign to the variable right in the next loop.

Compiler will probably optimize this out but it is little bit confusing for the code reading.

mm/memcontrol.c +2 -3
Index: linux-2.6.38-rc8/mm/memcontrol.c
===================================================================
@@ -3347,10 +3347,9 @@ unsigned long mem_cgroup_soft_limit_recl
 				 */
 				next_mz =
 				__mem_cgroup_largest_soft_limit_node(mctz);
-				if (next_mz == mz) {
+				if (next_mz == mz)
 					css_put(&next_mz->mem->css);
-					next_mz = NULL;
-				} else /* next_mz == NULL or other memcg */
+				else /* next_mz == NULL or other memcg */
 					break;
 			} while (1);
 		}
Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v2 1/1
#6 lore raw
Quoted 11 lines

From: Michal Hocko <[email protected]>
Subject: Remove pointless next_mz nullification in mem_cgroup_soft_limit_reclaim

next_mz is assigned to NULL if __mem_cgroup_largest_soft_limit_node selects the same mz. This doesn't make much sense as we assign to the variable right in the next loop.

Compiler will probably optimize this out but it is little bit confusing for the code reading.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author Acked-by Daisuke Nishimura
#7 lore raw
Quoted 7 lines · Daisuke Nishimura
Quoted 7 lines

From: Michal Hocko <[email protected]>
Subject: Remove pointless next_mz nullification in mem_cgroup_soft_limit_reclaim

next_mz is assigned to NULL if __mem_cgroup_largest_soft_limit_node selects the same mz. This doesn't make much sense as we assign to the variable right in the next loop.

Quoted 6 lines
Quoted 4 lines

Compiler will probably optimize this out but it is little bit confusing for the code reading.

Thanks Daisuke.

Andrew, should this go though your mm tree?
---
From: Michal Hocko <[email protected]>
Subject: Remove pointless next_mz nullification in mem_cgroup_soft_limit_reclaim

next_mz is assigned to NULL if __mem_cgroup_largest_soft_limit_node selects the same mz. This doesn't make much sense as we assign to the variable right in the next loop.

Compiler will probably optimize this out but it is little bit confusing for the code reading.

mm/memcontrol.c +2 -3
Index: linux-2.6.38-rc8/mm/memcontrol.c
===================================================================
@@ -3347,10 +3347,9 @@ unsigned long mem_cgroup_soft_limit_recl
 				 */
 				next_mz =
 				__mem_cgroup_largest_soft_limit_node(mctz);
-				if (next_mz == mz) {
+				if (next_mz == mz)
 					css_put(&next_mz->mem->css);
-					next_mz = NULL;
-				} else /* next_mz == NULL or other memcg */
+				else /* next_mz == NULL or other memcg */
 					break;
 			} while (1);
 		}
Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>