Re: [RFC] rmap: fix "race" between do_wp_page and shrink_active_list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 11, 2015 at 12:36:52PM +0300, Kirill A. Shutemov wrote:
> On Mon, May 11, 2015 at 10:51:17AM +0300, Vladimir Davydov wrote:
> > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> > index 5e7c4f50a644..a529e0a35fe9 100644
> > --- a/include/linux/page-flags.h
> > +++ b/include/linux/page-flags.h
> > @@ -320,7 +320,8 @@ PAGEFLAG(Idle, idle)
> >  
> >  static inline int PageAnon(struct page *page)
> >  {
> > -	return ((unsigned long)page->mapping & PAGE_MAPPING_ANON) != 0;
> > +	return ((unsigned long)READ_ONCE(page->mapping) &
> > +		PAGE_MAPPING_ANON) != 0;
> 
> Why do we need this? Write side should be enough to get this
> deterministic.

Yeah, this seems to be completely redundant, my bad.

> 
> >  }
> >  
> >  #ifdef CONFIG_KSM
> > diff --git a/mm/rmap.c b/mm/rmap.c
> > index eca7416f55d7..aa60c63704e6 100644
> > --- a/mm/rmap.c
> > +++ b/mm/rmap.c
> > @@ -958,7 +958,7 @@ void page_move_anon_rmap(struct page *page,
> >  	VM_BUG_ON_PAGE(page->index != linear_page_index(vma, address), page);
> >  
> >  	anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON;
> > -	page->mapping = (struct address_space *) anon_vma;
> > +	WRITE_ONCE(page->mapping, (struct address_space *) anon_vma);
> >  }
> >  
> >  /**
> > @@ -987,7 +987,7 @@ static void __page_set_anon_rmap(struct page *page,
> >  		anon_vma = anon_vma->root;
> >  
> >  	anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON;
> > -	page->mapping = (struct address_space *) anon_vma;
> > +	WRITE_ONCE(page->mapping, (struct address_space *) anon_vma);
> >  	page->index = linear_page_index(vma, address);
> 
> No need: we don't hit this code if page is already PageAnon().

Agree.

> 
> >  }
> >  
> > @@ -1579,7 +1579,7 @@ static void __hugepage_set_anon_rmap(struct page *page,
> >  		anon_vma = anon_vma->root;
> >  
> >  	anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON;
> > -	page->mapping = (struct address_space *) anon_vma;
> > +	WRITE_ONCE(page->mapping, (struct address_space *) anon_vma);
> 
> Ditto.

Agree.

So we do need this eventually, don't we? Frankly, I doubted that,
because the fact that a compiler can do such wicked things really scares
me :-/

All right then, I'll resend the patch with your comments addressed.
Thank you for spending your time reviewing it.

Thanks,
Vladimir

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]