lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ef2e38bcab0d4cd3a8307a242a35eb431f16f6c3.camel@linux.intel.com>
Date: Thu, 13 Nov 2025 09:49:46 -0800
From: Tim Chen <tim.c.chen@...ux.intel.com>
To: Shrikanth Hegde <sshegde@...ux.ibm.com>, Peter Zijlstra
	 <peterz@...radead.org>
Cc: Ingo Molnar <mingo@...nel.org>, Chen Yu <yu.c.chen@...el.com>, Doug
 Nelson	 <doug.nelson@...el.com>, Mohini Narkhede
 <mohini.narkhede@...el.com>, 	linux-kernel@...r.kernel.org, Vincent Guittot
 <vincent.guittot@...aro.org>, K Prateek Nayak <kprateek.nayak@....com>,
 Srikar Dronamraju <srikar@...ux.ibm.com>, Linus Torvalds	
 <torvalds@...ux-foundation.org>
Subject: Re: [PATCH v4] sched/fair: Skip sched_balance_running cmpxchg when
 balance is not due

On Thu, 2025-11-13 at 09:55 +0530, Shrikanth Hegde wrote:
> 
> On 11/13/25 2:40 AM, Tim Chen wrote:
> > On Wed, 2025-11-12 at 12:21 +0100, Peter Zijlstra wrote:
> > > On Wed, Nov 12, 2025 at 04:39:43PM +0530, Shrikanth Hegde wrote:
> > > > 
> > > > 
> > > 
> > > > > So perhaps this is the better option -- or did I overlook something with
> > > > > should_we_balance? It doesn't look like that will make a different
> > > > > decision on the retry.
> > > > > 
> > > > 
> > > > I think in newidle balance, these checks are there in swb to bail of load balance.
> > > > redo logic catches it right?
> > > 
> > > Urgh, my brain still thinks we're not serializing on newidle. Perhaps I
> > > should make this 2 patches, one moving the serializing and one adding it
> > > to newidle.
> > > 
> > > > env->dst_rq lock is taken only in attach_tasks, meanwhile, if the wakeup happened,
> > > > pending would be set. is irq enabled or remote CPU can set ttwu_pending on this rq?
> > > > 
> > > >          if (env->idle == CPU_NEWLY_IDLE) {
> > > >                  if (env->dst_rq->nr_running > 0 || env->dst_rq->ttwu_pending)
> > > >                          return 0;
> > > >                  return 1;
> > > >          }
> > > 
> > > Right, that could get tickled.
> > 
> > How about something like the following on top of v4 patch?
> > This will avoid releasing the lock and take care of the NEWLY_IDLE case.
> > 
> > Tim
> > 
> > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > index 43c5ec039633..26179f4b77f6 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -11772,14 +11772,13 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
> >   		.fbq_type	= all,
> >   		.tasks		= LIST_HEAD_INIT(env.tasks),
> >   	};
> > -	bool need_unlock;
> > +	bool need_unlock = false;
> >   
> >   	cpumask_and(cpus, sched_domain_span(sd), cpu_active_mask);
> >   
> >   	schedstat_inc(sd->lb_count[idle]);
> >   
> >   redo:
> > -	need_unlock = false;
> >   	if (!should_we_balance(&env)) {
> >   		*continue_balancing = 0;
> >   		goto out_balanced;
> > @@ -11916,9 +11915,9 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
> >   			if (!cpumask_subset(cpus, env.dst_grpmask)) {
> >   				env.loop = 0;
> >   				env.loop_break = SCHED_NR_MIGRATE_BREAK;
> > -				if (need_unlock)
> > -					atomic_set_release(&sched_balance_running, 0);
> > -
> > +				if (env->idle == CPU_NEWLY_IDLE &&
> > +				    (env->dst_running > 0 || env->dst_rq->ttwu_pending))
> > +					goto out;
> 
> IIUC, we come here, it means busiest cpu was found, but due to
> affinity restrictions none of the tasks can come to this cpu.
> 
> So a redo is done excluding that busiest cpu if there are cpus other
> than the group_mask of this cpu. So doing a redo does make sense specially
> for newidle.
> 
> So doing bailing out might be wrong.

My understanding is the reason for the idle balancing is because the
dst_rq becomes idle.  If we see that the dst_rq already has something to run,
why add latency to search for more tasks to pull as it is likely the dst_rq
is the current cpu.

Tim

> 
> >   				goto redo;
> >   			}
> >   			goto out_all_pinned;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ