From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753239Ab2GWCbJ (ORCPT ); Sun, 22 Jul 2012 22:31:09 -0400 Received: from LGEMRELSE6Q.lge.com ([156.147.1.121]:53874 "EHLO LGEMRELSE6Q.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752881Ab2GWCbH (ORCPT ); Sun, 22 Jul 2012 22:31:07 -0400 X-AuditID: 9c930179-b7bdcae000003d91-8d-500cb769cb5a From: Namhyung Kim To: Vlad Zolotarov Cc: Ingo Molnar , linux-kernel@vger.kernel.org, "Shai Fultheim \(Shai\@ScaleMP.com\)" Subject: Re: [RFC] optimize the locking in the rebalance_domains() References: <1342974235.6692.20.camel@vlad> Date: Mon, 23 Jul 2012 11:25:39 +0900 In-Reply-To: <1342974235.6692.20.camel@vlad> (Vlad Zolotarov's message of "Sun, 22 Jul 2012 19:23:55 +0300") Message-ID: <87fw8j6wnw.fsf@sejong.aot.lge.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.97 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Anyway, wouldn't it be better using time_before() here? 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: