MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / pin_thread_arena

Function pin_thread_arena

nodedb-mem/src/arena.rs:104–123  ·  view source on GitHub ↗

Pin the calling thread to a dedicated jemalloc arena. Call this once at Data Plane core startup, before any allocations. Each core should get a unique `arena_index` (typically core ID). Returns the arena index that was assigned. On wasm32 the standard allocator is used and the supplied index is returned unchanged as a no-op.

(arena_index: u32)

Source from the content-addressed store, hash-verified

102/// Returns the arena index that was assigned. On wasm32 the standard allocator
103/// is used and the supplied index is returned unchanged as a no-op.
104pub fn pin_thread_arena(arena_index: u32) -> Result<u32> {
105 #[cfg(not(target_arch = "wasm32"))]
106 {
107 let narenas = read_narenas()?;
108
109 let target_arena = if (arena_index as usize) < narenas {
110 arena_index
111 } else {
112 create_arena()?
113 };
114
115 set_thread_arena(target_arena)?;
116 Ok(target_arena)
117 }
118 #[cfg(target_arch = "wasm32")]
119 {
120 // wasm32 uses the standard allocator; per-thread arena pinning is a no-op.
121 Ok(arena_index)
122 }
123}
124
125/// Query the current number of jemalloc arenas.
126#[cfg(not(target_arch = "wasm32"))]

Callers 3

pin_and_read_arenaFunction · 0.85
create_and_pin_new_arenaFunction · 0.85
spawn_coreFunction · 0.85

Calls 3

read_narenasFunction · 0.85
set_thread_arenaFunction · 0.85
create_arenaFunction · 0.70

Tested by 2

pin_and_read_arenaFunction · 0.68
create_and_pin_new_arenaFunction · 0.68