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

Function alloc_pages_on_heap

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

this function is exposed in malloc_mp.h */

Source from the content-addressed store, hash-verified

291
292/* this function is exposed in malloc_mp.h */
293struct malloc_elem *
294alloc_pages_on_heap(struct malloc_heap *heap, uint64_t pg_sz, size_t elt_size,
295 int socket, unsigned int flags, size_t align, size_t bound,
296 bool contig, struct rte_memseg **ms, int n_segs)
297{
298 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
299 struct rte_memseg_list *msl;
300 struct malloc_elem *elem = NULL;
301 size_t alloc_sz;
302 int allocd_pages, i;
303 bool dirty = false;
304 void *ret, *map_addr;
305
306 alloc_sz = (size_t)pg_sz * n_segs;
307
308 /* first, check if we're allowed to allocate this memory */
309 if (eal_memalloc_mem_alloc_validate(socket,
310 heap->total_size + alloc_sz) < 0) {
311 RTE_LOG(DEBUG, EAL, "User has disallowed allocation\n");
312 return NULL;
313 }
314
315 allocd_pages = eal_memalloc_alloc_seg_bulk(ms, n_segs, pg_sz,
316 socket, true);
317
318 /* make sure we've allocated our pages... */
319 if (allocd_pages < 0)
320 return NULL;
321
322 map_addr = ms[0]->addr;
323 msl = rte_mem_virt2memseg_list(map_addr);
324
325 /* check if we wanted contiguous memory but didn't get it */
326 if (contig && !eal_memalloc_is_contig(msl, map_addr, alloc_sz)) {
327 RTE_LOG(DEBUG, EAL, "%s(): couldn't allocate physically contiguous space\n",
328 __func__);
329 goto fail;
330 }
331
332 /*
333 * Once we have all the memseg lists configured, if there is a dma mask
334 * set, check iova addresses are not out of range. Otherwise the device
335 * setting the dma mask could have problems with the mapped memory.
336 *
337 * There are two situations when this can happen:
338 * 1) memory initialization
339 * 2) dynamic memory allocation
340 *
341 * For 1), an error when checking dma mask implies app can not be
342 * executed. For 2) implies the new memory can not be added.
343 */
344 if (mcfg->dma_maskbits &&
345 rte_mem_check_dma_mask_thread_unsafe(mcfg->dma_maskbits)) {
346 /*
347 * Currently this can only happen if IOMMU is enabled
348 * and the address width supported by the IOMMU hw is
349 * not enough for using the memory mapped IOVAs.
350 *

Callers 2

try_expand_heap_primaryFunction · 0.85
handle_alloc_requestFunction · 0.85

Calls 11

rte_mem_virt2memseg_listFunction · 0.85
eal_memalloc_is_contigFunction · 0.85
rte_eal_iova_modeFunction · 0.85
malloc_heap_add_memoryFunction · 0.85
find_suitable_elementFunction · 0.85
rollback_expand_heapFunction · 0.85
rte_eal_using_phys_addrsFunction · 0.50

Tested by

no test coverage detected