Skip to content

Commit 6fb1bba

Browse files
mairacanalpopcornmix
authored andcommitted
drm/v3d: Introduce gemfs
Commit eb8d395 upstream Create a separate "tmpfs" kernel mount for V3D. This will allow us to move away from the shmemfs `shm_mnt` and gives the flexibility to do things like set our own mount options. Here, the interest is to use "huge=", which should allow us to enable the use of THP for our shmem-backed objects. Signed-off-by: Maíra Canal <mcanal@igalia.com> Reviewed-by: Iago Toral Quiroga <itoral@igalia.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240923141348.2422499-6-mcanal@igalia.com
1 parent 6aed508 commit 6fb1bba

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

drivers/gpu/drm/v3d/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ v3d-y := \
1313
v3d_trace_points.o \
1414
v3d_sched.o \
1515
v3d_sysfs.o \
16-
v3d_submit.o
16+
v3d_submit.o \
17+
v3d_gemfs.o
1718

1819
v3d-$(CONFIG_DEBUG_FS) += v3d_debugfs.o
1920

drivers/gpu/drm/v3d/v3d_drv.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ struct v3d_dev {
143143
struct drm_mm mm;
144144
spinlock_t mm_lock;
145145

146+
/*
147+
* tmpfs instance used for shmem backed objects
148+
*/
149+
struct vfsmount *gemfs;
150+
146151
struct work_struct overflow_mem_work;
147152

148153
struct v3d_bin_job *bin_job;
@@ -540,6 +545,10 @@ void v3d_reset(struct v3d_dev *v3d);
540545
void v3d_invalidate_caches(struct v3d_dev *v3d);
541546
void v3d_clean_caches(struct v3d_dev *v3d);
542547

548+
/* v3d_gemfs.c */
549+
void v3d_gemfs_init(struct v3d_dev *v3d);
550+
void v3d_gemfs_fini(struct v3d_dev *v3d);
551+
543552
/* v3d_submit.c */
544553
void v3d_job_cleanup(struct v3d_job *job);
545554
void v3d_job_put(struct v3d_job *job);

drivers/gpu/drm/v3d/v3d_gem.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ v3d_gem_init(struct drm_device *dev)
291291
v3d_init_hw_state(v3d);
292292
v3d_mmu_set_page_table(v3d);
293293

294+
v3d_gemfs_init(v3d);
295+
294296
ret = v3d_sched_init(v3d);
295297
if (ret) {
296298
drm_mm_takedown(&v3d->mm);
@@ -308,6 +310,7 @@ v3d_gem_destroy(struct drm_device *dev)
308310
struct v3d_dev *v3d = to_v3d_dev(dev);
309311

310312
v3d_sched_fini(v3d);
313+
v3d_gemfs_fini(v3d);
311314

312315
/* Waiting for jobs to finish would need to be done before
313316
* unregistering V3D.

drivers/gpu/drm/v3d/v3d_gemfs.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/* Copyright (C) 2024 Raspberry Pi */
3+
4+
#include <linux/fs.h>
5+
#include <linux/mount.h>
6+
7+
#include "v3d_drv.h"
8+
9+
void v3d_gemfs_init(struct v3d_dev *v3d)
10+
{
11+
char huge_opt[] = "huge=within_size";
12+
struct file_system_type *type;
13+
struct vfsmount *gemfs;
14+
15+
/*
16+
* By creating our own shmemfs mountpoint, we can pass in
17+
* mount flags that better match our usecase. However, we
18+
* only do so on platforms which benefit from it.
19+
*/
20+
if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
21+
goto err;
22+
23+
type = get_fs_type("tmpfs");
24+
if (!type)
25+
goto err;
26+
27+
gemfs = vfs_kern_mount(type, SB_KERNMOUNT, type->name, huge_opt);
28+
if (IS_ERR(gemfs))
29+
goto err;
30+
31+
v3d->gemfs = gemfs;
32+
drm_info(&v3d->drm, "Using Transparent Hugepages\n");
33+
34+
return;
35+
36+
err:
37+
v3d->gemfs = NULL;
38+
drm_notice(&v3d->drm,
39+
"Transparent Hugepage support is recommended for optimal performance on this platform!\n");
40+
}
41+
42+
void v3d_gemfs_fini(struct v3d_dev *v3d)
43+
{
44+
if (v3d->gemfs)
45+
kern_unmount(v3d->gemfs);
46+
}

0 commit comments

Comments
 (0)