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" 1210be98a7SChris Wilson 1310be98a7SChris Wilson int i915_gemfs_init(struct drm_i915_private *i915) 1410be98a7SChris Wilson { 15*3ccadbceSMatthew Auld char huge_opt[] = "huge=within_size"; /* r/w */ 1610be98a7SChris Wilson struct file_system_type *type; 1710be98a7SChris Wilson struct vfsmount *gemfs; 1874388ca4STvrtko Ursulin char *opts; 1910be98a7SChris Wilson 2010be98a7SChris Wilson type = get_fs_type("tmpfs"); 2110be98a7SChris Wilson if (!type) 2210be98a7SChris Wilson return -ENODEV; 2310be98a7SChris Wilson 2472e67f04SChris Wilson /* 2572e67f04SChris Wilson * By creating our own shmemfs mountpoint, we can pass in 2672e67f04SChris Wilson * mount flags that better match our usecase. 2772e67f04SChris Wilson * 2872e67f04SChris Wilson * One example, although it is probably better with a per-file 2972e67f04SChris Wilson * control, is selecting huge page allocations ("huge=within_size"). 3074388ca4STvrtko Ursulin * However, we only do so to offset the overhead of iommu lookups 3174388ca4STvrtko Ursulin * due to bandwidth issues (slow reads) on Broadwell+. 3272e67f04SChris Wilson */ 3372e67f04SChris Wilson 3474388ca4STvrtko Ursulin opts = NULL; 3574388ca4STvrtko Ursulin if (intel_vtd_active()) { 3674388ca4STvrtko Ursulin if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { 3774388ca4STvrtko Ursulin opts = huge_opt; 3874388ca4STvrtko Ursulin drm_info(&i915->drm, 3974388ca4STvrtko Ursulin "Transparent Hugepage mode '%s'\n", 4074388ca4STvrtko Ursulin opts); 4174388ca4STvrtko Ursulin } else { 4274388ca4STvrtko Ursulin drm_notice(&i915->drm, 4374388ca4STvrtko Ursulin "Transparent Hugepage support is recommended for optimal performance when IOMMU is enabled!\n"); 4474388ca4STvrtko Ursulin } 4574388ca4STvrtko Ursulin } 4674388ca4STvrtko Ursulin 4774388ca4STvrtko Ursulin gemfs = vfs_kern_mount(type, SB_KERNMOUNT, type->name, opts); 4810be98a7SChris Wilson if (IS_ERR(gemfs)) 4910be98a7SChris Wilson return PTR_ERR(gemfs); 5010be98a7SChris Wilson 5110be98a7SChris Wilson i915->mm.gemfs = gemfs; 5210be98a7SChris Wilson 5310be98a7SChris Wilson return 0; 5410be98a7SChris Wilson } 5510be98a7SChris Wilson 5610be98a7SChris Wilson void i915_gemfs_fini(struct drm_i915_private *i915) 5710be98a7SChris Wilson { 5810be98a7SChris Wilson kern_unmount(i915->mm.gemfs); 5910be98a7SChris Wilson } 60