30#include <flow/util/string_ostream.hpp>
31#include <flow/util/util.hpp>
32#include <boost/system/error_code.hpp>
53 return allocate_helper(size, arena_id, MALLOCX_TCACHE(thread_cache_id));
70 deallocate_helper(address, MALLOCX_TCACHE_NONE);
75 deallocate_helper(address, MALLOCX_TCACHE(thread_cache_id));
87 using flow::util::Lock_guard;
88 using flow::util::Mutex_non_recursive;
89 using flow::error::Runtime_error;
90 using boost::system::system_category;
93 size_t output_size =
sizeof(arena_id);
94 extent_hooks_t** input_param;
98 input_param = &extent_hooks;
99 input_size =
sizeof(extent_hooks);
103 input_param =
nullptr;
118 throw Runtime_error{
Error_code{ec, system_category()},
"je_mallctl() error on creating arena"};
126 destroy_arena(arena_id, log_ctx, [](
auto&&,
auto&& destroy_arena_func)
128 destroy_arena_func();
135 using flow::util::Lock_guard;
136 using flow::util::Mutex_non_recursive;
142 string opts{extra_opts};
160 ([](
void* cbopaque,
const char* chunk)
161 { *(
static_cast<std::ostream*
>(cbopaque)) << chunk; },
163 &os, opts.empty() ? nullptr : opts.c_str());
175 flow::util::String_ostream os;
177 os.os() << std::flush;
184 FLOW_LOG_SET_CONTEXT(logger_ptr, Log_component::S_SHM);
187 FLOW_LOG_WITH_CHECKING(sev,
188 "jemalloc stats dump (knobs: "
190 "[" << extra_opts <<
"]]): "
212 using flow::util::Mutex_non_recursive;
215 static const auto s_mutex =
new Mutex_non_recursive;
221 using flow::util::Mutex_non_recursive;
224 static const auto s_mutex =
new Mutex_non_recursive;
arena_id_t create_arena(extent_hooks_t *extent_hooks) const
Creates a new segregated memory area (jemalloc-arena), wired to the given extent hooks (if any).
void deallocate_helper(void *address, int thread_cache_flags) const noexcept
Boring helper for deallocate_no_tcache() and deallocate(address, tcache_id).
void stats_dump_to_ostream(std::ostream &os=std::cout, Stat_format format=Stat_format::S_TEXT, util::String_view extra_opts={}) const
Writes a broad, raw, process-wide jemalloc statistics dump (all arenas) to os.
std::string stats_dump_to_string(Stat_format format=Stat_format::S_TEXT, util::String_view extra_opts={}) const
Like stats_dump_to_ostream() but returns the dump as a string.
void deallocate(void *address) const noexcept
Deallocates memory by using jemalloc's vanilla free() implementation.
void * allocate_no_tcache(size_t size, arena_id_t arena_id) const
Allocates uninitialized memory, in the specified jemalloc-arena, without the use of a thread cache.
void destroy_arena(arena_id_t arena_id, const flow::log::Log_context_mt *log_ctx, On_done_func &&on_done_func) const
Forwards to Thread_cache::destroy_arena_safely().
void deallocate_no_tcache(void *address) const noexcept
Deallocates memory similarly to deallocate(address), except that this is done without the use of a th...
void * allocate(size_t size) const
Allocates uninitialized memory by using jemalloc's vanilla malloc() implementation.
Stat_format
Output format for stats_dump_to_ostream() and the sibling stats-dump methods.
@ S_JSON
JSON (jemalloc malloc_stats_print() "J" option).
void * allocate_helper(size_t size, arena_id_t arena_id, int thread_cache_flags) const
Boring helper for allocate_no_tcache() and allocate(size, arena_id, tcache_id).
void log_stats_dump(flow::log::Logger *logger_ptr, Stat_format format=Stat_format::S_TEXT, flow::log::Sev sev=flow::log::Sev::S_INFO, util::String_view extra_opts={}) const
Like stats_dump_to_ostream() but logs the dump – as a single (multi-line) message – via logger_ptr at...
SHM-jemalloc internal (non-public) implementation details. See also stat-oriented sub-namespace: deta...
flow::util::Mutex_non_recursive & jemalloc_arena_list_mutex()
Returns the process-global mutex serializing any mutation of jemalloc's arena set (arena create/destr...
flow::util::Mutex_non_recursive & jemalloc_stats_mutex()
Returns the process-global mutex held throughout each of Flow-IPC's jemalloc-statistics operations – ...
ipc::shm sub-module with the SHM-jemalloc SHM-provider. See ipc::shm doc header for introduction.
unsigned int arena_id_t
Arena ID as dictated by jemalloc.
unsigned int tcache_id_t
Thread cache ID type as dictated by jemalloc.
flow::util::String_view String_view
Short-hand for Flow's String_view.
flow::Error_code Error_code
Short-hand for flow::Error_code which is very common.
#define IPC_SHM_ARENA_LEND_JEMALLOC_API(ARG_api_name)
To be used when invoking jemalloc public API functions, this evaluates to the given argument (which s...