linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
	"balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
	"nishimura@mxp.nes.nec.co.jp" <nishimura@mxp.nes.nec.co.jp>,
	"lizf@cn.fujitsu.com" <lizf@cn.fujitsu.com>,
	"menage@google.com" <menage@google.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [RFC][PATCH 5/6] fix inactive_ratio under hierarchy
Date: Thu, 11 Dec 2008 12:19:33 +0900	[thread overview]
Message-ID: <20081211121933.a2e25e75.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <20081211121006.4FF1.KOSAKI.MOTOHIRO@jp.fujitsu.com>

On Thu, 11 Dec 2008 12:14:04 +0900 (JST)
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:

> Hi
> 
> > ex)In following tree,
> > 	/opt/cgroup/01		limit=1G
> > 	/opt/cgroup/01/A	limit=500M
> > 	/opt/cgroup/01/A/B	limit=unlimited
> > 	/opt/cgroup/01/A/C	limit=50M
> > 	/opt/cgroup/01/Z	limit=700M
> > 
> > 
> > 	/opt/cgroup/01's inactive_ratio is calculated by limit of 1G.
> > 	/opt/cgroup/01/A's inactive_ratio is calculated by limit of 500M 
> > 	/opt/cgroup/01/A/B's inactive_ratio is calculated by limit of 500M.
> > 	/opt/cgroup/01/A/C's inactive_ratio is calculated by limit of 50M.
> > 	/opt/cgroup/01's inactive_ratio is calculated by limit of 700M.
> 
> this is one of good choice.
> but I think it is a bit complex rule.
> 
> 
> How about this?
> 
> ===============
> Currently, inactive_ratio of memcg is calculated at setting limit.
> because page_alloc.c does so and current implementation is straightforward porting.
> 
> However, memcg introduced hierarchy feature recently.
> In hierarchy restriction, memory limit is not only decided memory.limit_in_bytes of current cgroup,
> but also parent limit and sibling memory usage.
> 
> Then, The optimal inactive_ratio is changed frequently.
> So, everytime calculation is better.
> 
thx, I'll test this.

-Kame



> 
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> CC: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> CC: Balbir Singh <balbir@linux.vnet.ibm.com>
> ---
>  include/linux/memcontrol.h |    3 --
>  mm/memcontrol.c            |   64 +++++++++++++++++++++------------------------
>  mm/vmscan.c                |    2 -
>  3 files changed, 33 insertions(+), 36 deletions(-)
> 
> Index: b/include/linux/memcontrol.h
> ===================================================================
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -95,8 +95,7 @@ extern void mem_cgroup_note_reclaim_prio
>  							int priority);
>  extern void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem,
>  							int priority);
> -int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg,
> -				    struct zone *zone);
> +int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg);
>  unsigned long mem_cgroup_zone_nr_pages(struct mem_cgroup *memcg,
>  				       struct zone *zone,
>  				       enum lru_list lru);
> Index: b/mm/memcontrol.c
> ===================================================================
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -167,9 +167,6 @@ struct mem_cgroup {
>  
>  	unsigned int	swappiness;
>  
> -
> -	unsigned int inactive_ratio;
> -
>  	/*
>  	 * statistics. This must be placed at the end of memcg.
>  	 */
> @@ -433,15 +430,43 @@ void mem_cgroup_record_reclaim_priority(
>  	spin_unlock(&mem->reclaim_param_lock);
>  }
>  
> -int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg, struct zone *zone)
> +static int calc_inactive_ratio(struct mem_cgroup *memcg, unsigned long *present_pages)
>  {
>  	unsigned long active;
>  	unsigned long inactive;
> +	unsigned long gb;
> +	unsigned long inactive_ratio;
>  
>  	inactive = mem_cgroup_get_all_zonestat(memcg, LRU_INACTIVE_ANON);
>  	active = mem_cgroup_get_all_zonestat(memcg, LRU_ACTIVE_ANON);
>  
> -	if (inactive * memcg->inactive_ratio < active)
> +	gb = (inactive + active) >> (30 - PAGE_SHIFT);
> +	if (gb)
> +		inactive_ratio = int_sqrt(10 * gb);
> +	else
> +		inactive_ratio = 1;
> +
> +	if (present_pages) {
> +		present_pages[0] = inactive;
> +		present_pages[1] = active;
> +	}
> +
> +	return inactive_ratio;
> +}
> +
> +int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg)
> +{
> +	unsigned long active;
> +	unsigned long inactive;
> +	unsigned long present_pages[2];
> +	unsigned long inactive_ratio;
> +
> +	inactive_ratio = calc_inactive_ratio(memcg, present_pages);
> +
> +	inactive = present_pages[0];
> +	active = present_pages[1];
> +
> +	if (inactive * inactive_ratio < active)
>  		return 1;
>  
>  	return 0;
> @@ -1410,29 +1435,6 @@ int mem_cgroup_shrink_usage(struct mm_st
>  	return 0;
>  }
>  
> -/*
> - * The inactive anon list should be small enough that the VM never has to
> - * do too much work, but large enough that each inactive page has a chance
> - * to be referenced again before it is swapped out.
> - *
> - * this calculation is straightforward porting from
> - * page_alloc.c::setup_per_zone_inactive_ratio().
> - * it describe more detail.
> - */
> -static void mem_cgroup_set_inactive_ratio(struct mem_cgroup *memcg)
> -{
> -	unsigned int gb, ratio;
> -
> -	gb = res_counter_read_u64(&memcg->res, RES_LIMIT) >> 30;
> -	if (gb)
> -		ratio = int_sqrt(10 * gb);
> -	else
> -		ratio = 1;
> -
> -	memcg->inactive_ratio = ratio;
> -
> -}
> -
>  static DEFINE_MUTEX(set_limit_mutex);
>  
>  static int mem_cgroup_resize_limit(struct mem_cgroup *memcg,
> @@ -1472,9 +1474,6 @@ static int mem_cgroup_resize_limit(struc
>    		if (!progress)			retry_count--;
>  	}
>  
> -	if (!ret)
> -		mem_cgroup_set_inactive_ratio(memcg);
> -
>  	return ret;
>  }
>  
> @@ -1833,7 +1832,7 @@ static int mem_control_stat_show(struct 
>  	}
>  
>  #ifdef CONFIG_DEBUG_VM
> -	cb->fill(cb, "inactive_ratio", mem_cont->inactive_ratio);
> +	cb->fill(cb, "inactive_ratio", calc_inactive_ratio(mem_cont, NULL));
>  
>  	{
>  		int nid, zid;
> @@ -2125,7 +2124,6 @@ mem_cgroup_create(struct cgroup_subsys *
>  		res_counter_init(&mem->res, NULL);
>  		res_counter_init(&mem->memsw, NULL);
>  	}
> -	mem_cgroup_set_inactive_ratio(mem);
>  	mem->last_scanned_child = NULL;
>  	spin_lock_init(&mem->reclaim_param_lock);
>  
> Index: b/mm/vmscan.c
> ===================================================================
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -1394,7 +1394,7 @@ static int inactive_anon_is_low(struct z
>  	if (scanning_global_lru(sc))
>  		low = inactive_anon_is_low_global(zone);
>  	else
> -		low = mem_cgroup_inactive_anon_is_low(sc->mem_cgroup, zone);
> +		low = mem_cgroup_inactive_anon_is_low(sc->mem_cgroup);
>  	return low;
>  }
>  
> 
> 
> 

  reply	other threads:[~2008-12-11  3:19 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-09 11:02 [RFC][PATCH 0/6] cgroup id and mix fixes (2008/12/09) KAMEZAWA Hiroyuki
2008-12-09 11:04 ` [RFC][PATCH 1/6] memcg: Documentation for internal implementation KAMEZAWA Hiroyuki
2008-12-10  0:27   ` KAMEZAWA Hiroyuki
2008-12-10  1:02     ` Li Zefan
2008-12-10  1:07       ` KAMEZAWA Hiroyuki
2008-12-09 11:06 ` [RFC][PATCH 1/6] memcg: fix pre_destory handler KAMEZAWA Hiroyuki
2008-12-10  2:08   ` KAMEZAWA Hiroyuki
2008-12-10  2:19   ` Li Zefan
2008-12-10  2:23     ` KAMEZAWA Hiroyuki
2008-12-10  2:28   ` Daisuke Nishimura
2008-12-10  2:58     ` KAMEZAWA Hiroyuki
2008-12-10  3:03       ` Daisuke Nishimura
2008-12-10  4:17         ` KAMEZAWA Hiroyuki
2008-12-10 10:40   ` Paul Menage
2008-12-10 11:29     ` KAMEZAWA Hiroyuki
2008-12-10 13:25       ` Balbir Singh
2008-12-10 13:47         ` Daisuke Nishimura
2008-12-10 18:26           ` Paul Menage
2008-12-10 18:25         ` Paul Menage
2008-12-10 18:35       ` Paul Menage
2008-12-10 19:00         ` Paul Menage
2008-12-11  0:21           ` KAMEZAWA Hiroyuki
2008-12-11  0:24             ` Paul Menage
2008-12-11  1:06               ` KAMEZAWA Hiroyuki
2008-12-11 12:43               ` KAMEZAWA Hiroyuki
2008-12-11  0:25         ` KAMEZAWA Hiroyuki
2008-12-11  0:28           ` Paul Menage
2008-12-11  1:09             ` KAMEZAWA Hiroyuki
2008-12-09 11:08 ` [RFC][PATCH 2/6] cgroup id KAMEZAWA Hiroyuki
2008-12-09 11:09 ` [RFC][PATCH 4/6] Flat hierarchical reclaim by ID KAMEZAWA Hiroyuki
2008-12-09 12:27   ` Balbir Singh
2008-12-09 14:28     ` KAMEZAWA Hiroyuki
2008-12-09 15:46       ` Balbir Singh
2008-12-09 16:34         ` KAMEZAWA Hiroyuki
2008-12-10  2:49           ` Balbir Singh
2008-12-10  3:03             ` KAMEZAWA Hiroyuki
2008-12-09 11:10 ` [RFC][PATCH 5/6] fix inactive_ratio under hierarchy KAMEZAWA Hiroyuki
2008-12-11  3:14   ` KOSAKI Motohiro
2008-12-11  3:19     ` KAMEZAWA Hiroyuki [this message]
2008-12-09 11:12 ` [RFC][PATCH 6/6] fix oom " KAMEZAWA Hiroyuki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081211121933.a2e25e75.kamezawa.hiroyu@jp.fujitsu.com \
    --to=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=menage@google.com \
    --cc=nishimura@mxp.nes.nec.co.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox