lkml.org 
[lkml]   [2021]   [Mar]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v1 10/14] mm: multigenerational lru: core
On Sun, Mar 14, 2021 at 07:02:01PM -0700, Andi Kleen wrote:
> Yu Zhao <yuzhao@google.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 ();

\
 
 \ /
  Last update: 2021-03-15 04:39    [W:0.366 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site