From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27D4FC432C0 for ; Wed, 27 Nov 2019 08:32:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AAA9E2064B for ; Wed, 27 Nov 2019 08:32:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=shipmail.org header.i=@shipmail.org header.b="I1TSdGL3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AAA9E2064B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shipmail.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BEB046B0353; Wed, 27 Nov 2019 03:32:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC2846B0354; Wed, 27 Nov 2019 03:32:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F8826B0356; Wed, 27 Nov 2019 03:32:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id 889AC6B0353 for ; Wed, 27 Nov 2019 03:32:13 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 405BC2464 for ; Wed, 27 Nov 2019 08:32:13 +0000 (UTC) X-FDA: 76201390146.17.dogs28_4d617526a5127 X-HE-Tag: dogs28_4d617526a5127 X-Filterd-Recvd-Size: 7447 Received: from pio-pvt-msa3.bahnhof.se (pio-pvt-msa3.bahnhof.se [79.136.2.42]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 Nov 2019 08:32:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa3.bahnhof.se (Postfix) with ESMTP id 572F03F5E0; Wed, 27 Nov 2019 09:32:10 +0100 (CET) Authentication-Results: pio-pvt-msa3.bahnhof.se; dkim=pass (1024-bit key; unprotected) header.d=shipmail.org header.i=@shipmail.org header.b=I1TSdGL3; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at bahnhof.se Received: from pio-pvt-msa3.bahnhof.se ([127.0.0.1]) by localhost (pio-pvt-msa3.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bHNccKRAXQug; Wed, 27 Nov 2019 09:32:05 +0100 (CET) Received: from mail1.shipmail.org (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) (Authenticated sender: mb878879) by pio-pvt-msa3.bahnhof.se (Postfix) with ESMTPA id 4340D3F5BF; Wed, 27 Nov 2019 09:32:05 +0100 (CET) Received: from localhost.localdomain.localdomain (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) by mail1.shipmail.org (Postfix) with ESMTPSA id 0C26436060F; Wed, 27 Nov 2019 09:32:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1574843523; bh=yW4Kv+tDJBfAXwh/Zhx3QElV1XLWl/OFJo8EITEcphM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I1TSdGL39WpjjsQ2vSeU9iiNq16d55INmsc+XWaIEanIkMa6S+WwcROTsKAJiRiVr h7J04Wum3zSasmPtK2kGe8rGzik5iBffxWJWaoGfbvhuRIUzfweRmjRoKzd/FaaItI FkY5sYwAlCsxxOaGRz1nLUbwSDOZe8fLn8494EKY= From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m=20=28VMware=29?= To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-graphics-maintainer@vmware.com Cc: Thomas Hellstrom , Andrew Morton , Michal Hocko , "Matthew Wilcox (Oracle)" , "Kirill A. Shutemov" , Ralph Campbell , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , =?UTF-8?q?Christian=20K=C3=B6nig?= Subject: [RFC PATCH 6/7] drm/ttm: Introduce a huge page aligning TTM range manager. Date: Wed, 27 Nov 2019 09:31:19 +0100 Message-Id: <20191127083120.34611-7-thomas_os@shipmail.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191127083120.34611-1-thomas_os@shipmail.org> References: <20191127083120.34611-1-thomas_os@shipmail.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Thomas Hellstrom Using huge page-table entries require that the start of a buffer object is huge page size aligned. So introduce a ttm_bo_man_get_node_huge() function that attempts to accomplish this for allocations that are larger than the huge page size, and provide a new range-manager instance that uses that function. Cc: Andrew Morton Cc: Michal Hocko Cc: "Matthew Wilcox (Oracle)" Cc: "Kirill A. Shutemov" Cc: Ralph Campbell Cc: "J=C3=A9r=C3=B4me Glisse" Cc: "Christian K=C3=B6nig" Signed-off-by: Thomas Hellstrom --- drivers/gpu/drm/ttm/ttm_bo_manager.c | 92 ++++++++++++++++++++++++++++ include/drm/ttm/ttm_bo_driver.h | 1 + 2 files changed, 93 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/t= tm_bo_manager.c index 18d3debcc949..26aa1a2ae7f1 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c @@ -89,6 +89,89 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_man= ager *man, return 0; } =20 +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static int ttm_bo_insert_aligned(struct drm_mm *mm, struct drm_mm_node *= node, + unsigned long align_pages, + const struct ttm_place *place, + struct ttm_mem_reg *mem, + unsigned long lpfn, + enum drm_mm_insert_mode mode) +{ + if (align_pages >=3D mem->page_alignment && + (!mem->page_alignment || align_pages % mem->page_alignment =3D=3D 0= )) { + return drm_mm_insert_node_in_range(mm, node, + mem->num_pages, + align_pages, 0, + place->fpfn, lpfn, mode); + } + + return -ENOSPC; +} + +static int ttm_bo_man_get_node_huge(struct ttm_mem_type_manager *man, + struct ttm_buffer_object *bo, + const struct ttm_place *place, + struct ttm_mem_reg *mem) +{ + struct ttm_range_manager *rman =3D (struct ttm_range_manager *) man->pr= iv; + struct drm_mm *mm =3D &rman->mm; + struct drm_mm_node *node; + unsigned long align_pages; + unsigned long lpfn; + enum drm_mm_insert_mode mode =3D DRM_MM_INSERT_BEST; + int ret; + + node =3D kzalloc(sizeof(*node), GFP_KERNEL); + if (!node) + return -ENOMEM; + + lpfn =3D place->lpfn; + if (!lpfn) + lpfn =3D man->size; + + mode =3D DRM_MM_INSERT_BEST; + if (place->flags & TTM_PL_FLAG_TOPDOWN) + mode =3D DRM_MM_INSERT_HIGH; + + spin_lock(&rman->lock); + if (IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)) { + align_pages =3D (HPAGE_PUD_SIZE >> PAGE_SHIFT); + if (mem->num_pages >=3D align_pages) { + ret =3D ttm_bo_insert_aligned(mm, node, align_pages, + place, mem, lpfn, mode); + if (!ret) + goto found_unlock; + } + } + + align_pages =3D (HPAGE_PMD_SIZE >> PAGE_SHIFT); + if (mem->num_pages >=3D align_pages) { + ret =3D ttm_bo_insert_aligned(mm, node, align_pages, place, mem, + lpfn, mode); + if (!ret) + goto found_unlock; + } + + ret =3D drm_mm_insert_node_in_range(mm, node, mem->num_pages, + mem->page_alignment, 0, + place->fpfn, lpfn, mode); +found_unlock: + spin_unlock(&rman->lock); + + if (unlikely(ret)) { + kfree(node); + } else { + mem->mm_node =3D node; + mem->start =3D node->start; + } + + return 0; +} +#else +#define ttm_bo_man_get_node_huge ttm_bo_man_get_node +#endif + + static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man, struct ttm_mem_reg *mem) { @@ -154,3 +237,12 @@ const struct ttm_mem_type_manager_func ttm_bo_manage= r_func =3D { .debug =3D ttm_bo_man_debug }; EXPORT_SYMBOL(ttm_bo_manager_func); + +const struct ttm_mem_type_manager_func ttm_bo_manager_huge_func =3D { + .init =3D ttm_bo_man_init, + .takedown =3D ttm_bo_man_takedown, + .get_node =3D ttm_bo_man_get_node_huge, + .put_node =3D ttm_bo_man_put_node, + .debug =3D ttm_bo_man_debug +}; +EXPORT_SYMBOL(ttm_bo_manager_huge_func); diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_dri= ver.h index cac7a8a0825a..868bd0d4be6a 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -888,5 +888,6 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object = *bo); pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp); =20 extern const struct ttm_mem_type_manager_func ttm_bo_manager_func; +extern const struct ttm_mem_type_manager_func ttm_bo_manager_huge_func; =20 #endif --=20 2.21.0