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 #ifdef __linux__ 17 char huge_opt[] = "huge=within_size"; /* r/w */ 18 struct file_system_type *type; 19 struct vfsmount *gemfs; 20 21 /* 22 * By creating our own shmemfs mountpoint, we can pass in 23 * mount flags that better match our usecase. 24 * 25 * One example, although it is probably better with a per-file 26 * control, is selecting huge page allocations ("huge=within_size"). 27 * However, we only do so on platforms which benefit from it, or to 28 * offset the overhead of iommu lookups, where with latter it is a net 29 * win even on platforms which would otherwise see some performance 30 * regressions such a slow reads issue on Broadwell and Skylake. 31 */ 32 33 if (GRAPHICS_VER(i915) < 11 && !i915_vtd_active(i915)) 34 return; 35 36 if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) 37 goto err; 38 39 type = get_fs_type("tmpfs"); 40 if (!type) 41 goto err; 42 43 gemfs = vfs_kern_mount(type, SB_KERNMOUNT, type->name, huge_opt); 44 if (IS_ERR(gemfs)) 45 goto err; 46 47 i915->mm.gemfs = gemfs; 48 drm_info(&i915->drm, "Using Transparent Hugepages\n"); 49 return; 50 51 err: 52 drm_notice(&i915->drm, 53 "Transparent Hugepage support is recommended for optimal performance%s\n", 54 GRAPHICS_VER(i915) >= 11 ? " on this platform!" : 55 " when IOMMU is enabled!"); 56 #endif 57 } 58 59 void i915_gemfs_fini(struct drm_i915_private *i915) 60 { 61 #ifdef __linux__ 62 kern_unmount(i915->mm.gemfs); 63 #endif 64 } 65