Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/v3d: Use gemfs/THP in BO creation if available

Although Big/Super Pages could appear naturally, it would be quite hard
to have 1MB or 64KB allocated contiguously naturally. Therefore, we can
force the creation of large pages allocated contiguously by using a
mountpoint with "huge=within_size" enabled.

Therefore, as V3D has a mountpoint with "huge=within_size" (if user has
THP enabled), use this mountpoint for BO creation if available. This
will allow us to create large pages allocated contiguously and make use
of Big/Super Pages.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240923141348.2422499-10-mcanal@igalia.com

+19 -2
+19 -2
drivers/gpu/drm/v3d/v3d_bo.c
··· 107 107 struct v3d_dev *v3d = to_v3d_dev(obj->dev); 108 108 struct v3d_bo *bo = to_v3d_bo(obj); 109 109 struct sg_table *sgt; 110 + u64 align; 110 111 int ret; 111 112 112 113 /* So far we pin the BO in the MMU for its lifetime, so use ··· 117 116 if (IS_ERR(sgt)) 118 117 return PTR_ERR(sgt); 119 118 119 + if (!v3d->gemfs) 120 + align = SZ_4K; 121 + else if (obj->size >= SZ_1M) 122 + align = SZ_1M; 123 + else if (obj->size >= SZ_64K) 124 + align = SZ_64K; 125 + else 126 + align = SZ_4K; 127 + 120 128 spin_lock(&v3d->mm_lock); 121 129 /* Allocate the object's space in the GPU's page tables. 122 130 * Inserting PTEs will happen later, but the offset is for the ··· 133 123 */ 134 124 ret = drm_mm_insert_node_generic(&v3d->mm, &bo->node, 135 125 obj->size >> V3D_MMU_PAGE_SHIFT, 136 - SZ_4K >> V3D_MMU_PAGE_SHIFT, 0, 0); 126 + align >> V3D_MMU_PAGE_SHIFT, 0, 0); 137 127 spin_unlock(&v3d->mm_lock); 138 128 if (ret) 139 129 return ret; ··· 153 143 size_t unaligned_size) 154 144 { 155 145 struct drm_gem_shmem_object *shmem_obj; 146 + struct v3d_dev *v3d = to_v3d_dev(dev); 156 147 struct v3d_bo *bo; 157 148 int ret; 158 149 159 - shmem_obj = drm_gem_shmem_create(dev, unaligned_size); 150 + /* Let the user opt out of allocating the BOs with THP */ 151 + if (v3d->gemfs) 152 + shmem_obj = drm_gem_shmem_create_with_mnt(dev, unaligned_size, 153 + v3d->gemfs); 154 + else 155 + shmem_obj = drm_gem_shmem_create(dev, unaligned_size); 156 + 160 157 if (IS_ERR(shmem_obj)) 161 158 return ERR_CAST(shmem_obj); 162 159 bo = to_v3d_bo(&shmem_obj->base);