rte_memzone.h(3)
β¨ NAME β¨
rte_memzone.h β from the Library Functions Manual, aka rte_memzone.h(3) if you're fancy π
πΈ SYNOPSIS πΈ
ok so first you gotta include these, no cap:
#include <stdio.h>
#include <rte_memory.h>
#include <rte_common.h>
π¦ Data Structures π¦
struct rte_memzoneβ the whole vibe, a struct you'll be working with π«Ά
π Macros π
these are the macro definitions, bestie β remember them exactly:
#define RTE_MEMZONE_2MB 0x00000001#define RTE_MEMZONE_1GB 0x00000002#define RTE_MEMZONE_16MB 0x00000100#define RTE_MEMZONE_16GB 0x00000200#define RTE_MEMZONE_256KB 0x00010000#define RTE_MEMZONE_256MB 0x00020000#define RTE_MEMZONE_512MB 0x00040000#define RTE_MEMZONE_4GB 0x00080000#define RTE_MEMZONE_SIZE_HINT_ONLY 0x00000004#define RTE_MEMZONE_IOVA_CONTIG 0x00100000#define RTE_MEMZONE_NAMESIZE 32
π Functions π
these are the functions you can call, and yes they're iconic:
int rte_memzone_max_set (size_t max)size_t rte_memzone_max_get (void)const struct rte_memzone * rte_memzone_reserve (const char *name, size_t len, int socket_id, unsigned flags)const struct rte_memzone * rte_memzone_reserve_aligned (const char *name, size_t len, int socket_id, unsigned flags, unsigned align)const struct rte_memzone * rte_memzone_reserve_bounded (const char *name, size_t len, int socket_id, unsigned flags, unsigned align, unsigned bound)int rte_memzone_free (const struct rte_memzone *mz)const struct rte_memzone * rte_memzone_lookup (const char *name)void rte_memzone_dump (FILE *f)void rte_memzone_walk (void(*func)(const struct rte_memzone *, void *arg), void *arg)
π₯ Detailed Description π₯
RTE Memzone
okay so the goal of the memzone allocator is literally to reserve contiguous portions of physical memory. these zones are identified by a name, periodt.
the memzone descriptors are shared by all partitions and are located in a known place of physical memory. this zone is accessed using rte_eal_get_configuration(). the lookup (by name) of a memory zone can be done in any partition and returns the same physical address, no cap.
a reserved memory zone cannot be unreserved. the reservation shall be done at initialization time only β so don't even try to free it later, bestie π
Definition in file rte_memzone.h.
β Macro Definition Documentation β
#define RTE_MEMZONE_2MB 0x00000001
Use 2MB pages. π
Definition at line 33 of file rte_memzone.h.
#define RTE_MEMZONE_1GB 0x00000002
Use 1GB pages. β¨
Definition at line 34 of file rte_memzone.h.
#define RTE_MEMZONE_16MB 0x00000100
Use 16MB pages. πΈ
Definition at line 35 of file rte_memzone.h.
#define RTE_MEMZONE_16GB 0x00000200
Use 16GB pages. π¦
Definition at line 36 of file rte_memzone.h.
#define RTE_MEMZONE_256KB 0x00010000
Use 256KB pages. π
Definition at line 37 of file rte_memzone.h.
#define RTE_MEMZONE_256MB 0x00020000
Use 256MB pages. π
Definition at line 38 of file rte_memzone.h.
#define RTE_MEMZONE_512MB 0x00040000
Use 512MB pages. π
Definition at line 39 of file rte_memzone.h.
#define RTE_MEMZONE_4GB 0x00080000
Use 4GB pages. π
Definition at line 40 of file rte_memzone.h.
#define RTE_MEMZONE_SIZE_HINT_ONLY 0x00000004
Use available page size. β
Definition at line 41 of file rte_memzone.h.
#define RTE_MEMZONE_IOVA_CONTIG 0x00100000
Ask for IOVA-contiguous memzone. π
Definition at line 42 of file rte_memzone.h.
#define RTE_MEMZONE_NAMESIZE 32
Maximum length of memory zone name. π
Definition at line 50 of file rte_memzone.h.
β¨ FUNCTION DOCUMENTATION β¨
okay bestie, this is where it gets juicy. all the actual functions you'll be calling. buckle up π
πΈ int rte_memzone_max_set (size_t max) πΈ
Sets the max number of memzones. the ceiling. the limit. the "no more after this" π
π¨ Important, no cap: this function can only be called prior to rte_eal_init(). once EAL is up, that ship has sailed, bestie.
Parameters:
maxβ the max number of memzones. as in, the most. the cap. the vibe limit.
Returns:
0on success-1otherwise (sad girl hours π)
π size_t rte_memzone_max_get (void ) π
Reads back the max number of memzones. like checking the receipt π§Ύ
Note: the maximum value will not change after you call rte_eal_init(). it's locked in, periodt.
Returns:
- the maximum number of memzones.
β¨ const struct rte_memzone * rte_memzone_reserve (const char * name, size_t len, int socket_id, unsigned flags) β¨
Reserves a portion of physical memory. this is the main character function of this whole header, fr fr π
It reserves some memory and hands you back a pointer to a correctly filled memzone descriptor. if the allocation can't happen? you get NULL. no notes.
Note, and this one matters: Reserving memzones withlenset to0will only attempt to allocate memzones from memory that is already available. It will not trigger any new allocations. so like, it's shopping your closet, not going to the mall. : When reserving memzones withlenset to0, it is preferable to also set a validsocket_id. Settingsocket_idtoSOCKET_ID_ANYis supported, but will likely not yield expected results. Specifically, the resulting memzone may not necessarily be the biggest memzone available, but rather biggest memzone available on socket id corresponding to an lcore from which reservation was called. ikykw π«Ά
Parameters:
nameβ the name of the memzone. if it already exists, the function will fail and returnNULL. (names are taken, bestie, find a new one)lenβ the size of the memory to be reserved. if it's0, the biggest contiguous zone will be reserved. big back big back energy.socket_idβ the socket identifier in the case of NUMA. the value can beSOCKET_ID_ANYif there is no NUMA constraint for the reserved zone.flagsβ used to request memzones to be taken from specifically sized hugepages. your page-size menu, order up:RTE_MEMZONE_2MBβ Reserved from 2MB pagesRTE_MEMZONE_1GBβ Reserved from 1GB pagesRTE_MEMZONE_16MBβ Reserved from 16MB pagesRTE_MEMZONE_16GBβ Reserved from 16GB pagesRTE_MEMZONE_256KBβ Reserved from 256KB pagesRTE_MEMZONE_256MBβ Reserved from 256MB pagesRTE_MEMZONE_512MBβ Reserved from 512MB pagesRTE_MEMZONE_4GBβ Reserved from 4GB pagesRTE_MEMZONE_SIZE_HINT_ONLYβ Allow alternative page size to be used if the requested page size is unavailable. If this flag is not set, the function will return error on an unavailable size request.RTE_MEMZONE_IOVA_CONTIGβ Ensure reserved memzone is IOVA-contiguous. This option should be used when allocating memory intended for hardware rings etc.
Returns:
a pointer to a correctly-filled read-only memzone descriptor, or NULL on error. on the error case, rte_errno will be set appropriately:
E_RTE_NO_CONFIGβ function could not get pointer torte_configstructureENOSPCβ the maximum number of memzones has already been allocatedEEXISTβ a memzone with the same name already existsENOMEMβ no appropriate memory area found in which to create memzoneEINVALβ invalid parameters
π const struct rte_memzone * rte_memzone_reserve_aligned (const char * name, size_t len, int socket_id, unsigned flags, unsigned align) π
Reserves a portion of physical memory with alignment on a specified boundary. it's the same girl but with rules about where she stands π
This function reserves some memory with alignment on a specified boundary, and returns a pointer to a correctly filled memzone descriptor. If the allocation cannot be done or if the alignment is not a power of 2, it returns NULL. no half-measures.
Note, same disclaimer as above, do not skip: Reserving memzones withlenset to0will only attempt to allocate memzones from memory that is already available. It will not trigger any new allocations. : When reserving memzones withlenset to0, it is preferable to also set a validsocket_id. Settingsocket_idtoSOCKET_ID_ANYis supported, but will likely not yield expected results. Specifically, the resulting memzone may not necessarily be the biggest memzone available, but rather biggest memzone available on socket id corresponding to an lcore from which reservation was called.
Parameters:
nameβ the name of the memzone. if it already exists, the function will fail and returnNULL.lenβ the size of the memory to be reserved. if it is0, the biggest contiguous zone will be reserved.socket_idβ the socket identifier in the case of NUMA. the value can beSOCKET_ID_ANYif there is no NUMA constraint for the reserved zone.flagsβ used to request memzones to be taken from specifically sized hugepages:RTE_MEMZONE_2MBβ Reserved from 2MB pagesRTE_MEMZONE_1GBβ Reserved from 1GB pagesRTE_MEMZONE_16MBβ Reserved from 16MB pagesRTE_MEMZONE_16GBβ Reserved from 16GB pagesRTE_MEMZONE_256KBβ Reserved from 256KB pagesRTE_MEMZONE_256MBβ Reserved from 256MB pagesRTE_MEMZONE_512MBβ Reserved from 512MB pagesRTE_MEMZONE_4GBβ Reserved from 4GB pagesRTE_MEMZONE_SIZE_HINT_ONLYβ Allow alternative page size to be used if the requested page size is unavailable. If this flag is not set, the function will return error on an unavailable size request.RTE_MEMZONE_IOVA_CONTIGβ Ensure reserved memzone is IOVA-contiguous. This option should be used when allocating memory intended for hardware rings etc.
alignβ alignment for the resulting memzone. must be a power of 2. π₯
Returns:
a pointer to a correctly-filled read-only memzone descriptor, or NULL on error. on the error case, rte_errno will be set appropriately:
E_RTE_NO_CONFIGβ function could not get pointer torte_configstructureENOSPCβ the maximum number of memzones has already been allocatedEEXISTβ a memzone with the same name already existsENOMEMβ no appropriate memory area found in which to create memzoneEINVALβ invalid parameters
π const struct rte_memzone * rte_memzone_reserve_bounded (const char * name, size_t len, int socket_id, unsigned flags, unsigned align, unsigned bound) π
Reserves a portion of physical memory with specified alignment AND boundary. two constraints, twice the drama, still slaying π
This function reserves some memory with specified alignment and boundary, and returns a pointer to a correctly filled memzone descriptor. If the allocation cannot be done or if the alignment or boundary are not a power of 2, it returns NULL. The memory buffer is reserved in a way, that it wouldn't cross the specified boundary. That implies that the requested length should be less or equal than the boundary. read that twice, bestie, it's a real constraint π«
Note, yes it's the same note, yes it still applies, no I'm not skipping it: Reserving memzones withlenset to0will only attempt to allocate memzones from memory that is already available. It will not trigger any new allocations. : When reserving memzones withlenset to0, it is preferable to also set a validsocket_id. Settingsocket_idtoSOCKET_ID_ANYis supported, but will likely not yield expected results. Specifically, the resulting memzone may not necessarily be the biggest memzone available, but rather biggest memzone available on socket id corresponding to an lcore from which reservation was called.
Parameters:
nameβ the name of the memzone. if it already exists, the function will fail and returnNULL.lenβ the size of the memory to be reserved. if it is0, the biggest contiguous zone will be reserved.socket_idβ the socket identifier in the case of NUMA. the value can beSOCKET_ID_ANYif there is no NUMA constraint for the reserved zone.flagsβ used to request memzones to be taken from specifically sized hugepages:RTE_MEMZONE_2MBβ Reserved from 2MB pagesRTE_MEMZONE_1GBβ Reserved from 1GB pagesRTE_MEMZONE_16MBβ Reserved from 16MB pagesRTE_MEMZONE_16GBβ Reserved from 16GB pagesRTE_MEMZONE_256KBβ Reserved from 256KB pagesRTE_MEMZONE_256MBβ Reserved from 256MB pagesRTE_MEMZONE_512MBβ Reserved from 512MB pagesRTE_MEMZONE_4GBβ Reserved from 4GB pagesRTE_MEMZONE_SIZE_HINT_ONLYβ Allow alternative page size to be used if the requested page size is unavailable. If this flag is not set, the function will return error on an unavailable size request.RTE_MEMZONE_IOVA_CONTIGβ Ensure reserved memzone is IOVA-contiguous. This option should be used when allocating memory intended for hardware rings etc.
alignβ alignment for the resulting memzone. must be a power of 2.boundβ boundary for the resulting memzone. must be a power of 2 or zero. a zero value implies no boundary condition. zero = unbothered, moisturized, in her lane.
Returns:
a pointer to a correctly-filled read-only memzone descriptor, or NULL on error. on the error case, rte_errno will be set appropriately:
E_RTE_NO_CONFIGβ function could not get pointer torte_configstructureENOSPCβ the maximum number of memzones has already been allocatedEEXISTβ a memzone with the same name already existsENOMEMβ no appropriate memory area found in which to create memzoneEINVALβ invalid parameters
π¦ int rte_memzone_free (const struct rte_memzone * mz) π¦
Frees a memzone. giving memory back to the universe. releasing, letting go, character development ποΈ
Parameters:
mzβ a pointer to the memzone
Returns:
-EINVALβ invalid parameter.0β success
π const struct rte_memzone * rte_memzone_lookup (const char * name) π
Looks up a memzone. like searching a name in the group chat π¬
Get a pointer to a descriptor of an already reserved memory zone identified by the name given as an argument.
Parameters:
nameβ the name of the memzone.
Returns:
a pointer to a read-only memzone descriptor.
π void rte_memzone_dump (FILE * f) π
Dumps all reserved memzones to a file. the receipts, printed. forensic era π
Parameters:
fβ a pointer to a file for output
π§ void rte_memzone_walk (void(* func )(const struct rte_memzone *, void *arg), void * arg) π§
Walks the list of all memzones. strolling through memory, one zone at a time πΆββοΈ
Parameters:
funcβ iterator functionargβ argument passed to iterator
π Author π
Generated automatically by Doxygen for DPDK from the source code. (not a human author, just robot magic β¨π€)
and that's the whole page, bestie π«Ά this was DPDK, Version 25.11.3, and you've been reading rte_memzone.h(3). go reserve something iconic ππΈβ¨
π¦ where this page comes from
- ubuntu resolute: dpdk-doc 25.11.3-0ubuntu0.26.04.1 Β· BSD-3-Clause
- ubuntu stonking: dpdk-doc 25.11.3-1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms