aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.c14
-rw-r--r--config.h1
-rw-r--r--main.c2
-rw-r--r--shm.c32
-rw-r--r--shm.h1
5 files changed, 39 insertions, 11 deletions
diff --git a/config.c b/config.c
index 80163e2e..16831248 100644
--- a/config.c
+++ b/config.c
@@ -22,6 +22,7 @@
#include "wayland.h"
#define ALEN(v) (sizeof(v) / sizeof(v[0]))
+#define min(x, y) ((x) < (y) ? (x) : (y))
static const uint32_t default_foreground = 0xdcdccc;
static const uint32_t default_background = 0x111111;
@@ -621,6 +622,18 @@ parse_section_tweak(
LOG_WARN("tweak: delayed-render-upper=%lu", ns);
}
+ else if (strcmp(key, "max-shm-pool-size-mb") == 0) {
+ unsigned long mb;
+ if (!str_to_ulong(value, 10, &mb)) {
+ LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value);
+ return false;
+ }
+
+ conf->tweak.max_shm_pool_size = min(mb * 1024 * 1024, INT32_MAX);
+ LOG_WARN("tweak: max-shm-pool-size=%lu bytes",
+ conf->tweak.max_shm_pool_size);
+ }
+
else {
LOG_ERR("%s:%u: invalid key: %s", path, lineno, key);
return false;
@@ -890,6 +903,7 @@ config_load(struct config *conf, const char *conf_path)
.tweak = {
.delayed_render_lower_ns = 500000, /* 0.5ms */
.delayed_render_upper_ns = 16666666 / 2, /* half a frame period (60Hz) */
+ .max_shm_pool_size = 512 * 1024 * 1024,
},
};
diff --git a/config.h b/config.h
index 596aa368..f53a1b7b 100644
--- a/config.h
+++ b/config.h
@@ -77,6 +77,7 @@ struct config {
struct {
uint64_t delayed_render_lower_ns;
uint64_t delayed_render_upper_ns;
+ off_t max_shm_pool_size;
} tweak;
};
diff --git a/main.c b/main.c
index b6ca0fa4..b7dbef13 100644
--- a/main.c
+++ b/main.c
@@ -330,6 +330,8 @@ main(int argc, char *const *argv)
} while (errno == ERANGE);
}
+ shm_set_max_pool_size(conf.tweak.max_shm_pool_size);
+
if ((fdm = fdm_init()) == NULL)
goto out;
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)
{
diff --git a/shm.h b/shm.h
index fe3f4b93..aff53d76 100644
--- a/shm.h
+++ b/shm.h
@@ -37,6 +37,7 @@ struct buffer *shm_get_buffer(
struct wl_shm *shm, int width, int height, unsigned long cookie, bool scrollable);
void shm_fini(void);
+void shm_set_max_pool_size(off_t max_pool_size);
bool shm_can_scroll(const struct buffer *buf);
bool shm_scroll(struct wl_shm *shm, struct buffer *buf, int rows,
int top_margin, int top_keep_rows,