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

Linus Torvalds
2020-08-11T20:06:26Z

;

On Tue, Aug 11, 2020 at 12:24 PM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> Now I wonder if there's any other case of FOLL_WRITE that is missing.

Actually, now I wonder if we really should have tried to handle the
wrong-way cow reuse case some other way entirely.

When discussing this wrong-way-COW issue originally I looked at just doing

struct page *page = vmf->page;

if (page_count(page) != 1)
goto copy;
if (!trylock_page(page))
goto copy;
if (page_mapcount(page) != 1 && page_count(page) != 1) {
unlock_page(page);
goto copy;
}
/* Ok, we've got the only map reference, and the only
* page count reference, and the page is locked,
* it's dark out, and we're wearing sunglasses. Hit it.
*/
wp_page_reuse(vmf);
unlock_page(page);
return VM_FAULT_WRITE

at the top of the PageAnon() case in do_wp_page(), and be entirely done with it.

Make the rule be that we *only* re-use the page if there is no
question what-so-ever that we're the only possible owner of it.
Anything else at all - whether they be GUP users, other processes,
KSM, hughepage collapsing, whatever: don't even try.

That would possibly cause a lot of extra copies, but our rules for
"can we re-use this page" are just crazy complicated. And now the
"minimal" thing of just always breaking COW ends up causing
complications of its own.

IOW, maybe all of this falls under "yeah, we have historical reasons
for all of it, but it's just not worth the pain".

We do a _lot_ of complex stuff just to check whether we could possibly
share the page.

Maybe trying to reuse the page just isn't worth it?

Adding Andrea to the cc (although he probably sees this through
linux-mm anyway). Maybe he can go "naah, that will be horribly bad,
because..."

Then we could get rid of all the FAULT_FORCE_COW games again entirely,
and people can point fingers at me and laugh behind my back because of
what a bad idea it was.

Linus