From 7404ace40c1b54db14a95f3f64b9f92104e8024a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 22 Mar 2020 20:36:15 +0100 Subject: [PATCH] shm: verify the system supports FALLOC_FL_PUNCH_HOLE --- shm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/shm.c b/shm.c index 1d36137b..2f74fc0b 100644 --- a/shm.c +++ b/shm.c @@ -25,6 +25,9 @@ static tll(struct buffer) buffers; +static bool can_punch_hole = false; +static bool can_punch_hole_initialized = false; + static void buffer_destroy(struct buffer *buf) { @@ -226,6 +229,12 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie) goto err; } + if (!can_punch_hole_initialized) { + can_punch_hole_initialized = true; + can_punch_hole = fallocate( + pool_fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 1) == 0; + } + /* Push to list of available buffers, but marked as 'busy' */ tll_push_back( buffers, @@ -274,6 +283,9 @@ shm_scroll(struct wl_shm *shm, struct buffer *buf, int rows) assert(buf->real_mmapped); assert(buf->fd >= 0); + if (!can_punch_hole) + return false; + LOG_DBG("scrolling %d rows (%d bytes)", rows, rows * buf->stride); assert(rows > 0);