[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YE7Wd+0t3G/3hc/c@google.com>
Date: Sun, 14 Mar 2021 21:37:27 -0600
From: Yu Zhao <yuzhao@...gle.com>
To: Andi Kleen <ak@...ux.intel.com>
Cc: linux-mm@...ck.org, Alex Shi <alex.shi@...ux.alibaba.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Hillf Danton <hdanton@...a.com>,
Johannes Weiner <hannes@...xchg.org>,
Joonsoo Kim <iamjoonsoo.kim@....com>,
Matthew Wilcox <willy@...radead.org>,
Mel Gorman <mgorman@...e.de>, Michal Hocko <mhocko@...e.com>,
Roman Gushchin <guro@...com>, Vlastimil Babka <vbabka@...e.cz>,
Wei Yang <richard.weiyang@...ux.alibaba.com>,
Yang Shi <shy828301@...il.com>,
Ying Huang <ying.huang@...el.com>,
linux-kernel@...r.kernel.org, page-reclaim@...gle.com
Subject: Re: [PATCH v1 10/14] mm: multigenerational lru: core
On Sun, Mar 14, 2021 at 07:02:01PM -0700, Andi Kleen wrote:
> Yu Zhao <yuzhao@...gle.com> writes:
Hi Andi!
Recovering the context a bit:
err = -EBUSY;
> > +
> > +#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?
contended:
...
cond_resched();
} while (err == -EAGAIN && !mm_is_oom_victim(mm) && !mm_has_migrated(mm, memcg));
So if it's contended, we break the loop.
> 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?
Thanks for noticing this. A shorthand macro would be nice. Hmm... let
me investigate. I don't know how to do this off the top of my head:
A macro can be used like
cmpxchg_macro() {
func();
}
without backslashes and it'll be expanded to
do {
func();
} while ();
Powered by blists - more mailing lists