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

From: Linus Torvalds
Date: Fri Aug 21 2020 - 14:23:59 EST


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.

Linus