From patchwork Tue Oct 10 08:53:43 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: 9995335 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 D5F9F60230 for ; Tue, 10 Oct 2017 08:53:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6FFA28389 for ; Tue, 10 Oct 2017 08:53:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BACC728396; Tue, 10 Oct 2017 08:53:55 +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 74A8D28389 for ; Tue, 10 Oct 2017 08:53:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6FB866E1AA; Tue, 10 Oct 2017 08:53:51 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id EB33589EBD; Tue, 10 Oct 2017 08:53:49 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id l10so21511649wmg.1; Tue, 10 Oct 2017 01:53:49 -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=nyA20bAfEubJw4O7RffKNH9erZP7vQl6USzu57UT7fw=; b=kbNQn63b8OjI0NTBI47ijMWgTkw0JMWU9g5BRbBIP7ZldtDiDhB+VnlKMZWFPFSihq 71b+HEBp4wiELHEoMjm0ZO6H4JblWZaj3IGv6aV7My+SZgdkKcZSHeCgaP4mufR12Xh2 bkTEThnGkJR2RMBiGndz2V/nvgscNBi85GCflfYRd7GNPn/+GlPZYQbsWMufPiUiNkyz 5wOGr8zlPlh2pug/crLdC4Ct1jLWPdl5As3hMCA7zKforMOgaEJK4KnVz703+xPD+oxR 46DfIJHWtpzkkCIMORC5Opx0GiYWbPxHfQ/KQbuFCuHIBOBgWrZuD9cE35TEgVlzxu/f D+yQ== 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=nyA20bAfEubJw4O7RffKNH9erZP7vQl6USzu57UT7fw=; b=ezFxvXzpN2CtJkh4C8fcTRk2H58ArnUYm/BJyhc0OoVfk/qvorgKfI3wYDP4qqwrVp /q55VowRk0upIud+s9CDH9O7ftuN5MHwYBNmjluGybKjqvK1/zbIE0SWJFiYfikBqaac V+axpMlRQcQR8Z2cSHb2zjcGs/UWJNgHo4vX9szgsZY8YAw3vI2xya7kTlSGKNje16m6 oi1dHLpITF1sHcMiV9L6NZYlQ1aK/XAnbQTx5PhuQjpgw/D5ZwHI4DflgSwzFqPHkSnC zoDXHP1lOdHjyO3JsCP19/W0aXIB6DoeTZKm5ElYbGNMzWjZpgG4o+YY9Lw/G3agE6AM Vo/g== X-Gm-Message-State: AMCzsaWMwDFClPGdxLLoLJ0o5NHfB+AdceTFh4HWvK09wCTphvDbKIWM dqkS5aka7+xkEQO4HDfHk9weJqsu X-Google-Smtp-Source: AOwi7QBjSxXEJ1T3LHbLBaLfs6pu1j0T6Kibiq/7I+kDXQgiRTmdPFjkhbLUZLUWdSMOBAZhMhBlMg== X-Received: by 10.223.199.69 with SMTP id b5mr11522894wrh.270.1507625628381; Tue, 10 Oct 2017 01:53:48 -0700 (PDT) Received: from localhost.localdomain ([2a02:908:1251:7981:c8a1:1d38:1f91:26ed]) by smtp.gmail.com with ESMTPSA id r15sm6041462wrc.30.2017.10.10.01.53.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 01:53:47 -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 2/4] drm/ttm: add transparent huge page support for cached allocations v2 Date: Tue, 10 Oct 2017 10:53:43 +0200 Message-Id: <1507625625-8665-2-git-send-email-deathsimple@vodafone.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507625625-8665-1-git-send-email-deathsimple@vodafone.de> References: <1507625625-8665-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. v2: avoid compound pages for now Signed-off-by: Christian König Acked-by: Felix Kuehling Acked-by: Alex Deucher --- drivers/gpu/drm/ttm/ttm_page_alloc.c | 50 ++++++++++++++++++++++++++++++------ 1 file changed, 42 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..1bc6053 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,33 @@ 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; + huge_flags &= ~__GFP_COMP; + 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 +786,8 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags, return -ENOMEM; } - pages[r] = p; + pages[i++] = p; + --npages; } return 0; }