From patchwork Tue Jun 21 16:17:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 902592 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5LGJQop022874 for ; Tue, 21 Jun 2011 16:19:46 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3A95B9F711 for ; Tue, 21 Jun 2011 09:19:26 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (server109-228-6-236.live-servers.net [109.228.6.236]) by gabe.freedesktop.org (Postfix) with ESMTP id 953689ED2C for ; Tue, 21 Jun 2011 09:17:39 -0700 (PDT) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.66.37; Received: from arrandale.alporthouse.com (unverified [78.156.66.37]) by fireflyinternet.com (Firefly Internet SMTP) with ESMTP id 37599450-1500050 for multiple; Tue, 21 Jun 2011 17:17:28 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Tue, 21 Jun 2011 17:17:23 +0100 Message-Id: <1308673044-10612-3-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1308673044-10612-1-git-send-email-chris@chris-wilson.co.uk> References: <013811$h8tfb@fmsmga002.fm.intel.com> <1308673044-10612-1-git-send-email-chris@chris-wilson.co.uk> X-Originating-IP: 78.156.66.37 Subject: [Intel-gfx] [PATCH 2/3] x86, pat: Perform interval rbtree lookup of memtype first X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 21 Jun 2011 16:19:46 +0000 (UTC) The PAT interval tree is only defined for non-RAM ranges, and is both a shorter list and log-n lookup compared to the linear walk over the resource ranges looking for "System RAM". In the case of heavy vm_insert_pfn() users like the gpu drivers, which regularly modify the contents of the AGP aperture, this gives a significant reduction in the overhead of faulting in fresh addresses. However, note that in 1f9cc3cb6a27521ed (x86, pat: Update the page flags for memtype atomically instead of using memtype_lock), the contention upon the memtype_lock in lookup_memtype() was observed to be behind a factor of 50x reduction in page fault rate for 32 cpus running vm_insert_pfn(). By performing the locked lookup of memtype first, we are once again exposed to that contention for is_ram pages. Though in effect we will be just moving the contention from resource_lock (rwlock) to memtype_lock (spinlock) Signed-off-by: Chris Wilson %%Cc: Robin Holt %%Cc: Suresh Siddha %%Cc: H. Peter Anvin --- arch/x86/mm/pat.c | 24 +++++++++++++----------- 1 files changed, 13 insertions(+), 11 deletions(-) diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c index f6ff57b..18d4aa9 100644 --- a/arch/x86/mm/pat.c +++ b/arch/x86/mm/pat.c @@ -384,10 +384,21 @@ int free_memtype(u64 start, u64 end) */ static unsigned long lookup_memtype(u64 paddr) { - int rettype = _PAGE_CACHE_WB; + int rettype = -1; struct memtype *entry; if (x86_platform.is_untracked_pat_range(paddr, paddr + PAGE_SIZE)) + return _PAGE_CACHE_WB; + + spin_lock(&memtype_lock); + + entry = rbt_memtype_lookup(paddr); + if (entry != NULL) + rettype = entry->type; + + spin_unlock(&memtype_lock); + + if (rettype != -1) return rettype; if (pat_pagerange_is_ram(paddr, paddr + PAGE_SIZE)) { @@ -404,16 +415,7 @@ static unsigned long lookup_memtype(u64 paddr) return rettype; } - spin_lock(&memtype_lock); - - entry = rbt_memtype_lookup(paddr); - if (entry != NULL) - rettype = entry->type; - else - rettype = _PAGE_CACHE_UC_MINUS; - - spin_unlock(&memtype_lock); - return rettype; + return _PAGE_CACHE_UC_MINUS; } /**