| 1 | // SPDX-License-Identifier: MIT |
| 2 | /* |
| 3 | * Copyright © 2017 Intel Corporation |
| 4 | */ |
| 5 | |
| 6 | #include <linux/fs.h> |
| 7 | #include <linux/mount.h> |
| 8 | #include <linux/fs_context.h> |
| 9 | |
| 10 | #include <drm/drm_print.h> |
| 11 | |
| 12 | #include "i915_drv.h" |
| 13 | #include "i915_gemfs.h" |
| 14 | #include "i915_utils.h" |
| 15 | |
| 16 | void i915_gemfs_init(struct drm_i915_private *i915) |
| 17 | { |
| 18 | struct file_system_type *type; |
| 19 | struct fs_context *fc; |
| 20 | struct vfsmount *gemfs; |
| 21 | int ret; |
| 22 | |
| 23 | /* |
| 24 | * By creating our own shmemfs mountpoint, we can pass in |
| 25 | * mount flags that better match our usecase. |
| 26 | * |
| 27 | * One example, although it is probably better with a per-file |
| 28 | * control, is selecting huge page allocations ("huge=within_size"). |
| 29 | * However, we only do so on platforms which benefit from it, or to |
| 30 | * offset the overhead of iommu lookups, where with latter it is a net |
| 31 | * win even on platforms which would otherwise see some performance |
| 32 | * regressions such a slow reads issue on Broadwell and Skylake. |
| 33 | */ |
| 34 | |
| 35 | if (GRAPHICS_VER(i915) < 11 && !i915_vtd_active(i915)) |
| 36 | return; |
| 37 | |
| 38 | if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) |
| 39 | goto err; |
| 40 | |
| 41 | type = get_fs_type(name: "tmpfs" ); |
| 42 | if (!type) |
| 43 | goto err; |
| 44 | |
| 45 | fc = fs_context_for_mount(fs_type: type, SB_KERNMOUNT); |
| 46 | if (IS_ERR(ptr: fc)) |
| 47 | goto err; |
| 48 | ret = vfs_parse_fs_string(fc, key: "source" , value: "tmpfs" ); |
| 49 | if (!ret) |
| 50 | ret = vfs_parse_fs_string(fc, key: "huge" , value: "within_size" ); |
| 51 | if (!ret) |
| 52 | gemfs = fc_mount_longterm(fc); |
| 53 | put_fs_context(fc); |
| 54 | if (ret) |
| 55 | goto err; |
| 56 | |
| 57 | i915->mm.gemfs = gemfs; |
| 58 | drm_info(&i915->drm, "Using Transparent Hugepages\n" ); |
| 59 | return; |
| 60 | |
| 61 | err: |
| 62 | drm_notice(&i915->drm, |
| 63 | "Transparent Hugepage support is recommended for optimal performance%s\n" , |
| 64 | GRAPHICS_VER(i915) >= 11 ? " on this platform!" : |
| 65 | " when IOMMU is enabled!" ); |
| 66 | } |
| 67 | |
| 68 | void i915_gemfs_fini(struct drm_i915_private *i915) |
| 69 | { |
| 70 | kern_unmount(mnt: i915->mm.gemfs); |
| 71 | } |
| 72 | |