4 * Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifndef _RTE_MALLOC_H_
36 #define _RTE_MALLOC_H_
40 * RTE Malloc. This library provides methods for dynamically allocating memory
51 * This function allocates memory from the huge-page area of memory. The memory
55 * A string identifying the type of allocated objects (useful for debug
56 * purposes, such as identifying the cause of a memory leak). Can be NULL.
58 * Size (in bytes) to be allocated.
60 * If 0, the return is a pointer that is suitably aligned for any kind of
61 * variable (in the same manner as malloc()).
62 * Otherwise, the return is a pointer that is a multiple of *align*. In
63 * this case, it must be a power of two. (Minimum alignment is the
64 * cacheline size, i.e. 64-bytes)
66 * - NULL on error. Not enough memory, or invalid arguments (size is 0,
67 * align is not a power of two).
68 * - Otherwise, the pointer to the allocated object.
71 rte_malloc(const char *type, size_t size, unsigned align);
74 * Allocate zero'ed memory from the heap.
76 * Equivalent to rte_malloc() except that the memory zone is
77 * initialised with zeros.
80 * A string identifying the type of allocated objects (useful for debug
81 * purposes, such as identifying the cause of a memory leak). Can be NULL.
83 * Size (in bytes) to be allocated.
85 * If 0, the return is a pointer that is suitably aligned for any kind of
86 * variable (in the same manner as malloc()).
87 * Otherwise, the return is a pointer that is a multiple of *align*. In
88 * this case, it must obviously be a power of two. (Minimum alignment is the
89 * cacheline size, i.e. 64-bytes)
91 * - NULL on error. Not enough memory, or invalid arguments (size is 0,
92 * align is not a power of two).
93 * - Otherwise, the pointer to the allocated object.
96 rte_zmalloc(const char *type, size_t size, unsigned align);
99 * Replacement function for calloc(), using huge-page memory. Memory area is
100 * initialised with zeros.
103 * A string identifying the type of allocated objects (useful for debug
104 * purposes, such as identifying the cause of a memory leak). Can be NULL.
106 * Number of elements to be allocated.
108 * Size (in bytes) of a single element.
110 * If 0, the return is a pointer that is suitably aligned for any kind of
111 * variable (in the same manner as malloc()).
112 * Otherwise, the return is a pointer that is a multiple of *align*. In
113 * this case, it must obviously be a power of two. (Minimum alignment is the
114 * cacheline size, i.e. 64-bytes)
116 * - NULL on error. Not enough memory, or invalid arguments (size is 0,
117 * align is not a power of two).
118 * - Otherwise, the pointer to the allocated object.
121 rte_calloc(const char *type, size_t num, size_t size, unsigned align);
124 * Replacement function for realloc(), using huge-page memory. Reserved area
125 * memory is resized, preserving contents.
128 * Pointer to already allocated memory
130 * Size (in bytes) of new area. If this is 0, memory is freed.
132 * If 0, the return is a pointer that is suitably aligned for any kind of
133 * variable (in the same manner as malloc()).
134 * Otherwise, the return is a pointer that is a multiple of *align*. In
135 * this case, it must obviously be a power of two. (Minimum alignment is the
136 * cacheline size, i.e. 64-bytes)
138 * - NULL on error. Not enough memory, or invalid arguments (size is 0,
139 * align is not a power of two).
140 * - Otherwise, the pointer to the reallocated memory.
143 rte_realloc(void *ptr, size_t size, unsigned align);
146 * Frees the memory space pointed to by the provided pointer.
148 * This pointer must have been returned by a previous call to
149 * rte_malloc(), rte_zmalloc(), rte_calloc() or rte_realloc(). The behaviour of
150 * rte_free() is undefined if the pointer does not match this requirement.
152 * If the pointer is NULL, the function does nothing.
155 * The pointer to memory to be freed.
161 * If malloc debug is enabled, check a memory block for header
162 * and trailer markers to indicate that all is well with the block.
163 * If size is non-null, also return the size of the block.
166 * pointer to the start of a data block, must have been returned
167 * by a previous call to rte_malloc(), rte_zmalloc(), rte_calloc()
170 * if non-null, and memory block pointer is valid, returns the size
171 * of the memory block
173 * -1 on error, invalid pointer passed or header and trailer markers
174 * are missing or corrupted
178 rte_malloc_validate(void *ptr, size_t *size);
183 * Dump for the specified type to the console. If the type argument is
184 * NULL, all memory types will be dumped.
187 * A string identifying the type of objects to dump, or NULL
188 * to dump all objects.
191 rte_malloc_dump_stats(const char *type);
194 * Set the maximum amount of allocated memory for this type.
197 * A string identifying the type of allocated objects.
199 * The maximum amount of allocated bytes for this type.
205 rte_malloc_set_limit(const char *type, size_t max);
211 #endif /* _RTE_MALLOC_H_ */