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