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

Function find_biggest_element

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

* Iterates through the freelist for a heap to find a free element with the * biggest size and requested alignment. Will also set size to whatever element * size that was found. * Returns null on failure, or pointer to element on success. */

Source from the content-addressed store, hash-verified

181 * Returns null on failure, or pointer to element on success.
182 */
183static struct malloc_elem *
184find_biggest_element(struct malloc_heap *heap, size_t *size,
185 unsigned int flags, size_t align, bool contig)
186{
187 struct malloc_elem *elem, *max_elem = NULL;
188 size_t idx, max_size = 0;
189
190 for (idx = 0; idx < RTE_HEAP_NUM_FREELISTS; idx++) {
191 for (elem = LIST_FIRST(&heap->free_head[idx]);
192 !!elem; elem = LIST_NEXT(elem, free_list)) {
193 size_t cur_size;
194 if ((flags & RTE_MEMZONE_SIZE_HINT_ONLY) == 0 &&
195 !check_hugepage_sz(flags,
196 elem->msl->page_sz))
197 continue;
198 if (contig) {
199 cur_size =
200 malloc_elem_find_max_iova_contig(elem,
201 align);
202 } else {
203 void *data_start = RTE_PTR_ADD(elem,
204 MALLOC_ELEM_HEADER_LEN);
205 void *data_end = RTE_PTR_ADD(elem, elem->size -
206 MALLOC_ELEM_TRAILER_LEN);
207 void *aligned = RTE_PTR_ALIGN_CEIL(data_start,
208 align);
209 /* check if aligned data start is beyond end */
210 if (aligned >= data_end)
211 continue;
212 cur_size = RTE_PTR_DIFF(data_end, aligned);
213 }
214 if (cur_size > max_size) {
215 max_size = cur_size;
216 max_elem = elem;
217 }
218 }
219 }
220
221 *size = max_size;
222 return max_elem;
223}
224
225/*
226 * Main function to allocate a block of memory from the heap.

Callers 1

heap_alloc_biggestFunction · 0.85

Calls 2

check_hugepage_szFunction · 0.85

Tested by

no test coverage detected