[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YnxczoehQJ+x6m9Y@google.com>
Date: Wed, 11 May 2022 18:03:10 -0700
From: Minchan Kim <minchan@...nel.org>
To: "Paul E. McKenney" <paulmck@...nel.org>
Cc: John Hubbard <jhubbard@...dia.com>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-mm <linux-mm@...ck.org>,
LKML <linux-kernel@...r.kernel.org>,
John Dias <joaodias@...gle.com>,
David Hildenbrand <david@...hat.com>
Subject: Re: [PATCH v4] mm: fix is_pinnable_page against on cma page
On Wed, May 11, 2022 at 05:49:49PM -0700, Paul E. McKenney wrote:
> On Wed, May 11, 2022 at 05:34:52PM -0700, John Hubbard wrote:
> > On 5/11/22 17:26, Minchan Kim wrote:
> > > > > Let me try to say this more clearly: I don't think that the following
> > > > > __READ_ONCE() statement can actually help anything, given that
> > > > > get_pageblock_migratetype() is non-inlined:
> > > > >
> > > > > + int __mt = get_pageblock_migratetype(page);
> > > > > + int mt = __READ_ONCE(__mt);
> > > > > +
> > > > > + if (mt & (MIGRATE_CMA | MIGRATE_ISOLATE))
> > > > > + return false;
> > > > >
> > > > >
> > > > > Am I missing anything here?
> > > >
> > > > In the absence of future aggression from link-time optimizations (LTO),
> > > > you are missing nothing.
> > >
> > > A thing I want to note is Android kernel uses LTO full mode.
> >
> > Thanks Paul for explaining the state of things.
> >
> > Minchan, how about something like very close to your original draft,
> > then, but with a little note, and the "&" as well:
> >
> > int __mt = get_pageblock_migratetype(page);
> >
> > /*
> > * Defend against future compiler LTO features, or code refactoring
> > * that inlines the above function, by forcing a single read. Because, this
> > * routine races with set_pageblock_migratetype(), and we want to avoid
> > * reading zero, when actually one or the other flags was set.
> > */
> > int mt = __READ_ONCE(__mt);
> >
> > if (mt & (MIGRATE_CMA | MIGRATE_ISOLATE))
> > return false;
> >
> >
> > ...which should make everyone comfortable and protected from the
> > future sins of the compiler and linker teams? :)
>
> This would work, but it would force a store to the stack and an immediate
> reload. Which might be OK on this code path.
>
> But using READ_ONCE() in (I think?) __get_pfnblock_flags_mask()
> would likely generate the same code that is produced today.
>
> word = READ_ONCE(bitmap[word_bitidx]);
>
> But I could easily have missed a turn in that cascade of functions. ;-)
>
> Or there might be some code path that really hates a READ_ONCE() in
> that place.
My worry about chaning __get_pfnblock_flags_mask is it's called
multiple hot places in mm codes so I didn't want to add overhead
to them.
Powered by blists - more mailing lists