#include "util/locks.h"
Data Structures | |
struct | alloc_cache |
Structure that provides allocation. More... | |
Defines | |
#define | alloc_special_clean(x) (x)->id = 0; |
clean the special type. | |
#define | alloc_special_next(x) ((alloc_special_t*)((x)->entry.overflow_next)) |
access next pointer. | |
#define | alloc_set_special_next(x, y) ((x)->entry.overflow_next) = (struct lruhash_entry*)(y); |
set next pointer. | |
#define | ALLOC_SPECIAL_MAX 10 |
how many blocks to cache locally. | |
Typedefs | |
typedef struct ub_packed_rrset_key | alloc_special_t |
The special type, packed rrset. | |
Functions | |
void | alloc_init (struct alloc_cache *alloc, struct alloc_cache *super, int thread_num) |
Init alloc (zeroes the struct). | |
void | alloc_clear (struct alloc_cache *alloc) |
Free the alloc. | |
alloc_special_t * | alloc_special_obtain (struct alloc_cache *alloc) |
Get a new special_t element. | |
void | alloc_special_release (struct alloc_cache *alloc, alloc_special_t *mem) |
Return special_t back to pool. | |
uint64_t | alloc_get_id (struct alloc_cache *alloc) |
Set ID number of special type to a fresh new ID number. | |
size_t | alloc_get_mem (struct alloc_cache *alloc) |
Get memory size of alloc cache, alloc structure including special types. | |
void | alloc_stats (struct alloc_cache *alloc) |
Print debug information (statistics). | |
struct regional * | alloc_reg_obtain (struct alloc_cache *alloc) |
Get a new regional for query states. | |
void | alloc_reg_release (struct alloc_cache *alloc, struct regional *r) |
Put regional for query states back into alloc cache. | |
void | alloc_set_id_cleanup (struct alloc_cache *alloc, void(*cleanup)(void *), void *arg) |
Set cleanup on ID overflow callback function. |
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.
#define alloc_special_clean | ( | x | ) | (x)->id = 0; |
#define alloc_special_next | ( | x | ) | ((alloc_special_t*)((x)->entry.overflow_next)) |
access next pointer.
(in available spot). Pass pointer.
Referenced by alloc_clear(), alloc_get_mem(), alloc_special_obtain(), and pushintosuper().
#define alloc_set_special_next | ( | x, | |||
y | ) | ((x)->entry.overflow_next) = (struct lruhash_entry*)(y); |
set next pointer.
(in available spot). Pass pointers.
Referenced by alloc_clear(), alloc_special_release(), prealloc(), and pushintosuper().
#define ALLOC_SPECIAL_MAX 10 |
how many blocks to cache locally.
Referenced by alloc_special_release(), prealloc(), and pushintosuper().
typedef struct ub_packed_rrset_key alloc_special_t |
The special type, packed rrset.
Not allowed to be used for other memory
void alloc_init | ( | struct alloc_cache * | alloc, | |
struct alloc_cache * | super, | |||
int | thread_num | |||
) |
Init alloc (zeroes the struct).
alloc,: | this parameter is allocated by the caller. | |
super,: | super to use (init that before with super_init). Pass this argument NULL to init the toplevel alloc structure. | |
thread_num,: | thread number for id creation of special type. |
References alloc_cache::cleanup, alloc_cache::cleanup_arg, alloc_cache::last_id, alloc_cache::lock, alloc_cache::max_reg_blocks, alloc_cache::next_id, alloc_cache::num_reg_blocks, prealloc_blocks(), alloc_cache::reg_list, alloc_cache::super, alloc_cache::thread_num, and THRNUM_SHIFT.
Referenced by alloc_test(), context_obtain_alloc(), daemon_init(), dstest_file(), msgparse_test(), nsec3_hash_test(), ub_ctx_create(), verifytest_file(), and worker_init().
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).
alloc,: | is almost zeroed on exit (except some stats). |
References alloc_set_special_next, alloc_special_next, ub_packed_rrset_key::entry, lruhash_entry::lock, alloc_cache::lock, regional::next, alloc_cache::num_quar, alloc_cache::num_reg_blocks, alloc_cache::quar, alloc_cache::reg_list, and alloc_cache::super.
Referenced by alloc_test(), daemon_delete(), dstest_file(), msgparse_test(), nsec3_hash_test(), ub_ctx_delete(), verifytest_file(), and worker_delete().
alloc_special_t* alloc_special_obtain | ( | struct alloc_cache * | alloc | ) |
Get a new special_t element.
alloc,: | where to alloc it. |
References alloc_get_id(), alloc_setup_special(), alloc_special_next, fatal_exit(), ub_packed_rrset_key::id, alloc_cache::lock, log_assert, alloc_cache::num_quar, prealloc(), alloc_cache::quar, and alloc_cache::super.
Referenced by alloc_test(), repinfo_alloc_rrset_keys(), and store_rrset().
void alloc_special_release | ( | struct alloc_cache * | alloc, | |
alloc_special_t * | mem | |||
) |
Return special_t back to pool.
The block is cleaned up (zeroed) which also invalidates the ID inside.
alloc,: | where to alloc it. | |
mem,: | block to free. |
References alloc_set_special_next, alloc_special_clean, ALLOC_SPECIAL_MAX, alloc_cache::lock, log_assert, alloc_cache::num_quar, pushintosuper(), alloc_cache::quar, and alloc_cache::super.
Referenced by alloc_test(), store_rrset(), ub_packed_rrset_parsedelete(), and ub_rrset_key_delete().
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.
alloc,: | the alloc cache |
References alloc_cache::cleanup, alloc_cache::cleanup_arg, fptr_whitelist_alloc_cleanup(), alloc_cache::last_id, log_warn(), alloc_cache::next_id, alloc_cache::thread_num, and THRNUM_SHIFT.
Referenced by alloc_special_obtain(), and rrset_update_id().
size_t alloc_get_mem | ( | struct alloc_cache * | alloc | ) |
Get memory size of alloc cache, alloc structure including special types.
alloc,: | on what alloc. |
References ALLOC_REG_SIZE, alloc_special_next, ub_packed_rrset_key::entry, lruhash_entry::lock, alloc_cache::lock, alloc_cache::num_quar, alloc_cache::num_reg_blocks, alloc_cache::quar, and alloc_cache::super.
Referenced by worker_mem_report().
void alloc_stats | ( | struct alloc_cache * | alloc | ) |
Print debug information (statistics).
alloc,: | on what alloc. |
References log_info(), alloc_cache::num_quar, alloc_cache::num_reg_blocks, and alloc_cache::super.
Referenced by alloc_test().
struct regional* alloc_reg_obtain | ( | struct alloc_cache * | alloc | ) | [read] |
Get a new regional for query states.
alloc,: | where to alloc it. |
References ALLOC_REG_SIZE, regional::next, alloc_cache::num_reg_blocks, alloc_cache::reg_list, and regional_create_custom().
Referenced by mesh_state_create().
void alloc_reg_release | ( | struct alloc_cache * | alloc, | |
struct regional * | r | |||
) |
Put regional for query states back into alloc cache.
alloc,: | where to alloc it. | |
r,: | regional to put back. |
References log_assert, alloc_cache::max_reg_blocks, regional::next, alloc_cache::num_reg_blocks, alloc_cache::reg_list, regional_destroy(), and regional_free_all().
Referenced by mesh_state_cleanup(), and mesh_state_create().
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.
alloc,: | the alloc | |
cleanup,: | the callback function, called as cleanup(arg). | |
arg,: | user argument to callback function. |
References alloc_cache::cleanup, and alloc_cache::cleanup_arg.
Referenced by libworker_setup(), and worker_init().