xref: /linux/drivers/gpu/drm/i915/gem/i915_gemfs.c (revision 23dd74db02d75579d8d4eb0b88c7ad119e782269)
110be98a7SChris Wilson /*
210be98a7SChris Wilson  * SPDX-License-Identifier: MIT
310be98a7SChris Wilson  *
410be98a7SChris Wilson  * Copyright © 2017 Intel Corporation
510be98a7SChris Wilson  */
610be98a7SChris Wilson 
710be98a7SChris Wilson #include <linux/fs.h>
810be98a7SChris Wilson #include <linux/mount.h>
910be98a7SChris Wilson 
1010be98a7SChris Wilson #include "i915_drv.h"
1110be98a7SChris Wilson #include "i915_gemfs.h"
12a7f46d5bSTvrtko Ursulin #include "i915_utils.h"
1310be98a7SChris Wilson 
1410be98a7SChris Wilson int i915_gemfs_init(struct drm_i915_private *i915)
1510be98a7SChris Wilson {
163ccadbceSMatthew Auld 	char huge_opt[] = "huge=within_size"; /* r/w */
1710be98a7SChris Wilson 	struct file_system_type *type;
1810be98a7SChris Wilson 	struct vfsmount *gemfs;
1974388ca4STvrtko Ursulin 	char *opts;
2010be98a7SChris Wilson 
2110be98a7SChris Wilson 	type = get_fs_type("tmpfs");
2210be98a7SChris Wilson 	if (!type)
2310be98a7SChris Wilson 		return -ENODEV;
2410be98a7SChris Wilson 
2572e67f04SChris Wilson 	/*
2672e67f04SChris Wilson 	 * By creating our own shmemfs mountpoint, we can pass in
2772e67f04SChris Wilson 	 * mount flags that better match our usecase.
2872e67f04SChris Wilson 	 *
2972e67f04SChris Wilson 	 * One example, although it is probably better with a per-file
3072e67f04SChris Wilson 	 * control, is selecting huge page allocations ("huge=within_size").
31*23dd74dbSTvrtko Ursulin 	 * However, we only do so on platforms which benefit from it, or to
32*23dd74dbSTvrtko Ursulin 	 * offset the overhead of iommu lookups, where with latter it is a net
33*23dd74dbSTvrtko Ursulin 	 * win even on platforms which would otherwise see some performance
34*23dd74dbSTvrtko Ursulin 	 * regressions such a slow reads issue on Broadwell and Skylake.
3572e67f04SChris Wilson 	 */
3672e67f04SChris Wilson 
3774388ca4STvrtko Ursulin 	opts = NULL;
38*23dd74dbSTvrtko Ursulin 	if (GRAPHICS_VER(i915) >= 11 || i915_vtd_active(i915)) {
3974388ca4STvrtko Ursulin 		if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
4074388ca4STvrtko Ursulin 			opts = huge_opt;
4174388ca4STvrtko Ursulin 			drm_info(&i915->drm,
4274388ca4STvrtko Ursulin 				 "Transparent Hugepage mode '%s'\n",
4374388ca4STvrtko Ursulin 				 opts);
4474388ca4STvrtko Ursulin 		} else {
4574388ca4STvrtko Ursulin 			drm_notice(&i915->drm,
46*23dd74dbSTvrtko Ursulin 				   "Transparent Hugepage support is recommended for optimal performance%s\n",
47*23dd74dbSTvrtko Ursulin 				   GRAPHICS_VER(i915) >= 11 ?
48*23dd74dbSTvrtko Ursulin 				   " on this platform!" :
49*23dd74dbSTvrtko Ursulin 				   " when IOMMU is enabled!");
5074388ca4STvrtko Ursulin 		}
5174388ca4STvrtko Ursulin 	}
5274388ca4STvrtko Ursulin 
5374388ca4STvrtko Ursulin 	gemfs = vfs_kern_mount(type, SB_KERNMOUNT, type->name, opts);
5410be98a7SChris Wilson 	if (IS_ERR(gemfs))
5510be98a7SChris Wilson 		return PTR_ERR(gemfs);
5610be98a7SChris Wilson 
5710be98a7SChris Wilson 	i915->mm.gemfs = gemfs;
5810be98a7SChris Wilson 
5910be98a7SChris Wilson 	return 0;
6010be98a7SChris Wilson }
6110be98a7SChris Wilson 
6210be98a7SChris Wilson void i915_gemfs_fini(struct drm_i915_private *i915)
6310be98a7SChris Wilson {
6410be98a7SChris Wilson 	kern_unmount(i915->mm.gemfs);
6510be98a7SChris Wilson }
66