aboutsummaryrefslogtreecommitdiff
path: root/shm.c (follow)
Commit message (Collapse)AuthorAgeLines
* shm: don’t check for __i386__ and __x86_64__ - there are other architectures out thereDaniel Eklöf2021-01-23-11/+11
| | | | | Instead, check for __SIZEOF_POINTER__ == 8, since what we’re really interested in is whether we have enough virtual address space or not.
* shm: unbreak build without memfd_createJan Beich2021-01-23-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | New FreeBSD versions have memfd_create but other BSDs don't. pgo/pgo.c:260:22: error: implicit declaration of function 'memfd_create' is invalid in C99 [-Werror,-Wimplicit-function-declaration] int mem_fd = memfd_create("foot-pgo-ptmx", MFD_CLOEXEC); ^ pgo/pgo.c:260:52: error: use of undeclared identifier 'MFD_CLOEXEC' int mem_fd = memfd_create("foot-pgo-ptmx", MFD_CLOEXEC); ^ shm.c:13:10: fatal error: 'linux/mman.h' file not found #include <linux/mman.h> ^~~~~~~~~~~~~~ shm.c:277:15: error: implicit declaration of function 'memfd_create' is invalid in C99 [-Werror,-Wimplicit-function-declaration] pool_fd = memfd_create("foot-wayland-shm-buffer-pool", MFD_CLOEXEC | MFD_ALLOW_SEALING); ^ shm.c:277:60: error: use of undeclared identifier 'MFD_CLOEXEC' pool_fd = memfd_create("foot-wayland-shm-buffer-pool", MFD_CLOEXEC | MFD_ALLOW_SEALING); ^ shm.c:277:74: error: use of undeclared identifier 'MFD_ALLOW_SEALING' pool_fd = memfd_create("foot-wayland-shm-buffer-pool", MFD_CLOEXEC | MFD_ALLOW_SEALING); ^ shm.c:339:15: error: use of undeclared identifier 'F_SEAL_GROW' F_SEAL_GROW | F_SEAL_SHRINK | /*F_SEAL_FUTURE_WRITE |*/ F_SEAL_SEAL) < 0) ^ shm.c:339:29: error: use of undeclared identifier 'F_SEAL_SHRINK' F_SEAL_GROW | F_SEAL_SHRINK | /*F_SEAL_FUTURE_WRITE |*/ F_SEAL_SEAL) < 0) ^ shm.c:339:71: error: use of undeclared identifier 'F_SEAL_SEAL' F_SEAL_GROW | F_SEAL_SHRINK | /*F_SEAL_FUTURE_WRITE |*/ F_SEAL_SEAL) < 0) ^ shm.c:338:24: error: use of undeclared identifier 'F_ADD_SEALS' if (fcntl(pool_fd, F_ADD_SEALS, ^
* shm: disable fallocate optimization if not supportedJan Beich2021-01-23-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | shm.c:301:26: error: implicit declaration of function 'fallocate' is invalid in C99 [-Werror,-Wimplicit-function-declaration] can_punch_hole = fallocate( ^ shm.c:302:22: error: use of undeclared identifier 'FALLOC_FL_PUNCH_HOLE' pool_fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 1) == 0; ^ shm.c:302:45: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE' pool_fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 1) == 0; ^ shm.c:432:9: error: implicit declaration of function 'fallocate' is invalid in C99 [-Werror,-Wimplicit-function-declaration] if (fallocate( ^ shm.c:434:13: error: use of undeclared identifier 'FALLOC_FL_PUNCH_HOLE' FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^ shm.c:434:36: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE' FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^ shm.c:501:9: error: implicit declaration of function 'fallocate' is invalid in C99 [-Werror,-Wimplicit-function-declaration] if (fallocate( ^ shm.c:503:13: error: use of undeclared identifier 'FALLOC_FL_PUNCH_HOLE' FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^ shm.c:503:36: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE' FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^ shm.c:597:9: error: implicit declaration of function 'fallocate' is invalid in C99 [-Werror,-Wimplicit-function-declaration] if (fallocate( ^ shm.c:599:13: error: use of undeclared identifier 'FALLOC_FL_PUNCH_HOLE' FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^ shm.c:599:36: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE' FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^
* shm: silence -Wunused-function on i386Jan Beich2021-01-23-0/+2
| | | | | | shm.c:134:1: error: unused function 'page_size' [-Werror,-Wunused-function] page_size(void) ^
* debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes2021-01-16-24/+24
|
* Print stack trace on assert() failure or when calling fatal_error()Craig Barnes2021-01-16-1/+1
| | | | | | Note: this uses the __sanitizer_print_stack_trace() function from the AddressSanitizer runtime, so it only works when AddressSanitizer is in use.
* shm: fix badly indented function return typeDaniel Eklöf2020-12-07-1/+1
|
* shm: MAP_UNINITIALIZED is a linux only mmap flagDaniel Eklöf2020-10-10-0/+4
|
* fix some buggy comparisons relating to signed/unsigned typesCraig Barnes2020-08-25-2/+4
|
* Cast printf formatter %p arguments to void*Daniel Eklöf2020-08-23-4/+4
|
* shm: don't even try to punch a memfd hole in 32-bitDaniel Eklöf2020-08-11-0/+6
| | | | | This ensures we don't issue a warning if we fail, something that will just confuse users, as SHM scrolling is disabled in 32-bit anyway.
* Convert most dynamic allocations to use functions from xmalloc.hCraig Barnes2020-08-08-1/+2
|
* Replace GCC "unused" and "format" attributes with portable macrosCraig Barnes2020-08-07-1/+2
|
* render: re-write cell clipping to use pixman destination clippingDaniel Eklöf2020-06-04-11/+23
| | | | | | | | | | | | Our home rolled clip-to-cell code was, obviously, not correct. The original problem was that we couldn't use pixman clipping since we have multiple threads writing to the same pixman image, and thus there would be races between the threads setting clipping. The fix is actually simple - just instantiate one pixman image (referencing the same backing image data) for each rendering thread.
* shm: #ifdef conditional code to measure total size of SHM allocationsDaniel Eklöf2020-04-18-0/+20
|
* shm: memfd seal failures are not fatal errorsDaniel Eklöf2020-04-03-1/+1
|
* conf: max-shm-pool-size-mb=0 now disables SHM scrollingDaniel Eklöf2020-03-26-7/+6
|
* shm: make max pool size user configurable (via a 'tweak' setting)Daniel Eklöf2020-03-25-11/+21
|
* shm: handle ftruncate failureDaniel Eklöf2020-03-25-1/+5
|
* shm: seal the memfdDaniel Eklöf2020-03-25-0/+9
| | | | | | 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.
* shm: scroll: keep shm pool around, and fix its size at max allowedDaniel Eklöf2020-03-25-124/+129
| | | | | | | | | | | | | | | | | 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.
* shm: scroll: implement offset wrap-aroundDaniel Eklöf2020-03-24-41/+152
| | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* shm: shm_scroll(): initial implementation of reverse scrollingDaniel Eklöf2020-03-23-8/+92
| | | | | | | | | 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).
* shm: scroll: move top/bottom region handling from renderer into shmDaniel Eklöf2020-03-23-6/+43
| | | | | This allows us to restore the regions without copying the contents to temporary memory.
* shm: add shm_can_scroll()Daniel Eklöf2020-03-23-0/+7
|
* shm: print performance warning when FALLOC_FL_PUNCH_HOLE isn't supportedDaniel Eklöf2020-03-22-3/+6
|
* shm: verify the system supports FALLOC_FL_PUNCH_HOLEDaniel Eklöf2020-03-22-0/+12
|
* shm: scroll: no need to instantiate a new buffer when ftruncate() failsDaniel Eklöf2020-03-22-21/+1
|
* shm: new function, shm_scroll()Daniel Eklöf2020-03-22-68/+199
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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).
* shm: log size of purged bufferDaniel Eklöf2020-03-18-2/+3
|
* shm: we don't really handle SHM failures, so just abort()Daniel Eklöf2020-03-10-0/+2
|
* shm: mmap returns MAP_FAILED, so use that as guard valueDaniel Eklöf2020-03-10-2/+2
|
* shm: set pool_fd=1 after closing it, to avoid double-closing on errorDaniel Eklöf2020-03-10-1/+1
|
* shm: try to mmap with MAP_UNINITIALIZEDDaniel Eklöf2020-03-10-1/+2
| | | | | This flag is expected to be ignored on most systems, but can't hurt to try.
* shm: log errno error message tooDaniel Eklöf2020-03-10-1/+1
|
* shm: log 'size' when failing to fallocate()Daniel Eklöf2020-03-01-1/+1
|
* shm: handle EINTR in posix_fallocate()Daniel Eklöf2020-02-25-1/+4
|
* shm: prefer posix_fallocate over ftruncateDaniel Eklöf2020-02-15-3/+14
|
* fcft: include <fcft/fcft.h>, and use fcft/stride.h instead of local copyDaniel Eklöf2019-12-01-1/+1
|
* tllist: is now an external "library", so use <> includesDaniel Eklöf2019-11-17-1/+2
|
* scan-build: fix a couple of minor warnings from a scan-build runDaniel Eklöf2019-11-05-1/+1
|
* shm: purge buffers *before* we (maybe) return one from the cacheDaniel Eklöf2019-11-02-16/+16
|
* shm: automatic buffer purging is now delayed one cycleDaniel Eklöf2019-11-02-5/+20
| | | | | This ensures we don't purge a buffer that a user is holding a reference to.
* shm: add shm_purge()Daniel Eklöf2019-11-01-0/+17
| | | | Destroys *all* buffers associated with the specified cookie.
* shm: purge unused buffersDaniel Eklöf2019-11-01-7/+28
| | | | | | 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.
* shm: associate a 'cookie' with each bufferDaniel Eklöf2019-11-01-4/+10
| | | | | | | When re-using a buffer from cache, only re-use ones with a matching cookie. This prevents contention between multiple terminal windows.
* shm: get_buffer(): remove 'copies' argument; it's not usedDaniel Eklöf2019-11-01-3/+1
|
* shm: add debug logging of how large the allocated memory buffer isDaniel Eklöf2019-11-01-0/+3
|
* shm: fix name of memfdDaniel Eklöf2019-11-01-1/+1
|
* refactor: break out stride calculation to new functionDaniel Eklöf2019-08-18-4/+2
|
* shm/render: there's no need to have one pixman image per threadDaniel Eklöf2019-08-16-24/+7
|
* Remove all references to cairo; we now use pixman onlyDaniel Eklöf2019-08-16-52/+8
|
* wip: render background and glyphs using pixmanDaniel Eklöf2019-08-16-1/+27
|
* wip: initial multithreaded rendererDaniel Eklöf2019-07-29-21/+48
|
* shm: width/height must matchDaniel Eklöf2019-06-12-0/+3
|
* initial commit: maps an XDG toplevel windowDaniel Eklöf2019-06-12-0/+163