From nobody Mon Dec 1 22:36:47 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FC71333748; Fri, 28 Nov 2025 18:53:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764355984; cv=none; b=dnH+oRlYtPWe5PuLDMdt+zAQr/smsw0WeNUUFdlg83EALZ9UA2r/gQB+o947ZIpuVK8zjxQve/7J+/wHJvLX/Be4P0A71l1LHxM6FeI2LLTcAaCyUiaYDm3vzTxbRJNuBmWdKfbUFivqFmrWSiLa+pII3JifdQKPPsQvDU4qMik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764355984; c=relaxed/simple; bh=F21lcLtx1NkP7OSa7ulUeqIgfho6clTQ3QePI0r5YA0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bjapi3dP6TKt3vb96EGt5UDvRF0/Z9FD7iS88n+vwF8jzYoKNVwY6Mv9JafMks0y1jH9MgqX8tROtoFipQDiNomioe4sfZidRHPou2NK1jNkppRJhI3BlJwXweTXV3Ip6hmk1N50VjhqUri3Mx98PFh4j6Ps56RKPeGctlbc+9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=ArCsQWHK; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="ArCsQWHK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1764355980; bh=F21lcLtx1NkP7OSa7ulUeqIgfho6clTQ3QePI0r5YA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ArCsQWHK7nbNMXtphbQOnBkwkSM/j/mbZRuNJTsC37rZcWSU3R+RfrWd8L0+481Zs MyvPAy3N+lIjuxSNqHhnXaAjH2xY4UCNyiocsqXpQSPeIuddCxFuugjeK6lIuh0i4v nrSHdFwcLsPYxN46pBb4PoD2GZX8bmEZFrRv5P6qzAz4e1UKwwAKmjz5b0eMFsnYlh +z+a6si7g0Nk0Nl2rjrXQ3yeCx3AhCP7Y3USlmw5PMb1ZF6yWdqPkv4UMeXk+k0v02 RAeCvuOB2z4bbpyMUIV3ZpFPaNmVfCtCLl7mzd/HavLIrFq5f41+7PDnDoIiSFJGvg GbsyB7hLWRHcA== Received: from debian-rockchip-rock5b-rk3588.. (unknown [IPv6:2a01:e0a:5e3:6100:2e0:4cff:fe03:d8c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: loicmolinari) by bali.collaboradmins.com (Postfix) with ESMTPSA id EFF2017E1423; Fri, 28 Nov 2025 19:52:59 +0100 (CET) From: =?UTF-8?q?Lo=C3=AFc=20Molinari?= To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Boris Brezillon , Rob Herring , Steven Price , Liviu Dudau , Melissa Wen , =?UTF-8?q?Ma=C3=ADra=20Canal?= , Hugh Dickins , Baolin Wang , Andrew Morton , =?UTF-8?q?Lo=C3=AFc=20Molinari?= , Al Viro , =?UTF-8?q?Miko=C5=82aj=20Wasiak?= , Christian Brauner , Nitin Gote , Andi Shyti , Jonathan Corbet , Christopher Healy , Matthew Wilcox , Bagas Sanjaya Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, kernel@collabora.com Subject: [PATCH v10 05/10] drm/i915: Use huge tmpfs mountpoint helpers Date: Fri, 28 Nov 2025 19:52:47 +0100 Message-ID: <20251128185252.3092-6-loic.molinari@collabora.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251128185252.3092-1-loic.molinari@collabora.com> References: <20251128185252.3092-1-loic.molinari@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Make use of the new drm_gem_huge_mnt_create() and drm_gem_get_huge_mnt() helpers to avoid code duplication. Now that it's just a few lines long, the single function in i915_gemfs.c is moved into v3d_gem_shmem.c. v3: - use huge tmpfs mountpoint in drm_device - move i915_gemfs.c into i915_gem_shmem.c v4: - clean up mountpoint creation error handling v5: - use drm_gem_has_huge_mnt() helper v7: - include in i915_gem_shmem.c v8: - keep logging notice message with CONFIG_TRANSPARENT_HUGEPAGE=3Dn - don't access huge_mnt field with CONFIG_TRANSPARENT_HUGEPAGE=3Dn v9: - replace drm_gem_has_huge_mnt() by drm_gem_get_huge_mnt() - remove useless ternary op test in selftests/huge_pages.c Signed-off-by: Lo=C3=AFc Molinari --- drivers/gpu/drm/i915/Makefile | 3 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 48 +++++++++---- drivers/gpu/drm/i915/gem/i915_gemfs.c | 71 ------------------- drivers/gpu/drm/i915/gem/i915_gemfs.h | 14 ---- .../gpu/drm/i915/gem/selftests/huge_pages.c | 16 +++-- drivers/gpu/drm/i915/i915_drv.h | 5 -- 6 files changed, 47 insertions(+), 110 deletions(-) delete mode 100644 drivers/gpu/drm/i915/gem/i915_gemfs.c delete mode 100644 drivers/gpu/drm/i915/gem/i915_gemfs.h diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile index 84ec79b64960..b5a8c0a6b747 100644 --- a/drivers/gpu/drm/i915/Makefile +++ b/drivers/gpu/drm/i915/Makefile @@ -169,8 +169,7 @@ gem-y +=3D \ gem/i915_gem_ttm_move.o \ gem/i915_gem_ttm_pm.o \ gem/i915_gem_userptr.o \ - gem/i915_gem_wait.o \ - gem/i915_gemfs.o + gem/i915_gem_wait.o i915-y +=3D \ $(gem-y) \ i915_active.o \ diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i9= 15/gem/i915_gem_shmem.c index 26dda55a07ff..15c2c6fde2ac 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -9,14 +9,16 @@ #include =20 #include +#include +#include =20 #include "gem/i915_gem_region.h" #include "i915_drv.h" #include "i915_gem_object.h" #include "i915_gem_tiling.h" -#include "i915_gemfs.h" #include "i915_scatterlist.h" #include "i915_trace.h" +#include "i915_utils.h" =20 /* * Move folios to appropriate lru and release the batch, decrementing the @@ -497,6 +499,7 @@ static int __create_shmem(struct drm_i915_private *i915, resource_size_t size) { unsigned long flags =3D VM_NORESERVE; + struct vfsmount *huge_mnt; struct file *filp; =20 drm_gem_private_object_init(&i915->drm, obj, size); @@ -515,9 +518,9 @@ static int __create_shmem(struct drm_i915_private *i915, if (BITS_PER_LONG =3D=3D 64 && size > MAX_LFS_FILESIZE) return -E2BIG; =20 - if (i915->mm.gemfs) - filp =3D shmem_file_setup_with_mnt(i915->mm.gemfs, "i915", size, - flags); + huge_mnt =3D drm_gem_get_huge_mnt(&i915->drm); + if (huge_mnt) + filp =3D shmem_file_setup_with_mnt(huge_mnt, "i915", size, flags); else filp =3D shmem_file_setup("i915", size, flags); if (IS_ERR(filp)) @@ -644,21 +647,40 @@ i915_gem_object_create_shmem_from_data(struct drm_i91= 5_private *i915, =20 static int init_shmem(struct intel_memory_region *mem) { - i915_gemfs_init(mem->i915); - intel_memory_region_set_name(mem, "system"); + struct drm_i915_private *i915 =3D mem->i915; =20 - return 0; /* We have fallback to the kernel mnt if gemfs init failed. */ -} + /* + * By creating our own shmemfs mountpoint, we can pass in + * mount flags that better match our usecase. + * + * One example, although it is probably better with a per-file + * control, is selecting huge page allocations ("huge=3Dwithin_size"). + * However, we only do so on platforms which benefit from it, or to + * offset the overhead of iommu lookups, where with latter it is a net + * win even on platforms which would otherwise see some performance + * regressions such a slow reads issue on Broadwell and Skylake. + */ =20 -static int release_shmem(struct intel_memory_region *mem) -{ - i915_gemfs_fini(mem->i915); - return 0; + if (GRAPHICS_VER(i915) < 11 && !i915_vtd_active(i915)) + goto no_thp; + + drm_gem_huge_mnt_create(&i915->drm, "within_size"); + if (drm_gem_get_huge_mnt(&i915->drm)) + drm_info(&i915->drm, "Using Transparent Hugepages\n"); + else + drm_notice(&i915->drm, + "Transparent Hugepage support is recommended for optimal performance= %s\n", + GRAPHICS_VER(i915) >=3D 11 ? " on this platform!" : + " when IOMMU is enabled!"); + + no_thp: + intel_memory_region_set_name(mem, "system"); + + return 0; /* We have fallback to the kernel mnt if huge mnt failed. */ } =20 static const struct intel_memory_region_ops shmem_region_ops =3D { .init =3D init_shmem, - .release =3D release_shmem, .init_object =3D shmem_object_init, }; =20 diff --git a/drivers/gpu/drm/i915/gem/i915_gemfs.c b/drivers/gpu/drm/i915/g= em/i915_gemfs.c deleted file mode 100644 index 1f1290214031..000000000000 --- a/drivers/gpu/drm/i915/gem/i915_gemfs.c +++ /dev/null @@ -1,71 +0,0 @@ -// SPDX-License-Identifier: MIT -/* - * Copyright =C2=A9 2017 Intel Corporation - */ - -#include -#include -#include - -#include - -#include "i915_drv.h" -#include "i915_gemfs.h" -#include "i915_utils.h" - -void i915_gemfs_init(struct drm_i915_private *i915) -{ - struct file_system_type *type; - struct fs_context *fc; - struct vfsmount *gemfs; - int ret; - - /* - * By creating our own shmemfs mountpoint, we can pass in - * mount flags that better match our usecase. - * - * One example, although it is probably better with a per-file - * control, is selecting huge page allocations ("huge=3Dwithin_size"). - * However, we only do so on platforms which benefit from it, or to - * offset the overhead of iommu lookups, where with latter it is a net - * win even on platforms which would otherwise see some performance - * regressions such a slow reads issue on Broadwell and Skylake. - */ - - if (GRAPHICS_VER(i915) < 11 && !i915_vtd_active(i915)) - return; - - if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) - goto err; - - type =3D get_fs_type("tmpfs"); - if (!type) - goto err; - - fc =3D fs_context_for_mount(type, SB_KERNMOUNT); - if (IS_ERR(fc)) - goto err; - ret =3D vfs_parse_fs_string(fc, "source", "tmpfs"); - if (!ret) - ret =3D vfs_parse_fs_string(fc, "huge", "within_size"); - if (!ret) - gemfs =3D fc_mount_longterm(fc); - put_fs_context(fc); - if (ret) - goto err; - - i915->mm.gemfs =3D gemfs; - drm_info(&i915->drm, "Using Transparent Hugepages\n"); - return; - -err: - drm_notice(&i915->drm, - "Transparent Hugepage support is recommended for optimal performance%= s\n", - GRAPHICS_VER(i915) >=3D 11 ? " on this platform!" : - " when IOMMU is enabled!"); -} - -void i915_gemfs_fini(struct drm_i915_private *i915) -{ - kern_unmount(i915->mm.gemfs); -} diff --git a/drivers/gpu/drm/i915/gem/i915_gemfs.h b/drivers/gpu/drm/i915/g= em/i915_gemfs.h deleted file mode 100644 index 16d4333c9a4e..000000000000 --- a/drivers/gpu/drm/i915/gem/i915_gemfs.h +++ /dev/null @@ -1,14 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * Copyright =C2=A9 2017 Intel Corporation - */ - -#ifndef __I915_GEMFS_H__ -#define __I915_GEMFS_H__ - -struct drm_i915_private; - -void i915_gemfs_init(struct drm_i915_private *i915); -void i915_gemfs_fini(struct drm_i915_private *i915); - -#endif diff --git a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c b/drivers/gpu/= drm/i915/gem/selftests/huge_pages.c index bd08605a1611..28aef75630a2 100644 --- a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c +++ b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c @@ -1316,7 +1316,7 @@ typedef struct drm_i915_gem_object * =20 static inline bool igt_can_allocate_thp(struct drm_i915_private *i915) { - return i915->mm.gemfs && has_transparent_hugepage(); + return !!drm_gem_get_huge_mnt(&i915->drm); } =20 static struct drm_i915_gem_object * @@ -1761,7 +1761,9 @@ static int igt_tmpfs_fallback(void *arg) struct drm_i915_private *i915 =3D arg; struct i915_address_space *vm; struct i915_gem_context *ctx; - struct vfsmount *gemfs =3D i915->mm.gemfs; +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + struct vfsmount *huge_mnt =3D i915->drm.huge_mnt; +#endif struct drm_i915_gem_object *obj; struct i915_vma *vma; struct file *file; @@ -1782,10 +1784,12 @@ static int igt_tmpfs_fallback(void *arg) /* * Make sure that we don't burst into a ball of flames upon falling back * to tmpfs, which we rely on if on the off-chance we encounter a failure - * when setting up gemfs. + * when setting up a huge mountpoint. */ =20 - i915->mm.gemfs =3D NULL; +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + i915->drm.huge_mnt =3D NULL; +#endif =20 obj =3D i915_gem_object_create_shmem(i915, PAGE_SIZE); if (IS_ERR(obj)) { @@ -1819,7 +1823,9 @@ static int igt_tmpfs_fallback(void *arg) out_put: i915_gem_object_put(obj); out_restore: - i915->mm.gemfs =3D gemfs; +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + i915->drm.huge_mnt =3D huge_mnt; +#endif =20 i915_vm_put(vm); out: diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_dr= v.h index 95f9ddf22ce4..93a5af3de334 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -141,11 +141,6 @@ struct i915_gem_mm { */ atomic_t free_count; =20 - /** - * tmpfs instance used for shmem backed objects - */ - struct vfsmount *gemfs; - struct intel_memory_region *regions[INTEL_REGION_UNKNOWN]; =20 struct notifier_block oom_notifier; --=20 2.47.3