Skip to content

Conversation

@timwoj
Copy link
Contributor

@timwoj timwoj commented Sep 1, 2025

libkqueue allocates the the number of available file descriptors for the fd_map array in linux/platform.c to. That limit is vast in Docker, for complicated reasons:

1073741816

The library allocates arrays of that size in several places, but in only one does it then also initialize every member of the array (to -1). Since calloc/mmap are optimized to allocate lazily, this means that only that instance winds up immediately actually using ~4GB in memory.

The initialization of the int array uses -1 to indicate that a field isn't in use. The patch changes this to use 0 as unused, simply bumping the stored fds by one upon insert and decrementing by one on access, via helpers.

Fixes #153

libkqueue allocates the the number of available file descriptors for the fd_map
array in linux/platform.c to. That limit is vast in Docker, for complicated
reasons:

1073741816

The library allocates arrays of that size in several places, but in only one
does it then also _initialize_ every member of the array (to -1). Since
calloc/mmap are optimized to allocate lazily, this means that only that instance
winds up immediately actually using ~4GB in memory.

The initialization of the int array uses -1 to indicate that a field isn't in
use. The patch changes this to use 0 as unused, simply bumping the stored fds by
one upon insert and decrementing by one on access, via helpers.
@arr2036 arr2036 merged commit a83d56a into mheily:master Sep 1, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

High memory usage from monitoring_thread_loop

3 participants