Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Evented::Arena to allocate in blocks [fixup #14996] #15205

Conversation

ysbaddaden
Copy link
Contributor

Follow up to #14996

Replaces the static mmap that must accommodate for as many file descriptors as allowed by ulimit/rlimit. Despite being virtual memory, not really allocated in practice, this led to out-of-memory errors in some situations.

The arena now dynamically allocates individual blocks as needed (no more virtual memory). For simplicity reasons it will only ever grow, and won't shrink (we may think of a solution for this later). The original safety guarantees still hold: once an entry has been allocated in the arena, its pointer won't change.

The event loop still limits the arena capacity to the hardware limit (ulimit: open files).

Side effect: the arena don't need to remember the maximum fd/index anymore; that was only needed for fork; we can simply iterate the allocated blocks now.

The main advantage is the ability to grow on demand and avoid a large
single contiguous mmap of memory that needs to preallocates most of the
memory.

We also don't need to remember the maximum reached index anymore, which
is replaced with a `#each_index` method (only needed to allow `fork`).
@ysbaddaden ysbaddaden self-assigned this Nov 19, 2024
@straight-shoota straight-shoota changed the title EventLoop: allocate arena into blocks EventLoop: allocate arena into blocks [fixup #14996] Nov 19, 2024
src/crystal/system/unix/evented/arena.cr Outdated Show resolved Hide resolved
src/crystal/system/unix/evented/arena.cr Outdated Show resolved Hide resolved
src/crystal/system/unix/evented/arena.cr Outdated Show resolved Hide resolved
src/crystal/system/unix/evented/arena.cr Outdated Show resolved Hide resolved
@straight-shoota straight-shoota added this to the 1.15.0 milestone Nov 19, 2024
@straight-shoota straight-shoota changed the title EventLoop: allocate arena into blocks [fixup #14996] Refactor Evented::Arena to allocate in blocks [fixup #14996] Nov 21, 2024
@straight-shoota straight-shoota merged commit 02df7ff into crystal-lang:master Nov 21, 2024
69 checks passed
@ysbaddaden ysbaddaden deleted the feature/lifetime-evloop+block-arena branch November 21, 2024 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants