* Allocate a block of virtual memory that is large enough to start with a * base_block_t header, followed by an object of specified size and alignment. * On success a pointer to the initialized base_block_t header is returned. */
| 157 | * On success a pointer to the initialized base_block_t header is returned. |
| 158 | */ |
| 159 | static base_block_t * |
| 160 | base_block_alloc(extent_hooks_t *extent_hooks, unsigned ind, |
| 161 | pszind_t *pind_last, size_t *extent_sn_next, size_t size, |
| 162 | size_t alignment) { |
| 163 | alignment = ALIGNMENT_CEILING(alignment, QUANTUM); |
| 164 | size_t usize = ALIGNMENT_CEILING(size, alignment); |
| 165 | size_t header_size = sizeof(base_block_t); |
| 166 | size_t gap_size = ALIGNMENT_CEILING(header_size, alignment) - |
| 167 | header_size; |
| 168 | /* |
| 169 | * Create increasingly larger blocks in order to limit the total number |
| 170 | * of disjoint virtual memory ranges. Choose the next size in the page |
| 171 | * size class series (skipping size classes that are not a multiple of |
| 172 | * HUGEPAGE), or a size large enough to satisfy the requested size and |
| 173 | * alignment, whichever is larger. |
| 174 | */ |
| 175 | size_t min_block_size = HUGEPAGE_CEILING(sz_psz2u(header_size + gap_size |
| 176 | + usize)); |
| 177 | pszind_t pind_next = (*pind_last + 1 < NPSIZES) ? *pind_last + 1 : |
| 178 | *pind_last; |
| 179 | size_t next_block_size = HUGEPAGE_CEILING(sz_pind2sz(pind_next)); |
| 180 | size_t block_size = (min_block_size > next_block_size) ? min_block_size |
| 181 | : next_block_size; |
| 182 | base_block_t *block = (base_block_t *)base_map(extent_hooks, ind, |
| 183 | block_size); |
| 184 | if (block == NULL) { |
| 185 | return NULL; |
| 186 | } |
| 187 | *pind_last = sz_psz2ind(block_size); |
| 188 | block->size = block_size; |
| 189 | block->next = NULL; |
| 190 | assert(block_size >= header_size); |
| 191 | base_extent_init(extent_sn_next, &block->extent, |
| 192 | (void *)((uintptr_t)block + header_size), block_size - header_size); |
| 193 | return block; |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | * Allocate an extent that is at least as large as specified size, with |
no test coverage detected