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_config.h>
73 #include <rte_spinlock.h>
75 #include <rte_debug.h>
76 #include <rte_lcore.h>
77 #include <rte_memory.h>
78 #include <rte_branch_prediction.h>
80 #include <rte_memcpy.h>
81 #include <rte_common.h>
87 #define RTE_MEMPOOL_HEADER_COOKIE1 0xbadbadbadadd2e55ULL /**< Header cookie. */
88 #define RTE_MEMPOOL_HEADER_COOKIE2 0xf2eef2eedadd2e55ULL /**< Header cookie. */
89 #define RTE_MEMPOOL_TRAILER_COOKIE 0xadd2e55badbadbadULL /**< Trailer cookie.*/
91 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
93 * A structure that stores the mempool statistics (per-lcore).
95 struct rte_mempool_debug_stats {
96 uint64_t put_bulk; /**< Number of puts. */
97 uint64_t put_objs; /**< Number of objects successfully put. */
98 uint64_t get_success_bulk; /**< Successful allocation number. */
99 uint64_t get_success_objs; /**< Objects successfully allocated. */
100 uint64_t get_fail_bulk; /**< Failed allocation number. */
101 uint64_t get_fail_objs; /**< Objects that failed to be allocated. */
102 } __rte_cache_aligned;
106 * A structure that stores a per-core object cache.
108 struct rte_mempool_cache {
109 uint32_t size; /**< Size of the cache */
110 uint32_t flushthresh; /**< Threshold before we flush excess elements */
111 uint32_t len; /**< Current cache count */
113 * Cache is allocated to this size to allow it to overflow in certain
114 * cases to avoid needless emptying of cache.
116 void *objs[RTE_MEMPOOL_CACHE_MAX_SIZE * 3]; /**< Cache objects */
117 } __rte_cache_aligned;
120 * A structure that stores the size of mempool elements.
122 struct rte_mempool_objsz {
123 uint32_t elt_size; /**< Size of an element. */
124 uint32_t header_size; /**< Size of header (before elt). */
125 uint32_t trailer_size; /**< Size of trailer (after elt). */
127 /**< Total size of an object (header + elt + trailer). */
130 /**< Maximum length of a memory pool's name. */
131 #define RTE_MEMPOOL_NAMESIZE (RTE_RING_NAMESIZE - \
132 sizeof(RTE_MEMPOOL_MZ_PREFIX) + 1)
133 #define RTE_MEMPOOL_MZ_PREFIX "MP_"
136 #define RTE_MEMPOOL_MZ_FORMAT RTE_MEMPOOL_MZ_PREFIX "%s"
138 #define MEMPOOL_PG_SHIFT_MAX (sizeof(uintptr_t) * CHAR_BIT - 1)
140 /** Mempool over one chunk of physically continuous memory */
141 #define MEMPOOL_PG_NUM_DEFAULT 1
143 #ifndef RTE_MEMPOOL_ALIGN
144 #define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE
147 #define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1)
150 * Mempool object header structure
152 * Each object stored in mempools are prefixed by this header structure,
153 * it allows to retrieve the mempool pointer from the object and to
154 * iterate on all objects attached to a mempool. When debug is enabled,
155 * a cookie is also added in this structure preventing corruptions and
158 struct rte_mempool_objhdr {
159 STAILQ_ENTRY(rte_mempool_objhdr) next; /**< Next in list. */
160 struct rte_mempool *mp; /**< The mempool owning the object. */
163 rte_iova_t iova; /**< IO address of the object. */
164 phys_addr_t physaddr; /**< deprecated - Physical address of the object. */
166 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
167 uint64_t cookie; /**< Debug cookie. */
172 * A list of object headers type
174 STAILQ_HEAD(rte_mempool_objhdr_list, rte_mempool_objhdr);
176 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
179 * Mempool object trailer structure
181 * In debug mode, each object stored in mempools are suffixed by this
182 * trailer structure containing a cookie preventing memory corruptions.
184 struct rte_mempool_objtlr {
185 uint64_t cookie; /**< Debug cookie. */
191 * A list of memory where objects are stored
193 STAILQ_HEAD(rte_mempool_memhdr_list, rte_mempool_memhdr);
196 * Callback used to free a memory chunk
198 typedef void (rte_mempool_memchunk_free_cb_t)(struct rte_mempool_memhdr *memhdr,
202 * Mempool objects memory header structure
204 * The memory chunks where objects are stored. Each chunk is virtually
205 * and physically contiguous.
207 struct rte_mempool_memhdr {
208 STAILQ_ENTRY(rte_mempool_memhdr) next; /**< Next in list. */
209 struct rte_mempool *mp; /**< The mempool owning the chunk */
210 void *addr; /**< Virtual address of the chunk */
213 rte_iova_t iova; /**< IO address of the chunk */
214 phys_addr_t phys_addr; /**< Physical address of the chunk */
216 size_t len; /**< length of the chunk */
217 rte_mempool_memchunk_free_cb_t *free_cb; /**< Free callback */
218 void *opaque; /**< Argument passed to the free callback */
222 * The RTE mempool structure.
226 * Note: this field kept the RTE_MEMZONE_NAMESIZE size due to ABI
227 * compatibility requirements, it could be changed to
228 * RTE_MEMPOOL_NAMESIZE next time the ABI changes
230 char name[RTE_MEMZONE_NAMESIZE]; /**< Name of mempool. */
233 void *pool_data; /**< Ring or pool to store objects. */
234 uint64_t pool_id; /**< External mempool identifier. */
236 void *pool_config; /**< optional args for ops alloc. */
237 const struct rte_memzone *mz; /**< Memzone where pool is alloc'd. */
238 unsigned int flags; /**< Flags of the mempool. */
239 int socket_id; /**< Socket id passed at create. */
240 uint32_t size; /**< Max size of the mempool. */
242 /**< Size of per-lcore default local cache. */
244 uint32_t elt_size; /**< Size of an element. */
245 uint32_t header_size; /**< Size of header (before elt). */
246 uint32_t trailer_size; /**< Size of trailer (after elt). */
248 unsigned private_data_size; /**< Size of private data. */
250 * Index into rte_mempool_ops_table array of mempool ops
251 * structs, which contain callback function pointers.
252 * We're using an index here rather than pointers to the callbacks
253 * to facilitate any secondary processes that may want to use
258 struct rte_mempool_cache *local_cache; /**< Per-lcore local cache */
260 uint32_t populated_size; /**< Number of populated objects. */
261 struct rte_mempool_objhdr_list elt_list; /**< List of objects in pool */
262 uint32_t nb_mem_chunks; /**< Number of memory chunks */
263 struct rte_mempool_memhdr_list mem_list; /**< List of memory chunks */
265 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
266 /** Per-lcore statistics. */
267 struct rte_mempool_debug_stats stats[RTE_MAX_LCORE];
269 } __rte_cache_aligned;
271 #define MEMPOOL_F_NO_SPREAD 0x0001 /**< Do not spread among memory channels. */
272 #define MEMPOOL_F_NO_CACHE_ALIGN 0x0002 /**< Do not align objs on cache lines.*/
273 #define MEMPOOL_F_SP_PUT 0x0004 /**< Default put is "single-producer".*/
274 #define MEMPOOL_F_SC_GET 0x0008 /**< Default get is "single-consumer".*/
275 #define MEMPOOL_F_POOL_CREATED 0x0010 /**< Internal: pool is created. */
276 #define MEMPOOL_F_NO_PHYS_CONTIG 0x0020 /**< Don't need physically contiguous objs. */
278 * This capability flag is advertised by a mempool handler, if the whole
279 * memory area containing the objects must be physically contiguous.
280 * Note: This flag should not be passed by application.
282 #define MEMPOOL_F_CAPA_PHYS_CONTIG 0x0040
284 * This capability flag is advertised by a mempool handler. Used for a case
285 * where mempool driver wants object start address(vaddr) aligned to block
286 * size(/ total element size).
289 * - This flag should not be passed by application.
290 * Flag used for mempool driver only.
291 * - Mempool driver must also set MEMPOOL_F_CAPA_PHYS_CONTIG flag along with
292 * MEMPOOL_F_CAPA_BLK_ALIGNED_OBJECTS.
294 #define MEMPOOL_F_CAPA_BLK_ALIGNED_OBJECTS 0x0080
297 * @internal When debug is enabled, store some statistics.
300 * Pointer to the memory pool.
302 * Name of the statistics field to increment in the memory pool.
304 * Number to add to the object-oriented statistics.
306 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
307 #define __MEMPOOL_STAT_ADD(mp, name, n) do { \
308 unsigned __lcore_id = rte_lcore_id(); \
309 if (__lcore_id < RTE_MAX_LCORE) { \
310 mp->stats[__lcore_id].name##_objs += n; \
311 mp->stats[__lcore_id].name##_bulk += 1; \
315 #define __MEMPOOL_STAT_ADD(mp, name, n) do {} while(0)
319 * Calculate the size of the mempool header.
322 * Pointer to the memory pool.
324 * Size of the per-lcore cache.
326 #define MEMPOOL_HEADER_SIZE(mp, cs) \
327 (sizeof(*(mp)) + (((cs) == 0) ? 0 : \
328 (sizeof(struct rte_mempool_cache) * RTE_MAX_LCORE)))
330 /* return the header of a mempool object (internal) */
331 static inline struct rte_mempool_objhdr *__mempool_get_header(void *obj)
333 return (struct rte_mempool_objhdr *)RTE_PTR_SUB(obj,
334 sizeof(struct rte_mempool_objhdr));
338 * Return a pointer to the mempool owning this object.
341 * An object that is owned by a pool. If this is not the case,
342 * the behavior is undefined.
344 * A pointer to the mempool structure.
346 static inline struct rte_mempool *rte_mempool_from_obj(void *obj)
348 struct rte_mempool_objhdr *hdr = __mempool_get_header(obj);
352 /* return the trailer of a mempool object (internal) */
353 static inline struct rte_mempool_objtlr *__mempool_get_trailer(void *obj)
355 struct rte_mempool *mp = rte_mempool_from_obj(obj);
356 return (struct rte_mempool_objtlr *)RTE_PTR_ADD(obj, mp->elt_size);
360 * @internal Check and update cookies or panic.
363 * Pointer to the memory pool.
364 * @param obj_table_const
365 * Pointer to a table of void * pointers (objects).
367 * Index of object in object table.
369 * - 0: object is supposed to be allocated, mark it as free
370 * - 1: object is supposed to be free, mark it as allocated
371 * - 2: just check that cookie is valid (free or allocated)
373 void rte_mempool_check_cookies(const struct rte_mempool *mp,
374 void * const *obj_table_const, unsigned n, int free);
376 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
377 #define __mempool_check_cookies(mp, obj_table_const, n, free) \
378 rte_mempool_check_cookies(mp, obj_table_const, n, free)
380 #define __mempool_check_cookies(mp, obj_table_const, n, free) do {} while(0)
381 #endif /* RTE_LIBRTE_MEMPOOL_DEBUG */
383 #define RTE_MEMPOOL_OPS_NAMESIZE 32 /**< Max length of ops struct name. */
386 * Prototype for implementation specific data provisioning function.
388 * The function should provide the implementation specific memory for
389 * use by the other mempool ops functions in a given mempool ops struct.
390 * E.g. the default ops provides an instance of the rte_ring for this purpose.
391 * it will most likely point to a different type of data structure, and
392 * will be transparent to the application programmer.
393 * This function should set mp->pool_data.
395 typedef int (*rte_mempool_alloc_t)(struct rte_mempool *mp);
398 * Free the opaque private data pointed to by mp->pool_data pointer.
400 typedef void (*rte_mempool_free_t)(struct rte_mempool *mp);
403 * Enqueue an object into the external pool.
405 typedef int (*rte_mempool_enqueue_t)(struct rte_mempool *mp,
406 void * const *obj_table, unsigned int n);
409 * Dequeue an object from the external pool.
411 typedef int (*rte_mempool_dequeue_t)(struct rte_mempool *mp,
412 void **obj_table, unsigned int n);
415 * Return the number of available objects in the external pool.
417 typedef unsigned (*rte_mempool_get_count)(const struct rte_mempool *mp);
420 * Get the mempool capabilities.
422 typedef int (*rte_mempool_get_capabilities_t)(const struct rte_mempool *mp,
423 unsigned int *flags);
426 * Notify new memory area to mempool.
428 typedef int (*rte_mempool_ops_register_memory_area_t)
429 (const struct rte_mempool *mp, char *vaddr, rte_iova_t iova, size_t len);
431 /** Structure defining mempool operations structure */
432 struct rte_mempool_ops {
433 char name[RTE_MEMPOOL_OPS_NAMESIZE]; /**< Name of mempool ops struct. */
434 rte_mempool_alloc_t alloc; /**< Allocate private data. */
435 rte_mempool_free_t free; /**< Free the external pool. */
436 rte_mempool_enqueue_t enqueue; /**< Enqueue an object. */
437 rte_mempool_dequeue_t dequeue; /**< Dequeue an object. */
438 rte_mempool_get_count get_count; /**< Get qty of available objs. */
440 * Get the mempool capabilities
442 rte_mempool_get_capabilities_t get_capabilities;
444 * Notify new memory area to mempool
446 rte_mempool_ops_register_memory_area_t register_memory_area;
447 } __rte_cache_aligned;
449 #define RTE_MEMPOOL_MAX_OPS_IDX 16 /**< Max registered ops structs */
452 * Structure storing the table of registered ops structs, each of which contain
453 * the function pointers for the mempool ops functions.
454 * Each process has its own storage for this ops struct array so that
455 * the mempools can be shared across primary and secondary processes.
456 * The indices used to access the array are valid across processes, whereas
457 * any function pointers stored directly in the mempool struct would not be.
458 * This results in us simply having "ops_index" in the mempool struct.
460 struct rte_mempool_ops_table {
461 rte_spinlock_t sl; /**< Spinlock for add/delete. */
462 uint32_t num_ops; /**< Number of used ops structs in the table. */
464 * Storage for all possible ops structs.
466 struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX];
467 } __rte_cache_aligned;
469 /** Array of registered ops structs. */
470 extern struct rte_mempool_ops_table rte_mempool_ops_table;
473 * @internal Get the mempool ops struct from its index.
476 * The index of the ops struct in the ops struct table. It must be a valid
477 * index: (0 <= idx < num_ops).
479 * The pointer to the ops struct in the table.
481 static inline struct rte_mempool_ops *
482 rte_mempool_get_ops(int ops_index)
484 RTE_VERIFY((ops_index >= 0) && (ops_index < RTE_MEMPOOL_MAX_OPS_IDX));
486 return &rte_mempool_ops_table.ops[ops_index];
490 * @internal Wrapper for mempool_ops alloc callback.
493 * Pointer to the memory pool.
495 * - 0: Success; successfully allocated mempool pool_data.
496 * - <0: Error; code of alloc function.
499 rte_mempool_ops_alloc(struct rte_mempool *mp);
502 * @internal Wrapper for mempool_ops dequeue callback.
505 * Pointer to the memory pool.
507 * Pointer to a table of void * pointers (objects).
509 * Number of objects to get.
511 * - 0: Success; got n objects.
512 * - <0: Error; code of dequeue function.
515 rte_mempool_ops_dequeue_bulk(struct rte_mempool *mp,
516 void **obj_table, unsigned n)
518 struct rte_mempool_ops *ops;
520 ops = rte_mempool_get_ops(mp->ops_index);
521 return ops->dequeue(mp, obj_table, n);
525 * @internal wrapper for mempool_ops enqueue callback.
528 * Pointer to the memory pool.
530 * Pointer to a table of void * pointers (objects).
532 * Number of objects to put.
534 * - 0: Success; n objects supplied.
535 * - <0: Error; code of enqueue function.
538 rte_mempool_ops_enqueue_bulk(struct rte_mempool *mp, void * const *obj_table,
541 struct rte_mempool_ops *ops;
543 ops = rte_mempool_get_ops(mp->ops_index);
544 return ops->enqueue(mp, obj_table, n);
548 * @internal wrapper for mempool_ops get_count callback.
551 * Pointer to the memory pool.
553 * The number of available objects in the external pool.
556 rte_mempool_ops_get_count(const struct rte_mempool *mp);
559 * @internal wrapper for mempool_ops get_capabilities callback.
562 * Pointer to the memory pool.
564 * Pointer to the mempool flags.
566 * - 0: Success; The mempool driver has advertised his pool capabilities in
568 * - -ENOTSUP - doesn't support get_capabilities ops (valid case).
569 * - Otherwise, pool create fails.
572 rte_mempool_ops_get_capabilities(const struct rte_mempool *mp,
573 unsigned int *flags);
575 * @internal wrapper for mempool_ops register_memory_area callback.
576 * API to notify the mempool handler when a new memory area is added to pool.
579 * Pointer to the memory pool.
581 * Pointer to the buffer virtual address.
583 * Pointer to the buffer IO address.
588 * - -ENOTSUP - doesn't support register_memory_area ops (valid error case).
589 * - Otherwise, rte_mempool_populate_phys fails thus pool create fails.
592 rte_mempool_ops_register_memory_area(const struct rte_mempool *mp,
593 char *vaddr, rte_iova_t iova, size_t len);
596 * @internal wrapper for mempool_ops free callback.
599 * Pointer to the memory pool.
602 rte_mempool_ops_free(struct rte_mempool *mp);
605 * Set the ops of a mempool.
607 * This can only be done on a mempool that is not populated, i.e. just after
608 * a call to rte_mempool_create_empty().
611 * Pointer to the memory pool.
613 * Name of the ops structure to use for this mempool.
615 * Opaque data that can be passed by the application to the ops functions.
617 * - 0: Success; the mempool is now using the requested ops functions.
618 * - -EINVAL - Invalid ops struct name provided.
619 * - -EEXIST - mempool already has an ops struct assigned.
622 rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
626 * Register mempool operations.
629 * Pointer to an ops structure to register.
631 * - >=0: Success; return the index of the ops struct in the table.
632 * - -EINVAL - some missing callbacks while registering ops struct.
633 * - -ENOSPC - the maximum number of ops structs has been reached.
635 int rte_mempool_register_ops(const struct rte_mempool_ops *ops);
638 * Macro to statically register the ops of a mempool handler.
639 * Note that the rte_mempool_register_ops fails silently here when
640 * more than RTE_MEMPOOL_MAX_OPS_IDX is registered.
642 #define MEMPOOL_REGISTER_OPS(ops) \
643 void mp_hdlr_init_##ops(void); \
644 void __attribute__((constructor, used)) mp_hdlr_init_##ops(void)\
646 rte_mempool_register_ops(&ops); \
650 * An object callback function for mempool.
652 * Used by rte_mempool_create() and rte_mempool_obj_iter().
654 typedef void (rte_mempool_obj_cb_t)(struct rte_mempool *mp,
655 void *opaque, void *obj, unsigned obj_idx);
656 typedef rte_mempool_obj_cb_t rte_mempool_obj_ctor_t; /* compat */
659 * A memory callback function for mempool.
661 * Used by rte_mempool_mem_iter().
663 typedef void (rte_mempool_mem_cb_t)(struct rte_mempool *mp,
664 void *opaque, struct rte_mempool_memhdr *memhdr,
668 * A mempool constructor callback function.
670 * Arguments are the mempool and the opaque pointer given by the user in
671 * rte_mempool_create().
673 typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);
676 * Create a new mempool named *name* in memory.
678 * This function uses ``rte_memzone_reserve()`` to allocate memory. The
679 * pool contains n elements of elt_size. Its size is set to n.
682 * The name of the mempool.
684 * The number of elements in the mempool. The optimum size (in terms of
685 * memory usage) for a mempool is when n is a power of two minus one:
688 * The size of each element.
690 * If cache_size is non-zero, the rte_mempool library will try to
691 * limit the accesses to the common lockless pool, by maintaining a
692 * per-lcore object cache. This argument must be lower or equal to
693 * CONFIG_RTE_MEMPOOL_CACHE_MAX_SIZE and n / 1.5. It is advised to choose
694 * cache_size to have "n modulo cache_size == 0": if this is
695 * not the case, some elements will always stay in the pool and will
696 * never be used. The access to the per-lcore table is of course
697 * faster than the multi-producer/consumer pool. The cache can be
698 * disabled if the cache_size argument is set to 0; it can be useful to
699 * avoid losing objects in cache.
700 * @param private_data_size
701 * The size of the private data appended after the mempool
702 * structure. This is useful for storing some private data after the
703 * mempool structure, as is done for rte_mbuf_pool for example.
705 * A function pointer that is called for initialization of the pool,
706 * before object initialization. The user can initialize the private
707 * data in this function if needed. This parameter can be NULL if
710 * An opaque pointer to data that can be used in the mempool
711 * constructor function.
713 * A function pointer that is called for each object at
714 * initialization of the pool. The user can set some meta data in
715 * objects if needed. This parameter can be NULL if not needed.
716 * The obj_init() function takes the mempool pointer, the init_arg,
717 * the object pointer and the object number as parameters.
718 * @param obj_init_arg
719 * An opaque pointer to data that can be used as an argument for
720 * each call to the object constructor function.
722 * The *socket_id* argument is the socket identifier in the case of
723 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
724 * constraint for the reserved zone.
726 * The *flags* arguments is an OR of following flags:
727 * - MEMPOOL_F_NO_SPREAD: By default, objects addresses are spread
728 * between channels in RAM: the pool allocator will add padding
729 * between objects depending on the hardware configuration. See
730 * Memory alignment constraints for details. If this flag is set,
731 * the allocator will just align them to a cache line.
732 * - MEMPOOL_F_NO_CACHE_ALIGN: By default, the returned objects are
733 * cache-aligned. This flag removes this constraint, and no
734 * padding will be present between objects. This flag implies
735 * MEMPOOL_F_NO_SPREAD.
736 * - MEMPOOL_F_SP_PUT: If this flag is set, the default behavior
737 * when using rte_mempool_put() or rte_mempool_put_bulk() is
738 * "single-producer". Otherwise, it is "multi-producers".
739 * - MEMPOOL_F_SC_GET: If this flag is set, the default behavior
740 * when using rte_mempool_get() or rte_mempool_get_bulk() is
741 * "single-consumer". Otherwise, it is "multi-consumers".
742 * - MEMPOOL_F_NO_PHYS_CONTIG: If set, allocated objects won't
743 * necessarily be contiguous in physical memory.
745 * The pointer to the new allocated mempool, on success. NULL on error
746 * with rte_errno set appropriately. Possible rte_errno values include:
747 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
748 * - E_RTE_SECONDARY - function was called from a secondary process instance
749 * - EINVAL - cache size provided is too large
750 * - ENOSPC - the maximum number of memzones has already been allocated
751 * - EEXIST - a memzone with the same name already exists
752 * - ENOMEM - no appropriate memory area found in which to create memzone
755 rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
756 unsigned cache_size, unsigned private_data_size,
757 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
758 rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
759 int socket_id, unsigned flags);
762 * Create a new mempool named *name* in memory.
764 * The pool contains n elements of elt_size. Its size is set to n.
765 * This function uses ``memzone_reserve()`` to allocate the mempool header
766 * (and the objects if vaddr is NULL).
767 * Depending on the input parameters, mempool elements can be either allocated
768 * together with the mempool header, or an externally provided memory buffer
769 * could be used to store mempool objects. In later case, that external
770 * memory buffer can consist of set of disjoint physical pages.
773 * The name of the mempool.
775 * The number of elements in the mempool. The optimum size (in terms of
776 * memory usage) for a mempool is when n is a power of two minus one:
779 * The size of each element.
781 * Size of the cache. See rte_mempool_create() for details.
782 * @param private_data_size
783 * The size of the private data appended after the mempool
784 * structure. This is useful for storing some private data after the
785 * mempool structure, as is done for rte_mbuf_pool for example.
787 * A function pointer that is called for initialization of the pool,
788 * before object initialization. The user can initialize the private
789 * data in this function if needed. This parameter can be NULL if
792 * An opaque pointer to data that can be used in the mempool
793 * constructor function.
795 * A function called for each object at initialization of the pool.
796 * See rte_mempool_create() for details.
797 * @param obj_init_arg
798 * An opaque pointer passed to the object constructor function.
800 * The *socket_id* argument is the socket identifier in the case of
801 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
802 * constraint for the reserved zone.
804 * Flags controlling the behavior of the mempool. See
805 * rte_mempool_create() for details.
807 * Virtual address of the externally allocated memory buffer.
808 * Will be used to store mempool objects.
810 * Array of IO addresses of the pages that comprises given memory buffer.
812 * Number of elements in the iova array.
814 * LOG2 of the physical pages size.
816 * The pointer to the new allocated mempool, on success. NULL on error
817 * with rte_errno set appropriately. See rte_mempool_create() for details.
820 rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
821 unsigned cache_size, unsigned private_data_size,
822 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
823 rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
824 int socket_id, unsigned flags, void *vaddr,
825 const rte_iova_t iova[], uint32_t pg_num, uint32_t pg_shift);
828 * Create an empty mempool
830 * The mempool is allocated and initialized, but it is not populated: no
831 * memory is allocated for the mempool elements. The user has to call
832 * rte_mempool_populate_*() to add memory chunks to the pool. Once
833 * populated, the user may also want to initialize each object with
834 * rte_mempool_obj_iter().
837 * The name of the mempool.
839 * The maximum number of elements that can be added in the mempool.
840 * The optimum size (in terms of memory usage) for a mempool is when n
841 * is a power of two minus one: n = (2^q - 1).
843 * The size of each element.
845 * Size of the cache. See rte_mempool_create() for details.
846 * @param private_data_size
847 * The size of the private data appended after the mempool
848 * structure. This is useful for storing some private data after the
849 * mempool structure, as is done for rte_mbuf_pool for example.
851 * The *socket_id* argument is the socket identifier in the case of
852 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
853 * constraint for the reserved zone.
855 * Flags controlling the behavior of the mempool. See
856 * rte_mempool_create() for details.
858 * The pointer to the new allocated mempool, on success. NULL on error
859 * with rte_errno set appropriately. See rte_mempool_create() for details.
862 rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
863 unsigned cache_size, unsigned private_data_size,
864 int socket_id, unsigned flags);
868 * Unlink the mempool from global list, free the memory chunks, and all
869 * memory referenced by the mempool. The objects must not be used by
870 * other cores as they will be freed.
873 * A pointer to the mempool structure.
876 rte_mempool_free(struct rte_mempool *mp);
879 * Add physically contiguous memory for objects in the pool at init
881 * Add a virtually and physically contiguous memory chunk in the pool
882 * where objects can be instantiated.
884 * If the given IO address is unknown (iova = RTE_BAD_IOVA),
885 * the chunk doesn't need to be physically contiguous (only virtually),
886 * and allocated objects may span two pages.
889 * A pointer to the mempool structure.
891 * The virtual address of memory that should be used to store objects.
895 * The length of memory in bytes.
897 * The callback used to free this chunk when destroying the mempool.
899 * An opaque argument passed to free_cb.
901 * The number of objects added on success.
902 * On error, the chunk is not added in the memory list of the
903 * mempool and a negative errno is returned.
905 int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
906 rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb,
910 int rte_mempool_populate_phys(struct rte_mempool *mp, char *vaddr,
911 phys_addr_t paddr, size_t len, rte_mempool_memchunk_free_cb_t *free_cb,
915 * Add physical memory for objects in the pool at init
917 * Add a virtually contiguous memory chunk in the pool where objects can
918 * be instantiated. The IO addresses corresponding to the virtual
919 * area are described in iova[], pg_num, pg_shift.
922 * A pointer to the mempool structure.
924 * The virtual address of memory that should be used to store objects.
926 * An array of IO addresses of each page composing the virtual area.
928 * Number of elements in the iova array.
930 * LOG2 of the physical pages size.
932 * The callback used to free this chunk when destroying the mempool.
934 * An opaque argument passed to free_cb.
936 * The number of objects added on success.
937 * On error, the chunks are not added in the memory list of the
938 * mempool and a negative errno is returned.
940 int rte_mempool_populate_iova_tab(struct rte_mempool *mp, char *vaddr,
941 const rte_iova_t iova[], uint32_t pg_num, uint32_t pg_shift,
942 rte_mempool_memchunk_free_cb_t *free_cb, void *opaque);
945 int rte_mempool_populate_phys_tab(struct rte_mempool *mp, char *vaddr,
946 const phys_addr_t paddr[], uint32_t pg_num, uint32_t pg_shift,
947 rte_mempool_memchunk_free_cb_t *free_cb, void *opaque);
950 * Add virtually contiguous memory for objects in the pool at init
952 * Add a virtually contiguous memory chunk in the pool where objects can
956 * A pointer to the mempool structure.
958 * The virtual address of memory that should be used to store objects.
959 * Must be page-aligned.
961 * The length of memory in bytes. Must be page-aligned.
963 * The size of memory pages in this virtual area.
965 * The callback used to free this chunk when destroying the mempool.
967 * An opaque argument passed to free_cb.
969 * The number of objects added on success.
970 * On error, the chunk is not added in the memory list of the
971 * mempool and a negative errno is returned.
974 rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
975 size_t len, size_t pg_sz, rte_mempool_memchunk_free_cb_t *free_cb,
979 * Add memory for objects in the pool at init
981 * This is the default function used by rte_mempool_create() to populate
982 * the mempool. It adds memory allocated using rte_memzone_reserve().
985 * A pointer to the mempool structure.
987 * The number of objects added on success.
988 * On error, the chunk is not added in the memory list of the
989 * mempool and a negative errno is returned.
991 int rte_mempool_populate_default(struct rte_mempool *mp);
994 * Add memory from anonymous mapping for objects in the pool at init
996 * This function mmap an anonymous memory zone that is locked in
997 * memory to store the objects of the mempool.
1000 * A pointer to the mempool structure.
1002 * The number of objects added on success.
1003 * On error, the chunk is not added in the memory list of the
1004 * mempool and a negative errno is returned.
1006 int rte_mempool_populate_anon(struct rte_mempool *mp);
1009 * Call a function for each mempool element
1011 * Iterate across all objects attached to a rte_mempool and call the
1012 * callback function on it.
1015 * A pointer to an initialized mempool.
1017 * A function pointer that is called for each object.
1019 * An opaque pointer passed to the callback function.
1021 * Number of objects iterated.
1023 uint32_t rte_mempool_obj_iter(struct rte_mempool *mp,
1024 rte_mempool_obj_cb_t *obj_cb, void *obj_cb_arg);
1027 * Call a function for each mempool memory chunk
1029 * Iterate across all memory chunks attached to a rte_mempool and call
1030 * the callback function on it.
1033 * A pointer to an initialized mempool.
1035 * A function pointer that is called for each memory chunk.
1037 * An opaque pointer passed to the callback function.
1039 * Number of memory chunks iterated.
1041 uint32_t rte_mempool_mem_iter(struct rte_mempool *mp,
1042 rte_mempool_mem_cb_t *mem_cb, void *mem_cb_arg);
1045 * Dump the status of the mempool to a file.
1048 * A pointer to a file for output
1050 * A pointer to the mempool structure.
1052 void rte_mempool_dump(FILE *f, struct rte_mempool *mp);
1055 * Create a user-owned mempool cache.
1057 * This can be used by non-EAL threads to enable caching when they
1058 * interact with a mempool.
1061 * The size of the mempool cache. See rte_mempool_create()'s cache_size
1062 * parameter description for more information. The same limits and
1063 * considerations apply here too.
1065 * The socket identifier in the case of NUMA. The value can be
1066 * SOCKET_ID_ANY if there is no NUMA constraint for the reserved zone.
1068 struct rte_mempool_cache *
1069 rte_mempool_cache_create(uint32_t size, int socket_id);
1072 * Free a user-owned mempool cache.
1075 * A pointer to the mempool cache.
1078 rte_mempool_cache_free(struct rte_mempool_cache *cache);
1081 * Flush a user-owned mempool cache to the specified mempool.
1084 * A pointer to the mempool cache.
1086 * A pointer to the mempool.
1088 static __rte_always_inline void
1089 rte_mempool_cache_flush(struct rte_mempool_cache *cache,
1090 struct rte_mempool *mp)
1092 rte_mempool_ops_enqueue_bulk(mp, cache->objs, cache->len);
1097 * Get a pointer to the per-lcore default mempool cache.
1100 * A pointer to the mempool structure.
1102 * The logical core id.
1104 * A pointer to the mempool cache or NULL if disabled or non-EAL thread.
1106 static __rte_always_inline struct rte_mempool_cache *
1107 rte_mempool_default_cache(struct rte_mempool *mp, unsigned lcore_id)
1109 if (mp->cache_size == 0)
1112 if (lcore_id >= RTE_MAX_LCORE)
1115 return &mp->local_cache[lcore_id];
1119 * @internal Put several objects back in the mempool; used internally.
1121 * A pointer to the mempool structure.
1123 * A pointer to a table of void * pointers (objects).
1125 * The number of objects to store back in the mempool, must be strictly
1128 * A pointer to a mempool cache structure. May be NULL if not needed.
1130 static __rte_always_inline void
1131 __mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1132 unsigned int n, struct rte_mempool_cache *cache)
1136 /* increment stat now, adding in mempool always success */
1137 __MEMPOOL_STAT_ADD(mp, put, n);
1139 /* No cache provided or if put would overflow mem allocated for cache */
1140 if (unlikely(cache == NULL || n > RTE_MEMPOOL_CACHE_MAX_SIZE))
1143 cache_objs = &cache->objs[cache->len];
1146 * The cache follows the following algorithm
1147 * 1. Add the objects to the cache
1148 * 2. Anything greater than the cache min value (if it crosses the
1149 * cache flush threshold) is flushed to the ring.
1152 /* Add elements back into the cache */
1153 rte_memcpy(&cache_objs[0], obj_table, sizeof(void *) * n);
1157 if (cache->len >= cache->flushthresh) {
1158 rte_mempool_ops_enqueue_bulk(mp, &cache->objs[cache->size],
1159 cache->len - cache->size);
1160 cache->len = cache->size;
1167 /* push remaining objects in ring */
1168 #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
1169 if (rte_mempool_ops_enqueue_bulk(mp, obj_table, n) < 0)
1170 rte_panic("cannot put objects in mempool\n");
1172 rte_mempool_ops_enqueue_bulk(mp, obj_table, n);
1178 * Put several objects back in the mempool.
1181 * A pointer to the mempool structure.
1183 * A pointer to a table of void * pointers (objects).
1185 * The number of objects to add in the mempool from the obj_table.
1187 * A pointer to a mempool cache structure. May be NULL if not needed.
1189 static __rte_always_inline void
1190 rte_mempool_generic_put(struct rte_mempool *mp, void * const *obj_table,
1191 unsigned int n, struct rte_mempool_cache *cache)
1193 __mempool_check_cookies(mp, obj_table, n, 0);
1194 __mempool_generic_put(mp, obj_table, n, cache);
1198 * Put several objects back in the mempool.
1200 * This function calls the multi-producer or the single-producer
1201 * version depending on the default behavior that was specified at
1202 * mempool creation time (see flags).
1205 * A pointer to the mempool structure.
1207 * A pointer to a table of void * pointers (objects).
1209 * The number of objects to add in the mempool from obj_table.
1211 static __rte_always_inline void
1212 rte_mempool_put_bulk(struct rte_mempool *mp, void * const *obj_table,
1215 struct rte_mempool_cache *cache;
1216 cache = rte_mempool_default_cache(mp, rte_lcore_id());
1217 rte_mempool_generic_put(mp, obj_table, n, cache);
1221 * Put one object back in the mempool.
1223 * This function calls the multi-producer or the single-producer
1224 * version depending on the default behavior that was specified at
1225 * mempool creation time (see flags).
1228 * A pointer to the mempool structure.
1230 * A pointer to the object to be added.
1232 static __rte_always_inline void
1233 rte_mempool_put(struct rte_mempool *mp, void *obj)
1235 rte_mempool_put_bulk(mp, &obj, 1);
1239 * @internal Get several objects from the mempool; used internally.
1241 * A pointer to the mempool structure.
1243 * A pointer to a table of void * pointers (objects).
1245 * The number of objects to get, must be strictly positive.
1247 * A pointer to a mempool cache structure. May be NULL if not needed.
1249 * - >=0: Success; number of objects supplied.
1250 * - <0: Error; code of ring dequeue function.
1252 static __rte_always_inline int
1253 __mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1254 unsigned int n, struct rte_mempool_cache *cache)
1257 uint32_t index, len;
1260 /* No cache provided or cannot be satisfied from cache */
1261 if (unlikely(cache == NULL || n >= cache->size))
1264 cache_objs = cache->objs;
1266 /* Can this be satisfied from the cache? */
1267 if (cache->len < n) {
1268 /* No. Backfill the cache first, and then fill from it */
1269 uint32_t req = n + (cache->size - cache->len);
1271 /* How many do we require i.e. number to fill the cache + the request */
1272 ret = rte_mempool_ops_dequeue_bulk(mp,
1273 &cache->objs[cache->len], req);
1274 if (unlikely(ret < 0)) {
1276 * In the offchance that we are buffer constrained,
1277 * where we are not able to allocate cache + n, go to
1278 * the ring directly. If that fails, we are truly out of
1287 /* Now fill in the response ... */
1288 for (index = 0, len = cache->len - 1; index < n; ++index, len--, obj_table++)
1289 *obj_table = cache_objs[len];
1293 __MEMPOOL_STAT_ADD(mp, get_success, n);
1299 /* get remaining objects from ring */
1300 ret = rte_mempool_ops_dequeue_bulk(mp, obj_table, n);
1303 __MEMPOOL_STAT_ADD(mp, get_fail, n);
1305 __MEMPOOL_STAT_ADD(mp, get_success, n);
1311 * Get several objects from the mempool.
1313 * If cache is enabled, objects will be retrieved first from cache,
1314 * subsequently from the common pool. Note that it can return -ENOENT when
1315 * the local cache and common pool are empty, even if cache from other
1319 * A pointer to the mempool structure.
1321 * A pointer to a table of void * pointers (objects) that will be filled.
1323 * The number of objects to get from mempool to obj_table.
1325 * A pointer to a mempool cache structure. May be NULL if not needed.
1327 * - 0: Success; objects taken.
1328 * - -ENOENT: Not enough entries in the mempool; no object is retrieved.
1330 static __rte_always_inline int
1331 rte_mempool_generic_get(struct rte_mempool *mp, void **obj_table,
1332 unsigned int n, struct rte_mempool_cache *cache)
1335 ret = __mempool_generic_get(mp, obj_table, n, cache);
1337 __mempool_check_cookies(mp, obj_table, n, 1);
1342 * Get several objects from the mempool.
1344 * This function calls the multi-consumers or the single-consumer
1345 * version, depending on the default behaviour that was specified at
1346 * mempool creation time (see flags).
1348 * If cache is enabled, objects will be retrieved first from cache,
1349 * subsequently from the common pool. Note that it can return -ENOENT when
1350 * the local cache and common pool are empty, even if cache from other
1354 * A pointer to the mempool structure.
1356 * A pointer to a table of void * pointers (objects) that will be filled.
1358 * The number of objects to get from the mempool to obj_table.
1360 * - 0: Success; objects taken
1361 * - -ENOENT: Not enough entries in the mempool; no object is retrieved.
1363 static __rte_always_inline int
1364 rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
1366 struct rte_mempool_cache *cache;
1367 cache = rte_mempool_default_cache(mp, rte_lcore_id());
1368 return rte_mempool_generic_get(mp, obj_table, n, cache);
1372 * Get one object from the mempool.
1374 * This function calls the multi-consumers or the single-consumer
1375 * version, depending on the default behavior that was specified at
1376 * mempool creation (see flags).
1378 * If cache is enabled, objects will be retrieved first from cache,
1379 * subsequently from the common pool. Note that it can return -ENOENT when
1380 * the local cache and common pool are empty, even if cache from other
1384 * A pointer to the mempool structure.
1386 * A pointer to a void * pointer (object) that will be filled.
1388 * - 0: Success; objects taken.
1389 * - -ENOENT: Not enough entries in the mempool; no object is retrieved.
1391 static __rte_always_inline int
1392 rte_mempool_get(struct rte_mempool *mp, void **obj_p)
1394 return rte_mempool_get_bulk(mp, obj_p, 1);
1398 * Return the number of entries in the mempool.
1400 * When cache is enabled, this function has to browse the length of
1401 * all lcores, so it should not be used in a data path, but only for
1402 * debug purposes. User-owned mempool caches are not accounted for.
1405 * A pointer to the mempool structure.
1407 * The number of entries in the mempool.
1409 unsigned int rte_mempool_avail_count(const struct rte_mempool *mp);
1412 * Return the number of elements which have been allocated from the mempool
1414 * When cache is enabled, this function has to browse the length of
1415 * all lcores, so it should not be used in a data path, but only for
1419 * A pointer to the mempool structure.
1421 * The number of free entries in the mempool.
1424 rte_mempool_in_use_count(const struct rte_mempool *mp);
1427 * Test if the mempool is full.
1429 * When cache is enabled, this function has to browse the length of all
1430 * lcores, so it should not be used in a data path, but only for debug
1431 * purposes. User-owned mempool caches are not accounted for.
1434 * A pointer to the mempool structure.
1436 * - 1: The mempool is full.
1437 * - 0: The mempool is not full.
1440 rte_mempool_full(const struct rte_mempool *mp)
1442 return !!(rte_mempool_avail_count(mp) == mp->size);
1446 * Test if the mempool is empty.
1448 * When cache is enabled, this function has to browse the length of all
1449 * lcores, so it should not be used in a data path, but only for debug
1450 * purposes. User-owned mempool caches are not accounted for.
1453 * A pointer to the mempool structure.
1455 * - 1: The mempool is empty.
1456 * - 0: The mempool is not empty.
1459 rte_mempool_empty(const struct rte_mempool *mp)
1461 return !!(rte_mempool_avail_count(mp) == 0);
1465 * Return the IO address of elt, which is an element of the pool mp.
1468 * A pointer (virtual address) to the element of the pool.
1470 * The IO address of the elt element.
1471 * If the mempool was created with MEMPOOL_F_NO_PHYS_CONTIG, the
1472 * returned value is RTE_BAD_IOVA.
1474 static inline rte_iova_t
1475 rte_mempool_virt2iova(const void *elt)
1477 const struct rte_mempool_objhdr *hdr;
1478 hdr = (const struct rte_mempool_objhdr *)RTE_PTR_SUB(elt,
1484 static inline phys_addr_t
1485 rte_mempool_virt2phy(__rte_unused const struct rte_mempool *mp, const void *elt)
1487 return rte_mempool_virt2iova(elt);
1491 * Check the consistency of mempool objects.
1493 * Verify the coherency of fields in the mempool structure. Also check
1494 * that the cookies of mempool objects (even the ones that are not
1495 * present in pool) have a correct value. If not, a panic will occur.
1498 * A pointer to the mempool structure.
1500 void rte_mempool_audit(struct rte_mempool *mp);
1503 * Return a pointer to the private data in an mempool structure.
1506 * A pointer to the mempool structure.
1508 * A pointer to the private data.
1510 static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
1513 MEMPOOL_HEADER_SIZE(mp, mp->cache_size);
1517 * Dump the status of all mempools on the console
1520 * A pointer to a file for output
1522 void rte_mempool_list_dump(FILE *f);
1525 * Search a mempool from its name
1528 * The name of the mempool.
1530 * The pointer to the mempool matching the name, or NULL if not found.
1532 * with rte_errno set appropriately. Possible rte_errno values include:
1533 * - ENOENT - required entry not available to return.
1536 struct rte_mempool *rte_mempool_lookup(const char *name);
1539 * Get the header, trailer and total size of a mempool element.
1541 * Given a desired size of the mempool element and mempool flags,
1542 * calculates header, trailer, body and total sizes of the mempool object.
1545 * The size of each element, without header and trailer.
1547 * The flags used for the mempool creation.
1548 * Consult rte_mempool_create() for more information about possible values.
1549 * The size of each element.
1551 * The calculated detailed size the mempool object. May be NULL.
1553 * Total size of the mempool object.
1555 uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
1556 struct rte_mempool_objsz *sz);
1559 * Get the size of memory required to store mempool elements.
1561 * Calculate the maximum amount of memory required to store given number
1562 * of objects. Assume that the memory buffer will be aligned at page
1565 * Note that if object size is bigger then page size, then it assumes
1566 * that pages are grouped in subsets of physically continuous pages big
1567 * enough to store at least one object.
1570 * Number of elements.
1571 * @param total_elt_sz
1572 * The size of each element, including header and trailer, as returned
1573 * by rte_mempool_calc_obj_size().
1575 * LOG2 of the physical pages size. If set to 0, ignore page boundaries.
1577 * The mempool flags.
1579 * Required memory size aligned at page boundary.
1581 size_t rte_mempool_xmem_size(uint32_t elt_num, size_t total_elt_sz,
1582 uint32_t pg_shift, unsigned int flags);
1585 * Get the size of memory required to store mempool elements.
1587 * Calculate how much memory would be actually required with the given
1588 * memory footprint to store required number of objects.
1591 * Virtual address of the externally allocated memory buffer.
1592 * Will be used to store mempool objects.
1594 * Number of elements.
1595 * @param total_elt_sz
1596 * The size of each element, including header and trailer, as returned
1597 * by rte_mempool_calc_obj_size().
1599 * Array of IO addresses of the pages that comprises given memory buffer.
1601 * Number of elements in the iova array.
1603 * LOG2 of the physical pages size.
1605 * The mempool flags.
1607 * On success, the number of bytes needed to store given number of
1608 * objects, aligned to the given page size. If the provided memory
1609 * buffer is too small, return a negative value whose absolute value
1610 * is the actual number of elements that can be stored in that buffer.
1612 ssize_t rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num,
1613 size_t total_elt_sz, const rte_iova_t iova[], uint32_t pg_num,
1614 uint32_t pg_shift, unsigned int flags);
1617 * Walk list of all memory pools
1622 * Argument passed to iterator
1624 void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),
1631 #endif /* _RTE_MEMPOOL_H_ */