Received: by 10.192.165.148 with SMTP id m20csp2253011imm; Thu, 26 Apr 2018 08:07:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpUp0djxJFENt21KBSCEvWSRDOiZKZOg4lMQuednawmgxb4hIIrV7LGFfjSicYwHsRqQZDQ X-Received: by 10.98.198.217 with SMTP id x86mr5706281pfk.192.1524755275013; Thu, 26 Apr 2018 08:07:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524755274; cv=none; d=google.com; s=arc-20160816; b=mem0SeJ3tRNazMOfNf35IKLkMc++8/clFJh7wt8tk3DnrR/nyL/0eB3EK2nyO8EU7e 0p71UDIBjdSukz84TnW/1di8iCoIDlyk3UDr7KWOvqmz1sq22GXbbsKJ3JO7jKCZptaP 70aeasFxQaBZJraGw8JTPl/CDGPqtpyVfy66LcAfUWjPO7lPMaZkOgpz/Jk8vhatR6HZ BHBdP2sBENppgmMiTGeQ7hYkr5j/wu2Q5UmmQJQeVIFwiqpxcCUAnb7sP9NukXojCcyw Ku2FIYPKzca5qD9Vi6Nn6FAx92RAR6qGXm2TCA5yBPM9xbHG5keaMYZQujzmASuA2T1n Z7mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:arc-authentication-results; bh=AzCWJT/R0DnfNjxekXvfEpC7vXA2jax9JCHTDFTrLAM=; b=YWedt3R1/vY+YKnyDxHgYH+wuET5kzOXndkOLlzG3i9dM5mpA1bdm+BQtV7w6t2+9M CGXsX0pYxvT9/5OlWGXoQVIC097rnk4fPCgVVUoGo8Q9bFBdW2WHTVDRRWG1AHm4Z5Dd ROKfD2wb7l7RE7qJFGAKfUC7wF7F9E8OOpI862qgQeZvVFWBiqUgw1GtuDL2ERmIAhMh VPlfHao7W9LcZBp0rkqn5fPok6i6rGphBoUOhwJka6Ca32fcz77Y5u+tiforDRjwXsM5 5+GHbBp0r+5vC5+nJ+rDCoxcWeoUdYtDYKwAV4hQBm1L+ZxxQ9VCmNhIJ4z0adCIgTb6 3QQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m13si16253544pgs.49.2018.04.26.08.07.39; Thu, 26 Apr 2018 08:07:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756671AbeDZPGZ (ORCPT + 99 others); Thu, 26 Apr 2018 11:06:25 -0400 Received: from mail.netline.ch ([148.251.143.178]:56512 "EHLO netline-mail3.netline.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756611AbeDZPGX (ORCPT ); Thu, 26 Apr 2018 11:06:23 -0400 Received: from localhost (localhost [127.0.0.1]) by netline-mail3.netline.ch (Postfix) with ESMTP id 7087E2A604B; Thu, 26 Apr 2018 17:06:22 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at netline-mail3.netline.ch Received: from netline-mail3.netline.ch ([127.0.0.1]) by localhost (netline-mail3.netline.ch [127.0.0.1]) (amavisd-new, port 10024) with LMTP id zlx6ts9BfkAy; Thu, 26 Apr 2018 17:06:20 +0200 (CEST) Received: from kaveri (145.233.60.188.dynamic.wline.res.cust.swisscom.ch [188.60.233.145]) by netline-mail3.netline.ch (Postfix) with ESMTPSA id 298AB2A604A; Thu, 26 Apr 2018 17:06:19 +0200 (CEST) Received: from daenzer by kaveri with local (Exim 4.91) (envelope-from ) id 1fBiTS-0003W0-R0; Thu, 26 Apr 2018 17:06:18 +0200 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= To: =?UTF-8?q?Christian=20K=C3=B6nig?= , Roger He Cc: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] drm/ttm: Add TTM_PAGE_FLAG_TRANSHUGE Date: Thu, 26 Apr 2018 17:06:17 +0200 Message-Id: <20180426150618.13470-1-michel@daenzer.net> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michel Dänzer When it's set, TTM tries to allocate huge pages if possible. Drivers which can take advantage of huge pages should set it. Drivers not setting this flag no longer incur any overhead related to allocating or freeing huge pages. Cc: stable@vger.kernel.org Signed-off-by: Michel Dänzer --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- drivers/gpu/drm/ttm/ttm_page_alloc.c | 14 ++++++++++---- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 8 +++++--- include/drm/ttm/ttm_tt.h | 1 + 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index dfd22db13fb1..e03e9e361e2a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -988,7 +988,7 @@ static struct ttm_tt *amdgpu_ttm_tt_create(struct ttm_buffer_object *bo, return NULL; } gtt->ttm.ttm.func = &amdgpu_backend_func; - if (ttm_sg_tt_init(>t->ttm, bo, page_flags)) { + if (ttm_sg_tt_init(>t->ttm, bo, page_flags | TTM_PAGE_FLAG_TRANSHUGE)) { kfree(gtt); return NULL; } diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index f0481b7b60c5..2ce91272b111 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -760,7 +760,7 @@ static void ttm_put_pages(struct page **pages, unsigned npages, int flags, { struct ttm_page_pool *pool = ttm_get_pool(flags, false, cstate); #ifdef CONFIG_TRANSPARENT_HUGEPAGE - struct ttm_page_pool *huge = ttm_get_pool(flags, true, cstate); + struct ttm_page_pool *huge = NULL; #endif unsigned long irq_flags; unsigned i; @@ -780,7 +780,8 @@ static void ttm_put_pages(struct page **pages, unsigned npages, int flags, } #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (!(flags & TTM_PAGE_FLAG_DMA32)) { + if ((flags & (TTM_PAGE_FLAG_DMA32 | TTM_PAGE_FLAG_TRANSHUGE)) == + TTM_PAGE_FLAG_TRANSHUGE) { for (j = 0; j < HPAGE_PMD_NR; ++j) if (p++ != pages[i + j]) break; @@ -805,6 +806,8 @@ static void ttm_put_pages(struct page **pages, unsigned npages, int flags, i = 0; #ifdef CONFIG_TRANSPARENT_HUGEPAGE + if (flags & TTM_PAGE_FLAG_TRANSHUGE) + huge = ttm_get_pool(flags, true, cstate); if (huge) { unsigned max_size, n2free; @@ -877,7 +880,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags, { struct ttm_page_pool *pool = ttm_get_pool(flags, false, cstate); #ifdef CONFIG_TRANSPARENT_HUGEPAGE - struct ttm_page_pool *huge = ttm_get_pool(flags, true, cstate); + struct ttm_page_pool *huge = NULL; #endif struct list_head plist; struct page *p = NULL; @@ -906,7 +909,8 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags, i = 0; #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (!(gfp_flags & GFP_DMA32)) { + if ((flags & (TTM_PAGE_FLAG_DMA32 | TTM_PAGE_FLAG_TRANSHUGE)) == + TTM_PAGE_FLAG_TRANSHUGE) { while (npages >= HPAGE_PMD_NR) { gfp_t huge_flags = gfp_flags; @@ -946,6 +950,8 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags, count = 0; #ifdef CONFIG_TRANSPARENT_HUGEPAGE + if (flags & TTM_PAGE_FLAG_TRANSHUGE) + huge = ttm_get_pool(flags, true, cstate); if (huge && npages >= HPAGE_PMD_NR) { INIT_LIST_HEAD(&plist); ttm_page_pool_get_pages(huge, &plist, flags, cstate, diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c index 8a25d1974385..291b04213ec5 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c @@ -949,7 +949,8 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, type = ttm_to_type(ttm->page_flags, ttm->caching_state); #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (ttm->page_flags & TTM_PAGE_FLAG_DMA32) + if ((ttm->page_flags & (TTM_PAGE_FLAG_DMA32 | TTM_PAGE_FLAG_TRANSHUGE)) + != TTM_PAGE_FLAG_TRANSHUGE) goto skip_huge; pool = ttm_dma_find_pool(dev, type | IS_HUGE); @@ -1035,7 +1036,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev) { struct ttm_tt *ttm = &ttm_dma->ttm; struct ttm_mem_global *mem_glob = ttm->bdev->glob->mem_glob; - struct dma_pool *pool; + struct dma_pool *pool = NULL; struct dma_page *d_page, *next; enum pool_type type; bool is_cached = false; @@ -1045,7 +1046,8 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev) type = ttm_to_type(ttm->page_flags, ttm->caching_state); #ifdef CONFIG_TRANSPARENT_HUGEPAGE - pool = ttm_dma_find_pool(dev, type | IS_HUGE); + if (ttm->page_flags & TTM_PAGE_FLAG_TRANSHUGE) + pool = ttm_dma_find_pool(dev, type | IS_HUGE); if (pool) { count = 0; list_for_each_entry_safe(d_page, next, &ttm_dma->pages_list, diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h index c0e928abf592..c7d2120f0362 100644 --- a/include/drm/ttm/ttm_tt.h +++ b/include/drm/ttm/ttm_tt.h @@ -41,6 +41,7 @@ struct ttm_operation_ctx; #define TTM_PAGE_FLAG_DMA32 (1 << 7) #define TTM_PAGE_FLAG_SG (1 << 8) #define TTM_PAGE_FLAG_NO_RETRY (1 << 9) +#define TTM_PAGE_FLAG_TRANSHUGE (1 << 10) enum ttm_caching_state { tt_uncached, -- 2.17.0