Skip to contentSkip to conversation

memcg: fix return value of mem_cgroup_hierarchy_write()

PATCH In review Li Zefan 4 participants 5 messages Jan 14, 2009

Subsystems (2)
lore
Share & tools
lore

Li Zefan

author
#0 lore raw

PATCH 1/1 memcg: fix return value of mem_cgroup_hierarchy_write()

When there are sub-dirs, writing to memory.use_hierarchy returns -EBUSY, this doesn't seem to fit the meaning of EBUSY, and is inconsistent with memory.swappiness, which returns -EINVAL in this case.

---
 mm/memcontrol.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
mm/memcontrol.c +5 -5
index bc8f101..2497f7d 100644
@@ -1760,6 +1760,9 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft,
 	struct cgroup *parent = cont->parent;
 	struct mem_cgroup *parent_mem = NULL;
 
+	if (val != 0 && val != 1)
+		return -EINVAL;
+
 	if (parent)
 		parent_mem = mem_cgroup_from_cont(parent);
 
@@ -1773,12 +1776,9 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft,
 	 * set if there are no children.
 	 */
 	if ((!parent_mem || !parent_mem->use_hierarchy) &&
-				(val == 1 || val == 0)) {
-		if (list_empty(&cont->children))
+	    list_empty(&cont->children))
 			mem->use_hierarchy = val;
-		else
-			retval = -EBUSY;
-	} else
+	else
 		retval = -EINVAL;
 	cgroup_unlock();
 
Signature · 7 lines
1.5.4.rc3

--
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 4 lines · On Wed, 14 Jan 2009 16:10:52 +0800 Li Zefan <[email protected]> wrote:

When there are sub-dirs, writing to memory.use_hierarchy returns -EBUSY, this doesn't seem to fit the meaning of EBUSY, and is inconsistent with memory.swappiness, which returns -EINVAL in this case.

Hmm...I'm not sure what error code is the best.

In usual, -EINVAL means parameter to write() is bad. In this case, it isn't.

Considering that, -EBUSY seems ok at returning error because of children. How about change swappiness to return -EBUSY ?

Thanks,
-Kame

Quoted 37 lines
---
 mm/memcontrol.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
mm/memcontrol.c +5 -5
index bc8f101..2497f7d 100644
@@ -1760,6 +1760,9 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft,
 	struct cgroup *parent = cont->parent;
 	struct mem_cgroup *parent_mem = NULL;
 
+	if (val != 0 && val != 1)
+		return -EINVAL;
+
 	if (parent)
 		parent_mem = mem_cgroup_from_cont(parent);
 
@@ -1773,12 +1776,9 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft,
 	 * set if there are no children.
 	 */
 	if ((!parent_mem || !parent_mem->use_hierarchy) &&
-				(val == 1 || val == 0)) {
-		if (list_empty(&cont->children))
+	    list_empty(&cont->children))
 			mem->use_hierarchy = val;
-		else
-			retval = -EBUSY;
-	} else
+	else
 		retval = -EINVAL;
 	cgroup_unlock();
 
Signature · 1 line
1.5.4.rc3

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

#2 lore raw
In reply to Li Zefan
Quoted 4 lines · Li Zefan

When there are sub-dirs, writing to memory.use_hierarchy returns -EBUSY, this doesn't seem to fit the meaning of EBUSY, and is inconsistent with memory.swappiness, which returns -EINVAL in this case.

I also think -EBUSY is not so bad in this case.

Thanks,
Daisuke Nishimura.

Quoted 36 lines
---
 mm/memcontrol.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
mm/memcontrol.c +5 -5
index bc8f101..2497f7d 100644
@@ -1760,6 +1760,9 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft,
 	struct cgroup *parent = cont->parent;
 	struct mem_cgroup *parent_mem = NULL;
 
+	if (val != 0 && val != 1)
+		return -EINVAL;
+
 	if (parent)
 		parent_mem = mem_cgroup_from_cont(parent);
 
@@ -1773,12 +1776,9 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft,
 	 * set if there are no children.
 	 */
 	if ((!parent_mem || !parent_mem->use_hierarchy) &&
-				(val == 1 || val == 0)) {
-		if (list_empty(&cont->children))
+	    list_empty(&cont->children))
 			mem->use_hierarchy = val;
-		else
-			retval = -EBUSY;
-	} else
+	else
 		retval = -EINVAL;
 	cgroup_unlock();
 
Signature · 1 line
1.5.4.rc3

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

#3 lore raw
In reply to Li Zefan
Quoted 5 lines · Li Zefan

When there are sub-dirs, writing to memory.use_hierarchy returns -EBUSY, this doesn't seem to fit the meaning of EBUSY, and is inconsistent with memory.swappiness, which returns -EINVAL in this case.

The patch does much more than the changelog says. The reason for EBUSY is that the group is in use due to children or existing references and tasks. I think EBUSY is the correct error code to return.

Signature · 7 lines
	Balbir

--
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>
author
#4 lore raw
Quoted 6 lines · Balbir Singh
Quoted 4 lines · Li Zefan

When there are sub-dirs, writing to memory.use_hierarchy returns -EBUSY, this doesn't seem to fit the meaning of EBUSY, and is inconsistent with memory.swappiness, which returns -EINVAL in this case.

Quoted 6 lines
Quoted 1 line

The patch does much more than the changelog says. The reason for EBUSY is that the group is in use due to children or existing references and tasks. I think EBUSY is the correct error code to return.

Sounds reasonable for me. Thanks.

Regards
Li Zefan

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