> On Feb 25, 2020, at 8:29 PM, Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote: > > On Tue, Feb 25, 2020 at 11:55:26AM -0500, Qian Cai wrote: >> - if (pgdat->kswapd_classzone_idx == MAX_NR_ZONES) >> - pgdat->kswapd_classzone_idx = classzone_idx; >> - else >> - pgdat->kswapd_classzone_idx = max(pgdat->kswapd_classzone_idx, >> - classzone_idx); >> + if (READ_ONCE(pgdat->kswapd_classzone_idx) == MAX_NR_ZONES || >> + READ_ONCE(pgdat->kswapd_classzone_idx) < classzone_idx) >> + WRITE_ONCE(pgdat->kswapd_classzone_idx, classzone_idx); >> + >> pgdat->kswapd_order = max(pgdat->kswapd_order, order); > > Doesn't this line have the exact same problem you're "solving" above? Good catch. I missed that. > > Also, why would you do this crazy "f(READ_ONCE(x)) || g(READ_ONCE(x))? > Surely you should be stashing READ_ONCE(x) into a local variable? Not a bad idea. > > And there are a _lot_ of places which access kswapd_classzone_idx > without a lock. Are you sure this patch is sufficient? I am not sure, but KCSAN did not complain about other places after running extended period of testing, so I will look into once other places show up later.