Esempio n. 1
0
 * scan fails. Once the new memseg is added, it re-scans and should return
 * the new element after releasing the lock.
 */
void *
malloc_heap_alloc(struct malloc_heap *heap,
		const char *type __attribute__((unused)), size_t size, unsigned flags,
		size_t align, size_t bound)
{
	struct malloc_elem *elem;

	size = RTE_CACHE_LINE_ROUNDUP(size);
	align = RTE_CACHE_LINE_ROUNDUP(align);

	rte_spinlock_lock(&heap->lock);

	elem = find_suitable_element(heap, size, flags, align, bound);
	if (elem != NULL) {
		elem = malloc_elem_alloc(elem, size, align, bound);
		/* increase heap's count of allocated elements */
		heap->alloc_count++;
	}
	rte_spinlock_unlock(&heap->lock);

	return elem == NULL ? NULL : (void *)(&elem[1]);
}

/*
 * Function to retrieve data for heap on given socket
 */
int
malloc_heap_get_stats(struct malloc_heap *heap,
Esempio n. 2
0
}

/*
 * Main function called by malloc to allocate a block of memory from the
 * heap. It locks the free list, scans it, and adds a new memzone if the
 * scan fails. Once the new memzone is added, it re-scans and should return
 * the new element after releasing the lock.
 */
void *
malloc_heap_alloc(struct malloc_heap *heap,
		const char *type __attribute__((unused)), size_t size, unsigned align)
{
	size = RTE_CACHE_LINE_ROUNDUP(size);
	align = RTE_CACHE_LINE_ROUNDUP(align);
	rte_spinlock_lock(&heap->lock);
	struct malloc_elem *elem = find_suitable_element(heap, size, align);
	if (elem == NULL){
		if ((malloc_heap_add_memzone(heap, size, align)) == 0)
			elem = find_suitable_element(heap, size, align);
	}

	if (elem != NULL){
		elem = malloc_elem_alloc(elem, size, align);
		/* increase heap's count of allocated elements */
		heap->alloc_count++;
	}
	rte_spinlock_unlock(&heap->lock);
	return elem == NULL ? NULL : (void *)(&elem[1]);

}