| 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 "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 | struct file_system_type *type; | 
|---|
| 17 | struct fs_context *fc; | 
|---|
| 18 | struct vfsmount *gemfs; | 
|---|
| 19 | int ret; | 
|---|
| 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(name: "tmpfs"); | 
|---|
| 40 | if (!type) | 
|---|
| 41 | goto err; | 
|---|
| 42 |  | 
|---|
| 43 | fc = fs_context_for_mount(fs_type: type, SB_KERNMOUNT); | 
|---|
| 44 | if (IS_ERR(ptr: fc)) | 
|---|
| 45 | goto err; | 
|---|
| 46 | ret = vfs_parse_fs_string(fc, key: "source", value: "tmpfs"); | 
|---|
| 47 | if (!ret) | 
|---|
| 48 | ret = vfs_parse_fs_string(fc, key: "huge", value: "within_size"); | 
|---|
| 49 | if (!ret) | 
|---|
| 50 | gemfs = fc_mount_longterm(fc); | 
|---|
| 51 | put_fs_context(fc); | 
|---|
| 52 | if (ret) | 
|---|
| 53 | goto err; | 
|---|
| 54 |  | 
|---|
| 55 | i915->mm.gemfs = gemfs; | 
|---|
| 56 | drm_info(&i915->drm, "Using Transparent Hugepages\n"); | 
|---|
| 57 | return; | 
|---|
| 58 |  | 
|---|
| 59 | err: | 
|---|
| 60 | drm_notice(&i915->drm, | 
|---|
| 61 | "Transparent Hugepage support is recommended for optimal performance%s\n", | 
|---|
| 62 | GRAPHICS_VER(i915) >= 11 ? " on this platform!": | 
|---|
| 63 | " when IOMMU is enabled!"); | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | void i915_gemfs_fini(struct drm_i915_private *i915) | 
|---|
| 67 | { | 
|---|
| 68 | kern_unmount(mnt: i915->mm.gemfs); | 
|---|
| 69 | } | 
|---|
| 70 |  | 
|---|