linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: nishimura@mxp.nes.nec.co.jp, lizf@cn.fujitsu.com,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Linux/PPC Development <linuxppc-dev@ozlabs.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	Balbir Singh <balbir@linux.vnet.ibm.com>
Subject: Re: [BUGFIX][PATCH] memcg: avoid use cmpxchg in swap cgroup maintainance (Was Re: 34-rc1-git3 build failure with CGROUP_MEM_RES_CTLR_SWAP=y
Date: Mon, 15 Mar 2010 14:21:52 +1100	[thread overview]
Message-ID: <1268623312.2209.108.camel@pasglop> (raw)
In-Reply-To: <20100315100202.eb735f59.kamezawa.hiroyu@jp.fujitsu.com>


> Oh..ok, powerpc (and other archs?) can't do 2byte cmpxchg and xchg.
> Then, we should use spinlock rather than that.
> 
> How about this ? Nishimura-san, could you consider something better ?
> We need a quick fix.

sparc64 is the same as powerpc in that regard, maybe others. 

Cheers,
Ben.

> ==
> swap_cgroup uses 2bytes data and uses cmpxchg in a new operation.
> 2byte cmpxchg/xchg is not available on some archs. This patch replaces
> cmpxchg/xchg with operations under lock.
> 
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> ---
>  mm/page_cgroup.c |   20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> Index: mmotm-2.6.34-Mar11/mm/page_cgroup.c
> ===================================================================
> --- mmotm-2.6.34-Mar11.orig/mm/page_cgroup.c
> +++ mmotm-2.6.34-Mar11/mm/page_cgroup.c
> @@ -284,6 +284,7 @@ static DEFINE_MUTEX(swap_cgroup_mutex);
>  struct swap_cgroup_ctrl {
>  	struct page **map;
>  	unsigned long length;
> +	spinlock_t	lock;
>  };
>  
>  struct swap_cgroup_ctrl swap_cgroup_ctrl[MAX_SWAPFILES];
> @@ -353,16 +354,22 @@ unsigned short swap_cgroup_cmpxchg(swp_e
>  	struct swap_cgroup_ctrl *ctrl;
>  	struct page *mappage;
>  	struct swap_cgroup *sc;
> +	unsigned long flags;
> +	unsigned short retval;
>  
>  	ctrl = &swap_cgroup_ctrl[type];
>  
>  	mappage = ctrl->map[idx];
>  	sc = page_address(mappage);
>  	sc += pos;
> -	if (cmpxchg(&sc->id, old, new) == old)
> -		return old;
> +	spin_lock_irqsave(&ctrl->lock, flags);
> +	retval = sc->id;
> +	if (retval == old)
> +		sc->id = new;
>  	else
> -		return 0;
> +		retval = 0;
> +	spin_unlock_irqrestore(&ctrl->lock, flags);
> +	return retval;
>  }
>  
>  /**
> @@ -383,13 +390,17 @@ unsigned short swap_cgroup_record(swp_en
>  	struct page *mappage;
>  	struct swap_cgroup *sc;
>  	unsigned short old;
> +	unsigned long flags;
>  
>  	ctrl = &swap_cgroup_ctrl[type];
>  
>  	mappage = ctrl->map[idx];
>  	sc = page_address(mappage);
>  	sc += pos;
> -	old = xchg(&sc->id, id);
> +	spin_lock_irqsave(&ctrl->lock, flags);
> +	old = sc->id;
> +	sc->id = id;
> +	spin_unlock_irqrestore(&ctrl->lock, flags);
>  
>  	return old;
>  }
> @@ -441,6 +452,7 @@ int swap_cgroup_swapon(int type, unsigne
>  	mutex_lock(&swap_cgroup_mutex);
>  	ctrl->length = length;
>  	ctrl->map = array;
> +	spin_lock_init(&ctrl->lock);
>  	if (swap_cgroup_prepare(type)) {
>  		/* memory shortage */
>  		ctrl->map = NULL;
> 
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev

  parent reply	other threads:[~2010-03-15  3:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-14 10:48 34-rc1-git3 build failure with CGROUP_MEM_RES_CTLR_SWAP=y Sachin Sant
2010-03-15  1:02 ` [BUGFIX][PATCH] memcg: avoid use cmpxchg in swap cgroup maintainance (Was " KAMEZAWA Hiroyuki
2010-03-15  2:14   ` Balbir Singh
2010-03-15  3:16   ` Daisuke Nishimura
2010-03-15  3:21   ` Benjamin Herrenschmidt [this message]
2010-03-15  1:04 ` Michael Ellerman

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=1268623312.2209.108.camel@pasglop \
    --to=benh@kernel.crashing.org \
    --cc=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=lizf@cn.fujitsu.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;
as well as URLs for NNTP newsgroup(s).