public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vlad Zolotarov <vlad@scalemp.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	linux-kernel@vger.kernel.org,
	"Shai Fultheim (Shai@ScaleMP.com)" <Shai@scalemp.com>
Subject: Re: [RFC] optimize the locking in the rebalance_domains()
Date: Mon, 23 Jul 2012 10:50:38 +0300	[thread overview]
Message-ID: <1343029838.6692.26.camel@vlad> (raw)
In-Reply-To: <87fw8j6wnw.fsf@sejong.aot.lge.com>

On Mon, 2012-07-23 at 11:25 +0900, Namhyung Kim wrote:
> Hi, Vlad
> 
> On Sun, 22 Jul 2012 19:23:55 +0300, Vlad Zolotarov wrote:
> > Ingo, we've noticed that rebalance_domains() will try to take a lock
> > every time it's called (every jiffy) if SD_SERIALIZE is set (which is a
> > default configuration). This is done regardless the fact that maybe
> > there hasn't passed enough time since the last rebalancing in which case
> > there is no need to take a lock the first place.
> >
> > The above creates a heavy false sharing problem on the "balancing"
> > spin-lock on large SMP systems: try_lock() is implemented with an
> > (atomic) xchng instruction which invalidates the cache line "balancing"
> > belongs to and therefore creates an intensive cross-NUMA-nodes traffic.
> >
> > The below patch will minimize the above phenomena to the time slots it's
> > really needed, namely when the "interval" has really passed.
> >
> > Pls., comment.
> >
> > thanks,
> > vlad
> >
> > ---
> >  kernel/sched/fair.c |   20 +++++++++++---------
> >  1 file changed, 11 insertions(+), 9 deletions(-)
> >
> > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > index c099cc6..6777d38 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -4689,6 +4689,9 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)
> >  		interval = msecs_to_jiffies(interval);
> >  		interval = clamp(interval, 1UL, max_load_balance_interval);
> >  
> > +                if (!time_after_eq(jiffies, sd->last_balance + interval))
> > +			goto out;
> > +
> 
> First line looks like white-space-damaged.

Looks like it. ;) Thanks for catching. I'll surely fix it if we get to
posting the patch for applying.

> Anyway, wouldn't it be better using time_before() here?

Sure. I'll fix it as well. However I'd like to hear what u and other
people on the mailing list think about the idea in general.

Thanks,
vlad

> 
> Thanks,
> Namhyung
> 
> 
> >  		need_serialize = sd->flags & SD_SERIALIZE;
> >  
> >  		if (need_serialize) {
> > @@ -4696,16 +4699,15 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)
> >  				goto out;
> >  		}
> >  
> > -		if (time_after_eq(jiffies, sd->last_balance + interval)) {
> > -			if (load_balance(cpu, rq, sd, idle, &balance)) {
> > -				/*
> > -				 * We've pulled tasks over so either we're no
> > -				 * longer idle.
> > -				 */
> > -				idle = CPU_NOT_IDLE;
> > -			}
> > -			sd->last_balance = jiffies;
> > +		if (load_balance(cpu, rq, sd, idle, &balance)) {
> > +			/*
> > +			 * We've pulled tasks over so either we're no
> > +			 * longer idle.
> > +			 */
> > +			idle = CPU_NOT_IDLE;
> >  		}
> > +		sd->last_balance = jiffies;
> > +
> >  		if (need_serialize)
> >  			spin_unlock(&balancing);
> >  out:



      reply	other threads:[~2012-07-23  7:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-22 16:23 [RFC] optimize the locking in the rebalance_domains() Vlad Zolotarov
2012-07-22 16:33 ` Vlad Zolotarov
2012-07-23  2:25 ` Namhyung Kim
2012-07-23  7:50   ` Vlad Zolotarov [this message]

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=1343029838.6692.26.camel@vlad \
    --to=vlad@scalemp.com \
    --cc=Shai@scalemp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.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