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

Function malloc_elem_join_adjacent_free

dpdk/lib/eal/common/malloc_elem.c:511–562  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

509}
510
511struct malloc_elem *
512malloc_elem_join_adjacent_free(struct malloc_elem *elem)
513{
514 /*
515 * check if next element exists, is adjacent and is free, if so join
516 * with it, need to remove from free list.
517 */
518 if (elem->next != NULL && elem->next->state == ELEM_FREE &&
519 next_elem_is_adjacent(elem)) {
520 void *erase;
521 size_t erase_len;
522
523 /* we will want to erase the trailer and header */
524 erase = RTE_PTR_SUB(elem->next, MALLOC_ELEM_TRAILER_LEN);
525 erase_len = MALLOC_ELEM_OVERHEAD + elem->next->pad;
526
527 /* remove from free list, join to this one */
528 malloc_elem_free_list_remove(elem->next);
529 join_elem(elem, elem->next);
530
531 /* erase header, trailer and pad */
532 memset(erase, MALLOC_POISON, erase_len);
533 }
534
535 /*
536 * check if prev element exists, is adjacent and is free, if so join
537 * with it, need to remove from free list.
538 */
539 if (elem->prev != NULL && elem->prev->state == ELEM_FREE &&
540 prev_elem_is_adjacent(elem)) {
541 struct malloc_elem *new_elem;
542 void *erase;
543 size_t erase_len;
544
545 /* we will want to erase trailer and header */
546 erase = RTE_PTR_SUB(elem, MALLOC_ELEM_TRAILER_LEN);
547 erase_len = MALLOC_ELEM_OVERHEAD + elem->pad;
548
549 /* remove from free list, join to this one */
550 malloc_elem_free_list_remove(elem->prev);
551
552 new_elem = elem->prev;
553 join_elem(new_elem, elem);
554
555 /* erase header, trailer and pad */
556 memset(erase, MALLOC_POISON, erase_len);
557
558 elem = new_elem;
559 }
560
561 return elem;
562}
563
564/*
565 * free a malloc_elem block by adding it to the free list. If the

Callers 2

malloc_elem_freeFunction · 0.85
malloc_heap_add_memoryFunction · 0.85

Calls 5

next_elem_is_adjacentFunction · 0.85
join_elemFunction · 0.85
memsetFunction · 0.85
prev_elem_is_adjacentFunction · 0.85

Tested by

no test coverage detected