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 int 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 char *opts; 20 21 type = get_fs_type("tmpfs"); 22 if (!type) 23 return -ENODEV; 24 25 /* 26 * By creating our own shmemfs mountpoint, we can pass in 27 * mount flags that better match our usecase. 28 * 29 * One example, although it is probably better with a per-file 30 * control, is selecting huge page allocations ("huge=within_size"). 31 * However, we only do so to offset the overhead of iommu lookups 32 * due to bandwidth issues (slow reads) on Broadwell+. 33 */ 34 35 opts = NULL; 36 if (i915_vtd_active(i915)) { 37 if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { 38 opts = huge_opt; 39 drm_info(&i915->drm, 40 "Transparent Hugepage mode '%s'\n", 41 opts); 42 } else { 43 drm_notice(&i915->drm, 44 "Transparent Hugepage support is recommended for optimal performance when IOMMU is enabled!\n"); 45 } 46 } 47 48 gemfs = vfs_kern_mount(type, SB_KERNMOUNT, type->name, opts); 49 if (IS_ERR(gemfs)) 50 return PTR_ERR(gemfs); 51 52 i915->mm.gemfs = gemfs; 53 54 return 0; 55 } 56 57 void i915_gemfs_fini(struct drm_i915_private *i915) 58 { 59 kern_unmount(i915->mm.gemfs); 60 } 61