Electroneum
alloc.h File Reference
#include "util/locks.h"
Include dependency graph for alloc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  alloc_cache
 

Macros

#define alloc_special_clean(x)   (x)->id = 0;
 
#define alloc_special_next(x)   ((alloc_special_type*)((x)->entry.overflow_next))
 
#define alloc_set_special_next(x, y)   ((x)->entry.overflow_next) = (struct lruhash_entry*)(y);
 
#define ALLOC_SPECIAL_MAX   10
 

Typedefs

typedef struct ub_packed_rrset_key alloc_special_type
 

Functions

void alloc_init (struct alloc_cache *alloc, struct alloc_cache *super, int thread_num)
 
void alloc_clear (struct alloc_cache *alloc)
 
void alloc_clear_special (struct alloc_cache *alloc)
 
alloc_special_typealloc_special_obtain (struct alloc_cache *alloc)
 
void alloc_special_release (struct alloc_cache *alloc, alloc_special_type *mem)
 
uint64_t alloc_get_id (struct alloc_cache *alloc)
 
size_t alloc_get_mem (struct alloc_cache *alloc)
 
void alloc_stats (struct alloc_cache *alloc)
 
struct regionalalloc_reg_obtain (struct alloc_cache *alloc)
 
void alloc_reg_release (struct alloc_cache *alloc, struct regional *r)
 
void alloc_set_id_cleanup (struct alloc_cache *alloc, void(*cleanup)(void *), void *arg)
 

Detailed Description

This file contains memory allocation functions.

The reasons for this service are: o Avoid locking costs of getting global lock to call malloc(). o The packed rrset type needs to be kept on special freelists, so that they are reused for other packet rrset allocations.

Definition in file alloc.h.

Macro Definition Documentation

◆ alloc_set_special_next

#define alloc_set_special_next (   x,
 
)    ((x)->entry.overflow_next) = (struct lruhash_entry*)(y);

set next pointer. (in available spot). Pass pointers.

Definition at line 62 of file alloc.h.

◆ alloc_special_clean

#define alloc_special_clean (   x)    (x)->id = 0;

clean the special type. Pass pointer.

Definition at line 58 of file alloc.h.

◆ ALLOC_SPECIAL_MAX

#define ALLOC_SPECIAL_MAX   10

how many blocks to cache locally.

Definition at line 66 of file alloc.h.

◆ alloc_special_next

#define alloc_special_next (   x)    ((alloc_special_type*)((x)->entry.overflow_next))

access next pointer. (in available spot). Pass pointer.

Definition at line 60 of file alloc.h.

Typedef Documentation

◆ alloc_special_type

The special type, packed rrset. Not allowed to be used for other memory

Definition at line 56 of file alloc.h.

Function Documentation

◆ alloc_clear()

void alloc_clear ( struct alloc_cache alloc)

Free the alloc. Pushes all the cached items into the super structure. Or deletes them if alloc->super is NULL. Does not free the alloc struct itself (it was also allocated by caller).

Parameters
allocis almost zeroed on exit (except some stats).

◆ alloc_clear_special()

void alloc_clear_special ( struct alloc_cache alloc)

Free the special alloced items. The rrset and message caches must be empty, there must be no more references to rrset pointers into the rrset cache.

Parameters
allocthe special allocs are freed.

◆ alloc_get_id()

uint64_t alloc_get_id ( struct alloc_cache alloc)

Set ID number of special type to a fresh new ID number. In case of ID number overflow, the rrset cache has to be cleared.

Parameters
allocthe alloc cache
Returns
: fresh id is returned.

◆ alloc_get_mem()

size_t alloc_get_mem ( struct alloc_cache alloc)

Get memory size of alloc cache, alloc structure including special types.

Parameters
allocon what alloc.
Returns
size in bytes.

◆ alloc_init()

void alloc_init ( struct alloc_cache alloc,
struct alloc_cache super,
int  thread_num 
)

Init alloc (zeroes the struct).

Parameters
allocthis parameter is allocated by the caller.
supersuper to use (init that before with super_init). Pass this argument NULL to init the toplevel alloc structure.
thread_numthread number for id creation of special type.

◆ alloc_reg_obtain()

struct regional* alloc_reg_obtain ( struct alloc_cache alloc)

Get a new regional for query states

Parameters
allocwhere to alloc it.
Returns
regional for use or NULL on alloc failure.

◆ alloc_reg_release()

void alloc_reg_release ( struct alloc_cache alloc,
struct regional r 
)

Put regional for query states back into alloc cache.

Parameters
allocwhere to alloc it.
rregional to put back.

◆ alloc_set_id_cleanup()

void alloc_set_id_cleanup ( struct alloc_cache alloc,
void(*)(void *)  cleanup,
void *  arg 
)

Set cleanup on ID overflow callback function. This should remove all RRset ID references from the program. Clear the caches.

Parameters
allocthe alloc
cleanupthe callback function, called as cleanup(arg).
arguser argument to callback function.

◆ alloc_special_obtain()

alloc_special_type* alloc_special_obtain ( struct alloc_cache alloc)

Get a new special_type element.

Parameters
allocwhere to alloc it.
Returns
: memory block. Will not return NULL (instead fatal_exit). The block is zeroed.

◆ alloc_special_release()

void alloc_special_release ( struct alloc_cache alloc,
alloc_special_type mem 
)

Return special_type back to pool. The block is cleaned up (zeroed) which also invalidates the ID inside.

Parameters
allocwhere to alloc it.
memblock to free.

◆ alloc_stats()

void alloc_stats ( struct alloc_cache alloc)

Print debug information (statistics).

Parameters
allocon what alloc.