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

Function malloc_heap_free

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

Source from the content-addressed store, hash-verified

862}
863
864int
865malloc_heap_free(struct malloc_elem *elem)
866{
867 struct malloc_heap *heap;
868 void *start, *aligned_start, *end, *aligned_end;
869 size_t len, aligned_len, page_sz;
870 struct rte_memseg_list *msl;
871 unsigned int i, n_segs, before_space, after_space;
872 int ret;
873 bool unmapped = false;
874 const struct internal_config *internal_conf =
875 eal_get_internal_configuration();
876
877 if (!malloc_elem_cookies_ok(elem) || elem->state != ELEM_BUSY)
878 return -1;
879
880 asan_clear_redzone(elem);
881
882 /* elem may be merged with previous element, so keep heap address */
883 heap = elem->heap;
884 msl = elem->msl;
885 page_sz = (size_t)msl->page_sz;
886
887 rte_spinlock_lock(&(heap->lock));
888
889 void *asan_ptr = RTE_PTR_ADD(elem, MALLOC_ELEM_HEADER_LEN + elem->pad);
890 size_t asan_data_len = elem->size - MALLOC_ELEM_OVERHEAD - elem->pad;
891
892 /* mark element as free */
893 elem->state = ELEM_FREE;
894
895 elem = malloc_elem_free(elem);
896
897 /* anything after this is a bonus */
898 ret = 0;
899
900 /* ...of which we can't avail if we are in legacy mode, or if this is an
901 * externally allocated segment.
902 */
903 if (internal_conf->legacy_mem || (msl->external > 0))
904 goto free_unlock;
905
906 /* check if we can free any memory back to the system */
907 if (elem->size < page_sz)
908 goto free_unlock;
909
910 /* if user requested to match allocations, the sizes must match - if not,
911 * we will defer freeing these hugepages until the entire original allocation
912 * can be freed
913 */
914 if (internal_conf->match_allocations && elem->size != elem->orig_size)
915 goto free_unlock;
916
917 /* probably, but let's make sure, as we may not be using up full page */
918 start = elem;
919 len = elem->size;
920 aligned_start = RTE_PTR_ALIGN_CEIL(start, page_sz);
921 end = RTE_PTR_ADD(elem, len);

Callers 2

mem_freeFunction · 0.85

Calls 15

malloc_elem_cookies_okFunction · 0.85
asan_clear_redzoneFunction · 0.85
malloc_elem_freeFunction · 0.85
rte_mem_virt2memsegFunction · 0.85
rte_mcfg_mem_write_lockFunction · 0.85
malloc_elem_hide_regionFunction · 0.85
rte_eal_process_typeFunction · 0.85
malloc_heap_free_pagesFunction · 0.85
memsetFunction · 0.85

Tested by

no test coverage detected