linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Balbir Singh <balbir@linux.vnet.ibm.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"nishimura@mxp.nes.nec.co.jp" <nishimura@mxp.nes.nec.co.jp>
Subject: Re: [RFC][PATCH 4/5] memcg: per-cpu charge stock
Date: Mon, 31 Aug 2009 16:40:27 +0530	[thread overview]
Message-ID: <20090831111027.GI4770@balbir.in.ibm.com> (raw)
In-Reply-To: <20090828132706.e35caf80.kamezawa.hiroyu@jp.fujitsu.com>

* KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> [2009-08-28 13:27:06]:

> 
> For avoiding frequent access to res_counter at charge, add per-cpu
> local charge. Comparing with modifing res_coutner (with percpu_counter),
> this approach
> Pros.
> 	- we don't have to touch res_counter's cache line
> 	- we don't have to chase res_counter's hierarchy
> 	- we don't have to call res_counter function.
> Cons.
> 	- we need our own code.
> 
> Considering trade-off, I think this is worth to do.

I prefer the other part due to

1. Code reuse (any enhancements made will benefit us)
2. Custom batching that can be done easily
3. Remember hierarchy is explicitly enabled and we've documented that
it is expensive



>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> ---
>  mm/memcontrol.c |   46 +++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 37 insertions(+), 9 deletions(-)
> 
> Index: mmotm-2.6.31-Aug27/mm/memcontrol.c
> ===================================================================
> --- mmotm-2.6.31-Aug27.orig/mm/memcontrol.c
> +++ mmotm-2.6.31-Aug27/mm/memcontrol.c
> @@ -71,7 +71,7 @@ enum mem_cgroup_stat_index {
>  	MEM_CGROUP_STAT_PGPGOUT_COUNT,	/* # of pages paged out */
>  	MEM_CGROUP_STAT_EVENTS,	/* sum of pagein + pageout for internal use */
>  	MEM_CGROUP_STAT_SWAPOUT, /* # of pages, swapped out */
> -
> +	MEM_CGROUP_STAT_STOCK, /* # of private charges pre-allocated */
>  	MEM_CGROUP_STAT_NSTATS,
>  };
> 
> @@ -1266,6 +1266,32 @@ done:
>  	unlock_page_cgroup(pc);
>  }
> 
> +#define CHARGE_SIZE	(4 * ((NR_CPUS >> 5) + 1) * PAGE_SIZE)
> +
> +bool consume_local_stock(struct mem_cgroup *mem)
> +{
> +	struct mem_cgroup_stat_cpu *cstat;
> +	int cpu = get_cpu();
> +	bool ret = true;
> +
> +	cstat = &mem->stat.cpustat[cpu];
> +	if (cstat->count[MEM_CGROUP_STAT_STOCK])
> +		cstat->count[MEM_CGROUP_STAT_STOCK] -= PAGE_SIZE;
> +	else
> +		ret = false;
> +	put_cpu();
> +	return ret;
> +}
> +
> +void do_local_stock(struct mem_cgroup *mem, int val)
> +{
> +	struct mem_cgroup_stat_cpu *cstat;
> +	int cpu = get_cpu();
> +	cstat = &mem->stat.cpustat[cpu];
> +	__mem_cgroup_stat_add_safe(cstat, MEM_CGROUP_STAT_STOCK, val);
> +	put_cpu();
> +}
> +
>  /*
>   * Unlike exported interface, "oom" parameter is added. if oom==true,
>   * oom-killer can be invoked.
> @@ -1297,28 +1323,30 @@ static int __mem_cgroup_try_charge(struc
>  	} else {
>  		css_get(&mem->css);
>  	}
> -	if (unlikely(!mem))
> +	/* css_get() against root cgroup is NOOP. we can ignore it */
> +	if (!mem || mem_cgroup_is_root(mem))
>  		return 0;
> 
>  	VM_BUG_ON(css_is_removed(&mem->css));
> 
> +	if (consume_local_stock(mem))
> +		goto got;
> +
>  	while (1) {
>  		int ret = 0;
>  		unsigned long flags = 0;
> 
> -		if (mem_cgroup_is_root(mem))
> -			goto done;
> -		ret = res_counter_charge(&mem->res, PAGE_SIZE, &fail_res);
> +		ret = res_counter_charge(&mem->res, CHARGE_SIZE, &fail_res);
> 
>  		if (likely(!ret)) {
>  			if (!do_swap_account)
>  				break;
> -			ret = res_counter_charge(&mem->memsw, PAGE_SIZE,
> +			ret = res_counter_charge(&mem->memsw, CHARGE_SIZE,
>  						&fail_res);
>  			if (likely(!ret))
>  				break;
>  			/* mem+swap counter fails */
> -			res_counter_uncharge(&mem->res, PAGE_SIZE);
> +			res_counter_uncharge(&mem->res, CHARGE_SIZE);
>  			flags |= MEM_CGROUP_RECLAIM_NOSWAP;
>  			mem_over_limit = mem_cgroup_from_res_counter(fail_res,
>  									memsw);
> @@ -1356,7 +1384,8 @@ static int __mem_cgroup_try_charge(struc
>  			goto nomem;
>  		}
>  	}
> -
> +	do_local_stock(mem, CHARGE_SIZE - PAGE_SIZE);
> +got:
>  	/*
>  	 * check hierarchy root's event counter and modify softlimit-tree
>  	 * if necessary.
> @@ -1364,7 +1393,6 @@ static int __mem_cgroup_try_charge(struc
>  	mem_over_soft_limit = mem_cgroup_soft_limit_check(mem);
>  	if (mem_over_soft_limit)
>  		mem_cgroup_update_tree(mem_over_soft_limit, page);
> -done:
>  	return 0;
>  nomem:
>  	css_put(&mem->css);
> 

-- 
	Balbir

--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2009-08-31 11:10 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-28  4:20 [RFC][PATCH 0/5] memcg: reduce lock conetion KAMEZAWA Hiroyuki
2009-08-28  4:23 ` [RFC][PATCH 1/5] memcg: change for softlimit KAMEZAWA Hiroyuki
2009-08-28  7:20   ` Balbir Singh
2009-08-28  7:35     ` KAMEZAWA Hiroyuki
2009-08-28 13:26       ` Balbir Singh
2009-08-28 14:29         ` KAMEZAWA Hiroyuki
2009-08-28 14:40           ` KAMEZAWA Hiroyuki
2009-08-28 14:46             ` Balbir Singh
2009-08-28 15:06               ` KAMEZAWA Hiroyuki
2009-08-28 15:08                 ` Balbir Singh
2009-08-28 15:12                   ` KAMEZAWA Hiroyuki
2009-08-28 15:15                     ` Balbir Singh
2009-08-28 14:45           ` Balbir Singh
2009-08-28 14:58             ` KAMEZAWA Hiroyuki
2009-08-28 15:07               ` Balbir Singh
2009-08-28  4:24 ` [RFC][PATCH 2/5] memcg: uncharge in batched manner KAMEZAWA Hiroyuki
2009-08-28  4:53   ` KAMEZAWA Hiroyuki
2009-08-28  4:55     ` KAMEZAWA Hiroyuki
2009-08-28 15:10   ` Balbir Singh
2009-08-28 15:21     ` KAMEZAWA Hiroyuki
2009-08-28 16:03       ` Balbir Singh
2009-08-31 11:02   ` Balbir Singh
2009-08-31 11:59     ` KAMEZAWA Hiroyuki
2009-08-31 12:10       ` Balbir Singh
2009-08-31 12:14         ` KAMEZAWA Hiroyuki
2009-08-31 12:23           ` Balbir Singh
2009-08-31 14:36             ` KAMEZAWA Hiroyuki
2009-08-28  4:25 ` [RFC][PATCH 3/5] memcg: unmap, truncate, invalidate uncharege in batch KAMEZAWA Hiroyuki
2009-08-31 11:02   ` Balbir Singh
2009-08-28  4:27 ` [RFC][PATCH 4/5] memcg: per-cpu charge stock KAMEZAWA Hiroyuki
2009-08-31 11:10   ` Balbir Singh [this message]
2009-08-31 12:07     ` KAMEZAWA Hiroyuki
2009-08-28  4:28 ` [RFC][PATCH 5/5] memcg: drain per cpu stock KAMEZAWA Hiroyuki
2009-08-31 11:11   ` Balbir Singh
2009-08-31 12:09     ` KAMEZAWA Hiroyuki
2009-08-28  4:28 ` [RFC][PATCH 0/5] memcg: reduce lock conetion Balbir Singh
2009-08-28  4:33   ` 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=20090831111027.GI4770@balbir.in.ibm.com \
    --to=balbir@linux.vnet.ibm.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --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;
as well as URLs for NNTP newsgroup(s).