summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/shm.c12
-rw-r--r--src/surface.c14
2 files changed, 26 insertions, 0 deletions
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;
diff --git a/src/surface.c b/src/surface.c
index e640c40..b8ed88e 100644
--- a/src/surface.c
+++ b/src/surface.c
@@ -32,6 +32,20 @@ void surface_init(
MAP_SHARED,
surface->shm_pool_fd,
0);
+#ifdef __linux__
+ /*
+ * On linux, ask for Transparent HugePages if available and our
+ * buffer's at least 2MiB. This can greatly speed up the first
+ * cairo_paint() by reducing page faults, but unfortunately is disabled
+ * for shared memory at the time of writing.
+ *
+ * MADV_HUGEPAGE isn't available on *BSD, which we could conceivably be
+ * running on.
+ */
+ if (surface->shm_pool_size >= (2 << 20)) {
+ madvise(surface->shm_pool_data, surface->shm_pool_size, MADV_HUGEPAGE);
+ }
+#endif
surface->wl_shm_pool = wl_shm_create_pool(
wl_shm,
surface->shm_pool_fd,