Allocate and register a new SLAB_PAGE_SIZE-aligned page, threading its chunks * onto the thread-local free list. Returns false on OOM (caller falls back to * malloc). Registration happens before any chunk is handed out so that a later * cross-thread free can always recover the page. */
| 214 | * malloc). Registration happens before any chunk is handed out so that a later |
| 215 | * cross-thread free can always recover the page. */ |
| 216 | static bool slab_grow(slab_state_t *s) { |
| 217 | void *mem = NULL; |
| 218 | if (cbm_aligned_alloc(&mem, SLAB_PAGE_SIZE, SLAB_PAGE_SIZE) != 0 || !mem) { |
| 219 | return false; |
| 220 | } |
| 221 | cbm_mem_class_add_external(CBM_MEM_CLASS_TS_TREE, SLAB_PAGE_SIZE); |
| 222 | slab_page_t *page = (slab_page_t *)mem; |
| 223 | page->next = s->pages; |
| 224 | atomic_init(&page->owner, s); |
| 225 | atomic_init(&page->remote_free_head, (slab_free_node_t *)NULL); |
| 226 | atomic_init(&page->refcount, 1u); /* owner guard */ |
| 227 | |
| 228 | if (!slab_map_register_page(page)) { |
| 229 | cbm_mem_class_remove_external(CBM_MEM_CLASS_TS_TREE, SLAB_PAGE_SIZE); |
| 230 | cbm_aligned_free(page); |
| 231 | return false; |
| 232 | } |
| 233 | s->pages = page; |
| 234 | |
| 235 | for (size_t i = 0; i < SLAB_PAGE_CHUNKS; i++) { |
| 236 | slab_free_node_t *node = |
| 237 | (slab_free_node_t *)((char *)page + SLAB_DATA_OFFSET + i * SLAB_CHUNK_SIZE); |
| 238 | node->next = s->freelist; |
| 239 | s->freelist = node; |
| 240 | } |
| 241 | return true; |
| 242 | } |
| 243 | |
| 244 | /* Refill the thread-local free list: first reclaim any cross-thread frees |
| 245 | * queued on owned pages, then grow a fresh page if still empty. */ |
no test coverage detected