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.
33 * version: DPDK.L.1.2.3-3
36 #ifndef _RTE_MALLOC_H_
37 #define _RTE_MALLOC_H_
41 * RTE Malloc. This library provides methods for dynamically allocating memory
52 * This function allocates memory from the huge-page area of memory. The memory
56 * A string identifying the type of allocated objects (useful for debug
57 * purposes, such as identifying the cause of a memory leak). Can be NULL.
59 * Size (in bytes) to be allocated.
61 * If 0, the return is a pointer that is suitably aligned for any kind of
62 * variable (in the same manner as malloc()).
63 * Otherwise, the return is a pointer that is a multiple of *align*. In
64 * this case, it must be a power of two. (Minimum alignment is the
65 * cacheline size, i.e. 64-bytes)
67 * - NULL on error. Not enough memory, or invalid arguments (size is 0,
68 * align is not a power of two).
69 * - Otherwise, the pointer to the allocated object.
72 rte_malloc(const char *type, size_t size, unsigned align);
75 * Allocate zero'ed memory from the heap.
77 * Equivalent to rte_malloc() except that the memory zone is
78 * initialised with zeros.
81 * A string identifying the type of allocated objects (useful for debug
82 * purposes, such as identifying the cause of a memory leak). Can be NULL.
84 * Size (in bytes) to be allocated.
86 * If 0, the return is a pointer that is suitably aligned for any kind of
87 * variable (in the same manner as malloc()).
88 * Otherwise, the return is a pointer that is a multiple of *align*. In
89 * this case, it must obviously be a power of two. (Minimum alignment is the
90 * cacheline size, i.e. 64-bytes)
92 * - NULL on error. Not enough memory, or invalid arguments (size is 0,
93 * align is not a power of two).
94 * - Otherwise, the pointer to the allocated object.
97 rte_zmalloc(const char *type, size_t size, unsigned align);
100 * Replacement function for calloc(), using huge-page memory. Memory area is
101 * initialised with zeros.
104 * A string identifying the type of allocated objects (useful for debug
105 * purposes, such as identifying the cause of a memory leak). Can be NULL.
107 * Number of elements to be allocated.
109 * Size (in bytes) of a single element.
111 * If 0, the return is a pointer that is suitably aligned for any kind of
112 * variable (in the same manner as malloc()).
113 * Otherwise, the return is a pointer that is a multiple of *align*. In
114 * this case, it must obviously be a power of two. (Minimum alignment is the
115 * cacheline size, i.e. 64-bytes)
117 * - NULL on error. Not enough memory, or invalid arguments (size is 0,
118 * align is not a power of two).
119 * - Otherwise, the pointer to the allocated object.
122 rte_calloc(const char *type, size_t num, size_t size, unsigned align);
125 * Replacement function for realloc(), using huge-page memory. Reserved area
126 * memory is resized, preserving contents.
129 * Pointer to already allocated memory
131 * Size (in bytes) of new area. If this is 0, memory is freed.
133 * If 0, the return is a pointer that is suitably aligned for any kind of
134 * variable (in the same manner as malloc()).
135 * Otherwise, the return is a pointer that is a multiple of *align*. In
136 * this case, it must obviously be a power of two. (Minimum alignment is the
137 * cacheline size, i.e. 64-bytes)
139 * - NULL on error. Not enough memory, or invalid arguments (size is 0,
140 * align is not a power of two).
141 * - Otherwise, the pointer to the reallocated memory.
144 rte_realloc(void *ptr, size_t size, unsigned align);
147 * Frees the memory space pointed to by the provided pointer.
149 * This pointer must have been returned by a previous call to
150 * rte_malloc(), rte_zmalloc(), rte_calloc() or rte_realloc(). The behaviour of
151 * rte_free() is undefined if the pointer does not match this requirement.
153 * If the pointer is NULL, the function does nothing.
156 * The pointer to memory to be freed.
162 * If malloc debug is enabled, check a memory block for header
163 * and trailer markers to indicate that all is well with the block.
164 * If size is non-null, also return the size of the block.
167 * pointer to the start of a data block, must have been returned
168 * by a previous call to rte_malloc(), rte_zmalloc(), rte_calloc()
171 * if non-null, and memory block pointer is valid, returns the size
172 * of the memory block
174 * -1 on error, invalid pointer passed or header and trailer markers
175 * are missing or corrupted
179 rte_malloc_validate(void *ptr, size_t *size);
184 * Dump for the specified type to the console. If the type argument is
185 * NULL, all memory types will be dumped.
188 * A string identifying the type of objects to dump, or NULL
189 * to dump all objects.
192 rte_malloc_dump_stats(const char *type);
195 * Set the maximum amount of allocated memory for this type.
198 * A string identifying the type of allocated objects.
200 * The maximum amount of allocated bytes for this type.
206 rte_malloc_set_limit(const char *type, size_t max);
212 #endif /* _RTE_MALLOC_H_ */