Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752738Ab3GSVYf (ORCPT ); Fri, 19 Jul 2013 17:24:35 -0400 Received: from g5t0007.atlanta.hp.com ([15.192.0.44]:35489 "EHLO g5t0007.atlanta.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752460Ab3GSVYV (ORCPT ); Fri, 19 Jul 2013 17:24:21 -0400 Message-ID: <1374269055.9305.19.camel@buesod1.americas.hpqcorp.net> Subject: Re: [PATCH] hugepage: allow parallelization of the hugepage fault path From: Davidlohr Bueso To: David Gibson Cc: Joonsoo Kim , Andrew Morton , Hugh Dickins , Rik van Riel , Michel Lespinasse , Mel Gorman , Konstantin Khlebnikov , Michal Hocko , "AneeshKumarK.V" , KAMEZAWA Hiroyuki , Hillf Danton , linux-mm@kvack.org, LKML , Eric B Munson , Anton Blanchard Date: Fri, 19 Jul 2013 14:24:15 -0700 In-Reply-To: <20130719071432.GB19634@voom.fritz.box> References: <1373671681.2448.10.camel@buesod1.americas.hpqcorp.net> <1373858204.13826.9.camel@buesod1.americas.hpqcorp.net> <20130715072432.GA28053@voom.fritz.box> <20130715160802.9d0cdc0ee012b5e119317a98@linux-foundation.org> <1374090625.15271.2.camel@buesod1.americas.hpqcorp.net> <20130718084235.GA9761@lge.com> <20130719071432.GB19634@voom.fritz.box> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.4.4 (3.4.4-2.fc17) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3065 Lines: 70 On Fri, 2013-07-19 at 17:14 +1000, David Gibson wrote: > On Thu, Jul 18, 2013 at 05:42:35PM +0900, Joonsoo Kim wrote: > > On Wed, Jul 17, 2013 at 12:50:25PM -0700, Davidlohr Bueso wrote: > > > From: David Gibson > > > > > > At present, the page fault path for hugepages is serialized by a > > > single mutex. This is used to avoid spurious out-of-memory conditions > > > when the hugepage pool is fully utilized (two processes or threads can > > > race to instantiate the same mapping with the last hugepage from the > > > pool, the race loser returning VM_FAULT_OOM). This problem is > > > specific to hugepages, because it is normal to want to use every > > > single hugepage in the system - with normal pages we simply assume > > > there will always be a few spare pages which can be used temporarily > > > until the race is resolved. > > > > > > Unfortunately this serialization also means that clearing of hugepages > > > cannot be parallelized across multiple CPUs, which can lead to very > > > long process startup times when using large numbers of hugepages. > > > > > > This patch improves the situation by replacing the single mutex with a > > > table of mutexes, selected based on a hash, which allows us to know > > > which page in the file we're instantiating. For shared mappings, the > > > hash key is selected based on the address space and file offset being faulted. > > > Similarly, for private mappings, the mm and virtual address are used. > > > > > > > Hello. > > > > With this table mutex, we cannot protect region tracking structure. > > See below comment. > > > > /* > > * Region tracking -- allows tracking of reservations and instantiated pages > > * across the pages in a mapping. > > * > > * The region data structures are protected by a combination of the mmap_sem > > * and the hugetlb_instantion_mutex. To access or modify a region the caller > > * must either hold the mmap_sem for write, or the mmap_sem for read and > > * the hugetlb_instantiation mutex: > > * > > * down_write(&mm->mmap_sem); > > * or > > * down_read(&mm->mmap_sem); > > * mutex_lock(&hugetlb_instantiation_mutex); > > */ > > Ugh. Who the hell added that. I guess you'll need to split of > another mutex for that purpose, afaict there should be no interaction > with the actual, intended purpose of the instantiation mutex. This was added in commit 84afd99b. One way to go would be to add a spinlock to protect changes to the regions - however reading the changelog, and based on David's previous explanation for the instantiation mutex, I don't see why it was added. In fact several places modify regions without holding the instantiation mutex, ie: hugetlb_reserve_pages() Am I missing something here? Thanks, Davidlohr -- 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/