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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180605081606.GE12217@hirez.programming.kicks-ass.net>
Date:   Tue, 5 Jun 2018 10:16:06 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     Srikar Dronamraju <srikar@...ux.vnet.ibm.com>
Cc:     Ingo Molnar <mingo@...nel.org>,
        LKML <linux-kernel@...r.kernel.org>,
        Mel Gorman <mgorman@...hsingularity.net>,
        Rik van Riel <riel@...riel.com>,
        Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH 13/19] mm/migrate: Use xchg instead of spinlock

On Tue, Jun 05, 2018 at 12:24:39AM -0700, Srikar Dronamraju wrote:
> * Peter Zijlstra <peterz@...radead.org> [2018-06-04 21:28:21]:
> 
> > >  	if (time_after(jiffies, pgdat->numabalancing_migrate_next_window)) {
> > > -		spin_lock(&pgdat->numabalancing_migrate_lock);
> > > -		pgdat->numabalancing_migrate_nr_pages = 0;
> > > -		pgdat->numabalancing_migrate_next_window = jiffies +
> > > -			msecs_to_jiffies(migrate_interval_millisecs);
> > > -		spin_unlock(&pgdat->numabalancing_migrate_lock);
> > > +		if (xchg(&pgdat->numabalancing_migrate_nr_pages, 0))
> > > +			pgdat->numabalancing_migrate_next_window = jiffies +
> > > +				msecs_to_jiffies(migrate_interval_millisecs);
> >
> > Note that both are in fact wrong. That wants to be something like:
> >
> > 	pgdat->numabalancing_migrate_next_window += interval;
> >
> > Otherwise you stretch every interval by 'jiffies - numabalancing_migrate_next_window'.
> 
> Okay, I get your point.

Note that in practise it probably doesn't matter, but it just upsets my
OCD ;-)

> > Also, that all wants READ_ONCE/WRITE_ONCE, irrespective of the
> > spinlock/xchg.

> unsigned long interval = READ_ONCE(pgdat->numabalancing_migrate_next_window);
> 
> if (time_after(jiffies, interval)) {
> 	interval += msecs_to_jiffies(migrate_interval_millisecs));
> 	if (xchg(&pgdat->numabalancing_migrate_nr_pages, 0))
> 		WRITE_ONCE(pgdat->numabalancing_migrate_next_window, interval);
> }
> 
> Something like this?

Almost, you forgot about the case where 'jiffies -
numabalancing_migrate_next_window > interval'.

That wants to be something like:

  unsigned long timo = READ_ONCE(stupid_long_name);

  if (time_after(jiffies, timo) && xchg(&other_long_name, 0)) {
	  do {
		  timo += msec_to_jiffies(..);
	  } while (unlikely(time_after(jiffies, timo);

	  WRITE_ONCE(stupid_long_name, timo);
  }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ