MoonGen
 All Files Functions Variables Pages
memory.lua File Reference

Memory ... More...

Go to the source code of this file.

Functions

function mod alloc (ctype, size)
 Off-heap allocation, not garbage-collected. More...
 
function mod free (buf)
 Free off-heap allocated object.
 
function mod allocHuge (ctype, size)
 Off-heap allocation on huge pages, not garbage-collected. More...
 
function mod enableCache ()
 Enable mempool recycling. More...
 
param n optional (default=2047)
 Create a new memory pool. More...
 
function mod createMemPool (...)
 
function mod freeMemPools ()
 Free all memory pools owned by this task. More...
 
function mempool retain ()
 Retain a memory pool. More...
 
function mempool bufArray (n)
 Create a new array of memory buffers (initialized to nil).
 
function bufArray offloadIPChecksums (ipv4, l2Len, l3Len, n)
 If called, IP chksum offloading will be done for the first n packets.
 
function bufArray setVlans (vlan, pcp, cfi)
 Offloads VLAN tags on all packets.
 
function bufArray alloc (size)
 Allocates buffers from the memory pool and fills the array.
 
function bufArray freeAll ()
 Free all buffers in the array. Stops when it encounters the first one that is null.
 
function bufArray free (n)
 Free the first n buffers.
 

Variables

 n = self
 Create a new array of memory buffers (initialized to nil).
 

Detailed Description

Memory ...

Todo:
TODO docu

Definition in file memory.lua.

Function Documentation

function mod alloc ( ctype  ,
size   
)

Off-heap allocation, not garbage-collected.

Parameters
ctypea ffi type, must be a pointer or array type
sizethe amount of memory to allocate
function mod allocHuge ( ctype  ,
size   
)

Off-heap allocation on huge pages, not garbage-collected.

See memory.alloc. TODO: add a free function for this

function mod createMemPool (   ...)
Parameters
socketoptional (default = socket of the calling thread), NUMA association. This cannot be the only argument in the call.
bufSizeoptional the size of each buffer, can only be used if all other args are passed as well
Examples:
l2-poisson-load-latency.lua, l3-tcp-syn-flood.lua, and quality-of-service-test.lua.
function mod enableCache ( )

Enable mempool recycling.

Calling this function enables the mempool cache. This prevents memory leaks as DPDK cannot delete mempools. Mempools with the same parameters created on the same core will be recycled. This is not yet enabled by default because I'm not 100% confident that it works properly in all cases. For example, mempools passed to other tasks will probably break stuff.

function mod freeMemPools ( )

Free all memory pools owned by this task.

All queues using these pools must be stopped before calling this.

param n optional ( default  = 2047)

Create a new memory pool.

Memory pools are recycled once the owning task terminates. Call :retain() for mempools that are passed to other tasks. A table with named arguments should be used.

Parameters
argsA table containing the following named arguments
function mempool retain ( )

Retain a memory pool.

This will prevent the pool from being returned to a pool of pools once the task ends.