Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932642AbbELJah (ORCPT ); Tue, 12 May 2015 05:30:37 -0400 Received: from mx2.parallels.com ([199.115.105.18]:44012 "EHLO mx2.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932431AbbELJ2M (ORCPT ); Tue, 12 May 2015 05:28:12 -0400 Date: Tue, 12 May 2015 12:27:47 +0300 From: Vladimir Davydov To: "Kirill A. Shutemov" CC: Rik van Riel , Hugh Dickins , Christoph Lameter , "Paul E. McKenney" , Peter Zijlstra , Andrew Morton , Minchan Kim , Johannes Weiner , Michal Hocko , Greg Thelen , Michel Lespinasse , David Rientjes , Pavel Emelyanov , Cyrill Gorcunov , , Subject: Re: [RFC] rmap: fix "race" between do_wp_page and shrink_active_list Message-ID: <20150512092747.GC17628@esperanza> References: <1431330677-24476-1-git-send-email-vdavydov@parallels.com> <20150511093652.GA11257@node.dhcp.inet.fi> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20150511093652.GA11257@node.dhcp.inet.fi> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2539 Lines: 76 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 from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/