On Thu, Jan 13, 2022 at 9:55 AM David Hildenbrand <david@xxxxxxxxxx> wrote: > > However, reuse_swap_page() currently does multiple things, and that's part of the issue. Yeah, I think it's a horrible function. The COW path was explicitly changed not to use it because it's so confusing. > While we're at it, is there a real reason we can't simplify to > > diff --git a/mm/memory.c b/mm/memory.c > index e8e2144cbfa6..ab114a5862a0 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3295,7 +3295,7 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) > - if (PageKsm(page) || page_mapcount(page) != 1 || page_count(page) != 1) { > + if (PageKsm(page) || page_count(page) != 1) { No, I think both the mapcount and the ksm check are bogus and should be removed, but they are both examples of "get rid of the nastiest complexity, leave the stuff that doesn't much matter". Somebody who really knows the ksm logic should check all the ksm tests. I really think they are pointless, and came from the old and horribly broken page_mapcount() logic that did *not* check page_count(). When you think page_mapcount() matters, suddenly you have to worry about all the other non-mapping uses of a page, which is why I think that ksm test still exists. But I didn't mind keeping a couple of extraneous tests that I didn't see the point of , as long as the core page-count-based logfc was solid Linus