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 IO address is unknown (iova = RTE_BAD_IOVA),
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.
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_iova(struct rte_mempool *mp, char *vaddr,
905 rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb,
909 int rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr,
910 phys_addr_t paddr, size_t len, rte_mempool_memchunk_free_cb_t *free_cb,
914 * Add physical memory for objects in the pool at init
916 * Add a virtually contiguous memory chunk in the pool where objects can
917 * be instantiated. The IO addresses corresponding to the virtual
918 * area are described in iova[], pg_num, pg_shift.
921 * A pointer to the mempool structure.
923 * The virtual address of memory that should be used to store objects.
925 * An array of IO addresses of each page composing the virtual area.
927 * Number of elements in the iova array.
929 * LOG2 of the physical pages size.
931 * The callback used to free this chunk when destroying the mempool.
933 * An opaque argument passed to free_cb.
935 * The number of objects added on success.
936 * On error, the chunks are not added in the memory list of the
937 * mempool and a negative errno is returned.
939 int rte_mempool_populate_iova_tab(struct rte_mempool *mp, char *vaddr,
940 const rte_iova_t iova[], uint32_t pg_num, uint32_t pg_shift,
941 rte_mempool_memchunk_free_cb_t *free_cb, void *opaque);
944 int rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr,
945 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift,
946 rte_mempool_memchunk_free_cb_t *free_cb, void *opaque);
949 * Add virtually contiguous memory for objects in the pool at init
951 * Add a virtually contiguous memory chunk in the pool where objects can
955 * A pointer to the mempool structure.
957 * The virtual address of memory that should be used to store objects.
958 * Must be page-aligned.
960 * The length of memory in bytes. Must be page-aligned.
962 * The size of memory pages in this virtual area.
964 * The callback used to free this chunk when destroying the mempool.
966 * An opaque argument passed to free_cb.
968 * The number of objects added on success.
969 * On error, the chunk is not added in the memory list of the
970 * mempool and a negative errno is returned.
973 rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
974 size_t len, size_t pg_sz, rte_mempool_memchunk_free_cb_t *free_cb,
978 * Add memory for objects in the pool at init
980 * This is the default function used by rte_mempool_create() to populate
981 * the mempool. It adds memory allocated using rte_memzone_reserve().
984 * A pointer to the mempool structure.
986 * The number of objects added on success.
987 * On error, the chunk is not added in the memory list of the
988 * mempool and a negative errno is returned.
990 int rte_mempool_populate_default(struct rte_mempool *mp);
993 * Add memory from anonymous mapping for objects in the pool at init
995 * This function mmap an anonymous memory zone that is locked in
996 * memory to store the objects of the mempool.
999 * A pointer to the mempool structure.
1001 * The number of objects added on success.
1002 * On error, the chunk is not added in the memory list of the
1003 * mempool and a negative errno is returned.
1005 int rte_mempool_populate_anon(struct rte_mempool *mp);
1008 * Call a function for each mempool element
1010 * Iterate across all objects attached to a rte_mempool and call the
1011 * callback function on it.
1014 * A pointer to an initialized mempool.
1016 * A function pointer that is called for each object.
1018 * An opaque pointer passed to the callback function.
1020 * Number of objects iterated.
1022 uint32_t rte_mempool_obj_iter(struct rte_mempool *mp,
1023 rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg);
1026 * Call a function for each mempool memory chunk
1028 * Iterate across all memory chunks attached to a rte_mempool and call
1029 * the callback function on it.
1032 * A pointer to an initialized mempool.
1034 * A function pointer that is called for each memory chunk.
1036 * An opaque pointer passed to the callback function.
1038 * Number of memory chunks iterated.
1040 uint32_t rte_mempool_mem_iter(struct rte_mempool *mp,
1041 rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg);
1044 * Dump the status of the mempool to a file.
1047 * A pointer to a file for output
1049 * A pointer to the mempool structure.
1051 void rte_mempool_dump(FILE *f, struct rte_mempool *mp);
1054 * Create a user-owned mempool cache.
1056 * This can be used by non-EAL threads to enable caching when they
1057 * interact with a mempool.
1060 * The size of the mempool cache. See rte_mempool_create()'s cache_size
1061 * parameter description for more information. The same limits and
1062 * considerations apply here too.
1064 * The socket identifier in the case of NUMA. The value can be
1065 * SOCKET_ID_ANY if there is no NUMA constraint for the reserved zone.
1067 struct rte_mempool_cache *
1068 rte_mempool_cache_create(uint32_t size, int socket_id);
1071 * Free a user-owned mempool cache.
1074 * A pointer to the mempool cache.
1077 rte_mempool_cache_free(struct rte_mempool_cache *cache);
1080 * Flush a user-owned mempool cache to the specified mempool.
1083 * A pointer to the mempool cache.
1085 * A pointer to the mempool.
1087 static __rte_always_inline void
1088 rte_mempool_cache_flush(struct rte_mempool_cache *cache,
1089 struct rte_mempool *mp)
1091 rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
1096 * Get a pointer to the per-lcore default mempool cache.
1099 * A pointer to the mempool structure.
1101 * The logical core id.
1103 * A pointer to the mempool cache or NULL if disabled or non-EAL thread.
1105 static __rte_always_inline struct rte_mempool_cache *
1106 rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
1108 if (mp->cache_size == 0)
1111 if (lcore_id >= RTE_MAX_LCORE)
1114 return &mp->local_cache[lcore_id];
1118 * @internal Put several objects back in the mempool; used internally.
1120 * A pointer to the mempool structure.
1122 * A pointer to a table of void * pointers (objects).
1124 * The number of objects to store back in the mempool, must be strictly
1127 * A pointer to a mempool cache structure. May be NULL if not needed.
1129 static __rte_always_inline void
1130 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1131 unsigned int n, struct rte_mempool_cache *cache)
1135 /* increment stat now, adding in mempool always success */
1136 __MEMPOOL_STAT_ADD(mp, put, n);
1138 /* No cache provided or if put would overflow mem allocated for cache */
1139 if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1142 cache_objs = &cache->objs[cache->len];
1145 * The cache follows the following algorithm
1146 * 1. Add the objects to the cache
1147 * 2. Anything greater than the cache min value (if it crosses the
1148 * cache flush threshold) is flushed to the ring.
1151 /* Add elements back into the cache */
1152 rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
1156 if (cache->len >= cache->flushthresh) {
1157 rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
1158 cache->len - cache->size);
1159 cache->len = cache->size;
1166 /* push remaining objects in ring */
1167 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
1168 if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1169 rte_panic("cannot put objects in mempool\n");
1171 rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1177 * Put several objects back in the mempool.
1180 * A pointer to the mempool structure.
1182 * A pointer to a table of void * pointers (objects).
1184 * The number of objects to add in the mempool from the obj_table.
1186 * A pointer to a mempool cache structure. May be NULL if not needed.
1188 static __rte_always_inline void
1189 rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1190 unsigned int n, struct rte_mempool_cache *cache)
1192 __mempool_check_cookies(mp, obj_table, n, 0);
1193 __mempool_generic_put(mp, obj_table, n, cache);
1197 * Put several objects back in the mempool.
1199 * This function calls the multi-producer or the single-producer
1200 * version depending on the default behavior that was specified at
1201 * mempool creation time (see flags).
1204 * A pointer to the mempool structure.
1206 * A pointer to a table of void * pointers (objects).
1208 * The number of objects to add in the mempool from obj_table.
1210 static __rte_always_inline void
1211 rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
1214 struct rte_mempool_cache *cache;
1215 cache = rte_mempool_default_cache(mp, rte_lcore_id());
1216 rte_mempool_generic_put(mp, obj_table, n, cache);
1220 * Put one object back in the mempool.
1222 * This function calls the multi-producer or the single-producer
1223 * version depending on the default behavior that was specified at
1224 * mempool creation time (see flags).
1227 * A pointer to the mempool structure.
1229 * A pointer to the object to be added.
1231 static __rte_always_inline void
1232 rte_mempool_put(struct rte_mempool *mp, void *obj)
1234 rte_mempool_put_bulk(mp, &obj, 1);
1238 * @internal Get several objects from the mempool; used internally.
1240 * A pointer to the mempool structure.
1242 * A pointer to a table of void * pointers (objects).
1244 * The number of objects to get, must be strictly positive.
1246 * A pointer to a mempool cache structure. May be NULL if not needed.
1248 * - >=0: Success; number of objects supplied.
1249 * - <0: Error; code of ring dequeue function.
1251 static __rte_always_inline int
1252 __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1253 unsigned int n, struct rte_mempool_cache *cache)
1256 uint32_t index, len;
1259 /* No cache provided or cannot be satisfied from cache */
1260 if (unlikely(cache == NULL || n >= cache->size))
1263 cache_objs = cache->objs;
1265 /* Can this be satisfied from the cache? */
1266 if (cache->len < n) {
1267 /* No. Backfill the cache first, and then fill from it */
1268 uint32_t req = n + (cache->size - cache->len);
1270 /* How many do we require i.e. number to fill the cache + the request */
1271 ret = rte_mempool_ops_dequeue_bulk(mp,
1272 &cache->objs[cache->len], req);
1273 if (unlikely(ret < 0)) {
1275 * In the offchance that we are buffer constrained,
1276 * where we are not able to allocate cache + n, go to
1277 * the ring directly. If that fails, we are truly out of
1286 /* Now fill in the response ... */
1287 for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
1288 *obj_table = cache_objs[len];
1292 __MEMPOOL_STAT_ADD(mp, get_success, n);
1298 /* get remaining objects from ring */
1299 ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, n);
1302 __MEMPOOL_STAT_ADD(mp, get_fail, n);
1304 __MEMPOOL_STAT_ADD(mp, get_success, n);
1310 * Get several objects from the mempool.
1312 * If cache is enabled, objects will be retrieved first from cache,
1313 * subsequently from the common pool. Note that it can return -ENOENT when
1314 * the local cache and common pool are empty, even if cache from other
1318 * A pointer to the mempool structure.
1320 * A pointer to a table of void * pointers (objects) that will be filled.
1322 * The number of objects to get from mempool to obj_table.
1324 * A pointer to a mempool cache structure. May be NULL if not needed.
1326 * - 0: Success; objects taken.
1327 * - -ENOENT: Not enough entries in the mempool; no object is retrieved.
1329 static __rte_always_inline int
1330 rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1331 unsigned int n, struct rte_mempool_cache *cache)
1334 ret = __mempool_generic_get(mp, obj_table, n, cache);
1336 __mempool_check_cookies(mp, obj_table, n, 1);
1341 * Get several objects from the mempool.
1343 * This function calls the multi-consumers or the single-consumer
1344 * version, depending on the default behaviour that was specified at
1345 * mempool creation time (see flags).
1347 * If cache is enabled, objects will be retrieved first from cache,
1348 * subsequently from the common pool. Note that it can return -ENOENT when
1349 * the local cache and common pool are empty, even if cache from other
1353 * A pointer to the mempool structure.
1355 * A pointer to a table of void * pointers (objects) that will be filled.
1357 * The number of objects to get from the mempool to obj_table.
1359 * - 0: Success; objects taken
1360 * - -ENOENT: Not enough entries in the mempool; no object is retrieved.
1362 static __rte_always_inline int
1363 rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
1365 struct rte_mempool_cache *cache;
1366 cache = rte_mempool_default_cache(mp, rte_lcore_id());
1367 return rte_mempool_generic_get(mp, obj_table, n, cache);
1371 * Get one object from the mempool.
1373 * This function calls the multi-consumers or the single-consumer
1374 * version, depending on the default behavior that was specified at
1375 * mempool creation (see flags).
1377 * If cache is enabled, objects will be retrieved first from cache,
1378 * subsequently from the common pool. Note that it can return -ENOENT when
1379 * the local cache and common pool are empty, even if cache from other
1383 * A pointer to the mempool structure.
1385 * A pointer to a void * pointer (object) that will be filled.
1387 * - 0: Success; objects taken.
1388 * - -ENOENT: Not enough entries in the mempool; no object is retrieved.
1390 static __rte_always_inline int
1391 rte_mempool_get(struct rte_mempool *mp, void **obj_p)
1393 return rte_mempool_get_bulk(mp, obj_p, 1);
1397 * Return the number of entries in the mempool.
1399 * When cache is enabled, this function has to browse the length of
1400 * all lcores, so it should not be used in a data path, but only for
1401 * debug purposes. User-owned mempool caches are not accounted for.
1404 * A pointer to the mempool structure.
1406 * The number of entries in the mempool.
1408 unsigned int rte_mempool_avail_count(const struct rte_mempool *mp);
1411 * Return the number of elements which have been allocated from the mempool
1413 * When cache is enabled, this function has to browse the length of
1414 * all lcores, so it should not be used in a data path, but only for
1418 * A pointer to the mempool structure.
1420 * The number of free entries in the mempool.
1423 rte_mempool_in_use_count(const struct rte_mempool *mp);
1426 * Test if the mempool is full.
1428 * When cache is enabled, this function has to browse the length of all
1429 * lcores, so it should not be used in a data path, but only for debug
1430 * purposes. User-owned mempool caches are not accounted for.
1433 * A pointer to the mempool structure.
1435 * - 1: The mempool is full.
1436 * - 0: The mempool is not full.
1439 rte_mempool_full(const struct rte_mempool *mp)
1441 return !!(rte_mempool_avail_count(mp) == mp->size);
1445 * Test if the mempool is empty.
1447 * When cache is enabled, this function has to browse the length of all
1448 * lcores, so it should not be used in a data path, but only for debug
1449 * purposes. User-owned mempool caches are not accounted for.
1452 * A pointer to the mempool structure.
1454 * - 1: The mempool is empty.
1455 * - 0: The mempool is not empty.
1458 rte_mempool_empty(const struct rte_mempool *mp)
1460 return !!(rte_mempool_avail_count(mp) == 0);
1464 * Return the IO address of elt, which is an element of the pool mp.
1467 * A pointer (virtual address) to the element of the pool.
1469 * The IO address of the elt element.
1470 * If the mempool was created with MEMPOOL_F_NO_PHYS_CONTIG, the
1471 * returned value is RTE_BAD_IOVA.
1473 static inline rte_iova_t
1474 rte_mempool_virt2iova(const void *elt)
1476 const struct rte_mempool_objhdr *hdr;
1477 hdr = (const struct rte_mempool_objhdr *)RTE_PTR_SUB(elt,
1483 static inline phys_addr_t
1484 rte_mempool_virt2phy(__rte_unused const struct rte_mempool *mp, const void *elt)
1486 return rte_mempool_virt2iova(elt);
1490 * Check the consistency of mempool objects.
1492 * Verify the coherency of fields in the mempool structure. Also check
1493 * that the cookies of mempool objects (even the ones that are not
1494 * present in pool) have a correct value. If not, a panic will occur.
1497 * A pointer to the mempool structure.
1499 void rte_mempool_audit(struct rte_mempool *mp);
1502 * Return a pointer to the private data in an mempool structure.
1505 * A pointer to the mempool structure.
1507 * A pointer to the private data.
1509 static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
1512 MEMPOOL_HEADER_SIZE(mp, mp->cache_size);
1516 * Dump the status of all mempools on the console
1519 * A pointer to a file for output
1521 void rte_mempool_list_dump(FILE *f);
1524 * Search a mempool from its name
1527 * The name of the mempool.
1529 * The pointer to the mempool matching the name, or NULL if not found.
1531 * with rte_errno set appropriately. Possible rte_errno values include:
1532 * - ENOENT - required entry not available to return.
1535 struct rte_mempool *rte_mempool_lookup(const char *name);
1538 * Get the header, trailer and total size of a mempool element.
1540 * Given a desired size of the mempool element and mempool flags,
1541 * calculates header, trailer, body and total sizes of the mempool object.
1544 * The size of each element, without header and trailer.
1546 * The flags used for the mempool creation.
1547 * Consult rte_mempool_create() for more information about possible values.
1548 * The size of each element.
1550 * The calculated detailed size the mempool object. May be NULL.
1552 * Total size of the mempool object.
1554 uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
1555 struct rte_mempool_objsz *sz);
1558 * Get the size of memory required to store mempool elements.
1560 * Calculate the maximum amount of memory required to store given number
1561 * of objects. Assume that the memory buffer will be aligned at page
1564 * Note that if object size is bigger then page size, then it assumes
1565 * that pages are grouped in subsets of physically continuous pages big
1566 * enough to store at least one object.
1569 * Number of elements.
1570 * @param total_elt_sz
1571 * The size of each element, including header and trailer, as returned
1572 * by rte_mempool_calc_obj_size().
1574 * LOG2 of the physical pages size. If set to 0, ignore page boundaries.
1576 * The mempool flags.
1578 * Required memory size aligned at page boundary.
1580 size_t rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz,
1581 uint32_t pg_shift, unsigned int flags);
1584 * Get the size of memory required to store mempool elements.
1586 * Calculate how much memory would be actually required with the given
1587 * memory footprint to store required number of objects.
1590 * Virtual address of the externally allocated memory buffer.
1591 * Will be used to store mempool objects.
1593 * Number of elements.
1594 * @param total_elt_sz
1595 * The size of each element, including header and trailer, as returned
1596 * by rte_mempool_calc_obj_size().
1598 * Array of IO addresses of the pages that comprises given memory buffer.
1600 * Number of elements in the iova array.
1602 * LOG2 of the physical pages size.
1604 * The mempool flags.
1606 * On success, the number of bytes needed to store given number of
1607 * objects, aligned to the given page size. If the provided memory
1608 * buffer is too small, return a negative value whose absolute value
1609 * is the actual number of elements that can be stored in that buffer.
1611 ssize_t rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num,
1612 size_t total_elt_sz, const rte_iova_t iova[], uint32_t pg_num,
1613 uint32_t pg_shift, unsigned int flags);
1616 * Walk list of all memory pools
1621 * Argument passed to iterator
1623 void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),
1630 #endif /* _RTE_MEMPOOL_H_ */