linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: nishimura@mxp.nes.nec.co.jp,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	"balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>
Subject: Re: [PATCH 5/6] memcg: lazy lru freeing
Date: Thu, 9 Oct 2008 14:39:49 +0900	[thread overview]
Message-ID: <20081009143949.b3cf91b7.nishimura@mxp.nes.nec.co.jp> (raw)
In-Reply-To: <20081001170005.1997d7c8.kamezawa.hiroyu@jp.fujitsu.com>

On Wed, 1 Oct 2008 17:00:05 +0900, KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:
> Free page_cgroup from its LRU in batched manner.
> 
> When uncharge() is called, page is pushed onto per-cpu vector and
> removed from LRU, later.. This routine resembles to global LRU's pagevec.
> This patch is half of the whole patch and a set with following lazy LRU add
> patch.
> 
> After this, a pc, which is PageCgroupLRU(pc)==true, is on LRU.
> This LRU bit is guarded by lru_lock().
> 
>  PageCgroupUsed(pc) && PageCgroupLRU(pc) means "pc" is used and on LRU.
>  This check makes sense only when both 2 locks, lock_page_cgroup()/lru_lock(),
>  are aquired.
> 
>  PageCgroupUsed(pc) && !PageCgroupLRU(pc) means "pc" is used but not on LRU.
>  !PageCgroupUsed(pc) && PageCgroupLRU(pc) means "pc" is unused but still on
>  LRU. lru walk routine should avoid touching this.
> 
> Changelog (v5) => (v6):
>  - Fixing race and added PCG_LRU bit
> 
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> 

(snip)

> +static void
> +__release_page_cgroup(struct memcg_percpu_vec *mpv)
> +{
> +	unsigned long flags;
> +	struct mem_cgroup_per_zone *mz, *prev_mz;
> +	struct page_cgroup *pc;
> +	int i, nr;
> +
> +	local_irq_save(flags);
> +	nr = mpv->nr;
> +	mpv->nr = 0;
> +	prev_mz = NULL;
> +	for (i = nr - 1; i >= 0; i--) {
> +		pc = mpv->vec[i];
> +		mz = page_cgroup_zoneinfo(pc);
> +		if (prev_mz != mz) {
> +			if (prev_mz)
> +				spin_unlock(&prev_mz->lru_lock);
> +			prev_mz = mz;
> +			spin_lock(&mz->lru_lock);
> +		}
> +		/*
> +		 * this "pc" may be charge()->uncharge() while we are waiting
> +		 * for this. But charge() path check LRU bit and remove this
> +		 * from LRU if necessary.
> +		 */
> +		if (!PageCgroupUsed(pc) && PageCgroupLRU(pc)) {
> +			ClearPageCgroupLRU(pc);
> +			__mem_cgroup_remove_list(mz, pc);
> +			css_put(&pc->mem_cgroup->css);
> +		}
> +	}
> +	if (prev_mz)
> +		spin_unlock(&prev_mz->lru_lock);
> +	local_irq_restore(flags);
> +
> +}
> +
I'm wondering if page_cgroup_zoneinfo is safe without lock_page_cgroup
because it dereferences pc->mem_cgroup.
I'm worring if the pc has been moved to another lru by re-charge(and re-uncharge),
and __mem_cgroup_remove_list toches a wrong(old) group.

Hmm, there are many things to be done for re-charge and re-uncharge,
so "if (!PageCgroupUsed(pc) && PageCgroupLRU(pc))" would be enough.
(it can avoid race between re-charge.)

Another user of page_cgroup_zoneinfo without lock_page_cgroup is
__mem_cgroup_move_lists called by mem_cgroup_isolate_pages,
but mem_cgroup_isolate_pages handles pc which is actually on the mz->lru
so it would be ok.
(I think adding VM_BUG_ON(mz != page_cgroup_zoneifno(pc)) would make sense,
or add new arg *mz to __mem_cgroup_move_lists?)


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:[~2008-10-09  5:39 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-01  7:52 [PATCH 0/6] memcg update v6 (for review and discuss) KAMEZAWA Hiroyuki
2008-10-01  7:55 ` [PATCH 1/6] atomic page_cgroup flags KAMEZAWA Hiroyuki
2008-10-06  7:42   ` Balbir Singh
2008-10-01  7:56 ` [PATCH 2/6] memcg: allocate page_cgroup at boot KAMEZAWA Hiroyuki
2008-10-02  8:49   ` [PATCH 2/6] memcg: allocate page_cgroup at boot (hunk fix) KAMEZAWA Hiroyuki
2008-10-06 16:32     ` Balbir Singh
2008-10-06 10:11   ` [PATCH 2/6] memcg: allocate page_cgroup at boot Balbir Singh
2008-10-01  7:57 ` [PATCH 3/6] memcg: charge-commit-cancel protocl KAMEZAWA Hiroyuki
2008-10-01  8:33   ` Daisuke Nishimura
2008-10-01 10:04   ` kamezawa.hiroyu
2008-10-03 10:05   ` Daisuke Nishimura
2008-10-03 15:15   ` kamezawa.hiroyu
2008-10-03 15:25     ` Daisuke Nishimura
2008-10-08  9:05   ` [RFC] memcg: handle migration by charge-commit-cancel (was " KAMEZAWA Hiroyuki
2008-10-01  7:59 ` [PATCH 4/6] memcg: new force_empty and move_account KAMEZAWA Hiroyuki
2008-10-01 16:38   ` Randy Dunlap
2008-10-02  5:13     ` KAMEZAWA Hiroyuki
2008-10-01  8:00 ` [PATCH 5/6] memcg: lazy lru freeing KAMEZAWA Hiroyuki
2008-10-09  5:39   ` Daisuke Nishimura [this message]
2008-10-09  6:26     ` KAMEZAWA Hiroyuki
2008-10-01  8:01 ` [PATCH 6/6] memcg: lazy lru addition KAMEZAWA Hiroyuki
2008-10-09  6:21   ` Daisuke Nishimura
2008-10-09  6:51     ` KAMEZAWA Hiroyuki
2008-10-02  9:02 ` [PATCH 0/6] memcg update v6 (for review and discuss) KAMEZAWA Hiroyuki
2008-10-06 17:26   ` Balbir Singh
2008-10-07  1:22     ` 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=20081009143949.b3cf91b7.nishimura@mxp.nes.nec.co.jp \
    --to=nishimura@mxp.nes.nec.co.jp \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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