From 81025108db445ab31d7506a88e8919a5eebcadcb Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Tue, 9 Aug 2022 11:12:13 +0100 Subject: Add Transparent HugePage support on Linux. Currently, this is unlikely to be enabled for shared memory mappings on any user's system, so will not make a difference. If `/sys/kernel/mm/transparent_hugepage/shmem_enabled` is set to `advise` or higher, however, this commit should enable the use of hugepages. This can greatly speed up startup for large windows - for a 2880x1800 fullscreen window on my laptop, enabling hugepages halves startup time. From the kernel mailing lists, it looks like there's some work towards allowing applications to opt-in to THP support regardless of whether they're enabled, via `madvise(MADV_COLLAPSE)`, so this may be more useful in future. --- src/shm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/shm.c') diff --git a/src/shm.c b/src/shm.c index e145d4a..9e0833f 100644 --- a/src/shm.c +++ b/src/shm.c @@ -34,7 +34,19 @@ static int create_shm_file(void) int shm_allocate_file(size_t size) { +#ifdef __linux__ + /* + * On linux, we can just use memfd_create(). This is both simpler and + * potentially allows usage of Transparent HugePages, which speed up + * the first paint of a large screen buffer. + * + * This isn't available on *BSD, which we could conceivably be running + * on. + */ + int fd = memfd_create("wl_shm", 0); +#else int fd = create_shm_file(); +#endif if (fd < 0) return -1; int ret; -- cgit v1.2.3