xref: /linux/drivers/gpu/drm/i915/gem/i915_gemfs.c (revision fb7399cf2d0b33825b8039f95c45395c7deba25c)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2017 Intel Corporation
4  */
5 
6 #include <linux/fs.h>
7 #include <linux/mount.h>
8 
9 #include "i915_drv.h"
10 #include "i915_gemfs.h"
11 #include "i915_utils.h"
12 
13 void i915_gemfs_init(struct drm_i915_private *i915)
14 {
15 	char huge_opt[] = "huge=within_size"; /* r/w */
16 	struct file_system_type *type;
17 	struct vfsmount *gemfs;
18 
19 	/*
20 	 * By creating our own shmemfs mountpoint, we can pass in
21 	 * mount flags that better match our usecase.
22 	 *
23 	 * One example, although it is probably better with a per-file
24 	 * control, is selecting huge page allocations ("huge=within_size").
25 	 * However, we only do so on platforms which benefit from it, or to
26 	 * offset the overhead of iommu lookups, where with latter it is a net
27 	 * win even on platforms which would otherwise see some performance
28 	 * regressions such a slow reads issue on Broadwell and Skylake.
29 	 */
30 
31 	if (GRAPHICS_VER(i915) < 11 && !i915_vtd_active(i915))
32 		return;
33 
34 	if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
35 		goto err;
36 
37 	type = get_fs_type("tmpfs");
38 	if (!type)
39 		goto err;
40 
41 	gemfs = vfs_kern_mount(type, SB_KERNMOUNT, type->name, huge_opt);
42 	if (IS_ERR(gemfs))
43 		goto err;
44 
45 	i915->mm.gemfs = gemfs;
46 	drm_info(&i915->drm, "Using Transparent Hugepages\n");
47 	return;
48 
49 err:
50 	drm_notice(&i915->drm,
51 		   "Transparent Hugepage support is recommended for optimal performance%s\n",
52 		   GRAPHICS_VER(i915) >= 11 ? " on this platform!" :
53 					      " when IOMMU is enabled!");
54 }
55 
56 void i915_gemfs_fini(struct drm_i915_private *i915)
57 {
58 	kern_unmount(i915->mm.gemfs);
59 }
60