Re: [PATCH v3] mm/gup: Allow real explicit breaking of COW

From: Peter Xu
Date: Fri Aug 21 2020 - 15:31:14 EST


On Fri, Aug 21, 2020 at 11:23:31AM -0700, Linus Torvalds wrote:
> On Fri, Aug 21, 2020 at 11:08 AM Peter Xu <peterx@xxxxxxxxxx> wrote:
> >
> > IIUC, Jan wanted to point out the fact that KSM didn't increase page count for
> > stable pages (reasons are above get_ksm_page()).
>
> Ouch.
>
> > Do we still at least need to check the swap count if PageSwapCache(page)?
>
> No. Because a PageSwapCache() page should be a perfectly normal page
> cache thing. It will increment the page count if it's active.
>
> That PageKsm() thing that *doesn't* increment the page could does look
> worrisome, but
>
> > So we check page_count() (which covers KSM or normal pages) after we've got the
> > page lock, while we keep all the rest.
>
> Why would we keep the rest? I
>
> The actual thing I would really want to get rid of is the page lock,
> in fact. We shouldn't need it in this path, and it's the most
> expensive part of it all. But that's also why I did the page count
> test optimistically unlocked - because if page_count is 1, then we
> really shouldn't contend with anything else, so hopefully the
> (currently quite expensive) page locking is actually a non-issue once
> you get there.
>
> But the PageKsm() page_count() issue I didn't even realize. That worries me.

That's definitely tricky.. Though IMHO that's another KSM topic that we might
want to look into later besides the current effort to fix up the COW breaking
issue for gup. For now, it shouldn't be hard for us as long as we do cow
always for KSM pages. However, do we really want to revert the whole logic of
52d1e606ee73? Asking because it still seems to be an improvement to me (after
all we'll need to look after KSM pages here). So it seems still good to keep.

Thanks,

--
Peter Xu