MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / mi_region_try_claim

Function mi_region_try_claim

3rd/mimalloc-2.0.9/src/region.c:243–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

241
242
243static bool mi_region_try_claim(int numa_node, size_t blocks, bool allow_large, mem_region_t** region, mi_bitmap_index_t* bit_idx, mi_os_tld_t* tld)
244{
245 // try all regions for a free slot
246 const size_t count = mi_atomic_load_relaxed(&regions_count); // monotonic, so ok to be relaxed
247 size_t idx = tld->region_idx; // Or start at 0 to reuse low addresses? Starting at 0 seems to increase latency though
248 for (size_t visited = 0; visited < count; visited++, idx++) {
249 if (idx >= count) idx = 0; // wrap around
250 mem_region_t* r = &regions[idx];
251 // if this region suits our demand (numa node matches, large OS page matches)
252 if (mi_region_is_suitable(r, numa_node, allow_large)) {
253 // then try to atomically claim a segment(s) in this region
254 if (_mi_bitmap_try_find_claim_field(&r->in_use, 0, blocks, bit_idx)) {
255 tld->region_idx = idx; // remember the last found position
256 *region = r;
257 return true;
258 }
259 }
260 }
261 return false;
262}
263
264
265static void* mi_region_try_alloc(size_t blocks, bool* commit, bool* large, bool* is_pinned, bool* is_zero, size_t* memid, mi_os_tld_t* tld)

Callers 1

mi_region_try_allocFunction · 0.85

Calls 2

mi_region_is_suitableFunction · 0.85

Tested by

no test coverage detected