Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/i915: Use huge tmpfs mountpoint helpers

Make use of the new drm_gem_huge_mnt_create() and
drm_gem_get_huge_mnt() helpers to avoid code duplication. Now that
it's just a few lines long, the single function in i915_gemfs.c is
moved into i915_gem_shmem.c.

v3:
- use huge tmpfs mountpoint in drm_device
- move i915_gemfs.c into i915_gem_shmem.c

v4:
- clean up mountpoint creation error handling

v5:
- use drm_gem_has_huge_mnt() helper

v7:
- include <drm/drm_print.h> in i915_gem_shmem.c

v8:
- keep logging notice message with CONFIG_TRANSPARENT_HUGEPAGE=n
- don't access huge_mnt field with CONFIG_TRANSPARENT_HUGEPAGE=n

v9:
- replace drm_gem_has_huge_mnt() by drm_gem_get_huge_mnt()
- remove useless ternary op test in selftests/huge_pages.c

v12:
- fix layering violation in selftests (Tvrtko)
- fix incorrect filename in commit message

v13:
- add Tvrtko A-b

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
Acked-by: Tvrtko Ursulin <tursulin@ursulin.net>
Link: https://patch.msgid.link/20251205182231.194072-6-loic.molinari@collabora.com
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>

authored by

Loïc Molinari and committed by
Boris Brezillon
a8a9a590 6e0b1b82

+50 -125
+1 -2
drivers/gpu/drm/i915/Makefile
··· 169 169 gem/i915_gem_ttm_move.o \ 170 170 gem/i915_gem_ttm_pm.o \ 171 171 gem/i915_gem_userptr.o \ 172 - gem/i915_gem_wait.o \ 173 - gem/i915_gemfs.o 172 + gem/i915_gem_wait.o 174 173 i915-y += \ 175 174 $(gem-y) \ 176 175 i915_active.o \
+5 -4
drivers/gpu/drm/i915/gem/i915_gem_object_types.h
··· 348 348 */ 349 349 #define I915_BO_ALLOC_GPU_ONLY BIT(6) 350 350 #define I915_BO_ALLOC_CCS_AUX BIT(7) 351 + #define I915_BO_ALLOC_NOTHP BIT(8) 351 352 /* 352 353 * Object is allowed to retain its initial data and will not be cleared on first 353 354 * access if used along with I915_BO_ALLOC_USER. This is mainly to keep 354 355 * preallocated framebuffer data intact while transitioning it to i915drmfb. 355 356 */ 356 - #define I915_BO_PREALLOC BIT(8) 357 + #define I915_BO_PREALLOC BIT(9) 357 358 #define I915_BO_ALLOC_FLAGS (I915_BO_ALLOC_CONTIGUOUS | \ 358 359 I915_BO_ALLOC_VOLATILE | \ 359 360 I915_BO_ALLOC_CPU_CLEAR | \ ··· 364 363 I915_BO_ALLOC_GPU_ONLY | \ 365 364 I915_BO_ALLOC_CCS_AUX | \ 366 365 I915_BO_PREALLOC) 367 - #define I915_BO_READONLY BIT(9) 368 - #define I915_TILING_QUIRK_BIT 10 /* unknown swizzling; do not release! */ 369 - #define I915_BO_PROTECTED BIT(11) 366 + #define I915_BO_READONLY BIT(10) 367 + #define I915_TILING_QUIRK_BIT 11 /* unknown swizzling; do not release! */ 368 + #define I915_BO_PROTECTED BIT(12) 370 369 /** 371 370 * @mem_flags - Mutable placement-related flags 372 371 *
+41 -17
drivers/gpu/drm/i915/gem/i915_gem_shmem.c
··· 9 9 #include <linux/uio.h> 10 10 11 11 #include <drm/drm_cache.h> 12 + #include <drm/drm_gem.h> 13 + #include <drm/drm_print.h> 12 14 13 15 #include "gem/i915_gem_region.h" 14 16 #include "i915_drv.h" 15 17 #include "i915_gem_object.h" 16 18 #include "i915_gem_tiling.h" 17 - #include "i915_gemfs.h" 18 19 #include "i915_scatterlist.h" 19 20 #include "i915_trace.h" 21 + #include "i915_utils.h" 20 22 21 23 /* 22 24 * Move folios to appropriate lru and release the batch, decrementing the ··· 496 494 497 495 static int __create_shmem(struct drm_i915_private *i915, 498 496 struct drm_gem_object *obj, 499 - resource_size_t size) 497 + resource_size_t size, 498 + unsigned int flags) 500 499 { 501 - unsigned long flags = VM_NORESERVE; 500 + unsigned long shmem_flags = VM_NORESERVE; 501 + struct vfsmount *huge_mnt; 502 502 struct file *filp; 503 503 504 504 drm_gem_private_object_init(&i915->drm, obj, size); ··· 519 515 if (BITS_PER_LONG == 64 && size > MAX_LFS_FILESIZE) 520 516 return -E2BIG; 521 517 522 - if (i915->mm.gemfs) 523 - filp = shmem_file_setup_with_mnt(i915->mm.gemfs, "i915", size, 524 - flags); 518 + huge_mnt = drm_gem_get_huge_mnt(&i915->drm); 519 + if (!(flags & I915_BO_ALLOC_NOTHP) && huge_mnt) 520 + filp = shmem_file_setup_with_mnt(huge_mnt, "i915", size, 521 + shmem_flags); 525 522 else 526 - filp = shmem_file_setup("i915", size, flags); 523 + filp = shmem_file_setup("i915", size, shmem_flags); 527 524 if (IS_ERR(filp)) 528 525 return PTR_ERR(filp); 529 526 ··· 553 548 gfp_t mask; 554 549 int ret; 555 550 556 - ret = __create_shmem(i915, &obj->base, size); 551 + ret = __create_shmem(i915, &obj->base, size, flags); 557 552 if (ret) 558 553 return ret; 559 554 ··· 649 644 650 645 static int init_shmem(struct intel_memory_region *mem) 651 646 { 652 - i915_gemfs_init(mem->i915); 647 + struct drm_i915_private *i915 = mem->i915; 648 + 649 + /* 650 + * By creating our own shmemfs mountpoint, we can pass in 651 + * mount flags that better match our usecase. 652 + * 653 + * One example, although it is probably better with a per-file 654 + * control, is selecting huge page allocations ("huge=within_size"). 655 + * However, we only do so on platforms which benefit from it, or to 656 + * offset the overhead of iommu lookups, where with latter it is a net 657 + * win even on platforms which would otherwise see some performance 658 + * regressions such a slow reads issue on Broadwell and Skylake. 659 + */ 660 + 661 + if (GRAPHICS_VER(i915) < 11 && !i915_vtd_active(i915)) 662 + goto no_thp; 663 + 664 + drm_gem_huge_mnt_create(&i915->drm, "within_size"); 665 + if (drm_gem_get_huge_mnt(&i915->drm)) 666 + drm_info(&i915->drm, "Using Transparent Hugepages\n"); 667 + else 668 + drm_notice(&i915->drm, 669 + "Transparent Hugepage support is recommended for optimal performance%s\n", 670 + GRAPHICS_VER(i915) >= 11 ? " on this platform!" : 671 + " when IOMMU is enabled!"); 672 + 673 + no_thp: 653 674 intel_memory_region_set_name(mem, "system"); 654 675 655 - return 0; /* We have fallback to the kernel mnt if gemfs init failed. */ 656 - } 657 - 658 - static int release_shmem(struct intel_memory_region *mem) 659 - { 660 - i915_gemfs_fini(mem->i915); 661 - return 0; 676 + return 0; /* We have fallback to the kernel mnt if huge mnt failed. */ 662 677 } 663 678 664 679 static const struct intel_memory_region_ops shmem_region_ops = { 665 680 .init = init_shmem, 666 - .release = release_shmem, 667 681 .init_object = shmem_object_init, 668 682 }; 669 683
-71
drivers/gpu/drm/i915/gem/i915_gemfs.c
··· 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("tmpfs"); 42 - if (!type) 43 - goto err; 44 - 45 - fc = fs_context_for_mount(type, SB_KERNMOUNT); 46 - if (IS_ERR(fc)) 47 - goto err; 48 - ret = vfs_parse_fs_string(fc, "source", "tmpfs"); 49 - if (!ret) 50 - ret = vfs_parse_fs_string(fc, "huge", "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(i915->mm.gemfs); 71 - }
-14
drivers/gpu/drm/i915/gem/i915_gemfs.h
··· 1 - /* SPDX-License-Identifier: MIT */ 2 - /* 3 - * Copyright © 2017 Intel Corporation 4 - */ 5 - 6 - #ifndef __I915_GEMFS_H__ 7 - #define __I915_GEMFS_H__ 8 - 9 - struct drm_i915_private; 10 - 11 - void i915_gemfs_init(struct drm_i915_private *i915); 12 - void i915_gemfs_fini(struct drm_i915_private *i915); 13 - 14 - #endif
+3 -12
drivers/gpu/drm/i915/gem/selftests/huge_pages.c
··· 1316 1316 1317 1317 static inline bool igt_can_allocate_thp(struct drm_i915_private *i915) 1318 1318 { 1319 - return i915->mm.gemfs && has_transparent_hugepage(); 1319 + return !!drm_gem_get_huge_mnt(&i915->drm); 1320 1320 } 1321 1321 1322 1322 static struct drm_i915_gem_object * ··· 1761 1761 struct drm_i915_private *i915 = arg; 1762 1762 struct i915_address_space *vm; 1763 1763 struct i915_gem_context *ctx; 1764 - struct vfsmount *gemfs = i915->mm.gemfs; 1765 1764 struct drm_i915_gem_object *obj; 1766 1765 struct i915_vma *vma; 1767 1766 struct file *file; ··· 1778 1779 } 1779 1780 vm = i915_gem_context_get_eb_vm(ctx); 1780 1781 1781 - /* 1782 - * Make sure that we don't burst into a ball of flames upon falling back 1783 - * to tmpfs, which we rely on if on the off-chance we encounter a failure 1784 - * when setting up gemfs. 1785 - */ 1786 - 1787 - i915->mm.gemfs = NULL; 1788 - 1789 - obj = i915_gem_object_create_shmem(i915, PAGE_SIZE); 1782 + obj = i915_gem_object_create_region(i915->mm.regions[INTEL_REGION_SMEM], 1783 + PAGE_SIZE, 0, I915_BO_ALLOC_NOTHP); 1790 1784 if (IS_ERR(obj)) { 1791 1785 err = PTR_ERR(obj); 1792 1786 goto out_restore; ··· 1811 1819 out_put: 1812 1820 i915_gem_object_put(obj); 1813 1821 out_restore: 1814 - i915->mm.gemfs = gemfs; 1815 1822 1816 1823 i915_vm_put(vm); 1817 1824 out:
-5
drivers/gpu/drm/i915/i915_drv.h
··· 141 141 */ 142 142 atomic_t free_count; 143 143 144 - /** 145 - * tmpfs instance used for shmem backed objects 146 - */ 147 - struct vfsmount *gemfs; 148 - 149 144 struct intel_memory_region *regions[INTEL_REGION_UNKNOWN]; 150 145 151 146 struct notifier_block oom_notifier;