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:

  • 0 on success
  • -1 otherwise (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 with len set to 0 will 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 with len set to 0, it is preferable to also set a valid socket_id. Setting socket_id to SOCKET_ID_ANY is 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 return NULL. (names are taken, bestie, find a new one)
  • len β€” the size of the memory to be reserved. if it's 0, 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 be SOCKET_ID_ANY if 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 pages
    • RTE_MEMZONE_1GB β€” Reserved from 1GB pages
    • RTE_MEMZONE_16MB β€” Reserved from 16MB pages
    • RTE_MEMZONE_16GB β€” Reserved from 16GB pages
    • RTE_MEMZONE_256KB β€” Reserved from 256KB pages
    • RTE_MEMZONE_256MB β€” Reserved from 256MB pages
    • RTE_MEMZONE_512MB β€” Reserved from 512MB pages
    • RTE_MEMZONE_4GB β€” Reserved from 4GB pages
    • RTE_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 to rte_config structure
  • ENOSPC β€” the maximum number of memzones has already been allocated
  • EEXIST β€” a memzone with the same name already exists
  • ENOMEM β€” no appropriate memory area found in which to create memzone
  • EINVAL β€” 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 with len set to 0 will only attempt to allocate memzones from memory that is already available. It will not trigger any new allocations. : When reserving memzones with len set to 0, it is preferable to also set a valid socket_id. Setting socket_id to SOCKET_ID_ANY is 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 return NULL.
  • len β€” the size of the memory to be reserved. if it is 0, the biggest contiguous zone will be reserved.
  • socket_id β€” the socket identifier in the case of NUMA. the value can be SOCKET_ID_ANY if 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 pages
    • RTE_MEMZONE_1GB β€” Reserved from 1GB pages
    • RTE_MEMZONE_16MB β€” Reserved from 16MB pages
    • RTE_MEMZONE_16GB β€” Reserved from 16GB pages
    • RTE_MEMZONE_256KB β€” Reserved from 256KB pages
    • RTE_MEMZONE_256MB β€” Reserved from 256MB pages
    • RTE_MEMZONE_512MB β€” Reserved from 512MB pages
    • RTE_MEMZONE_4GB β€” Reserved from 4GB pages
    • RTE_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 to rte_config structure
  • ENOSPC β€” the maximum number of memzones has already been allocated
  • EEXIST β€” a memzone with the same name already exists
  • ENOMEM β€” no appropriate memory area found in which to create memzone
  • EINVAL β€” 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 with len set to 0 will only attempt to allocate memzones from memory that is already available. It will not trigger any new allocations. : When reserving memzones with len set to 0, it is preferable to also set a valid socket_id. Setting socket_id to SOCKET_ID_ANY is 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 return NULL.
  • len β€” the size of the memory to be reserved. if it is 0, the biggest contiguous zone will be reserved.
  • socket_id β€” the socket identifier in the case of NUMA. the value can be SOCKET_ID_ANY if 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 pages
    • RTE_MEMZONE_1GB β€” Reserved from 1GB pages
    • RTE_MEMZONE_16MB β€” Reserved from 16MB pages
    • RTE_MEMZONE_16GB β€” Reserved from 16GB pages
    • RTE_MEMZONE_256KB β€” Reserved from 256KB pages
    • RTE_MEMZONE_256MB β€” Reserved from 256MB pages
    • RTE_MEMZONE_512MB β€” Reserved from 512MB pages
    • RTE_MEMZONE_4GB β€” Reserved from 4GB pages
    • RTE_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 to rte_config structure
  • ENOSPC β€” the maximum number of memzones has already been allocated
  • EEXIST β€” a memzone with the same name already exists
  • ENOMEM β€” no appropriate memory area found in which to create memzone
  • EINVAL β€” 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 function
  • arg β€” 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