162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * SPDX-License-Identifier: MIT 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright © 2017 Intel Corporation 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#include <linux/fs.h> 862306a36Sopenharmony_ci#include <linux/mount.h> 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include "i915_drv.h" 1162306a36Sopenharmony_ci#include "i915_gemfs.h" 1262306a36Sopenharmony_ci#include "i915_utils.h" 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_civoid i915_gemfs_init(struct drm_i915_private *i915) 1562306a36Sopenharmony_ci{ 1662306a36Sopenharmony_ci char huge_opt[] = "huge=within_size"; /* r/w */ 1762306a36Sopenharmony_ci struct file_system_type *type; 1862306a36Sopenharmony_ci struct vfsmount *gemfs; 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci /* 2162306a36Sopenharmony_ci * By creating our own shmemfs mountpoint, we can pass in 2262306a36Sopenharmony_ci * mount flags that better match our usecase. 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * One example, although it is probably better with a per-file 2562306a36Sopenharmony_ci * control, is selecting huge page allocations ("huge=within_size"). 2662306a36Sopenharmony_ci * However, we only do so on platforms which benefit from it, or to 2762306a36Sopenharmony_ci * offset the overhead of iommu lookups, where with latter it is a net 2862306a36Sopenharmony_ci * win even on platforms which would otherwise see some performance 2962306a36Sopenharmony_ci * regressions such a slow reads issue on Broadwell and Skylake. 3062306a36Sopenharmony_ci */ 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci if (GRAPHICS_VER(i915) < 11 && !i915_vtd_active(i915)) 3362306a36Sopenharmony_ci return; 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) 3662306a36Sopenharmony_ci goto err; 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci type = get_fs_type("tmpfs"); 3962306a36Sopenharmony_ci if (!type) 4062306a36Sopenharmony_ci goto err; 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci gemfs = vfs_kern_mount(type, SB_KERNMOUNT, type->name, huge_opt); 4362306a36Sopenharmony_ci if (IS_ERR(gemfs)) 4462306a36Sopenharmony_ci goto err; 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci i915->mm.gemfs = gemfs; 4762306a36Sopenharmony_ci drm_info(&i915->drm, "Using Transparent Hugepages\n"); 4862306a36Sopenharmony_ci return; 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_cierr: 5162306a36Sopenharmony_ci drm_notice(&i915->drm, 5262306a36Sopenharmony_ci "Transparent Hugepage support is recommended for optimal performance%s\n", 5362306a36Sopenharmony_ci GRAPHICS_VER(i915) >= 11 ? " on this platform!" : 5462306a36Sopenharmony_ci " when IOMMU is enabled!"); 5562306a36Sopenharmony_ci} 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_civoid i915_gemfs_fini(struct drm_i915_private *i915) 5862306a36Sopenharmony_ci{ 5962306a36Sopenharmony_ci kern_unmount(i915->mm.gemfs); 6062306a36Sopenharmony_ci} 61