Re: [PATCH v3 04/16] mm/rmap: split page_dup_rmap() into page_dup_file_rmap() and page_try_dup_anon_rmap()

From: David Hildenbrand
Date: Tue Apr 12 2022 - 05:37:03 EST


On 11.04.22 20:18, Vlastimil Babka wrote:
> On 3/29/22 18:04, David Hildenbrand wrote:
>> ... and move the special check for pinned pages into
>> page_try_dup_anon_rmap() to prepare for tracking exclusive anonymous
>> pages via a new pageflag, clearing it only after making sure that there
>> are no GUP pins on the anonymous page.
>>
>> We really only care about pins on anonymous pages, because they are
>> prone to getting replaced in the COW handler once mapped R/O. For !anon
>> pages in cow-mappings (!VM_SHARED && VM_MAYWRITE) we shouldn't really
>> care about that, at least not that I could come up with an example.
>>
>> Let's drop the is_cow_mapping() check from page_needs_cow_for_dma(), as we
>> know we're dealing with anonymous pages. Also, drop the handling of
>> pinned pages from copy_huge_pud() and add a comment if ever supporting
>> anonymous pages on the PUD level.
>>
>> This is a preparation for tracking exclusivity of anonymous pages in
>> the rmap code, and disallowing marking a page shared (-> failing to
>> duplicate) if there are GUP pins on a page.
>>
>> Signed-off-by: David Hildenbrand <david@xxxxxxxxxx>
>
> Acked-by: Vlastimil Babka <vbabka@xxxxxxx>
>
> Nit:
>
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -825,7 +825,8 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
>> */
>> get_page(page);
>> rss[mm_counter(page)]++;
>> - page_dup_rmap(page, false);
>> + /* Cannot fail as these pages cannot get pinned. */
>> + BUG_ON(page_try_dup_anon_rmap(page, false, src_vma));
>
> Should we just call __page_dup_rmap() here? This is block for the condition
> is_device_private_entry(), and page_try_dup_anon_rmap() can't return -EBUSY
> for is_device_private_page().


Hi Vlastimil,

thanks for your review!

We want to keep page_try_dup_anon_rmap() here, because we extend
page_try_dup_anon_rmap() in patch #12 to properly clear
PageAnonExclusive() of there are no GUP pins. Just like with current
page_try_dup_anon_rmap(), that can't fail for device private pages.

--
Thanks,

David / dhildenb