MCPcopy Create free account
hub / github.com/F-Stack/f-stack / heap_alloc

Function heap_alloc

dpdk/lib/eal/common/malloc_heap.c:231–255  ·  view source on GitHub ↗

* Main function to allocate a block of memory from the heap. * It locks the free list, scans it, and adds a new memseg if the * scan fails. Once the new memseg is added, it re-scans and should return * the new element after releasing the lock. */

Source from the content-addressed store, hash-verified

229 * the new element after releasing the lock.
230 */
231static void *
232heap_alloc(struct malloc_heap *heap, const char *type __rte_unused, size_t size,
233 unsigned int flags, size_t align, size_t bound, bool contig)
234{
235 struct malloc_elem *elem;
236 size_t user_size = size;
237
238 size = RTE_CACHE_LINE_ROUNDUP(size);
239 align = RTE_CACHE_LINE_ROUNDUP(align);
240
241 /* roundup might cause an overflow */
242 if (size == 0)
243 return NULL;
244 elem = find_suitable_element(heap, size, flags, align, bound, contig);
245 if (elem != NULL) {
246 elem = malloc_elem_alloc(elem, size, align, bound, contig);
247
248 /* increase heap's count of allocated elements */
249 heap->alloc_count++;
250
251 asan_set_redzone(elem, user_size);
252 }
253
254 return elem == NULL ? NULL : (void *)(&elem[1]);
255}
256
257static void *
258heap_alloc_biggest(struct malloc_heap *heap, const char *type __rte_unused,

Callers 1

Calls 3

find_suitable_elementFunction · 0.85
malloc_elem_allocFunction · 0.85
asan_set_redzoneFunction · 0.85

Tested by

no test coverage detected