All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: linux-mm@kvack.org,
	"balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
	gthelen@google.com, m-ikeda@ds.jp.nec.com,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"menage@google.com" <menage@google.com>,
	"lizf@cn.fujitsu.com" <lizf@cn.fujitsu.com>,
	Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Subject: Re: [PATCH 4/5] memcg: lockless update of file stat with move-account safe method
Date: Tue, 31 Aug 2010 12:51:18 +0900	[thread overview]
Message-ID: <20100831125118.fa01f0c2.nishimura@mxp.nes.nec.co.jp> (raw)
In-Reply-To: <20100825171050.1574ba7c.kamezawa.hiroyu@jp.fujitsu.com>

On Wed, 25 Aug 2010 17:10:50 +0900
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:

> From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> 
> At accounting file events per memory cgroup, we need to find memory cgroup
> via page_cgroup->mem_cgroup. Now, we use lock_page_cgroup().
> 
> But, considering the context which page-cgroup for files are accessed,
> we can use alternative light-weight mutual execusion in the most case.
> At handling file-caches, the only race we have to take care of is "moving"
> account, IOW, overwriting page_cgroup->mem_cgroup. Because file status
> update is done while the page-cache is in stable state, we don't have to
> take care of race with charge/uncharge.
> 
> Unlike charge/uncharge, "move" happens not so frequently. It happens only when
> rmdir() and task-moving (with a special settings.)
> This patch adds a race-checker for file-cache-status accounting v.s. account
> moving. The new per-cpu-per-memcg counter MEM_CGROUP_ON_MOVE is added.
> The routine for account move 
>   1. Increment it before start moving
>   2. Call synchronize_rcu()
>   3. Decrement it after the end of moving.
> By this, file-status-counting routine can check it needs to call
> lock_page_cgroup(). In most case, I doesn't need to call it.
> 
> Changelog: 20100825
>  - added a comment about mc.lock
>  - fixed bad lock.
> Changelog: 20100804
>  - added a comment for possible optimization hint.
> Changelog: 20100730
>  - some cleanup.
> Changelog: 20100729
>  - replaced __this_cpu_xxx() with this_cpu_xxx
>    (because we don't call spinlock)
>  - added VM_BUG_ON().
> 
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

(snip)

> @@ -1505,29 +1551,36 @@ void mem_cgroup_update_file_mapped(struc
>  {
>  	struct mem_cgroup *mem;
>  	struct page_cgroup *pc;
> +	bool need_lock = false;
>  
>  	pc = lookup_page_cgroup(page);
>  	if (unlikely(!pc))
>  		return;
> -
> -	lock_page_cgroup(pc);
> +	rcu_read_lock();
>  	mem = id_to_memcg(pc->mem_cgroup, true);
It doesn't cause any problem, but I think it would be better to change this to
"id_to_memcg(..., false)". It's just under rcu_read_lock(), not under page_cgroup
lock anymore.

Otherwise, it looks good to me.

Reviewed-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>

Thanks,
Daisuke Nishimura.

WARNING: multiple messages have this Message-ID (diff)
From: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: linux-mm@kvack.org,
	"balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
	gthelen@google.com, m-ikeda@ds.jp.nec.com,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"menage@google.com" <menage@google.com>,
	"lizf@cn.fujitsu.com" <lizf@cn.fujitsu.com>,
	Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Subject: Re: [PATCH 4/5] memcg: lockless update of file stat with move-account safe method
Date: Tue, 31 Aug 2010 12:51:18 +0900	[thread overview]
Message-ID: <20100831125118.fa01f0c2.nishimura@mxp.nes.nec.co.jp> (raw)
In-Reply-To: <20100825171050.1574ba7c.kamezawa.hiroyu@jp.fujitsu.com>

On Wed, 25 Aug 2010 17:10:50 +0900
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:

> From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> 
> At accounting file events per memory cgroup, we need to find memory cgroup
> via page_cgroup->mem_cgroup. Now, we use lock_page_cgroup().
> 
> But, considering the context which page-cgroup for files are accessed,
> we can use alternative light-weight mutual execusion in the most case.
> At handling file-caches, the only race we have to take care of is "moving"
> account, IOW, overwriting page_cgroup->mem_cgroup. Because file status
> update is done while the page-cache is in stable state, we don't have to
> take care of race with charge/uncharge.
> 
> Unlike charge/uncharge, "move" happens not so frequently. It happens only when
> rmdir() and task-moving (with a special settings.)
> This patch adds a race-checker for file-cache-status accounting v.s. account
> moving. The new per-cpu-per-memcg counter MEM_CGROUP_ON_MOVE is added.
> The routine for account move 
>   1. Increment it before start moving
>   2. Call synchronize_rcu()
>   3. Decrement it after the end of moving.
> By this, file-status-counting routine can check it needs to call
> lock_page_cgroup(). In most case, I doesn't need to call it.
> 
> Changelog: 20100825
>  - added a comment about mc.lock
>  - fixed bad lock.
> Changelog: 20100804
>  - added a comment for possible optimization hint.
> Changelog: 20100730
>  - some cleanup.
> Changelog: 20100729
>  - replaced __this_cpu_xxx() with this_cpu_xxx
>    (because we don't call spinlock)
>  - added VM_BUG_ON().
> 
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

(snip)

> @@ -1505,29 +1551,36 @@ void mem_cgroup_update_file_mapped(struc
>  {
>  	struct mem_cgroup *mem;
>  	struct page_cgroup *pc;
> +	bool need_lock = false;
>  
>  	pc = lookup_page_cgroup(page);
>  	if (unlikely(!pc))
>  		return;
> -
> -	lock_page_cgroup(pc);
> +	rcu_read_lock();
>  	mem = id_to_memcg(pc->mem_cgroup, true);
It doesn't cause any problem, but I think it would be better to change this to
"id_to_memcg(..., false)". It's just under rcu_read_lock(), not under page_cgroup
lock anymore.

Otherwise, it looks good to me.

Reviewed-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>

Thanks,
Daisuke Nishimura.

--
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:[~2010-08-31  3:54 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-25  8:04 [PATCH 0/5] memcg: towards I/O aware memcg v6 KAMEZAWA Hiroyuki
2010-08-25  8:04 ` KAMEZAWA Hiroyuki
2010-08-25  8:06 ` [PATCH 1/5] cgroup: do ID allocation under css allocator KAMEZAWA Hiroyuki
2010-08-25  8:06   ` KAMEZAWA Hiroyuki
2010-08-25 14:15   ` Balbir Singh
2010-08-25 14:15     ` Balbir Singh
2010-08-26  0:13     ` KAMEZAWA Hiroyuki
2010-08-26  0:13       ` KAMEZAWA Hiroyuki
2010-08-31  6:33       ` Balbir Singh
2010-08-31  6:33         ` Balbir Singh
2010-08-30  5:44   ` Daisuke Nishimura
2010-08-30  5:44     ` Daisuke Nishimura
2010-08-25  8:07 ` [PATCH 2/5] memcg: quick memcg lookup array KAMEZAWA Hiroyuki
2010-08-25  8:07   ` KAMEZAWA Hiroyuki
2010-08-30  8:03   ` Daisuke Nishimura
2010-08-30  8:03     ` Daisuke Nishimura
2010-09-01  0:29     ` KAMEZAWA Hiroyuki
2010-09-01  0:29       ` KAMEZAWA Hiroyuki
2010-08-31  7:14   ` Balbir Singh
2010-08-31  7:14     ` Balbir Singh
2010-09-01  0:21     ` KAMEZAWA Hiroyuki
2010-09-01  0:21       ` KAMEZAWA Hiroyuki
2010-08-25  8:09 ` [PATCH 3/5] memcg: use ID instead of pointer in page_cgroup KAMEZAWA Hiroyuki
2010-08-25  8:09   ` KAMEZAWA Hiroyuki
2010-08-31  2:14   ` Daisuke Nishimura
2010-08-31  2:14     ` Daisuke Nishimura
2010-08-25  8:10 ` [PATCH 4/5] memcg: lockless update of file stat with move-account safe method KAMEZAWA Hiroyuki
2010-08-25  8:10   ` KAMEZAWA Hiroyuki
2010-08-31  3:51   ` Daisuke Nishimura [this message]
2010-08-31  3:51     ` Daisuke Nishimura
2010-09-01  0:31     ` KAMEZAWA Hiroyuki
2010-09-01  0:31       ` KAMEZAWA Hiroyuki
2010-08-25  8:11 ` [PATCH 5/5] memcg: generic file stat accounting interface KAMEZAWA Hiroyuki
2010-08-25  8:11   ` KAMEZAWA Hiroyuki
2010-08-31  4:33   ` Daisuke Nishimura
2010-08-31  4:33     ` Daisuke Nishimura
2010-09-01  0:31     ` KAMEZAWA Hiroyuki
2010-09-01  0:31       ` 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=20100831125118.fa01f0c2.nishimura@mxp.nes.nec.co.jp \
    --to=nishimura@mxp.nes.nec.co.jp \
    --cc=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=gthelen@google.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=m-ikeda@ds.jp.nec.com \
    --cc=menage@google.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.