* attempt to resize a malloc_elem by expanding into any free space * immediately after it in memory. */
| 662 | * immediately after it in memory. |
| 663 | */ |
| 664 | int |
| 665 | malloc_elem_resize(struct malloc_elem *elem, size_t size) |
| 666 | { |
| 667 | const size_t new_size = size + elem->pad + MALLOC_ELEM_OVERHEAD; |
| 668 | |
| 669 | /* if we request a smaller size, then always return ok */ |
| 670 | if (elem->size >= new_size) { |
| 671 | asan_clear_alloczone(elem); |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | /* check if there is a next element, it's free and adjacent */ |
| 676 | if (!elem->next || elem->next->state != ELEM_FREE || |
| 677 | !next_elem_is_adjacent(elem)) |
| 678 | return -1; |
| 679 | if (elem->size + elem->next->size < new_size) |
| 680 | return -1; |
| 681 | |
| 682 | /* we now know the element fits, so remove from free list, |
| 683 | * join the two |
| 684 | */ |
| 685 | malloc_elem_free_list_remove(elem->next); |
| 686 | join_elem(elem, elem->next); |
| 687 | |
| 688 | if (elem->size - new_size >= MIN_DATA_SIZE + MALLOC_ELEM_OVERHEAD) { |
| 689 | /* now we have a big block together. Lets cut it down a bit, by splitting */ |
| 690 | struct malloc_elem *split_pt = RTE_PTR_ADD(elem, new_size); |
| 691 | split_pt = RTE_PTR_ALIGN_CEIL(split_pt, RTE_CACHE_LINE_SIZE); |
| 692 | |
| 693 | asan_clear_split_alloczone(split_pt); |
| 694 | |
| 695 | split_elem(elem, split_pt); |
| 696 | malloc_elem_free_list_insert(split_pt); |
| 697 | } |
| 698 | |
| 699 | asan_clear_alloczone(elem); |
| 700 | |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | static inline const char * |
| 705 | elem_state_to_str(enum elem_state state) |
no test coverage detected