| 241 | |
| 242 | |
| 243 | static 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(®ions_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 = ®ions[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 | |
| 265 | static 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) |
no test coverage detected