lkml.org 
[lkml]   [2020]   [Sep]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 5/5] mm/thp: Split huge pmds/puds if they're pinned when fork()
On Mon 21-09-20 23:41:16, John Hubbard wrote:
> On 9/21/20 2:20 PM, Peter Xu wrote:
> ...
> > diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> > index 7ff29cc3d55c..c40aac0ad87e 100644
> > --- a/mm/huge_memory.c
> > +++ b/mm/huge_memory.c
> > @@ -1074,6 +1074,23 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
> > src_page = pmd_page(pmd);
> > VM_BUG_ON_PAGE(!PageHead(src_page), src_page);
> > +
> > + /*
> > + * If this page is a potentially pinned page, split and retry the fault
> > + * with smaller page size. Normally this should not happen because the
> > + * userspace should use MADV_DONTFORK upon pinned regions. This is a
> > + * best effort that the pinned pages won't be replaced by another
> > + * random page during the coming copy-on-write.
> > + */
> > + if (unlikely(READ_ONCE(src_mm->has_pinned) &&
> > + page_maybe_dma_pinned(src_page))) {
>
> This condition would make a good static inline function. It's used in 3
> places, and the condition is quite special and worth documenting, and
> having a separate function helps with that, because the function name
> adds to the story. I'd suggest approximately:
>
> page_likely_dma_pinned()
>
> for the name.

Well, but we should also capture that this really only works for anonymous
pages. For file pages mm->has_pinned does not work because the page may be
still pinned by completely unrelated process as Jann already properly
pointed out earlier in the thread. So maybe anon_page_likely_pinned()?
Possibly also assert PageAnon(page) in it if we want to be paranoid...

Honza

--
Jan Kara <jack@suse.com>
SUSE Labs, CR

\
 
 \ /
  Last update: 2020-09-22 12:34    [W:0.148 / U:3.480 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site