shm: scroll: implement offset wrap-around

* Impose a maximum memfd size limit. In theory, this can be
  2GB (wl_shm_create_pool() is the limiting factor - its size argument
  is an int32_t). For now, use 256MB.

  This is mainly to reduce the amount of virtual address space used by
  the compositor, which keeps at least one mmapping (of the entire
  memfd) around. One mmapping *per terminal window* that is.

  Given that we have 128TB with 48-bit virtual addresses, we could
  probably bump this to 2GB without any issues. However, 256MB should
  be enough.

  TODO: check how much we typically move the offset when scrolling in
  a fullscreen window on a 4K monitor. 256MB may turn out to be too
  small.

  On 32-bit shm_scroll() is completely disabled. There simply isn't
  enough address space.

* Wrapping is done by moving the offset to "the other end" of the
  memfd, and copying the buffer contents to the new, wrapped offset.

  The "normal" scrolling code then does the actual scrolling. This
  means we'll re-instantiate all objects twice when wrapping.
This commit is contained in:
Daniel Eklöf 2020-03-24 17:46:48 +01:00
parent dc393bd5d7
commit 5c5f1d096c
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 154 additions and 42 deletions

3
shm.h
View file

@ -2,6 +2,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <sys/types.h>
#include <pixman.h>
#include <wayland-client.h>
@ -24,7 +25,7 @@ struct buffer {
int fd; /* memfd */
void *real_mmapped; /* Address returned from mmap */
size_t mmap_size; /* Size of mmap (>= size) */
size_t offset; /* Offset into memfd where data begins */
off_t offset; /* Offset into memfd where data begins */
bool purge; /* True if this buffer should be destroyed */
};