Re: [PATCH v2 13/19] mm/migrate: Use xchg instead of spinlock

From: Peter Zijlstra
Date: Mon Jul 23 2018 - 10:04:32 EST


On Mon, Jul 23, 2018 at 04:20:32AM -0700, Srikar Dronamraju wrote:
> > If you maybe write that like:
> >
> > if (time_after(jiffies, next_window) &&
> > xchg(&pgdat->numabalancing_migrate_nr_pages, 0UL)) {
> >
> > do {
> > next_window += interval;
> > } while (unlikely(time_after(jiffies, next_window)));
> >
> > WRITE_ONCE(pgdat->numabalancing_migrate_next_window, next_window);
> > }
> >
> > Then you avoid an indent level and line-wrap, resulting imo easier to
> > read code.
> >
>
> Okay will do.

FWIW, that code seems to rely on @nr_pages != 0, otherwise you can have
the xchg fail even though time_after is true.

Probably not a problem, but it is a semantic change vs the spinlock.
Also, the spinlock thing could probably have changed to a trylock and
you'd have seens similar 'gains' I suppose.

Another difference vs the lock+unlock is that you lost the release
ordering. Again, probably not a big deal, but it does make the whole
things a little dodgy.