From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail203.messagelabs.com (mail203.messagelabs.com [216.82.254.243]) by kanga.kvack.org (Postfix) with ESMTP id 1FED1900086 for ; Thu, 14 Apr 2011 13:43:39 -0400 (EDT) Received: from hpaq12.eem.corp.google.com (hpaq12.eem.corp.google.com [172.25.149.12]) by smtp-out.google.com with ESMTP id p3EHhZnP012069 for ; Thu, 14 Apr 2011 10:43:35 -0700 Received: from gyf1 (gyf1.prod.google.com [10.243.50.65]) by hpaq12.eem.corp.google.com with ESMTP id p3EHfdTV019822 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Thu, 14 Apr 2011 10:43:34 -0700 Received: by gyf1 with SMTP id 1so592667gyf.6 for ; Thu, 14 Apr 2011 10:43:33 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <1302678187-24154-1-git-send-email-yinghan@google.com> <1302678187-24154-3-git-send-email-yinghan@google.com> Date: Thu, 14 Apr 2011 10:43:33 -0700 Message-ID: Subject: Re: [PATCH V3 2/7] Add per memcg reclaim watermarks From: Ying Han Content-Type: multipart/alternative; boundary=000e0cd67698d27b0404a0e47639 Sender: owner-linux-mm@kvack.org List-ID: To: Zhu Yanhai Cc: KAMEZAWA Hiroyuki , Pavel Emelyanov , Balbir Singh , Daisuke Nishimura , Li Zefan , Mel Gorman , Christoph Lameter , Johannes Weiner , Rik van Riel , Hugh Dickins , KOSAKI Motohiro , Tejun Heo , Michal Hocko , Andrew Morton , Dave Hansen , linux-mm@kvack.org --000e0cd67698d27b0404a0e47639 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Apr 14, 2011 at 1:24 AM, Zhu Yanhai wrote: > Hi Ying, > > 2011/4/13 Ying Han : > > +static void setup_per_memcg_wmarks(struct mem_cgroup *mem) > > +{ > > + u64 limit; > > + unsigned long wmark_ratio; > > + > > + wmark_ratio = get_wmark_ratio(mem); > > + limit = mem_cgroup_get_limit(mem); > > mem_cgroup_get_limit doesn't return the correct limit for you, > actually it's only for OOM killer. > You should use > limit = res_counter_read_u64(&mem->res, RES_LIMIT) directly. > Otherwise in the box which has swapon, you will get a huge > number here. > e.g. > [root@zyh-fedora a]# echo 500m > memory.limit_in_bytes > [root@zyh-fedora a]# cat memory.limit_in_bytes > 524288000 > [root@zyh-fedora a]# cat memory.reclaim_wmarks > low_wmark 9114218496 > high_wmark 9114218496 > thank you~ will fix it next post. --Ying > > Regards, > Zhu Yanhai > > > > + if (wmark_ratio == 0) { > > + res_counter_set_low_wmark_limit(&mem->res, limit); > > + res_counter_set_high_wmark_limit(&mem->res, limit); > > + } else { > > + unsigned long low_wmark, high_wmark; > > + unsigned long long tmp = (wmark_ratio * limit) / 100; > > + > > + low_wmark = tmp; > > + high_wmark = tmp - (tmp >> 8); > > + res_counter_set_low_wmark_limit(&mem->res, low_wmark); > > + res_counter_set_high_wmark_limit(&mem->res, high_wmark); > > + } > > +} > > + > > /* > > * Following LRU functions are allowed to be used without PCG_LOCK. > > * Operations are called by routine of global LRU independently from > memcg. > > @@ -1195,6 +1219,16 @@ static unsigned int get_swappiness(struct > mem_cgroup *memcg) > > return memcg->swappiness; > > } > > > > +static unsigned long get_wmark_ratio(struct mem_cgroup *memcg) > > +{ > > + struct cgroup *cgrp = memcg->css.cgroup; > > + > > + VM_BUG_ON(!cgrp); > > + VM_BUG_ON(!cgrp->parent); > > + > > + return memcg->wmark_ratio; > > +} > > + > > static void mem_cgroup_start_move(struct mem_cgroup *mem) > > { > > int cpu; > > @@ -3205,6 +3239,7 @@ static int mem_cgroup_resize_limit(struct > mem_cgroup *memcg, > > else > > memcg->memsw_is_minimum = false; > > } > > + setup_per_memcg_wmarks(memcg); > > mutex_unlock(&set_limit_mutex); > > > > if (!ret) > > @@ -3264,6 +3299,7 @@ static int mem_cgroup_resize_memsw_limit(struct > mem_cgroup *memcg, > > else > > memcg->memsw_is_minimum = false; > > } > > + setup_per_memcg_wmarks(memcg); > > mutex_unlock(&set_limit_mutex); > > > > if (!ret) > > @@ -4521,6 +4557,22 @@ static void __init enable_swap_cgroup(void) > > } > > #endif > > > > +int mem_cgroup_watermark_ok(struct mem_cgroup *mem, > > + int charge_flags) > > +{ > > + long ret = 0; > > + int flags = CHARGE_WMARK_LOW | CHARGE_WMARK_HIGH; > > + > > + VM_BUG_ON((charge_flags & flags) == flags); > > + > > + if (charge_flags & CHARGE_WMARK_LOW) > > + ret = res_counter_check_under_low_wmark_limit(&mem->res); > > + if (charge_flags & CHARGE_WMARK_HIGH) > > + ret = > res_counter_check_under_high_wmark_limit(&mem->res); > > + > > + return ret; > > +} > > + > > static int mem_cgroup_soft_limit_tree_init(void) > > { > > struct mem_cgroup_tree_per_node *rtpn; > > -- > > 1.7.3.1 > > > > -- > > To unsubscribe, send a message with 'unsubscribe linux-mm' in > > the body to majordomo@kvack.org. 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: email@kvack.org > > > --000e0cd67698d27b0404a0e47639 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Thu, Apr 14, 2011 at 1:24 AM, Zhu Yan= hai <zhu.yanha= i@gmail.com> wrote:
Hi Ying,

2011/4/13 Ying Han <yinghan@google= .com>:
> +static void setup_per_memcg_wmarks(struct mem_cgrou= p *mem)
> +{
> + =A0 =A0 =A0 u64 limit;
> + =A0 =A0 =A0 unsigned long wmark_ratio;
> +
> + =A0 =A0 =A0 wmark_ratio =3D get_wmark_ratio(mem);
> + =A0 =A0 =A0 limit =3D mem_cgroup_get_limit(mem);

mem_cgroup_get_limit doesn't return the correct limit for you, actually it's only for OOM killer.
You should use
limit =3D res_counter_read_u64(&mem->res, RES_LIMIT) directly.
Otherwise in the box which has swapon, you will get a huge
number here.
e.g.
=A0[root@zyh-fedora a]# echo 500m > memory.limit_in_bytes
[root@zyh-fedora a]# cat memory.limit_in_bytes
524288000
[root@zyh-fedora a]# cat memory.reclaim_wmarks
low_wmark 9114218496
high_wmark 9114218496

thank you~ will f= ix it next post.

--Ying=A0

Regards,
Zhu Yanhai


> + =A0 =A0 =A0 if (wmark_ratio =3D=3D 0) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 res_co= unter_set_low_wmark_limit(&mem->res, limit);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 res_counter_set_high_wmark_limit(&me= m->res, limit);
> + =A0 =A0 =A0 } else {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned long low_wmark, high_wmark;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned long long tmp =3D (wmark_ratio = * limit) / 100;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 low_wmark =3D tmp;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 high_wmark =3D tmp - (tmp >> 8); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 res_counter_set_low_wmark_limit(&mem= ->res, low_wmark);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 res_counter_set_high_wmark_limit(&me= m->res, high_wmark);
> + =A0 =A0 =A0 }
> +}
> +
> =A0/*
> =A0* Following LRU functions are allowed to be used without PCG_LOCK.<= br> > =A0* Operations are called by routine of global LRU independently from= memcg.
> @@ -1195,6 +1219,16 @@ static unsigned int get_swappiness(struct mem_c= group *memcg)
> =A0 =A0 =A0 =A0return memcg->swappiness;
> =A0}
>
> +static unsigned long get_wmark_ratio(struct mem_cgroup *memcg)
> +{
> + =A0 =A0 =A0 struct cgroup *cgrp =3D memcg->css.cgroup;
> +
> + =A0 =A0 =A0 VM_BUG_ON(!cgrp);
> + =A0 =A0 =A0 VM_BUG_ON(!cgrp->parent);
> +
> + =A0 =A0 =A0 return memcg->wmark_ratio;
> +}
> +
> =A0static void mem_cgroup_start_move(struct mem_cgroup *mem)
> =A0{
> =A0 =A0 =A0 =A0int cpu;
> @@ -3205,6 +3239,7 @@ static int mem_cgroup_resize_limit(struct mem_cg= roup *memcg,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0memcg-&= gt;memsw_is_minimum =3D false;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 setup_per_memcg_wmarks(memcg);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mutex_unlock(&set_limit_mutex);
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (!ret)
> @@ -3264,6 +3299,7 @@ static int mem_cgroup_resize_memsw_limit(struct = mem_cgroup *memcg,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0memcg-&= gt;memsw_is_minimum =3D false;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 setup_per_memcg_wmarks(memcg);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mutex_unlock(&set_limit_mutex);
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (!ret)
> @@ -4521,6 +4557,22 @@ static void __init enable_swap_cgroup(void)
> =A0}
> =A0#endif
>
> +int mem_cgroup_watermark_ok(struct mem_cgroup *mem,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int char= ge_flags)
> +{
> + =A0 =A0 =A0 long ret =3D 0;
> + =A0 =A0 =A0 int flags =3D CHARGE_WMARK_LOW | CHARGE_WMARK_HIGH;
> +
> + =A0 =A0 =A0 VM_BUG_ON((charge_flags & flags) =3D=3D flags);
> +
> + =A0 =A0 =A0 if (charge_flags & CHARGE_WMARK_LOW)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D res_counter_check_under_low_wmar= k_limit(&mem->res);
> + =A0 =A0 =A0 if (charge_flags & CHARGE_WMARK_HIGH)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D res_counter_check_under_high_wma= rk_limit(&mem->res);
> +
> + =A0 =A0 =A0 return ret;
> +}
> +
> =A0static int mem_cgroup_soft_limit_tree_init(void)
> =A0{
> =A0 =A0 =A0 =A0struct mem_cgroup_tree_per_node *rtpn;
> --
> 1.7.3.1
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in<= br> > the body to majordomo@kvack.org= . =A0For 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=3Dmailto:"dont@kvack.org"> emai= l@kvack.org </a>
>

--000e0cd67698d27b0404a0e47639-- -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. 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: email@kvack.org