MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / slab_map_set

Function slab_map_set

src/foundation/slab_alloc.c:169–204  ·  view source on GitHub ↗

Cold path. Sets the leaf entry for `base` to `val` (page to register, NULL to * unregister), allocating intermediate tables on demand. Returns false only if * a needed table allocation fails while registering. */

Source from the content-addressed store, hash-verified

167 * unregister), allocating intermediate tables on demand. Returns false only if
168 * a needed table allocation fails while registering. */
169static bool slab_map_set(uintptr_t base, slab_page_t *val) {
170 size_t i1, i2, i3;
171 if (!slab_map_indices(base, &i1, &i2, &i3)) {
172 return false;
173 }
174 slab_map_lock();
175 slab_map_l2_t *l2 = atomic_load_explicit(&g_slab_map_root[i1], memory_order_relaxed);
176 if (!l2) {
177 if (!val) {
178 slab_map_unlock();
179 return true; /* nothing to unregister */
180 }
181 l2 = (slab_map_l2_t *)cbm_calloc(CBM_MEM_CLASS_TS_TREE, sizeof(*l2));
182 if (!l2) {
183 slab_map_unlock();
184 return false;
185 }
186 atomic_store_explicit(&g_slab_map_root[i1], l2, memory_order_release);
187 }
188 slab_map_l3_t *l3 = atomic_load_explicit(&l2->e[i2], memory_order_relaxed);
189 if (!l3) {
190 if (!val) {
191 slab_map_unlock();
192 return true;
193 }
194 l3 = (slab_map_l3_t *)cbm_calloc(CBM_MEM_CLASS_TS_TREE, sizeof(*l3));
195 if (!l3) {
196 slab_map_unlock();
197 return false;
198 }
199 atomic_store_explicit(&l2->e[i2], l3, memory_order_release);
200 }
201 atomic_store_explicit(&l3->e[i3], val, memory_order_release);
202 slab_map_unlock();
203 return true;
204}
205
206/* ── Tier 1 helpers ────────────────────────────────────────────────── */
207

Callers 2

slab_map_register_pageFunction · 0.85
slab_map_unregister_pageFunction · 0.85

Calls 4

slab_map_indicesFunction · 0.85
slab_map_lockFunction · 0.85
slab_map_unlockFunction · 0.85
cbm_callocFunction · 0.85

Tested by

no test coverage detected