jemalloc / jemalloc

http://jemalloc.net/
Other
9.4k stars 1.44k forks source link

Strategies to preallocate pages for real-time applications? #2442

Open glenn-elliott opened 1 year ago

glenn-elliott commented 1 year ago

I am developing a real-time application that uses jemalloc and runs on the PREEMPT_RT Linux kernel. A best-practices document from the PREEMPT_RT project suggests that an application should preallocate its heap before starting real-time work. The provided example is for a glibc-managed heap.

I want to achieve something similar for my jemalloc-using application, with the goal of obtaining all of the pages from the OS that I expect jemalloc will need before the application starts real-time work. Does this question make sense in context of jemalloc's arena-based design? Unless I have overlooked something, I don't see any public API for merely allocating pages. If I disable dirty_decay_ms, can my problem be solved simply by allocating an enormous chunk of memory with jemalloc, fault every page, and free it? I'm not expecting to be so lucky.

It is feasible for me to generate a profile of my applications's heap needs with calls to mallctl(), though I don't think it would be fruitful for me to attempt to precisely describe the total number and size of all allocations in my application. I cannot guarantee the same precise allocation pattern for my application in every instance would run, though I can estimate a high water mark for dynamically allocated memory.

A question about preallocation has come up before, but in the context of persistent memory. Moreover, the author of that question wanted to reconstruct the jemalloc allocation state. I merely seek to obtain pages from the OS ahead of time.

daniel-brosche commented 1 year ago

I always wanted to use jemalloc for realtime applications. Is there a way to create a private arenas where the max size is limited and preallocated / reserved for more deterministic allocations?