xref: /linux/drivers/gpu/drm/i915/gem/i915_gemfs.c (revision 10be98a77c558f8cfb823cd2777171fbb35040f6)
1*10be98a7SChris Wilson /*
2*10be98a7SChris Wilson  * SPDX-License-Identifier: MIT
3*10be98a7SChris Wilson  *
4*10be98a7SChris Wilson  * Copyright © 2017 Intel Corporation
5*10be98a7SChris Wilson  */
6*10be98a7SChris Wilson 
7*10be98a7SChris Wilson #include <linux/fs.h>
8*10be98a7SChris Wilson #include <linux/mount.h>
9*10be98a7SChris Wilson #include <linux/pagemap.h>
10*10be98a7SChris Wilson 
11*10be98a7SChris Wilson #include "i915_drv.h"
12*10be98a7SChris Wilson #include "i915_gemfs.h"
13*10be98a7SChris Wilson 
14*10be98a7SChris Wilson int i915_gemfs_init(struct drm_i915_private *i915)
15*10be98a7SChris Wilson {
16*10be98a7SChris Wilson 	struct file_system_type *type;
17*10be98a7SChris Wilson 	struct vfsmount *gemfs;
18*10be98a7SChris Wilson 
19*10be98a7SChris Wilson 	type = get_fs_type("tmpfs");
20*10be98a7SChris Wilson 	if (!type)
21*10be98a7SChris Wilson 		return -ENODEV;
22*10be98a7SChris Wilson 
23*10be98a7SChris Wilson 	gemfs = kern_mount(type);
24*10be98a7SChris Wilson 	if (IS_ERR(gemfs))
25*10be98a7SChris Wilson 		return PTR_ERR(gemfs);
26*10be98a7SChris Wilson 
27*10be98a7SChris Wilson 	/*
28*10be98a7SChris Wilson 	 * Enable huge-pages for objects that are at least HPAGE_PMD_SIZE, most
29*10be98a7SChris Wilson 	 * likely 2M. Note that within_size may overallocate huge-pages, if say
30*10be98a7SChris Wilson 	 * we allocate an object of size 2M + 4K, we may get 2M + 2M, but under
31*10be98a7SChris Wilson 	 * memory pressure shmem should split any huge-pages which can be
32*10be98a7SChris Wilson 	 * shrunk.
33*10be98a7SChris Wilson 	 */
34*10be98a7SChris Wilson 
35*10be98a7SChris Wilson 	if (has_transparent_hugepage()) {
36*10be98a7SChris Wilson 		struct super_block *sb = gemfs->mnt_sb;
37*10be98a7SChris Wilson 		/* FIXME: Disabled until we get W/A for read BW issue. */
38*10be98a7SChris Wilson 		char options[] = "huge=never";
39*10be98a7SChris Wilson 		int flags = 0;
40*10be98a7SChris Wilson 		int err;
41*10be98a7SChris Wilson 
42*10be98a7SChris Wilson 		err = sb->s_op->remount_fs(sb, &flags, options);
43*10be98a7SChris Wilson 		if (err) {
44*10be98a7SChris Wilson 			kern_unmount(gemfs);
45*10be98a7SChris Wilson 			return err;
46*10be98a7SChris Wilson 		}
47*10be98a7SChris Wilson 	}
48*10be98a7SChris Wilson 
49*10be98a7SChris Wilson 	i915->mm.gemfs = gemfs;
50*10be98a7SChris Wilson 
51*10be98a7SChris Wilson 	return 0;
52*10be98a7SChris Wilson }
53*10be98a7SChris Wilson 
54*10be98a7SChris Wilson void i915_gemfs_fini(struct drm_i915_private *i915)
55*10be98a7SChris Wilson {
56*10be98a7SChris Wilson 	kern_unmount(i915->mm.gemfs);
57*10be98a7SChris Wilson }
58