2012-06-23 06:19:23

by Wanpeng Li

[permalink] [raw]
Subject: [PATCH 5/6] memcg: optimize memcg_get_hierarchical_limit

From: Wanpeng Li <[email protected]>

Optimize memcg_get_hierarchical_limit to save cpu cycle.

Signed-off-by: Wanpeng Li <[email protected]>
---
mm/memcontrol.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index c821e36..1ca79e2 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3917,9 +3917,9 @@ static void memcg_get_hierarchical_limit(struct mem_cgroup *memcg,

min_limit = res_counter_read_u64(&memcg->res, RES_LIMIT);
min_memsw_limit = res_counter_read_u64(&memcg->memsw, RES_LIMIT);
- cgroup = memcg->css.cgroup;
if (!memcg->use_hierarchy)
goto out;
+ cgroup = memcg->css.cgroup;

while (cgroup->parent) {
cgroup = cgroup->parent;
--
1.7.9.5


2012-06-23 09:40:22

by Johannes Weiner

[permalink] [raw]
Subject: Re: [PATCH 5/6] memcg: optimize memcg_get_hierarchical_limit

On Sat, Jun 23, 2012 at 02:18:17PM +0800, Wanpeng Li wrote:
> From: Wanpeng Li <[email protected]>
>
> Optimize memcg_get_hierarchical_limit to save cpu cycle.
>
> Signed-off-by: Wanpeng Li <[email protected]>

I really would have thought the compiler would detect it, but this
patch actually does switch around move and jump.

But this is miniscule and anything but a fastpath...

> ---
> mm/memcontrol.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index c821e36..1ca79e2 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3917,9 +3917,9 @@ static void memcg_get_hierarchical_limit(struct mem_cgroup *memcg,
>
> min_limit = res_counter_read_u64(&memcg->res, RES_LIMIT);
> min_memsw_limit = res_counter_read_u64(&memcg->memsw, RES_LIMIT);
> - cgroup = memcg->css.cgroup;
> if (!memcg->use_hierarchy)
> goto out;
> + cgroup = memcg->css.cgroup;
>
> while (cgroup->parent) {
> cgroup = cgroup->parent;
> --
> 1.7.9.5
>

2012-06-25 08:17:43

by Glauber Costa

[permalink] [raw]
Subject: Re: [PATCH 5/6] memcg: optimize memcg_get_hierarchical_limit

On 06/23/2012 10:18 AM, Wanpeng Li wrote:
> From: Wanpeng Li <[email protected]>
>
> Optimize memcg_get_hierarchical_limit to save cpu cycle.
>
> Signed-off-by: Wanpeng Li <[email protected]>
> ---
> mm/memcontrol.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index c821e36..1ca79e2 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3917,9 +3917,9 @@ static void memcg_get_hierarchical_limit(struct mem_cgroup *memcg,
>
> min_limit = res_counter_read_u64(&memcg->res, RES_LIMIT);
> min_memsw_limit = res_counter_read_u64(&memcg->memsw, RES_LIMIT);
> - cgroup = memcg->css.cgroup;
> if (!memcg->use_hierarchy)
> goto out;
> + cgroup = memcg->css.cgroup;
>
> while (cgroup->parent) {
> cgroup = cgroup->parent;
>
Seriously, this saves nothing.