CNDP  22.08.0
cne_mmap.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <cne_common.h>

Go to the source code of this file.

Data Structures

struct  mmap_sizes_t
 
struct  mmap_stats_t
 

Typedefs

typedef void mmap_t
 

Enumerations

enum  mmap_type_t { MMAP_HUGEPAGE_4KB , MMAP_HUGEPAGE_2MB , MMAP_HUGEPAGE_1GB , MMAP_HUGEPAGE_CNT }
 

Functions

CNDP_API mmap_tmmap_alloc (uint32_t bufcnt, uint32_t bufsz, mmap_type_t hugepage)
 
CNDP_API int mmap_free (mmap_t *mmap)
 
CNDP_API void * mmap_addr_at_offset (mmap_t *mm, size_t offset)
 
CNDP_API void * mmap_addr (mmap_t *mm)
 
CNDP_API size_t mmap_size (mmap_t *mm, uint32_t *bufcnt, uint32_t *bufsz)
 
CNDP_API mmap_type_t mmap_type_by_name (const char *htype)
 
CNDP_API const char * mmap_name_by_type (mmap_type_t typ)
 
CNDP_API void mmap_set_default (mmap_type_t htype)
 
CNDP_API void mmap_set_default_by_name (const char *name)
 

Detailed Description

CNE allocator for huge pages

Allocate memory using MMAP anonyuous memory using hugepages.

Definition in file cne_mmap.h.

Typedef Documentation

◆ mmap_t

typedef void mmap_t

Opaque pointer to internal mmap data

Definition at line 55 of file cne_mmap.h.

Enumeration Type Documentation

◆ mmap_type_t

Set of enums to help define HUGEPAGE sizes

Enumerator
MMAP_HUGEPAGE_4KB 

4KB pages or default system page size

MMAP_HUGEPAGE_2MB 

2MB page size

MMAP_HUGEPAGE_1GB 

1GB page size if supported

MMAP_HUGEPAGE_CNT 

Number of different page sizes supported

Definition at line 27 of file cne_mmap.h.

Function Documentation

◆ mmap_alloc()

CNDP_API mmap_t* mmap_alloc ( uint32_t  bufcnt,
uint32_t  bufsz,
mmap_type_t  hugepage 
)

Allocate memory on the correct socket and use hugepages if set.

Parameters
bufcntNumber of buffers in the memory pool
bufszThe size of the buffers in the memory pool
hugepageType of hugepage memory to allocate or non-hugepage memory.
Returns
The mmap_t structure pointer of the memory allocated or NULL on error
Examples
examples/cndpfwd/parse-args.c, examples/cnet-graph/parse-args.c, examples/cnet-quic/parse-args.c, examples/dlb_test/parse-args.c, and examples/l3fwd-graph/parse-args.c.

◆ mmap_free()

CNDP_API int mmap_free ( mmap_t mmap)

Free the memory allocated

Parameters
mmapstructure holding the mmap region information
Returns
0 if freed OK, else -1
Examples
examples/cndpfwd/main.c, examples/cndpfwd/parse-args.c, examples/cnet-graph/parse-args.c, examples/cnet-quic/parse-args.c, and examples/dlb_test/parse-args.c.

◆ mmap_addr_at_offset()

CNDP_API void* mmap_addr_at_offset ( mmap_t mm,
size_t  offset 
)

Return the address in the memory region for the buffer index and size of buffer.

Return the address based on the offset into the memory region.

Parameters
mmThe mmap_t pointer
offsetThe offset value
Returns
The address at offset in mmap memory

◆ mmap_addr()

CNDP_API void* mmap_addr ( mmap_t mm)

Returns the memory region for a given mmap_t pointer

Parameters
mmThe mmap_t pointer
Returns
The virtual address of the memory region or NULL on error
Examples
examples/cndpfwd/parse-args.c, examples/cnet-graph/parse-args.c, examples/cnet-quic/parse-args.c, examples/dlb_test/parse-args.c, and examples/l3fwd-graph/parse-args.c.

◆ mmap_size()

CNDP_API size_t mmap_size ( mmap_t mm,
uint32_t *  bufcnt,
uint32_t *  bufsz 
)

Return the true size of the memory mapped region

Parameters
mmThe mmap_t pointer
bufcntA uint32_t location to place the buffer count value, can be NULL.
bufszA uint32_t location to place the buffer size value, can be NULL.
Returns
The real size in bytes of the memory region or 0 on error
Examples
examples/cndpfwd/parse-args.c, examples/cnet-graph/parse-args.c, examples/cnet-quic/parse-args.c, examples/dlb_test/parse-args.c, and examples/l3fwd-graph/parse-args.c.

◆ mmap_type_by_name()

CNDP_API mmap_type_t mmap_type_by_name ( const char *  htype)

Find a memory hugepage type value by hugepage name

Parameters
htypeThe hugepage memory type string "4KB", "2MB" or "1GB" memory type
Returns
The integer value for the htype passed into the function. If the size string is not found then the default type is returned.

◆ mmap_name_by_type()

CNDP_API const char* mmap_name_by_type ( mmap_type_t  typ)

Find the hugepage memory string from a given type

Parameters
typThe integer value for a given type
Returns
The string pointer to a given mmap type or NULL if not found.

◆ mmap_set_default()

CNDP_API void mmap_set_default ( mmap_type_t  htype)

Set the default memory type for allocations

Parameters
htypeThe integer hugepage memory type

◆ mmap_set_default_by_name()

CNDP_API void mmap_set_default_by_name ( const char *  name)

Set the default memory type by hugepage memory string

Parameters
nameThe number for a memory type "4KB", "2MB", ...