On Tue, Jun 05, 2018 at 12:24:39AM -0700, Srikar Dronamraju wrote: > * Peter Zijlstra <pet...@infradead.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); }