[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <bec1b401-fb2e-6672-d904-396402434890@suse.cz>
Date: Mon, 11 Apr 2022 20:18:29 +0200
From: Vlastimil Babka <vbabka@...e.cz>
To: David Hildenbrand <david@...hat.com>, linux-kernel@...r.kernel.org
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Hugh Dickins <hughd@...gle.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
David Rientjes <rientjes@...gle.com>,
Shakeel Butt <shakeelb@...gle.com>,
John Hubbard <jhubbard@...dia.com>,
Jason Gunthorpe <jgg@...dia.com>,
Mike Kravetz <mike.kravetz@...cle.com>,
Mike Rapoport <rppt@...ux.ibm.com>,
Yang Shi <shy828301@...il.com>,
"Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>,
Matthew Wilcox <willy@...radead.org>,
Jann Horn <jannh@...gle.com>, Michal Hocko <mhocko@...nel.org>,
Nadav Amit <namit@...are.com>, Rik van Riel <riel@...riel.com>,
Roman Gushchin <guro@...com>,
Andrea Arcangeli <aarcange@...hat.com>,
Peter Xu <peterx@...hat.com>,
Donald Dutile <ddutile@...hat.com>,
Christoph Hellwig <hch@....de>,
Oleg Nesterov <oleg@...hat.com>, Jan Kara <jack@...e.cz>,
Liang Zhang <zhangliang5@...wei.com>,
Pedro Gomes <pedrodemargomes@...il.com>,
Oded Gabbay <oded.gabbay@...il.com>, linux-mm@...ck.org
Subject: Re: [PATCH v3 04/16] mm/rmap: split page_dup_rmap() into
page_dup_file_rmap() and page_try_dup_anon_rmap()
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@...hat.com>
Acked-by: Vlastimil Babka <vbabka@...e.cz>
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().
>
> /*
> * We do not preserve soft-dirty information, because so
> @@ -921,18 +922,24 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma,
> struct page *page;
>
> page = vm_normal_page(src_vma, addr, pte);
> - if (page && unlikely(page_needs_cow_for_dma(src_vma, page))) {
> + if (page && PageAnon(page)) {
> /*
> * If this page may have been pinned by the parent process,
> * copy the page immediately for the child so that we'll always
> * guarantee the pinned page won't be randomly replaced in the
> * future.
> */
> - return copy_present_page(dst_vma, src_vma, dst_pte, src_pte,
> - addr, rss, prealloc, page);
> + get_page(page);
> + if (unlikely(page_try_dup_anon_rmap(page, false, src_vma))) {
> + /* Page maybe pinned, we have to copy. */
> + put_page(page);
> + return copy_present_page(dst_vma, src_vma, dst_pte, src_pte,
> + addr, rss, prealloc, page);
> + }
> + rss[mm_counter(page)]++;
> } else if (page) {
> get_page(page);
> - page_dup_rmap(page, false);
> + page_dup_file_rmap(page, false);
> rss[mm_counter(page)]++;
> }
>
> diff --git a/mm/migrate.c b/mm/migrate.c
> index 3d60823afd2d..97de2fc17f34 100644
> --- a/mm/migrate.c
> +++ b/mm/migrate.c
> @@ -234,7 +234,7 @@ static bool remove_migration_pte(struct folio *folio,
> if (folio_test_anon(folio))
> hugepage_add_anon_rmap(new, vma, pvmw.address);
> else
> - page_dup_rmap(new, true);
> + page_dup_file_rmap(new, true);
> set_huge_pte_at(vma->vm_mm, pvmw.address, pvmw.pte, pte);
> } else
> #endif
Powered by blists - more mailing lists