Skip to content

ZEEK-ONLY: avoid initialization of every calloc'd int in fd_map#3

Merged
ckreibich merged 1 commit intomasterfrom
topic/christian/no-fdmap-initialization-master
Jun 5, 2025
Merged

ZEEK-ONLY: avoid initialization of every calloc'd int in fd_map#3
ckreibich merged 1 commit intomasterfrom
topic/christian/no-fdmap-initialization-master

Conversation

@ckreibich
Copy link
Copy Markdown
Member

Same as #2, but with adjusted merge target as per Tim's request.

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:

# ulimit -n
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.
@ckreibich
Copy link
Copy Markdown
Member Author

This also came up over in zeek/zeek#2951, linking here just for reference.

@ckreibich ckreibich merged commit c315890 into master Jun 5, 2025
0 of 7 checks passed
@ckreibich ckreibich deleted the topic/christian/no-fdmap-initialization-master branch June 5, 2025 22:32
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.

2 participants