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

Function rte_realloc_socket

dpdk/lib/eal/common/rte_malloc.c:164–210  ·  view source on GitHub ↗

* Resize allocated memory on specified heap. */

Source from the content-addressed store, hash-verified

162 * Resize allocated memory on specified heap.
163 */
164void *
165rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket)
166{
167 size_t user_size;
168
169 if (ptr == NULL)
170 return rte_malloc_socket(NULL, size, align, socket);
171
172 struct malloc_elem *elem = malloc_elem_from_data(ptr);
173 if (elem == NULL) {
174 RTE_LOG(ERR, EAL, "Error: memory corruption detected\n");
175 return NULL;
176 }
177
178 user_size = size;
179
180 size = RTE_CACHE_LINE_ROUNDUP(size), align = RTE_CACHE_LINE_ROUNDUP(align);
181
182 /* check requested socket id and alignment matches first, and if ok,
183 * see if we can resize block
184 */
185 if ((socket == SOCKET_ID_ANY ||
186 (unsigned int)socket == elem->heap->socket_id) &&
187 RTE_PTR_ALIGN(ptr, align) == ptr &&
188 malloc_heap_resize(elem, size) == 0) {
189 rte_eal_trace_mem_realloc(size, align, socket, ptr);
190
191 asan_set_redzone(elem, user_size);
192
193 return ptr;
194 }
195
196 /* either requested socket id doesn't match, alignment is off
197 * or we have no room to expand,
198 * so move the data.
199 */
200 void *new_ptr = rte_malloc_socket(NULL, size, align, socket);
201 if (new_ptr == NULL)
202 return NULL;
203 /* elem: |pad|data_elem|data|trailer| */
204 const size_t old_size = old_malloc_size(elem);
205 rte_memcpy(new_ptr, ptr, old_size < size ? old_size : size);
206 rte_free(ptr);
207
208 rte_eal_trace_mem_realloc(size, align, socket, new_ptr);
209 return new_ptr;
210}
211
212/*
213 * Resize allocated memory.

Callers 11

numa_reallocFunction · 0.85
__rte_node_stream_allocFunction · 0.85
rte_reallocFunction · 0.85
mana_mr_btree_expandFunction · 0.85
mlx5_reallocFunction · 0.85
qat_comp_build_requestFunction · 0.85
test_realloc_socketFunction · 0.85
test_realloc_numaFunction · 0.85

Calls 7

rte_malloc_socketFunction · 0.85
malloc_elem_from_dataFunction · 0.85
malloc_heap_resizeFunction · 0.85
asan_set_redzoneFunction · 0.85
old_malloc_sizeFunction · 0.85
rte_freeFunction · 0.85
rte_memcpyFunction · 0.50

Tested by 2

test_realloc_socketFunction · 0.68
test_realloc_numaFunction · 0.68