From patchwork Fri Sep 22 12:13:22 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: 9965919 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 1F14F600C5 for ; Fri, 22 Sep 2017 12:13:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 032F12988D for ; Fri, 22 Sep 2017 12:13:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC1A829892; Fri, 22 Sep 2017 12:13:43 +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 7F83C2988D for ; Fri, 22 Sep 2017 12:13:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EFDB46E9C1; Fri, 22 Sep 2017 12:13:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 614FD6E9BB; Fri, 22 Sep 2017 12:13:35 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id g50so553113wra.3; Fri, 22 Sep 2017 05:13:35 -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=8cSabT9rjugAACrXfQ8PhYiZdfkNeg8rVk/pr/PBtfc=; b=nBa1SAjankdZzDn7/Skl3fOId8ZEp9oplGlogMBYuzfSwsb87ko/AiDlwX8zvxw1v1 QvoF8aWy5s0JQzSDmpGtloyIuBFOwGKFFmFR9ueiLlsLR/UjjLrDfWioBjwcuZnyJvCi LshoVdaslvQq7qVbyTZUb1ir6Pf/E7nxSb/pfsdhl4d7+ZEMMkGLmRCCSNLWf5WBIAAb PLZIjGWqX1YhemxrvP28IljYtht1FwxFCVXn8mvB+l+rDX2aAn4p/lcaI+3pnAdG4lRz HD5IjkhKhcL56nl/IrnVz4CVT4OGw6tgOuD7Pny/0aMpEaF3o67ExznjaSs7WJX26Y7Q zmTg== 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=8cSabT9rjugAACrXfQ8PhYiZdfkNeg8rVk/pr/PBtfc=; b=X3pNdZ1AKEZdU7/aI1vgYY8A27nYn1bexDb4AU004vfkNxpbyCpZIPUgiBzbl3A2zc 4ZTjiUCImxwaKViEf9w8QQyi9cEJ/lFGQPP5PoY5/vkAthPf1WgYBbeq8JhR09U4lwPR Ha8eMHE1vnH87BZFgEySwa2FWeXq/mkBFgGx5L+aL1PQvoVsdG/0bLnfEq0KxlQT2ocy krBelDO5wG6M2+EUngDutn0P9oTmZ6PbZs1RdnojsRGO0h0n+Dln8qLJaKQdfg2vPBhc c6kuA2/uRsNeay+ZvgknXGpIfTk2ODuQ79CAhWDvvx1GbAUvQpGt/U69DauiP3fS4gzG yirw== X-Gm-Message-State: AHPjjUh+mAc7a08Jtrr/F+8Y9zZkMN3P3u/AO1etw87V3UO4StqOg+FH dyonQUSXJsIOfUuQC3f/n8WsZ6yA X-Google-Smtp-Source: AOwi7QAHHH+psDxjOFD9esIzk09nnAaLmviVm88sD7A1NEEzmVypQOzvUru5pZsREbhg6QNQQ8Y6mA== X-Received: by 10.223.128.4 with SMTP id 4mr4430626wrk.9.1506082413819; Fri, 22 Sep 2017 05:13:33 -0700 (PDT) Received: from localhost.localdomain ([2a02:908:1251:7981:98cd:d000:f7ff:c900]) by smtp.gmail.com with ESMTPSA id i50sm4044739wrf.84.2017.09.22.05.13.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Sep 2017 05:13:32 -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 6/9] drm/ttm: add transparent huge page support for cached allocations Date: Fri, 22 Sep 2017 14:13:22 +0200 Message-Id: <1506082405-1556-6-git-send-email-deathsimple@vodafone.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506082405-1556-1-git-send-email-deathsimple@vodafone.de> References: <1506082405-1556-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 --- 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 3309926..3dd2a8a 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; }