Re: [PATCH] mm: reuse the unshared swapcache page in do_wp_page

From: David Hildenbrand
Date: Thu Jan 20 2022 - 11:35:39 EST


>>
>> Sorry, I was less verbose because I was just sending out the
>> patch+description to Linus' reply and was assuming you're going to read
>> it anyways ;)
>
> This reply arrived before your reply to Linus ;-) Anyway ...

Yes, I could just have added that I'm going to reply with the patch to
Linus after Linus' mail flew in and I made up my mind how to proceed,
that would have been nicer :)

>
>> Yes, I'm speaking about exactly that fallback path.
>
> OK, so in that fallback path, we're already determined the THP has
> more than one reference to it (ok, maybe that extra reference was
> temporary and now gone), but we've already split the PMD down into

Yes, any extra references or concurrent writeback. Swapcache was once
example that my patch hopefully handles properly.

> PTEs, and COWed one of the other pages that was in the THP. If
> anything, we should be more aggressive about COWing the remaining
> pages in the THP, not looking for reasons why we might be able to
> avoid COWing this particular page.

At that point in time we didn't COW yet, we only PTE-mapped the THP, but
yes, once we reach do_wp_page() we will always COW, even if there are no
additional references anymore.

Ideas I had what we could do once we're in do_cow_page() and we spot
that we do have a PTE-mapped THP:
* Count the mappings in the process page table and use that as baseline
(instead of 1). Would fail if there are additional references.
* Try to split the compound page immediately. Will also fail if there
are additional references.

COWing more extremely sounds like an interesting idea to free up the
compound page after we fragmented it -- which will succeed once
additional references are gone.

--
Thanks,

David / dhildenb