Skip to contentSkip to conversation

soft limits and root cgroups

PATCH In review Kirill A. Shutemov 5 participants 7 messages Dec 7, 2009 – Dec 9, 2009

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

PATCH 1/1 soft limits and root cgroups

Currently, mem_cgroup_update_tree() on root cgroup calls only on uncharge, not on charge.

Is it a bug or not?

Patch to fix, if it's a bug:

mm/memcontrol.c +3 -1
index 8aa6026..6babef1 100644
@@ -1366,13 +1366,15 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm
                        goto nomem;
                }
        }
+
+done:
        /*
         * Insert ancestor (and ancestor's ancestors), to softlimit RB-tree.
         * if they exceeds softlimit.
         */
        if (mem_cgroup_soft_limit_check(mem))
                mem_cgroup_update_tree(mem, page);
-done:
+
        return 0;
 nomem:
        css_put(&mem->css);

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

PATCH 1/1 memcg: don't call mem_cgroup_soft_limit_check() against root cgroup (Re: [BUG?] [PATCH] soft limits and root cgroups)

hi,

Quoted 19 lines · Kirill A. Shutemov

Currently, mem_cgroup_update_tree() on root cgroup calls only on uncharge, not on charge.

Is it a bug or not?

Patch to fix, if it's a bug:

mm/memcontrol.c +2 -0
index 8aa6026..6babef1 100644
@@ -1366,13 +1366,15 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm
                        goto nomem;
                }
        }
+
+done:
        /*

mm/memcontrol.c static int __mem_cgroup_try_charge(struct mm_struct *mm · line 1380

Quoted 10 lines
mm/memcontrol.c +1 -1
         * Insert ancestor (and ancestor's ancestors), to softlimit RB-tree.
         * if they exceeds softlimit.
         */
        if (mem_cgroup_soft_limit_check(mem))
                mem_cgroup_update_tree(mem, page);
-done:
+
        return 0;
 nomem:
        css_put(&mem->css);

I think it's not a bug, because softlimit doesn't work for root cgroup. (IIUC, it's not disabled to write to <root cgroup>/memory.soft_limit_in_bytes, but it has no use because root cgroup doesn't use res_counter.)

So, I think not to call mem_cgroup_soft_limit_check()(and mem_cgroup_update_tree) against root cgroup on uncharge path would be a right fix.

How about this ?
===
From: Daisuke Nishimura <[email protected]>

current memory cgroup doesn't use res_counter about root cgroup, so soft limits on root cgroup has no use.
This patch disables writing to <root cgroup>/memory.soft_limit_in_bytes and changes uncharge path not to call mem_cgroup_soft_limit_check() against root cgroup.

---
 Documentation/cgroups/memory.txt |    1 +
 mm/memcontrol.c                  |    6 +++++-
 2 files changed, 6 insertions(+), 1 deletions(-)
Documentation/cgroups/memory.txt +1 -0
index b871f25..e1b5328 100644
@@ -413,6 +413,7 @@ NOTE1: Soft limits take effect over a long period of time, since they involve
        reclaiming memory for balancing between memory cgroups
 NOTE2: It is recommended to set the soft limit always below the hard limit,
        otherwise the hard limit will take precedence.
+NOTE3: We cannot set soft limits on the root cgroup any more.
 
 8. TODO
 
mm/memcontrol.c +5 -1
index 661b8c6..0751533 100644
@@ -2056,7 +2056,7 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
 	mz = page_cgroup_zoneinfo(pc);
 	unlock_page_cgroup(pc);
 
-	if (mem_cgroup_soft_limit_check(mem))
+	if (!mem_cgroup_is_root(mem) && mem_cgroup_soft_limit_check(mem))
 		mem_cgroup_update_tree(mem, page);
 	/* at swapout, this memcg will be accessed to record to swap */
 	if (ctype != MEM_CGROUP_CHARGE_TYPE_SWAPOUT)
@@ -2787,6 +2787,10 @@ static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft,
 			ret = mem_cgroup_resize_memsw_limit(memcg, val);
 		break;
 	case RES_SOFT_LIMIT:
+		if (mem_cgroup_is_root(memcg)) { /* Can't set limit on root */
+			ret = -EINVAL;
+			break;
+		}
 		ret = res_counter_memparse_write_strategy(buffer, &val);
 		if (ret)
 			break;

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

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

Re: [cleanup][PATCH mmotm]memcg: don't call mem_cgroup_soft_limit_check() against root cgroup (Re: [BUG?] [PATCH] soft limits and root cgroups)

Quoted 73 lines · * [email protected] <[email protected]> [2009-12-08…

hi,

Quoted 19 lines · Kirill A. Shutemov

Currently, mem_cgroup_update_tree() on root cgroup calls only on uncharge, not on charge.

Is it a bug or not?

Patch to fix, if it's a bug:

mm/memcontrol.c +2 -0
index 8aa6026..6babef1 100644
@@ -1366,13 +1366,15 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm
                        goto nomem;
                }
        }
+
+done:
        /*

mm/memcontrol.c static int __mem_cgroup_try_charge(struct mm_struct *mm · line 1380

Quoted 10 lines
mm/memcontrol.c +1 -1
         * Insert ancestor (and ancestor's ancestors), to softlimit RB-tree.
         * if they exceeds softlimit.
         */
        if (mem_cgroup_soft_limit_check(mem))
                mem_cgroup_update_tree(mem, page);
-done:
+
        return 0;
 nomem:
        css_put(&mem->css);

I think it's not a bug, because softlimit doesn't work for root cgroup. (IIUC, it's not disabled to write to <root cgroup>/memory.soft_limit_in_bytes, but it has no use because root cgroup doesn't use res_counter.)

So, I think not to call mem_cgroup_soft_limit_check()(and mem_cgroup_update_tree) against root cgroup on uncharge path would be a right fix.

How about this ?
===
From: Daisuke Nishimura <[email protected]>

current memory cgroup doesn't use res_counter about root cgroup, so soft limits on root cgroup has no use.
This patch disables writing to <root cgroup>/memory.soft_limit_in_bytes and changes uncharge path not to call mem_cgroup_soft_limit_check() against root cgroup.

---
 Documentation/cgroups/memory.txt |    1 +
 mm/memcontrol.c                  |    6 +++++-
 2 files changed, 6 insertions(+), 1 deletions(-)
Documentation/cgroups/memory.txt +1 -0
index b871f25..e1b5328 100644
@@ -413,6 +413,7 @@ NOTE1: Soft limits take effect over a long period of time, since they involve
        reclaiming memory for balancing between memory cgroups
 NOTE2: It is recommended to set the soft limit always below the hard limit,
        otherwise the hard limit will take precedence.
+NOTE3: We cannot set soft limits on the root cgroup any more.
 
 8. TODO
 
mm/memcontrol.c +0 -0
index 661b8c6..0751533 100644

mm/memcontrol.c __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype) · line 2060

Quoted 6 lines
mm/memcontrol.c +1 -1
@@ -2056,7 +2056,7 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
 	mz = page_cgroup_zoneinfo(pc);
 	unlock_page_cgroup(pc);
 
-	if (mem_cgroup_soft_limit_check(mem))
+	if (!mem_cgroup_is_root(mem) && mem_cgroup_soft_limit_check(mem))
 		mem_cgroup_update_tree(mem, page);

May be the mem_cgroup_is_root() check should go inside mem_cgroup_soft_limit_check() for future call sites as well.

Quoted 4 lines
mm/memcontrol.c +0 -0
 	/* at swapout, this memcg will be accessed to record to swap */
 	if (ctype != MEM_CGROUP_CHARGE_TYPE_SWAPOUT)

mm/memcontrol.c static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft, · line 2796

Quoted 10 lines
mm/memcontrol.c +4 -0
@@ -2787,6 +2787,10 @@ static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft,
 			ret = mem_cgroup_resize_memsw_limit(memcg, val);
 		break;
 	case RES_SOFT_LIMIT:
+		if (mem_cgroup_is_root(memcg)) { /* Can't set limit on root */
+			ret = -EINVAL;
+			break;
+		}
 		ret = res_counter_memparse_write_strategy(buffer, &val);
 		if (ret)
 			break;

looks good to me

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>
#3 lore raw

Re: [cleanup][PATCH mmotm]memcg: don't call mem_cgroup_soft_limit_check() against root cgroup (Re: [BUG?] [PATCH] soft limits and root cgroups)

Quoted 34 lines
Quoted 34 lines

From: Daisuke Nishimura <[email protected]>

current memory cgroup doesn't use res_counter about root cgroup, so soft limits on root cgroup has no use.
This patch disables writing to <root cgroup>/memory.soft_limit_in_bytes and changes uncharge path not to call mem_cgroup_soft_limit_check() against root cgroup.

---
 Documentation/cgroups/memory.txt |    1 +
 mm/memcontrol.c                  |    6 +++++-
 2 files changed, 6 insertions(+), 1 deletions(-)
Documentation/cgroups/memory.txt +1 -0
index b871f25..e1b5328 100644
@@ -413,6 +413,7 @@ NOTE1: Soft limits take effect over a long period of time, since they involve
        reclaiming memory for balancing between memory cgroups
 NOTE2: It is recommended to set the soft limit always below the hard limit,
        otherwise the hard limit will take precedence.
+NOTE3: We cannot set soft limits on the root cgroup any more.
 
 8. TODO
 
mm/memcontrol.c +0 -0
index 661b8c6..0751533 100644
@@ -2056,7 +2056,7 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
 	mz = page_cgroup_zoneinfo(pc);
 	unlock_page_cgroup(pc);
 
Quoted 7 lines

mm/memcontrol.c __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype) · line 2060

Quoted 3 lines
mm/memcontrol.c +1 -1
-	if (mem_cgroup_soft_limit_check(mem))
+	if (!mem_cgroup_is_root(mem) && mem_cgroup_soft_limit_check(mem))
 		mem_cgroup_update_tree(mem, page);

May be the mem_cgroup_is_root() check should go inside mem_cgroup_soft_limit_check() for future call sites as well.

I agree, thank you for your suggestion.
I'll update this patch with your ack, but considering it's in merge window now, I'll hold this patch a while(this is not a so urgent patch).

Thanks,
Daisuke Nishimura.

Quoted 17 lines
Quoted 4 lines
mm/memcontrol.c +0 -0
 	/* at swapout, this memcg will be accessed to record to swap */
 	if (ctype != MEM_CGROUP_CHARGE_TYPE_SWAPOUT)

mm/memcontrol.c static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft, · line 2796

Quoted 10 lines
mm/memcontrol.c +4 -0
@@ -2787,6 +2787,10 @@ static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft,
 			ret = mem_cgroup_resize_memsw_limit(memcg, val);
 		break;
 	case RES_SOFT_LIMIT:
+		if (mem_cgroup_is_root(memcg)) { /* Can't set limit on root */
+			ret = -EINVAL;
+			break;
+		}
 		ret = res_counter_memparse_write_strategy(buffer, &val);
 		if (ret)
 			break;

looks good to me

Quoted 5 lines
Signature · 1 line
	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>

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

Re: [cleanup][PATCH mmotm]memcg: don't call mem_cgroup_soft_limit_check() against root cgroup (Re: [BUG?] [PATCH] soft limits and root cgroups)

In reply to Daisuke Nishimura
Quoted 9 lines · On Tue, 8 Dec 2009 10:09:54 +0900 Daisuke Nishimura…

From: Daisuke Nishimura <[email protected]>

current memory cgroup doesn't use res_counter about root cgroup, so soft limits on root cgroup has no use.
This patch disables writing to <root cgroup>/memory.soft_limit_in_bytes and changes uncharge path not to call mem_cgroup_soft_limit_check() against root cgroup.

Thank you.

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

#5 lore raw
In reply to Kirill A. Shutemov
Quoted 4 lines · Kirill A. Shutemov

Currently, mem_cgroup_update_tree() on root cgroup calls only on uncharge, not on charge.

Is it a bug or not?

Any comments?

Quoted 21 lines

Patch to fix, if it's a bug:

mm/memcontrol.c +3 -1
index 8aa6026..6babef1 100644
@@ -1366,13 +1366,15 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm
                        goto nomem;
                }
        }
+
+done:
        /*
         * Insert ancestor (and ancestor's ancestors), to softlimit RB-tree.
         * if they exceeds softlimit.
         */
        if (mem_cgroup_soft_limit_check(mem))
                mem_cgroup_update_tree(mem, page);
-done:
+
        return 0;
Quoted 3 lines

 nomem:
       css_put(&mem->css);

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

#6 lore raw
Quoted 8 lines · On Wed, 9 Dec 2009 11:37:30 +0200 "Kirill A. Shutemov" <[email protected]>…
Quoted 4 lines · Kirill A. Shutemov

Currently, mem_cgroup_update_tree() on root cgroup calls only on uncharge, not on charge.

Is it a bug or not?

Any comments?

It's not a bug.
Please see my comments and patch ;)

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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>