From patchwork Thu Oct 5 13:07:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 9987111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2EB3F6029B for ; Thu, 5 Oct 2017 13:08:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FCCB28C66 for ; Thu, 5 Oct 2017 13:08:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1454228C90; Thu, 5 Oct 2017 13:08:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A9DA528C66 for ; Thu, 5 Oct 2017 13:08:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BF1116E7E2; Thu, 5 Oct 2017 13:08:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id DF19E6E7E2; Thu, 5 Oct 2017 13:08:08 +0000 (UTC) Received: by mail-wr0-x243.google.com with SMTP id l10so1316153wre.3; Thu, 05 Oct 2017 06:08:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=lVBvp0ZS0yzF/XA/ObDFraOJrCiSB6TP3JDurAYQvY4=; b=dIyKkxfcnownjZuBmX2I7EqiLD53tXt7gNN7QPqub3S6IuvqJoTWncP66L2YLGxGK1 K1vDgShq7mRyda/smRNBP1Skm/FtHUP+SKkWoE+dRKwHagZPuSV1M6A+ngI7V5P/rRnS OaQ0KtAklQRyIKpvC8aogE07AQxY3Mr+fTq6FZv76gant6xRe2h6ch/62XQDmQ19swoW X31wa873PUPX7firLA3l6foUlX0AA/SqBcDaK+4Z+sEno2+bk2oSckujUKqBEk8JnCeW Hju/PIo94bA0iujIrHuS8DtLNfmm0x48ZJBDNCg09y5fXi4y17KMk6EG7gj1s1v9ZiDc jGcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lVBvp0ZS0yzF/XA/ObDFraOJrCiSB6TP3JDurAYQvY4=; b=Ib5ZRD1mYkj9hdXEztuWBT7h+egMmarPQ9U0xEo+1hoJIQwSvbtBVX+pj1kyGOh8wh p7tqtu9w8Ud0n0IPUDFyJvO3N+4c1julyJbgiJSKjmrbVjDxnLLk+0cT9nd+G1HTCDNg NcgUN7UpkApvdAt2Q+l+z3IWr2LTAFIGqmnT35F7HWYfKpyt6vlkmOzPwQZlRMlCvMpZ WdXMGQiN2htW5luKtJh6GURax3oiXYrdi6haf4XwlqX6GZhUchEFWb5MNrUypEaMXfoC xS6Eu/nbPD/5SkW+slQkObaOymx4s4VqafB9GAbmv+OzKNmOPGbqsQEDg/3jiNnz0yh/ pARA== X-Gm-Message-State: AMCzsaXWHEbEwA/AQNCMFVhhn/Toz78AYN/nlu0zqw+Rx2QrPg+AsxlR 5olioORx97CwGt6eCDfVBIPnuEb5 X-Google-Smtp-Source: AOwi7QA1mZd5YSOsP1rY5NE+hSKmkST/esonowASveE/LHeAYCtGku4QRxFkhQ1m9YmXtKJd96VgyA== X-Received: by 10.223.184.115 with SMTP id u48mr9876724wrf.91.1507208887205; Thu, 05 Oct 2017 06:08:07 -0700 (PDT) Received: from localhost.localdomain ([2a02:908:1251:7981:c12c:1293:87f3:cbfe]) by smtp.gmail.com with ESMTPSA id 133sm15002742wmu.4.2017.10.05.06.08.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Oct 2017 06:08:06 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 3/6] drm/ttm: add transparent huge page support for cached allocations Date: Thu, 5 Oct 2017 15:07:51 +0200 Message-Id: <1507208874-3448-3-git-send-email-deathsimple@vodafone.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507208874-3448-1-git-send-email-deathsimple@vodafone.de> References: <1507208874-3448-1-git-send-email-deathsimple@vodafone.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Christian König Try to allocate huge pages when it makes sense. Signed-off-by: Christian König Acked-by: Felix Kuehling --- drivers/gpu/drm/ttm/ttm_page_alloc.c | 49 ++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index 6c852e8..e8d42d4 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -685,12 +685,24 @@ static void ttm_put_pages(struct page **pages, unsigned npages, int flags, if (pool == NULL) { /* No pool for this memory type so free the pages */ - for (i = 0; i < npages; i++) { - if (pages[i]) { - if (page_count(pages[i]) != 1) - pr_err("Erroneous page count. Leaking pages.\n"); - __free_page(pages[i]); - pages[i] = NULL; + i = 0; + while (i < npages) { + unsigned order; + + if (!pages[i]) { + ++i; + continue; + } + + if (page_count(pages[i]) != 1) + pr_err("Erroneous page count. Leaking pages.\n"); + order = compound_order(pages[i]); + __free_pages(pages[i], order); + + order = 1 << order; + while (order) { + pages[i++] = NULL; + --order; } } return; @@ -740,12 +752,32 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags, /* No pool for cached pages */ if (pool == NULL) { + unsigned i, j; + if (flags & TTM_PAGE_FLAG_DMA32) gfp_flags |= GFP_DMA32; else gfp_flags |= GFP_HIGHUSER; - for (r = 0; r < npages; ++r) { + i = 0; +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + while (npages >= HPAGE_PMD_NR) { + gfp_t huge_flags = gfp_flags; + + huge_flags |= GFP_TRANSHUGE; + huge_flags &= ~__GFP_MOVABLE; + p = alloc_pages(huge_flags, HPAGE_PMD_ORDER); + if (!p) + break; + + for (j = 0; j < HPAGE_PMD_NR; ++j) + pages[i++] = p++; + + npages -= HPAGE_PMD_NR; + } +#endif + + while (npages) { p = alloc_page(gfp_flags); if (!p) { @@ -753,7 +785,8 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags, return -ENOMEM; } - pages[r] = p; + pages[i++] = p; + --npages; } return 0; }