aboutsummaryrefslogtreecommitdiff
path: root/shm.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-03-25 19:48:02 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-03-25 19:48:02 +0000
commit0baa249d8b59007913dbf7db8aa8d94e6c2b9d44 (patch)
tree3a45d081f4efeee5cf03ebcb3e42e1399de1ed8e /shm.c
parentshm: handle ftruncate failure (diff)
shm: make max pool size user configurable (via a 'tweak' setting)
Diffstat (limited to 'shm.c')
-rw-r--r--shm.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/shm.c b/shm.c
index 7ac1f6c8..c2e99004 100644
--- a/shm.c
+++ b/shm.c
@@ -42,15 +42,23 @@
*
* On 32-bit the available address space is too small and SHM
* scrolling is disabled.
+ *
+ * Note: this is the _default_ size. It can be overridden by calling
+ * shm_set_max_pool_size();
*/
-static const off_t max_pool_size = 512 * 1024 * 1024;
-//static const off_t max_pool_size = INT32_MAX;
+static off_t max_pool_size = 512 * 1024 * 1024;
static tll(struct buffer) buffers;
static bool can_punch_hole = false;
static bool can_punch_hole_initialized = false;
+void
+shm_set_max_pool_size(off_t _max_pool_size)
+{
+ max_pool_size = _max_pool_size;
+}
+
static void
buffer_destroy_dont_close(struct buffer *buf)
{
@@ -80,6 +88,15 @@ buffer_destroy(struct buffer *buf)
buf->fd = -1;
}
+void
+shm_fini(void)
+{
+ tll_foreach(buffers, it) {
+ buffer_destroy(&it->item);
+ tll_remove(buffers, it);
+ }
+}
+
static void
buffer_release(void *data, struct wl_buffer *wl_buffer)
{
@@ -244,6 +261,8 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie,
off_t memfd_size = scrollable ? max_pool_size : size;
#endif
+ LOG_DBG("memfd-size: %lu, initial offset: %lu", memfd_size, initial_offset);
+
if (ftruncate(pool_fd, memfd_size) == -1) {
LOG_ERRNO("failed to set size of SHM backing memory file");
goto err;
@@ -333,15 +352,6 @@ err:
return NULL;
}
-void
-shm_fini(void)
-{
- tll_foreach(buffers, it) {
- buffer_destroy(&it->item);
- tll_remove(buffers, it);
- }
-}
-
bool
shm_can_scroll(const struct buffer *buf)
{