Commit graph

40 commits

Author SHA1 Message Date
Daniel Eklöf
c4aaba6299
conf: max-shm-pool-size-mb=0 now disables SHM scrolling 2020-03-26 18:04:30 +01:00
Daniel Eklöf
0baa249d8b
shm: make max pool size user configurable (via a 'tweak' setting) 2020-03-25 20:48:02 +01:00
Daniel Eklöf
e9f1638750
shm: handle ftruncate failure 2020-03-25 18:32:41 +01:00
Daniel Eklöf
dc42cc1d19
shm: seal the memfd
This both prevents accidental resizing of the memfd, and allows the
Wayland server to optimze reads from the buffer - it no longer has to
setup SIGBUS handlers.
2020-03-25 18:30:21 +01:00
Daniel Eklöf
03319560f5
shm: scroll: keep shm pool around, and fix its size at max allowed
This lessens the burden on (primarily) the compositor, since we no
longer tear down and re-create the SHM pool when scrolling.

The SHM pool is setup once, and its size is fixed at the maximum
allowed (512MB for now, 2GB would be possible).

This also allows us to mmap() the memfd once. The exposed raw pointer
is simply an offset from the memfd mmapping.

Note that this means e.g. rouge rendering code will be able to write
outside the buffer.

Finally, only do this if the caller explicitly wants to enable
scrolling. The memfd of other buffers are sized to the requested size.
2020-03-25 18:26:58 +01:00
Daniel Eklöf
5c5f1d096c
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.
2020-03-24 17:46:48 +01:00
Daniel Eklöf
759fd572e9
shm: shm_scroll(): initial implementation of reverse scrolling
Implemented by truncating the file size and moving the offset
backwards. This means we can only reverse scroll when we've previously
scrolled forward.

TODO: figure out if we can somehow do fast reverse scrolling even
though offset is 0 (or well, less than required for scrolling).
2020-03-23 21:14:51 +01:00
Daniel Eklöf
0de3701984
shm: scroll: move top/bottom region handling from renderer into shm
This allows us to restore the regions without copying the contents to
temporary memory.
2020-03-23 20:45:27 +01:00
Daniel Eklöf
5ffee08748
shm: add shm_can_scroll() 2020-03-23 19:31:05 +01:00
Daniel Eklöf
795b0e7ea1
shm: print performance warning when FALLOC_FL_PUNCH_HOLE isn't supported 2020-03-22 21:05:05 +01:00
Daniel Eklöf
7404ace40c
shm: verify the system supports FALLOC_FL_PUNCH_HOLE 2020-03-22 21:05:00 +01:00
Daniel Eklöf
3b9be09b06
shm: scroll: no need to instantiate a new buffer when ftruncate() fails 2020-03-22 20:34:58 +01:00
Daniel Eklöf
1224807f50
shm: new function, shm_scroll()
This function "scrolls" the buffer by the specified number of (pixel)
rows.

The idea is move the image offset by re-sizing the underlying memfd
object. I.e. to scroll forward, increase the size of the memfd file,
and move the pixman image offset forward (and the Wayland SHM buffer
as well).

Only increasing the file size would, obviously, cause the memfd file
to grow indefinitely. To deal with this, we "punch" a whole from the
beginning of the file to the new offset. This frees the associated
memory.

Thus, while we have a memfd file whose size is (as seen by
e.g. fstat()) is ever growing, the actual file size is always the
original buffer size.

Some notes:

* FALLOC_FL_PUNCH_HOLE can be quite slow when the number of used pages
  to drop is large.

* all normal fallocate() usages have been replaced with ftruncate(),
  as this is *much* faster. fallocate() guarantees subsequent writes
  wont fail. I.e. it actually reserves (disk) space. While it doesn't
  allocate on-disk blocks for on-disk files, it *does* zero-initialize
  the in-memory blocks. And this is slow. ftruncate() doesn't do this.

TODO: implement reverse scrolling (i.e. a negative row count).
2020-03-22 20:06:44 +01:00
Daniel Eklöf
7b610e018b
shm: log size of purged buffer 2020-03-18 16:41:38 +01:00
Daniel Eklöf
8a6cfb738b
shm: we don't really handle SHM failures, so just abort() 2020-03-10 18:06:10 +01:00
Daniel Eklöf
cf5da1039f
shm: mmap returns MAP_FAILED, so use that as guard value 2020-03-10 18:06:10 +01:00
Daniel Eklöf
867dc836ab
shm: set pool_fd=1 after closing it, to avoid double-closing on error 2020-03-10 18:06:10 +01:00
Daniel Eklöf
7efe2c6c97
shm: try to mmap with MAP_UNINITIALIZED
This flag is expected to be ignored on most systems, but can't hurt to
try.
2020-03-10 18:06:10 +01:00
Daniel Eklöf
1581143b0b
shm: log errno error message too 2020-03-10 18:06:09 +01:00
Daniel Eklöf
9d834bb43d
shm: log 'size' when failing to fallocate() 2020-03-01 12:19:28 +01:00
Daniel Eklöf
3f601a31dc
shm: handle EINTR in posix_fallocate() 2020-02-25 19:07:23 +01:00
Daniel Eklöf
db830643d2
shm: prefer posix_fallocate over ftruncate 2020-02-15 19:46:00 +01:00
Daniel Eklöf
30335ef32a
fcft: include <fcft/fcft.h>, and use fcft/stride.h instead of local copy 2019-12-01 14:03:24 +01:00
Daniel Eklöf
29cccadd1d
tllist: is now an external "library", so use <> includes 2019-11-17 19:19:55 +01:00
Daniel Eklöf
15b12f45c6
scan-build: fix a couple of minor warnings from a scan-build run 2019-11-05 10:39:36 +01:00
Daniel Eklöf
6ed97a47be
shm: purge buffers *before* we (maybe) return one from the cache 2019-11-02 01:31:48 +01:00
Daniel Eklöf
c6c75298f3
shm: automatic buffer purging is now delayed one cycle
This ensures we don't purge a buffer that a user is holding a
reference to.
2019-11-02 01:27:05 +01:00
Daniel Eklöf
8e5d386afc
shm: add shm_purge()
Destroys *all* buffers associated with the specified cookie.
2019-11-02 00:49:00 +01:00
Daniel Eklöf
5812242405
shm: purge unused buffers
When we need to create a new buffer (because the cache doesn't have
any buffers of correct size, or because they're all busy), purge
buffers with a size mismatch.
2019-11-02 00:35:02 +01:00
Daniel Eklöf
00b46455a0
shm: associate a 'cookie' with each buffer
When re-using a buffer from cache, only re-use ones with a matching
cookie.

This prevents contention between multiple terminal windows.
2019-11-02 00:33:37 +01:00
Daniel Eklöf
8df82938b0
shm: get_buffer(): remove 'copies' argument; it's not used 2019-11-02 00:23:51 +01:00
Daniel Eklöf
632b6ee0ea
shm: add debug logging of how large the allocated memory buffer is 2019-11-02 00:23:23 +01:00
Daniel Eklöf
f884f77d99
shm: fix name of memfd 2019-11-02 00:05:07 +01:00
Daniel Eklöf
33b5210a6a
refactor: break out stride calculation to new function 2019-08-18 17:59:43 +02:00
Daniel Eklöf
72d3cbca26
shm/render: there's no need to have one pixman image per thread 2019-08-16 22:54:05 +02:00
Daniel Eklöf
f45e5c6aef
Remove all references to cairo; we now use pixman only 2019-08-16 22:11:22 +02:00
Daniel Eklöf
bed7b34c28
wip: render background and glyphs using pixman 2019-08-16 20:40:32 +02:00
Daniel Eklöf
c531795b83
wip: initial multithreaded renderer 2019-07-29 20:13:26 +02:00
Daniel Eklöf
68108ad7d8
shm: width/height must match 2019-06-12 20:17:35 +02:00
Daniel Eklöf
910c540ea9
initial commit: maps an XDG toplevel window 2019-06-12 20:08:54 +02:00