Yu Zhao <yuzhao@xxxxxxxxxx> writes: > + > +#ifdef CONFIG_MEMCG > + if (memcg && atomic_read(&memcg->moving_account)) > + goto contended; > +#endif > + if (!mmap_read_trylock(mm)) > + goto contended; These are essentially spinloops. Surely you need a cpu_relax() somewhere? In general for all of spinloop like constructs it would be useful to consider how to teach lockdep about them. > + do { > + old_flags = READ_ONCE(page->flags); > + new_gen = ((old_flags & LRU_GEN_MASK) >> LRU_GEN_PGOFF) - 1; > + VM_BUG_ON_PAGE(new_gen < 0, page); > + if (new_gen >= 0 && new_gen != old_gen) > + goto sort; > + > + new_gen = (old_gen + 1) % MAX_NR_GENS; > + new_flags = (old_flags & ~LRU_GEN_MASK) | ((new_gen + 1UL) << LRU_GEN_PGOFF); > + /* mark page for reclaim if pending writeback */ > + if (front) > + new_flags |= BIT(PG_reclaim); > + } while (cmpxchg(&page->flags, old_flags, new_flags) != > old_flags); I see this cmpxchg flags pattern a lot. Could there be some common code factoring? -Andi