Skip to contentSkip to conversation

memsw: handle swapaccount kernel parameter correctly

PATCH In review Michal Hocko 3 participants 9 messages Jan 26, 2011 – Jan 28, 2011

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

PATCH 1/1 memsw: handle swapaccount kernel parameter correctly

Hi Andrew,
I am sorry but the patch which added swapaccount parameter is not correct (we have discussed it https://lkml.org/lkml/2010/11/16/103).
I didn't get the way how __setup parameters are handled correctly. The patch bellow fixes that.

I am CCing stable as well because the patch got into .37 kernel.

---

maintainer
#1 lore raw
Quoted 13 lines · On Wed, 26 Jan 2011 16:21:58 +0100 Michal Hocko <[email protected]> wrote:

I am sorry but the patch which added swapaccount parameter is not correct (we have discussed it https://lkml.org/lkml/2010/11/16/103).
I didn't get the way how __setup parameters are handled correctly. The patch bellow fixes that.

I am CCing stable as well because the patch got into .37 kernel.

---

Quoted 1 line

From 144c2e8aed27d82d48217896ee1f58dbaa7f1f84 Mon Sep 17 00:00:00 2001

From: Michal Hocko <[email protected]>
Date: Wed, 26 Jan 2011 14:12:41 +0100
Subject: [PATCH] memsw: handle swapaccount kernel parameter correctly

Quoted 5 lines

__setup based kernel command line parameters handled in obsolete_checksetup provides the parameter value including = (more precisely everything right after the parameter name) so we have to check for =0 resp. =1 here. If no value is given then we get an empty string rather then NULL.

This doesn't provide a description of the bug which just got fixed.

Quoted 1 line

From reading the code I think the current behaviour is

"swapaccount": works OK
"noswapaccount": works OK
"swapaccount=0": doesn't do anything
"swapaccount=1": doesn't do anything

but I might be wrong about that. Please send a changelog update to clarify all this.

#2 lore raw
Quoted 22 lines · Andrew Morton
Quoted 13 lines · On Wed, 26 Jan 2011 16:21:58 +0100 Michal Hocko <[email protected]> wrote:

I am sorry but the patch which added swapaccount parameter is not correct (we have discussed it https://lkml.org/lkml/2010/11/16/103).
I didn't get the way how __setup parameters are handled correctly. The patch bellow fixes that.

I am CCing stable as well because the patch got into .37 kernel.

---

Quoted 1 line

From 144c2e8aed27d82d48217896ee1f58dbaa7f1f84 Mon Sep 17 00:00:00 2001

From: Michal Hocko <[email protected]>
Date: Wed, 26 Jan 2011 14:12:41 +0100
Subject: [PATCH] memsw: handle swapaccount kernel parameter correctly

Quoted 5 lines

__setup based kernel command line parameters handled in obsolete_checksetup provides the parameter value including = (more precisely everything right after the parameter name) so we have to check for =0 resp. =1 here. If no value is given then we get an empty string rather then NULL.

Quoted 5 lines

This doesn't provide a description of the bug which just got fixed.

From reading the code I think the current behaviour is

"swapaccount": works OK

Not really because the original test was !s || s="1" but as I am writing in the commit message we are getting an empty string rather than NULL in no parameter value case..
So noswapaccount is actually the only thing that is working.

Quoted 6 lines

"noswapaccount": works OK
"swapaccount=0": doesn't do anything
"swapaccount=1": doesn't do anything

but I might be wrong about that. Please send a changelog update to clarify all this.

Sorry for not being specific enough. What about somthing like this:
---

Quoted 1 line

From 317dec3d13ef7f11e8f2699331bc32fcd6a8ea0e Mon Sep 17 00:00:00 2001

From: Michal Hocko <[email protected]>
Date: Wed, 26 Jan 2011 14:12:41 +0100
Subject: [PATCH] memsw: handle swapaccount kernel parameter correctly

__setup based kernel command line parameters handlers which are handled in obsolete_checksetup are provided with the parameter value including = (more precisely everything right after the parameter name).

This means that the current implementation of swapaccount[=1|0] doesn't work at all because if there is a value for the parameter then we are testing for "0" resp. "1" but we are getting "=0" resp. "=1" and if there is no parameter value we are getting an empty string rather than NULL.

The original noswapccount parameter, which doesn't care about the value, works correctly.

---
 mm/memcontrol.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
mm/memcontrol.c +3 -3
index db76ef7..cea2be48 100644
@@ -5013,9 +5013,9 @@ struct cgroup_subsys mem_cgroup_subsys = {
 static int __init enable_swap_account(char *s)
 {
 	/* consider enabled if no parameter or 1 is given */
-	if (!s || !strcmp(s, "1"))
+	if (!(*s) || !strcmp(s, "=1"))
 		really_do_swap_account = 1;
-	else if (!strcmp(s, "0"))
+	else if (!strcmp(s, "=0"))
 		really_do_swap_account = 0;
 	return 1;
 }
@@ -5023,7 +5023,7 @@ __setup("swapaccount", enable_swap_account);
 
 static int __init disable_swap_account(char *s)
 {
-	enable_swap_account("0");
+	enable_swap_account("=0");
 	return 1;
 }
 __setup("noswapaccount", disable_swap_account);
Signature · 10 lines
1.7.2.3


-- 
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic
#3 lore raw
Quoted 73 lines · On Thu, 27 Jan 2011 09:23:20 +0100 Michal Hocko <[email protected]> wrote:
Quoted 22 lines · Andrew Morton
Quoted 13 lines · On Wed, 26 Jan 2011 16:21:58 +0100 Michal Hocko <[email protected]> wrote:

I am sorry but the patch which added swapaccount parameter is not correct (we have discussed it https://lkml.org/lkml/2010/11/16/103).
I didn't get the way how __setup parameters are handled correctly. The patch bellow fixes that.

I am CCing stable as well because the patch got into .37 kernel.

---

Quoted 1 line

From 144c2e8aed27d82d48217896ee1f58dbaa7f1f84 Mon Sep 17 00:00:00 2001

From: Michal Hocko <[email protected]>
Date: Wed, 26 Jan 2011 14:12:41 +0100
Subject: [PATCH] memsw: handle swapaccount kernel parameter correctly

Quoted 5 lines

__setup based kernel command line parameters handled in obsolete_checksetup provides the parameter value including = (more precisely everything right after the parameter name) so we have to check for =0 resp. =1 here. If no value is given then we get an empty string rather then NULL.

Quoted 5 lines

This doesn't provide a description of the bug which just got fixed.

From reading the code I think the current behaviour is

"swapaccount": works OK

Not really because the original test was !s || s="1" but as I am writing in the commit message we are getting an empty string rather than NULL in no parameter value case..
So noswapaccount is actually the only thing that is working.

Quoted 6 lines

"noswapaccount": works OK
"swapaccount=0": doesn't do anything
"swapaccount=1": doesn't do anything

but I might be wrong about that. Please send a changelog update to clarify all this.

Sorry for not being specific enough. What about somthing like this:
---
From 317dec3d13ef7f11e8f2699331bc32fcd6a8ea0e Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Wed, 26 Jan 2011 14:12:41 +0100
Subject: [PATCH] memsw: handle swapaccount kernel parameter correctly

__setup based kernel command line parameters handlers which are handled in obsolete_checksetup are provided with the parameter value including = (more precisely everything right after the parameter name).

This means that the current implementation of swapaccount[=1|0] doesn't work at all because if there is a value for the parameter then we are testing for "0" resp. "1" but we are getting "=0" resp. "=1" and if there is no parameter value we are getting an empty string rather than NULL.

The original noswapccount parameter, which doesn't care about the value, works correctly.

---
 mm/memcontrol.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
mm/memcontrol.c +0 -0
index db76ef7..cea2be48 100644
@@ -5013,9 +5013,9 @@ struct cgroup_subsys mem_cgroup_subsys = {
 static int __init enable_swap_account(char *s)

mm/memcontrol.c struct cgroup_subsys mem_cgroup_subsys = { · line 5021

Quoted 10 lines
mm/memcontrol.c +2 -2
 {
 	/* consider enabled if no parameter or 1 is given */
-	if (!s || !strcmp(s, "1"))
+	if (!(*s) || !strcmp(s, "=1"))
 		really_do_swap_account = 1;
-	else if (!strcmp(s, "0"))
+	else if (!strcmp(s, "=0"))
 		really_do_swap_account = 0;
 	return 1;
 }

Hmm, usual callser of __setup() includes '=' to parameter name, as

mm/hugetlb.c:__setup("hugepages=", hugetlb_nrpages_setup); mm/hugetlb.c:__setup("default_hugepagesz=", hugetlb_default_setup);

How about moving "=" to __setup() ?

Thanks,
-Kame

#4 lore raw
Quoted 2 lines · KAMEZAWA Hiroyuki

On Thu, 27 Jan 2011 09:23:20 +0100
Michal Hocko <[email protected]> wrote:

[...]

Quoted 19 lines
Quoted 6 lines
mm/memcontrol.c +0 -0
index db76ef7..cea2be48 100644
@@ -5013,9 +5013,9 @@ struct cgroup_subsys mem_cgroup_subsys = {
 static int __init enable_swap_account(char *s)

mm/memcontrol.c struct cgroup_subsys mem_cgroup_subsys = { · line 5021

Quoted 10 lines
mm/memcontrol.c +2 -2
 {
 	/* consider enabled if no parameter or 1 is given */
-	if (!s || !strcmp(s, "1"))
+	if (!(*s) || !strcmp(s, "=1"))
 		really_do_swap_account = 1;
-	else if (!strcmp(s, "0"))
+	else if (!strcmp(s, "=0"))
 		really_do_swap_account = 0;
 	return 1;
 }

Hmm, usual callser of __setup() includes '=' to parameter name, as

Quoted 4 lines

mm/hugetlb.c:__setup("hugepages=", hugetlb_nrpages_setup); mm/hugetlb.c:__setup("default_hugepagesz=", hugetlb_default_setup);

How about moving "=" to __setup() ?

I have considered that as well but then we couldn't use swapaccount parameter without any value because the parameter parsing matches the whole string.
I found it better to have consistent [no]swapaccount with the =0|1 extension rather than keeping = in the setup like other users.

Sounds reasonable?

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 policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw
Quoted 28 lines · On Thu, 27 Jan 2011 10:29:51 +0100 Michal Hocko <[email protected]> wrote:
Quoted 2 lines · KAMEZAWA Hiroyuki

On Thu, 27 Jan 2011 09:23:20 +0100
Michal Hocko <[email protected]> wrote:

[...]

Quoted 19 lines
Quoted 6 lines
mm/memcontrol.c +0 -0
index db76ef7..cea2be48 100644
@@ -5013,9 +5013,9 @@ struct cgroup_subsys mem_cgroup_subsys = {
 static int __init enable_swap_account(char *s)

mm/memcontrol.c struct cgroup_subsys mem_cgroup_subsys = { · line 5021

Quoted 10 lines
mm/memcontrol.c +2 -2
 {
 	/* consider enabled if no parameter or 1 is given */
-	if (!s || !strcmp(s, "1"))
+	if (!(*s) || !strcmp(s, "=1"))
 		really_do_swap_account = 1;
-	else if (!strcmp(s, "0"))
+	else if (!strcmp(s, "=0"))
 		really_do_swap_account = 0;
 	return 1;
 }

Hmm, usual callser of __setup() includes '=' to parameter name, as

Quoted 4 lines

mm/hugetlb.c:__setup("hugepages=", hugetlb_nrpages_setup); mm/hugetlb.c:__setup("default_hugepagesz=", hugetlb_default_setup);

How about moving "=" to __setup() ?

Quoted 7 lines

I have considered that as well but then we couldn't use swapaccount parameter without any value because the parameter parsing matches the whole string.
I found it better to have consistent [no]swapaccount with the =0|1 extension rather than keeping = in the setup like other users.

Sounds reasonable?

Hmm. ok for this time.

Could you try to write a patch for feature-removal-schedule.txt and tries to remove noswapaccount and do clean up all ? (And add warning to noswapaccount will be removed.....in 2.6.40)

Thanks,
-Kame

#6 lore raw

PATCH 1/1 memsw: Deprecate noswapaccount kernel parameter and schedule it for removal

Quoted 3 lines · KAMEZAWA Hiroyuki

Could you try to write a patch for feature-removal-schedule.txt and tries to remove noswapaccount and do clean up all ? (And add warning to noswapaccount will be removed.....in 2.6.40)

Sure, no problem. What do you think about the following patch?
---

Acked-by on v1 1/1
#7 lore raw

Re: [PATCH] memsw: Deprecate noswapaccount kernel parameter and schedule it for removal

Quoted 19 lines · On Thu, 27 Jan 2011 11:47:59 +0100 Michal Hocko <[email protected]> wrote:
Quoted 3 lines · KAMEZAWA Hiroyuki

Could you try to write a patch for feature-removal-schedule.txt and tries to remove noswapaccount and do clean up all ? (And add warning to noswapaccount will be removed.....in 2.6.40)

Sure, no problem. What do you think about the following patch?
---
From a597421909a3291886345565c73102117a52301e Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 27 Jan 2011 11:41:01 +0100
Subject: [PATCH] memsw: Deprecate noswapaccount kernel parameter and schedule it for removal

noswapaccount couldn't be used to control memsw for both on/off cases so we have added swapaccount[=0|1] parameter. This way we can turn the feature in two ways noswapaccount resp. swapaccount=0. We have kept the original noswapaccount but I think we should remove it after some time as it just makes more command line parameters without any advantages and also the code to handle parameters is uglier if we want both parameters.

Quoted 2 lines

Nice!. Thank you.

Maybe other discussion as 2.6.40 is too early or some may happen. But Ack from me, at least.

--
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 policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw

Re: [PATCH] memsw: Deprecate noswapaccount kernel parameter and schedule it for removal

Quoted 22 lines · KAMEZAWA Hiroyuki
Quoted 19 lines · On Thu, 27 Jan 2011 11:47:59 +0100 Michal Hocko <[email protected]> wrote:
Quoted 3 lines · KAMEZAWA Hiroyuki

Could you try to write a patch for feature-removal-schedule.txt and tries to remove noswapaccount and do clean up all ? (And add warning to noswapaccount will be removed.....in 2.6.40)

Sure, no problem. What do you think about the following patch?
---
From a597421909a3291886345565c73102117a52301e Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Thu, 27 Jan 2011 11:41:01 +0100
Subject: [PATCH] memsw: Deprecate noswapaccount kernel parameter and schedule it for removal

noswapaccount couldn't be used to control memsw for both on/off cases so we have added swapaccount[=0|1] parameter. This way we can turn the feature in two ways noswapaccount resp. swapaccount=0. We have kept the original noswapaccount but I think we should remove it after some time as it just makes more command line parameters without any advantages and also the code to handle parameters is uglier if we want both parameters.

Quoted 5 lines
Quoted 2 lines

Nice!. Thank you.

Thanks

Quoted 3 lines

Maybe other discussion as 2.6.40 is too early or some may happen. But Ack from me, at least.

Sure.

Just for record here is the patch to remove and cleanup. I can split it into 2 patches (one for removal and the other for the cleanup) but this can be done later as well.
---