4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 * Copyright(c) 2016 6WIND S.A.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifndef _RTE_MEMPOOL_H_
36 #define _RTE_MEMPOOL_H_
42 * A memory pool is an allocator of fixed-size object. It is
43 * identified by its name, and uses a ring to store free objects. It
44 * provides some other optional services, like a per-core object
45 * cache, and an alignment helper to ensure that objects are padded
46 * to spread them equally on all RAM channels, ranks, and so on.
48 * Objects owned by a mempool should never be added in another
49 * mempool. When an object is freed using rte_mempool_put() or
50 * equivalent, the object data is not modified; the user can save some
51 * meta-data in the object data and retrieve them when allocating a
54 * Note: the mempool implementation is not preemptible. An lcore must not be
55 * interrupted by another task that uses the same mempool (because it uses a
56 * ring which is not preemptible). Also, usual mempool functions like
57 * rte_mempool_get() or rte_mempool_put() are designed to be called from an EAL
58 * thread due to the internal per-lcore cache. Due to the lack of caching,
59 * rte_mempool_get() or rte_mempool_put() performance will suffer when called
60 * by non-EAL threads. Instead, non-EAL threads should call
61 * rte_mempool_generic_get() or rte_mempool_generic_put() with a user cache
62 * created with rte_mempool_cache_create().
70 #include <sys/queue.h>
72 #include <rte_spinlock.h>
74 #include <rte_debug.h>
75 #include <rte_lcore.h>
76 #include <rte_memory.h>
77 #include <rte_branch_prediction.h>
79 #include <rte_memcpy.h>
80 #include <rte_common.h>
86 #define RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL /**< Header cookie. */
87 #define RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL /**< Header cookie. */
88 #define RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL /**< Trailer cookie.*/
90 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
92 * A structure that stores the mempool statistics (per-lcore).
94 struct rte_mempool_debug_stats {
95 uint64_t put_bulk; /**< Number of puts. */
96 uint64_t put_objs; /**< Number of objects successfully put. */
97 uint64_t get_success_bulk; /**< Successful allocation number. */
98 uint64_t get_success_objs; /**< Objects successfully allocated. */
99 uint64_t get_fail_bulk; /**< Failed allocation number. */
100 uint64_t get_fail_objs; /**< Objects that failed to be allocated. */
101 } __rte_cache_aligned;
105 * A structure that stores a per-core object cache.
107 struct rte_mempool_cache {
108 uint32_t size; /**< Size of the cache */
109 uint32_t flushthresh; /**< Threshold before we flush excess elements */
110 uint32_t len; /**< Current cache count */
112 * Cache is allocated to this size to allow it to overflow in certain
113 * cases to avoid needless emptying of cache.
115 void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects */
116 } __rte_cache_aligned;
119 * A structure that stores the size of mempool elements.
121 struct rte_mempool_objsz {
122 uint32_t elt_size; /**< Size of an element. */
123 uint32_t header_size; /**< Size of header (before elt). */
124 uint32_t trailer_size; /**< Size of trailer (after elt). */
126 /**< Total size of an object (header + elt + trailer). */
129 /**< Maximum length of a memory pool's name. */
130 #define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \
131 sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1)
132 #define RTE_MEMPOOL_MZ_PREFIX "MP_"
135 #define RTE_MEMPOOL_MZ_FORMAT RTE_MEMPOOL_MZ_PREFIX "%s"
137 #define MEMPOOL_PG_SHIFT_MAX (sizeof(uintptr_t) * CHAR_BIT - 1)
139 /** Mempool over one chunk of physically continuous memory */
140 #define MEMPOOL_PG_NUM_DEFAULT 1
142 #ifndef RTE_MEMPOOL_ALIGN
143 #define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE
146 #define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1)
149 * Mempool object header structure
151 * Each object stored in mempools are prefixed by this header structure,
152 * it allows to retrieve the mempool pointer from the object and to
153 * iterate on all objects attached to a mempool. When debug is enabled,
154 * a cookie is also added in this structure preventing corruptions and
157 struct rte_mempool_objhdr {
158 STAILQ_ENTRY(rte_mempool_objhdr) next; /**< Next in list. */
159 struct rte_mempool *mp; /**< The mempool owning the object. */
162 rte_iova_t iova; /**< IO address of the object. */
163 phys_addr_t physaddr; /**< deprecated - Physical address of the object. */
165 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
166 uint64_t cookie; /**< Debug cookie. */
171 * A list of object headers type
173 STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr);
175 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
178 * Mempool object trailer structure
180 * In debug mode, each object stored in mempools are suffixed by this
181 * trailer structure containing a cookie preventing memory corruptions.
183 struct rte_mempool_objtlr {
184 uint64_t cookie; /**< Debug cookie. */
190 * A list of memory where objects are stored
192 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
195 * Callback used to free a memory chunk
197 typedef void (rte_mempool_memchunk_free_cb_t)(struct rte_mempool_memhdr *memhdr,
201 * Mempool objects memory header structure
203 * The memory chunks where objects are stored. Each chunk is virtually
204 * and physically contiguous.
206 struct rte_mempool_memhdr {
207 STAILQ_ENTRY(rte_mempool_memhdr) next; /**< Next in list. */
208 struct rte_mempool *mp; /**< The mempool owning the chunk */
209 void *addr; /**< Virtual address of the chunk */
212 rte_iova_t iova; /**< IO address of the chunk */
213 phys_addr_t phys_addr; /**< Physical address of the chunk */
215 size_t len; /**< length of the chunk */
216 rte_mempool_memchunk_free_cb_t *free_cb; /**< Free callback */
217 void *opaque; /**< Argument passed to the free callback */
221 * The RTE mempool structure.
225 * Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI
226 * compatibility requirements, it could be changed to
227 * RTE_MEMPOOL_NAMESIZE next time the ABI changes
229 char name[RTE_MEMZONE_NAMESIZE]; /**< Name of mempool. */
232 void *pool_data; /**< Ring or pool to store objects. */
233 uint64_t pool_id; /**< External mempool identifier. */
235 void *pool_config; /**< optional args for ops alloc. */
236 const struct rte_memzone *mz; /**< Memzone where pool is alloc'd. */
237 unsigned int flags; /**< Flags of the mempool. */
238 int socket_id; /**< Socket id passed at create. */
239 uint32_t size; /**< Max size of the mempool. */
241 /**< Size of per-lcore default local cache. */
243 uint32_t elt_size; /**< Size of an element. */
244 uint32_t header_size; /**< Size of header (before elt). */
245 uint32_t trailer_size; /**< Size of trailer (after elt). */
247 unsigned private_data_size; /**< Size of private data. */
249 * Index into rte_mempool_ops_table array of mempool ops
250 * structs, which contain callback function pointers.
251 * We're using an index here rather than pointers to the callbacks
252 * to facilitate any secondary processes that may want to use
257 struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */
259 uint32_t populated_size; /**< Number of populated objects. */
260 struct rte_mempool_objhdr_list elt_list; /**< List of objects in pool */
261 uint32_t nb_mem_chunks; /**< Number of memory chunks */
262 struct rte_mempool_memhdr_list mem_list; /**< List of memory chunks */
264 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
265 /** Per-lcore statistics. */
266 struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];
268 } __rte_cache_aligned;
270 #define MEMPOOL_F_NO_SPREAD 0x0001 /**< Do not spread among memory channels. */
271 #define MEMPOOL_F_NO_CACHE_ALIGN 0x0002 /**< Do not align objs on cache lines.*/
272 #define MEMPOOL_F_SP_PUT 0x0004 /**< Default put is "single-producer".*/
273 #define MEMPOOL_F_SC_GET 0x0008 /**< Default get is "single-consumer".*/
274 #define MEMPOOL_F_POOL_CREATED 0x0010 /**< Internal: pool is created. */
275 #define MEMPOOL_F_NO_PHYS_CONTIG 0x0020 /**< Don't need physically contiguous objs. */
277 * This capability flag is advertised by a mempool handler, if the whole
278 * memory area containing the objects must be physically contiguous.
279 * Note: This flag should not be passed by application.
281 #define MEMPOOL_F_CAPA_PHYS_CONTIG 0x0040
283 * This capability flag is advertised by a mempool handler. Used for a case
284 * where mempool driver wants object start address(vaddr) aligned to block
285 * size(/ total element size).
288 * - This flag should not be passed by application.
289 * Flag used for mempool driver only.
290 * - Mempool driver must also set MEMPOOL_F_CAPA_PHYS_CONTIG flag along with
291 * MEMPOOL_F_CAPA_BLK_ALIGNED_OBJECTS.
293 #define MEMPOOL_F_CAPA_BLK_ALIGNED_OBJECTS 0x0080
296 * @internal When debug is enabled, store some statistics.
299 * Pointer to the memory pool.
301 * Name of the statistics field to increment in the memory pool.
303 * Number to add to the object-oriented statistics.
305 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
306 #define __MEMPOOL_STAT_ADD(mp, name, n) do { \
307 unsigned __lcore_id = rte_lcore_id(); \
308 if (__lcore_id < RTE_MAX_LCORE) { \
309 mp->stats[__lcore_id].name##_objs += n; \
310 mp->stats[__lcore_id].name##_bulk += 1; \
314 #define __MEMPOOL_STAT_ADD(mp, name, n) do {} while(0)
318 * Calculate the size of the mempool header.
321 * Pointer to the memory pool.
323 * Size of the per-lcore cache.
325 #define MEMPOOL_HEADER_SIZE(mp, cs) \
326 (sizeof(*(mp)) + (((cs) == 0) ? 0 : \
327 (sizeof(struct rte_mempool_cache) * RTE_MAX_LCORE)))
329 /* return the header of a mempool object (internal) */
330 static inline struct rte_mempool_objhdr *__mempool_get_header(void *obj)
332 return (struct rte_mempool_objhdr *)RTE_PTR_SUB(obj,
333 sizeof(struct rte_mempool_objhdr));
337 * Return a pointer to the mempool owning this object.
340 * An object that is owned by a pool. If this is not the case,
341 * the behavior is undefined.
343 * A pointer to the mempool structure.
345 static inline struct rte_mempool *rte_mempool_from_obj(void *obj)
347 struct rte_mempool_objhdr *hdr = __mempool_get_header(obj);
351 /* return the trailer of a mempool object (internal) */
352 static inline struct rte_mempool_objtlr *__mempool_get_trailer(void *obj)
354 struct rte_mempool *mp = rte_mempool_from_obj(obj);
355 return (struct rte_mempool_objtlr *)RTE_PTR_ADD(obj, mp->elt_size);
359 * @internal Check and update cookies or panic.
362 * Pointer to the memory pool.
363 * @param obj_table_const
364 * Pointer to a table of void * pointers (objects).
366 * Index of object in object table.
368 * - 0: object is supposed to be allocated, mark it as free
369 * - 1: object is supposed to be free, mark it as allocated
370 * - 2: just check that cookie is valid (free or allocated)
372 void rte_mempool_check_cookies(const struct rte_mempool *mp,
373 void * const *obj_table_const, unsigned n, int free);
375 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
376 #define __mempool_check_cookies(mp, obj_table_const, n, free) \
377 rte_mempool_check_cookies(mp, obj_table_const, n, free)
379 #define __mempool_check_cookies(mp, obj_table_const, n, free) do {} while(0)
380 #endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
382 #define RTE_MEMPOOL_OPS_NAMESIZE 32 /**< Max length of ops struct name. */
385 * Prototype for implementation specific data provisioning function.
387 * The function should provide the implementation specific memory for
388 * use by the other mempool ops functions in a given mempool ops struct.
389 * E.g. the default ops provides an instance of the rte_ring for this purpose.
390 * it will most likely point to a different type of data structure, and
391 * will be transparent to the application programmer.
392 * This function should set mp->pool_data.
394 typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);
397 * Free the opaque private data pointed to by mp->pool_data pointer.
399 typedef void (*rte_mempool_free_t)(struct rte_mempool *mp);
402 * Enqueue an object into the external pool.
404 typedef int (*rte_mempool_enqueue_t)(struct rte_mempool *mp,
405 void * const *obj_table, unsigned int n);
408 * Dequeue an object from the external pool.
410 typedef int (*rte_mempool_dequeue_t)(struct rte_mempool *mp,
411 void **obj_table, unsigned int n);
414 * Return the number of available objects in the external pool.
416 typedef unsigned (*rte_mempool_get_count)(const struct rte_mempool *mp);
419 * Get the mempool capabilities.
421 typedef int (*rte_mempool_get_capabilities_t)(const struct rte_mempool *mp,
422 unsigned int *flags);
425 * Notify new memory area to mempool.
427 typedef int (*rte_mempool_ops_register_memory_area_t)
428 (const struct rte_mempool *mp, char *vaddr, rte_iova_t iova, size_t len);
430 /** Structure defining mempool operations structure */
431 struct rte_mempool_ops {
432 char name[RTE_MEMPOOL_OPS_NAMESIZE]; /**< Name of mempool ops struct. */
433 rte_mempool_alloc_t alloc; /**< Allocate private data. */
434 rte_mempool_free_t free; /**< Free the external pool. */
435 rte_mempool_enqueue_t enqueue; /**< Enqueue an object. */
436 rte_mempool_dequeue_t dequeue; /**< Dequeue an object. */
437 rte_mempool_get_count get_count; /**< Get qty of available objs. */
439 * Get the mempool capabilities
441 rte_mempool_get_capabilities_t get_capabilities;
443 * Notify new memory area to mempool
445 rte_mempool_ops_register_memory_area_t register_memory_area;
446 } __rte_cache_aligned;
448 #define RTE_MEMPOOL_MAX_OPS_IDX 16 /**< Max registered ops structs */
451 * Structure storing the table of registered ops structs, each of which contain
452 * the function pointers for the mempool ops functions.
453 * Each process has its own storage for this ops struct array so that
454 * the mempools can be shared across primary and secondary processes.
455 * The indices used to access the array are valid across processes, whereas
456 * any function pointers stored directly in the mempool struct would not be.
457 * This results in us simply having "ops_index" in the mempool struct.
459 struct rte_mempool_ops_table {
460 rte_spinlock_t sl; /**< Spinlock for add/delete. */
461 uint32_t num_ops; /**< Number of used ops structs in the table. */
463 * Storage for all possible ops structs.
465 struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX];
466 } __rte_cache_aligned;
468 /** Array of registered ops structs. */
469 extern struct rte_mempool_ops_table rte_mempool_ops_table;
472 * @internal Get the mempool ops struct from its index.
475 * The index of the ops struct in the ops struct table. It must be a valid
476 * index: (0 <= idx < num_ops).
478 * The pointer to the ops struct in the table.
480 static inline struct rte_mempool_ops *
481 rte_mempool_get_ops(int ops_index)
483 RTE_VERIFY((ops_index >= 0) && (ops_index < RTE_MEMPOOL_MAX_OPS_IDX));
485 return &rte_mempool_ops_table.ops[ops_index];
489 * @internal Wrapper for mempool_ops alloc callback.
492 * Pointer to the memory pool.
494 * - 0: Success; successfully allocated mempool pool_data.
495 * - <0: Error; code of alloc function.
498 rte_mempool_ops_alloc(struct rte_mempool *mp);
501 * @internal Wrapper for mempool_ops dequeue callback.
504 * Pointer to the memory pool.
506 * Pointer to a table of void * pointers (objects).
508 * Number of objects to get.
510 * - 0: Success; got n objects.
511 * - <0: Error; code of dequeue function.
514 rte_mempool_ops_dequeue_bulk(struct rte_mempool *mp,
515 void **obj_table, unsigned n)
517 struct rte_mempool_ops *ops;
519 ops = rte_mempool_get_ops(mp->ops_index);
520 return ops->dequeue(mp, obj_table, n);
524 * @internal wrapper for mempool_ops enqueue callback.
527 * Pointer to the memory pool.
529 * Pointer to a table of void * pointers (objects).
531 * Number of objects to put.
533 * - 0: Success; n objects supplied.
534 * - <0: Error; code of enqueue function.
537 rte_mempool_ops_enqueue_bulk(struct rte_mempool *mp, void * const *obj_table,
540 struct rte_mempool_ops *ops;
542 ops = rte_mempool_get_ops(mp->ops_index);
543 return ops->enqueue(mp, obj_table, n);
547 * @internal wrapper for mempool_ops get_count callback.
550 * Pointer to the memory pool.
552 * The number of available objects in the external pool.
555 rte_mempool_ops_get_count(const struct rte_mempool *mp);
558 * @internal wrapper for mempool_ops get_capabilities callback.
561 * Pointer to the memory pool.
563 * Pointer to the mempool flags.
565 * - 0: Success; The mempool driver has advertised his pool capabilities in
567 * - -ENOTSUP - doesn't support get_capabilities ops (valid case).
568 * - Otherwise, pool create fails.
571 rte_mempool_ops_get_capabilities(const struct rte_mempool *mp,
572 unsigned int *flags);
574 * @internal wrapper for mempool_ops register_memory_area callback.
575 * API to notify the mempool handler when a new memory area is added to pool.
578 * Pointer to the memory pool.
580 * Pointer to the buffer virtual address.
582 * Pointer to the buffer IO address.
587 * - -ENOTSUP - doesn't support register_memory_area ops (valid error case).
588 * - Otherwise, rte_mempool_populate_phys fails thus pool create fails.
591 rte_mempool_ops_register_memory_area(const struct rte_mempool *mp,
592 char *vaddr, rte_iova_t iova, size_t len);
595 * @internal wrapper for mempool_ops free callback.
598 * Pointer to the memory pool.
601 rte_mempool_ops_free(struct rte_mempool *mp);
604 * Set the ops of a mempool.
606 * This can only be done on a mempool that is not populated, i.e. just after
607 * a call to rte_mempool_create_empty().
610 * Pointer to the memory pool.
612 * Name of the ops structure to use for this mempool.
614 * Opaque data that can be passed by the application to the ops functions.
616 * - 0: Success; the mempool is now using the requested ops functions.
617 * - -EINVAL - Invalid ops struct name provided.
618 * - -EEXIST - mempool already has an ops struct assigned.
621 rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
625 * Register mempool operations.
628 * Pointer to an ops structure to register.
630 * - >=0: Success; return the index of the ops struct in the table.
631 * - -EINVAL - some missing callbacks while registering ops struct.
632 * - -ENOSPC - the maximum number of ops structs has been reached.
634 int rte_mempool_register_ops(const struct rte_mempool_ops *ops);
637 * Macro to statically register the ops of a mempool handler.
638 * Note that the rte_mempool_register_ops fails silently here when
639 * more than RTE_MEMPOOL_MAX_OPS_IDX is registered.
641 #define MEMPOOL_REGISTER_OPS(ops) \
642 void mp_hdlr_init_##ops(void); \
643 void __attribute__((constructor, used)) mp_hdlr_init_##ops(void)\
645 rte_mempool_register_ops(&ops); \
649 * An object callback function for mempool.
651 * Used by rte_mempool_create() and rte_mempool_obj_iter().
653 typedef void (rte_mempool_obj_cb_t)(struct rte_mempool *mp,
654 void *opaque, void *obj, unsigned obj_idx);
655 typedef rte_mempool_obj_cb_t rte_mempool_obj_ctor_t; /* compat */
658 * A memory callback function for mempool.
660 * Used by rte_mempool_mem_iter().
662 typedef void (rte_mempool_mem_cb_t)(struct rte_mempool *mp,
663 void *opaque, struct rte_mempool_memhdr *memhdr,
667 * A mempool constructor callback function.
669 * Arguments are the mempool and the opaque pointer given by the user in
670 * rte_mempool_create().
672 typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);
675 * Create a new mempool named *name* in memory.
677 * This function uses ``rte_memzone_reserve()`` to allocate memory. The
678 * pool contains n elements of elt_size. Its size is set to n.
681 * The name of the mempool.
683 * The number of elements in the mempool. The optimum size (in terms of
684 * memory usage) for a mempool is when n is a power of two minus one:
687 * The size of each element.
689 * If cache_size is non-zero, the rte_mempool library will try to
690 * limit the accesses to the common lockless pool, by maintaining a
691 * per-lcore object cache. This argument must be lower or equal to
692 * CONFIG_RTE_MEMPOOL_CACHE_MAX_SIZE and n / 1.5. It is advised to choose
693 * cache_size to have "n modulo cache_size == 0": if this is
694 * not the case, some elements will always stay in the pool and will
695 * never be used. The access to the per-lcore table is of course
696 * faster than the multi-producer/consumer pool. The cache can be
697 * disabled if the cache_size argument is set to 0; it can be useful to
698 * avoid losing objects in cache.
699 * @param private_data_size
700 * The size of the private data appended after the mempool
701 * structure. This is useful for storing some private data after the
702 * mempool structure, as is done for rte_mbuf_pool for example.
704 * A function pointer that is called for initialization of the pool,
705 * before object initialization. The user can initialize the private
706 * data in this function if needed. This parameter can be NULL if
709 * An opaque pointer to data that can be used in the mempool
710 * constructor function.
712 * A function pointer that is called for each object at
713 * initialization of the pool. The user can set some meta data in
714 * objects if needed. This parameter can be NULL if not needed.
715 * The obj_init() function takes the mempool pointer, the init_arg,
716 * the object pointer and the object number as parameters.
717 * @param obj_init_arg
718 * An opaque pointer to data that can be used as an argument for
719 * each call to the object constructor function.
721 * The *socket_id* argument is the socket identifier in the case of
722 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
723 * constraint for the reserved zone.
725 * The *flags* arguments is an OR of following flags:
726 * - MEMPOOL_F_NO_SPREAD: By default, objects addresses are spread
727 * between channels in RAM: the pool allocator will add padding
728 * between objects depending on the hardware configuration. See
729 * Memory alignment constraints for details. If this flag is set,
730 * the allocator will just align them to a cache line.
731 * - MEMPOOL_F_NO_CACHE_ALIGN: By default, the returned objects are
732 * cache-aligned. This flag removes this constraint, and no
733 * padding will be present between objects. This flag implies
734 * MEMPOOL_F_NO_SPREAD.
735 * - MEMPOOL_F_SP_PUT: If this flag is set, the default behavior
736 * when using rte_mempool_put() or rte_mempool_put_bulk() is
737 * "single-producer". Otherwise, it is "multi-producers".
738 * - MEMPOOL_F_SC_GET: If this flag is set, the default behavior
739 * when using rte_mempool_get() or rte_mempool_get_bulk() is
740 * "single-consumer". Otherwise, it is "multi-consumers".
741 * - MEMPOOL_F_NO_PHYS_CONTIG: If set, allocated objects won't
742 * necessarily be contiguous in physical memory.
744 * The pointer to the new allocated mempool, on success. NULL on error
745 * with rte_errno set appropriately. Possible rte_errno values include:
746 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
747 * - E_RTE_SECONDARY - function was called from a secondary process instance
748 * - EINVAL - cache size provided is too large
749 * - ENOSPC - the maximum number of memzones has already been allocated
750 * - EEXIST - a memzone with the same name already exists
751 * - ENOMEM - no appropriate memory area found in which to create memzone
754 rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
755 unsigned cache_size, unsigned private_data_size,
756 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
757 rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
758 int socket_id, unsigned flags);
761 * Create a new mempool named *name* in memory.
763 * The pool contains n elements of elt_size. Its size is set to n.
764 * This function uses ``memzone_reserve()`` to allocate the mempool header
765 * (and the objects if vaddr is NULL).
766 * Depending on the input parameters, mempool elements can be either allocated
767 * together with the mempool header, or an externally provided memory buffer
768 * could be used to store mempool objects. In later case, that external
769 * memory buffer can consist of set of disjoint physical pages.
772 * The name of the mempool.
774 * The number of elements in the mempool. The optimum size (in terms of
775 * memory usage) for a mempool is when n is a power of two minus one:
778 * The size of each element.
780 * Size of the cache. See rte_mempool_create() for details.
781 * @param private_data_size
782 * The size of the private data appended after the mempool
783 * structure. This is useful for storing some private data after the
784 * mempool structure, as is done for rte_mbuf_pool for example.
786 * A function pointer that is called for initialization of the pool,
787 * before object initialization. The user can initialize the private
788 * data in this function if needed. This parameter can be NULL if
791 * An opaque pointer to data that can be used in the mempool
792 * constructor function.
794 * A function called for each object at initialization of the pool.
795 * See rte_mempool_create() for details.
796 * @param obj_init_arg
797 * An opaque pointer passed to the object constructor function.
799 * The *socket_id* argument is the socket identifier in the case of
800 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
801 * constraint for the reserved zone.
803 * Flags controlling the behavior of the mempool. See
804 * rte_mempool_create() for details.
806 * Virtual address of the externally allocated memory buffer.
807 * Will be used to store mempool objects.
809 * Array of IO addresses of the pages that comprises given memory buffer.
811 * Number of elements in the iova array.
813 * LOG2 of the physical pages size.
815 * The pointer to the new allocated mempool, on success. NULL on error
816 * with rte_errno set appropriately. See rte_mempool_create() for details.
819 rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
820 unsigned cache_size, unsigned private_data_size,
821 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
822 rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
823 int socket_id, unsigned flags, void *vaddr,
824 const rte_iova_t iova[], uint32_t pg_num, uint32_t pg_shift);
827 * Create an empty mempool
829 * The mempool is allocated and initialized, but it is not populated: no
830 * memory is allocated for the mempool elements. The user has to call
831 * rte_mempool_populate_*() to add memory chunks to the pool. Once
832 * populated, the user may also want to initialize each object with
833 * rte_mempool_obj_iter().
836 * The name of the mempool.
838 * The maximum number of elements that can be added in the mempool.
839 * The optimum size (in terms of memory usage) for a mempool is when n
840 * is a power of two minus one: n = (2^q - 1).
842 * The size of each element.
844 * Size of the cache. See rte_mempool_create() for details.
845 * @param private_data_size
846 * The size of the private data appended after the mempool
847 * structure. This is useful for storing some private data after the
848 * mempool structure, as is done for rte_mbuf_pool for example.
850 * The *socket_id* argument is the socket identifier in the case of
851 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
852 * constraint for the reserved zone.
854 * Flags controlling the behavior of the mempool. See
855 * rte_mempool_create() for details.
857 * The pointer to the new allocated mempool, on success. NULL on error
858 * with rte_errno set appropriately. See rte_mempool_create() for details.
861 rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
862 unsigned cache_size, unsigned private_data_size,
863 int socket_id, unsigned flags);
867 * Unlink the mempool from global list, free the memory chunks, and all
868 * memory referenced by the mempool. The objects must not be used by
869 * other cores as they will be freed.
872 * A pointer to the mempool structure.
875 rte_mempool_free(struct rte_mempool *mp);
878 * Add physically contiguous memory for objects in the pool at init
880 * Add a virtually and physically contiguous memory chunk in the pool
881 * where objects can be instantiated.
883 * If the given physical address is unknown (paddr = RTE_BAD_PHYS_ADDR),
884 * the chunk doesn't need to be physically contiguous (only virtually),
885 * and allocated objects may span two pages.
888 * A pointer to the mempool structure.
890 * The virtual address of memory that should be used to store objects.
892 * The physical address
894 * The length of memory in bytes.
896 * The callback used to free this chunk when destroying the mempool.
898 * An opaque argument passed to free_cb.
900 * The number of objects added on success.
901 * On error, the chunk is not added in the memory list of the
902 * mempool and a negative errno is returned.
904 int rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr,
905 phys_addr_t paddr, size_t len, rte_mempool_memchunk_free_cb_t *free_cb,
909 * Add physical memory for objects in the pool at init
911 * Add a virtually contiguous memory chunk in the pool where objects can
912 * be instantiated. The physical addresses corresponding to the virtual
913 * area are described in paddr[], pg_num, pg_shift.
916 * A pointer to the mempool structure.
918 * The virtual address of memory that should be used to store objects.
920 * An array of physical addresses of each page composing the virtual
923 * Number of elements in the paddr array.
925 * LOG2 of the physical pages size.
927 * The callback used to free this chunk when destroying the mempool.
929 * An opaque argument passed to free_cb.
931 * The number of objects added on success.
932 * On error, the chunks are not added in the memory list of the
933 * mempool and a negative errno is returned.
935 int rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr,
936 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift,
937 rte_mempool_memchunk_free_cb_t *free_cb, void *opaque);
940 * Add virtually contiguous memory for objects in the pool at init
942 * Add a virtually contiguous memory chunk in the pool where objects can
946 * A pointer to the mempool structure.
948 * The virtual address of memory that should be used to store objects.
949 * Must be page-aligned.
951 * The length of memory in bytes. Must be page-aligned.
953 * The size of memory pages in this virtual area.
955 * The callback used to free this chunk when destroying the mempool.
957 * An opaque argument passed to free_cb.
959 * The number of objects added on success.
960 * On error, the chunk is not added in the memory list of the
961 * mempool and a negative errno is returned.
964 rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
965 size_t len, size_t pg_sz, rte_mempool_memchunk_free_cb_t *free_cb,
969 * Add memory for objects in the pool at init
971 * This is the default function used by rte_mempool_create() to populate
972 * the mempool. It adds memory allocated using rte_memzone_reserve().
975 * A pointer to the mempool structure.
977 * The number of objects added on success.
978 * On error, the chunk is not added in the memory list of the
979 * mempool and a negative errno is returned.
981 int rte_mempool_populate_default(struct rte_mempool *mp);
984 * Add memory from anonymous mapping for objects in the pool at init
986 * This function mmap an anonymous memory zone that is locked in
987 * memory to store the objects of the mempool.
990 * A pointer to the mempool structure.
992 * The number of objects added on success.
993 * On error, the chunk is not added in the memory list of the
994 * mempool and a negative errno is returned.
996 int rte_mempool_populate_anon(struct rte_mempool *mp);
999 * Call a function for each mempool element
1001 * Iterate across all objects attached to a rte_mempool and call the
1002 * callback function on it.
1005 * A pointer to an initialized mempool.
1007 * A function pointer that is called for each object.
1009 * An opaque pointer passed to the callback function.
1011 * Number of objects iterated.
1013 uint32_t rte_mempool_obj_iter(struct rte_mempool *mp,
1014 rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg);
1017 * Call a function for each mempool memory chunk
1019 * Iterate across all memory chunks attached to a rte_mempool and call
1020 * the callback function on it.
1023 * A pointer to an initialized mempool.
1025 * A function pointer that is called for each memory chunk.
1027 * An opaque pointer passed to the callback function.
1029 * Number of memory chunks iterated.
1031 uint32_t rte_mempool_mem_iter(struct rte_mempool *mp,
1032 rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg);
1035 * Dump the status of the mempool to a file.
1038 * A pointer to a file for output
1040 * A pointer to the mempool structure.
1042 void rte_mempool_dump(FILE *f, struct rte_mempool *mp);
1045 * Create a user-owned mempool cache.
1047 * This can be used by non-EAL threads to enable caching when they
1048 * interact with a mempool.
1051 * The size of the mempool cache. See rte_mempool_create()'s cache_size
1052 * parameter description for more information. The same limits and
1053 * considerations apply here too.
1055 * The socket identifier in the case of NUMA. The value can be
1056 * SOCKET_ID_ANY if there is no NUMA constraint for the reserved zone.
1058 struct rte_mempool_cache *
1059 rte_mempool_cache_create(uint32_t size, int socket_id);
1062 * Free a user-owned mempool cache.
1065 * A pointer to the mempool cache.
1068 rte_mempool_cache_free(struct rte_mempool_cache *cache);
1071 * Flush a user-owned mempool cache to the specified mempool.
1074 * A pointer to the mempool cache.
1076 * A pointer to the mempool.
1078 static __rte_always_inline void
1079 rte_mempool_cache_flush(struct rte_mempool_cache *cache,
1080 struct rte_mempool *mp)
1082 rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
1087 * Get a pointer to the per-lcore default mempool cache.
1090 * A pointer to the mempool structure.
1092 * The logical core id.
1094 * A pointer to the mempool cache or NULL if disabled or non-EAL thread.
1096 static __rte_always_inline struct rte_mempool_cache *
1097 rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
1099 if (mp->cache_size == 0)
1102 if (lcore_id >= RTE_MAX_LCORE)
1105 return &mp->local_cache[lcore_id];
1109 * @internal Put several objects back in the mempool; used internally.
1111 * A pointer to the mempool structure.
1113 * A pointer to a table of void * pointers (objects).
1115 * The number of objects to store back in the mempool, must be strictly
1118 * A pointer to a mempool cache structure. May be NULL if not needed.
1120 static __rte_always_inline void
1121 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1122 unsigned int n, struct rte_mempool_cache *cache)
1126 /* increment stat now, adding in mempool always success */
1127 __MEMPOOL_STAT_ADD(mp, put, n);
1129 /* No cache provided or if put would overflow mem allocated for cache */
1130 if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1133 cache_objs = &cache->objs[cache->len];
1136 * The cache follows the following algorithm
1137 * 1. Add the objects to the cache
1138 * 2. Anything greater than the cache min value (if it crosses the
1139 * cache flush threshold) is flushed to the ring.
1142 /* Add elements back into the cache */
1143 rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
1147 if (cache->len >= cache->flushthresh) {
1148 rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
1149 cache->len - cache->size);
1150 cache->len = cache->size;
1157 /* push remaining objects in ring */
1158 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
1159 if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1160 rte_panic("cannot put objects in mempool\n");
1162 rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1168 * Put several objects back in the mempool.
1171 * A pointer to the mempool structure.
1173 * A pointer to a table of void * pointers (objects).
1175 * The number of objects to add in the mempool from the obj_table.
1177 * A pointer to a mempool cache structure. May be NULL if not needed.
1179 static __rte_always_inline void
1180 rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1181 unsigned int n, struct rte_mempool_cache *cache)
1183 __mempool_check_cookies(mp, obj_table, n, 0);
1184 __mempool_generic_put(mp, obj_table, n, cache);
1188 * Put several objects back in the mempool.
1190 * This function calls the multi-producer or the single-producer
1191 * version depending on the default behavior that was specified at
1192 * mempool creation time (see flags).
1195 * A pointer to the mempool structure.
1197 * A pointer to a table of void * pointers (objects).
1199 * The number of objects to add in the mempool from obj_table.
1201 static __rte_always_inline void
1202 rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
1205 struct rte_mempool_cache *cache;
1206 cache = rte_mempool_default_cache(mp, rte_lcore_id());
1207 rte_mempool_generic_put(mp, obj_table, n, cache);
1211 * Put one object back in the mempool.
1213 * This function calls the multi-producer or the single-producer
1214 * version depending on the default behavior that was specified at
1215 * mempool creation time (see flags).
1218 * A pointer to the mempool structure.
1220 * A pointer to the object to be added.
1222 static __rte_always_inline void
1223 rte_mempool_put(struct rte_mempool *mp, void *obj)
1225 rte_mempool_put_bulk(mp, &obj, 1);
1229 * @internal Get several objects from the mempool; used internally.
1231 * A pointer to the mempool structure.
1233 * A pointer to a table of void * pointers (objects).
1235 * The number of objects to get, must be strictly positive.
1237 * A pointer to a mempool cache structure. May be NULL if not needed.
1239 * - >=0: Success; number of objects supplied.
1240 * - <0: Error; code of ring dequeue function.
1242 static __rte_always_inline int
1243 __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1244 unsigned int n, struct rte_mempool_cache *cache)
1247 uint32_t index, len;
1250 /* No cache provided or cannot be satisfied from cache */
1251 if (unlikely(cache == NULL || n >= cache->size))
1254 cache_objs = cache->objs;
1256 /* Can this be satisfied from the cache? */
1257 if (cache->len < n) {
1258 /* No. Backfill the cache first, and then fill from it */
1259 uint32_t req = n + (cache->size - cache->len);
1261 /* How many do we require i.e. number to fill the cache + the request */
1262 ret = rte_mempool_ops_dequeue_bulk(mp,
1263 &cache->objs[cache->len], req);
1264 if (unlikely(ret < 0)) {
1266 * In the offchance that we are buffer constrained,
1267 * where we are not able to allocate cache + n, go to
1268 * the ring directly. If that fails, we are truly out of
1277 /* Now fill in the response ... */
1278 for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
1279 *obj_table = cache_objs[len];
1283 __MEMPOOL_STAT_ADD(mp, get_success, n);
1289 /* get remaining objects from ring */
1290 ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, n);
1293 __MEMPOOL_STAT_ADD(mp, get_fail, n);
1295 __MEMPOOL_STAT_ADD(mp, get_success, n);
1301 * Get several objects from the mempool.
1303 * If cache is enabled, objects will be retrieved first from cache,
1304 * subsequently from the common pool. Note that it can return -ENOENT when
1305 * the local cache and common pool are empty, even if cache from other
1309 * A pointer to the mempool structure.
1311 * A pointer to a table of void * pointers (objects) that will be filled.
1313 * The number of objects to get from mempool to obj_table.
1315 * A pointer to a mempool cache structure. May be NULL if not needed.
1317 * - 0: Success; objects taken.
1318 * - -ENOENT: Not enough entries in the mempool; no object is retrieved.
1320 static __rte_always_inline int
1321 rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1322 unsigned int n, struct rte_mempool_cache *cache)
1325 ret = __mempool_generic_get(mp, obj_table, n, cache);
1327 __mempool_check_cookies(mp, obj_table, n, 1);
1332 * Get several objects from the mempool.
1334 * This function calls the multi-consumers or the single-consumer
1335 * version, depending on the default behaviour that was specified at
1336 * mempool creation time (see flags).
1338 * If cache is enabled, objects will be retrieved first from cache,
1339 * subsequently from the common pool. Note that it can return -ENOENT when
1340 * the local cache and common pool are empty, even if cache from other
1344 * A pointer to the mempool structure.
1346 * A pointer to a table of void * pointers (objects) that will be filled.
1348 * The number of objects to get from the mempool to obj_table.
1350 * - 0: Success; objects taken
1351 * - -ENOENT: Not enough entries in the mempool; no object is retrieved.
1353 static __rte_always_inline int
1354 rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
1356 struct rte_mempool_cache *cache;
1357 cache = rte_mempool_default_cache(mp, rte_lcore_id());
1358 return rte_mempool_generic_get(mp, obj_table, n, cache);
1362 * Get one object from the mempool.
1364 * This function calls the multi-consumers or the single-consumer
1365 * version, depending on the default behavior that was specified at
1366 * mempool creation (see flags).
1368 * If cache is enabled, objects will be retrieved first from cache,
1369 * subsequently from the common pool. Note that it can return -ENOENT when
1370 * the local cache and common pool are empty, even if cache from other
1374 * A pointer to the mempool structure.
1376 * A pointer to a void * pointer (object) that will be filled.
1378 * - 0: Success; objects taken.
1379 * - -ENOENT: Not enough entries in the mempool; no object is retrieved.
1381 static __rte_always_inline int
1382 rte_mempool_get(struct rte_mempool *mp, void **obj_p)
1384 return rte_mempool_get_bulk(mp, obj_p, 1);
1388 * Return the number of entries in the mempool.
1390 * When cache is enabled, this function has to browse the length of
1391 * all lcores, so it should not be used in a data path, but only for
1392 * debug purposes. User-owned mempool caches are not accounted for.
1395 * A pointer to the mempool structure.
1397 * The number of entries in the mempool.
1399 unsigned int rte_mempool_avail_count(const struct rte_mempool *mp);
1402 * Return the number of elements which have been allocated from the mempool
1404 * When cache is enabled, this function has to browse the length of
1405 * all lcores, so it should not be used in a data path, but only for
1409 * A pointer to the mempool structure.
1411 * The number of free entries in the mempool.
1414 rte_mempool_in_use_count(const struct rte_mempool *mp);
1417 * Test if the mempool is full.
1419 * When cache is enabled, this function has to browse the length of all
1420 * lcores, so it should not be used in a data path, but only for debug
1421 * purposes. User-owned mempool caches are not accounted for.
1424 * A pointer to the mempool structure.
1426 * - 1: The mempool is full.
1427 * - 0: The mempool is not full.
1430 rte_mempool_full(const struct rte_mempool *mp)
1432 return !!(rte_mempool_avail_count(mp) == mp->size);
1436 * Test if the mempool is empty.
1438 * When cache is enabled, this function has to browse the length of all
1439 * lcores, so it should not be used in a data path, but only for debug
1440 * purposes. User-owned mempool caches are not accounted for.
1443 * A pointer to the mempool structure.
1445 * - 1: The mempool is empty.
1446 * - 0: The mempool is not empty.
1449 rte_mempool_empty(const struct rte_mempool *mp)
1451 return !!(rte_mempool_avail_count(mp) == 0);
1455 * Return the IO address of elt, which is an element of the pool mp.
1458 * A pointer (virtual address) to the element of the pool.
1460 * The IO address of the elt element.
1461 * If the mempool was created with MEMPOOL_F_NO_PHYS_CONTIG, the
1462 * returned value is RTE_BAD_IOVA.
1464 static inline rte_iova_t
1465 rte_mempool_virt2iova(const void *elt)
1467 const struct rte_mempool_objhdr *hdr;
1468 hdr = (const struct rte_mempool_objhdr *)RTE_PTR_SUB(elt,
1474 static inline phys_addr_t
1475 rte_mempool_virt2phy(__rte_unused const struct rte_mempool *mp, const void *elt)
1477 return rte_mempool_virt2iova(elt);
1481 * Check the consistency of mempool objects.
1483 * Verify the coherency of fields in the mempool structure. Also check
1484 * that the cookies of mempool objects (even the ones that are not
1485 * present in pool) have a correct value. If not, a panic will occur.
1488 * A pointer to the mempool structure.
1490 void rte_mempool_audit(struct rte_mempool *mp);
1493 * Return a pointer to the private data in an mempool structure.
1496 * A pointer to the mempool structure.
1498 * A pointer to the private data.
1500 static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
1503 MEMPOOL_HEADER_SIZE(mp, mp->cache_size);
1507 * Dump the status of all mempools on the console
1510 * A pointer to a file for output
1512 void rte_mempool_list_dump(FILE *f);
1515 * Search a mempool from its name
1518 * The name of the mempool.
1520 * The pointer to the mempool matching the name, or NULL if not found.
1522 * with rte_errno set appropriately. Possible rte_errno values include:
1523 * - ENOENT - required entry not available to return.
1526 struct rte_mempool *rte_mempool_lookup(const char *name);
1529 * Get the header, trailer and total size of a mempool element.
1531 * Given a desired size of the mempool element and mempool flags,
1532 * calculates header, trailer, body and total sizes of the mempool object.
1535 * The size of each element, without header and trailer.
1537 * The flags used for the mempool creation.
1538 * Consult rte_mempool_create() for more information about possible values.
1539 * The size of each element.
1541 * The calculated detailed size the mempool object. May be NULL.
1543 * Total size of the mempool object.
1545 uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
1546 struct rte_mempool_objsz *sz);
1549 * Get the size of memory required to store mempool elements.
1551 * Calculate the maximum amount of memory required to store given number
1552 * of objects. Assume that the memory buffer will be aligned at page
1555 * Note that if object size is bigger then page size, then it assumes
1556 * that pages are grouped in subsets of physically continuous pages big
1557 * enough to store at least one object.
1560 * Number of elements.
1561 * @param total_elt_sz
1562 * The size of each element, including header and trailer, as returned
1563 * by rte_mempool_calc_obj_size().
1565 * LOG2 of the physical pages size. If set to 0, ignore page boundaries.
1567 * The mempool flags.
1569 * Required memory size aligned at page boundary.
1571 size_t rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz,
1572 uint32_t pg_shift, unsigned int flags);
1575 * Get the size of memory required to store mempool elements.
1577 * Calculate how much memory would be actually required with the given
1578 * memory footprint to store required number of objects.
1581 * Virtual address of the externally allocated memory buffer.
1582 * Will be used to store mempool objects.
1584 * Number of elements.
1585 * @param total_elt_sz
1586 * The size of each element, including header and trailer, as returned
1587 * by rte_mempool_calc_obj_size().
1589 * Array of IO addresses of the pages that comprises given memory buffer.
1591 * Number of elements in the iova array.
1593 * LOG2 of the physical pages size.
1595 * The mempool flags.
1597 * On success, the number of bytes needed to store given number of
1598 * objects, aligned to the given page size. If the provided memory
1599 * buffer is too small, return a negative value whose absolute value
1600 * is the actual number of elements that can be stored in that buffer.
1602 ssize_t rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num,
1603 size_t total_elt_sz, const rte_iova_t iova[], uint32_t pg_num,
1604 uint32_t pg_shift, unsigned int flags);
1607 * Walk list of all memory pools
1612 * Argument passed to iterator
1614 void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),
1621 #endif /* _RTE_MEMPOOL_H_ */