From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753547AbbFVQBs (ORCPT ); Mon, 22 Jun 2015 12:01:48 -0400 Received: from cantor2.suse.de ([195.135.220.15]:52411 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750991AbbFVQBj (ORCPT ); Mon, 22 Jun 2015 12:01:39 -0400 Message-ID: <5588315D.5070804@suse.cz> Date: Mon, 22 Jun 2015 18:01:33 +0200 From: Vlastimil Babka User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: "Kirill A. Shutemov" CC: "Kirill A. Shutemov" , Andrew Morton , Andrea Arcangeli , Hugh Dickins , Dave Hansen , Mel Gorman , Rik van Riel , Christoph Lameter , Naoya Horiguchi , Steve Capper , "Aneesh Kumar K.V" , Johannes Weiner , Michal Hocko , Jerome Marchand , Sasha Levin , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCHv6 29/36] thp: implement split_huge_pmd() References: <1433351167-125878-1-git-send-email-kirill.shutemov@linux.intel.com> <1433351167-125878-30-git-send-email-kirill.shutemov@linux.intel.com> <557959BC.5000303@suse.cz> <20150622111434.GC7934@node.dhcp.inet.fi> In-Reply-To: <20150622111434.GC7934@node.dhcp.inet.fi> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/22/2015 01:14 PM, Kirill A. Shutemov wrote: > On Thu, Jun 11, 2015 at 11:49:48AM +0200, Vlastimil Babka wrote: >> On 06/03/2015 07:06 PM, Kirill A. Shutemov wrote: >> >> The order of actions here means that between TestSetPageDoubleMap() and the >> atomic incs, anyone calling page_mapcount() on one of the pages not >> processed by the for loop yet, will see a value lower by 1 from what he >> should see. I wonder if that can cause any trouble somewhere, especially if >> there's only one other compound mapping and page_mapcount() will return 0 >> instead of 1? > > Good catch. Thanks. > > What about this? > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 0f1f5731a893..cd0e6addb662 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -2636,15 +2636,25 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, > for (i = 0; i < HPAGE_PMD_NR; i++) > atomic_dec(&page[i]._mapcount); > } > - } else if (!TestSetPageDoubleMap(page)) { > + } else if (!PageDoubleMap(page)) { > /* > * The first PMD split for the compound page and we still > * have other PMD mapping of the page: bump _mapcount in > * every small page. > + * > * This reference will go away with last compound_mapcount. > + * > + * Note, we need to increment mapcounts before setting > + * PG_double_map to avoid false-negative page_mapped(). > */ > for (i = 0; i < HPAGE_PMD_NR; i++) > atomic_inc(&page[i]._mapcount); > + > + if (TestSetPageDoubleMap(page)) { > + /* Race with another __split_huge_pmd() for the page */ > + for (i = 0; i < HPAGE_PMD_NR; i++) > + atomic_dec(&page[i]._mapcount); > + } > } Yeah that should work. > smp_wmb(); /* make pte visible before pmd */ > >> Conversely, when clearing PageDoubleMap() above (or in one of those rmap >> functions IIRC), one could see mapcount inflated by one. But I guess that's >> less dangerous. > > I think it's safe. OK. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in Please read the FAQ at http://www.tux.org/lkml/