This file contains memory allocation functions. More...
#include "config.h"#include "util/alloc.h"#include "util/regional.h"#include "util/data/packed_rrset.h"#include "util/fptr_wlist.h"Defines | |
| #define | ALLOC_REG_SIZE 16384 |
| custom size of cached regional blocks | |
| #define | THRNUM_SHIFT 48 |
| number of bits for ID part of uint64, rest for number of threads. | |
Functions | |
| static void | alloc_setup_special (alloc_special_t *t) |
| setup new special type | |
| static void | prealloc (struct alloc_cache *alloc) |
| prealloc some entries in the cache. | |
| static void | prealloc_blocks (struct alloc_cache *alloc, size_t num) |
| prealloc region blocks | |
| 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. | |
| uint64_t | alloc_get_id (struct alloc_cache *alloc) |
| Set ID number of special type to a fresh new ID number. | |
| alloc_special_t * | alloc_special_obtain (struct alloc_cache *alloc) |
| Get a new special_t element. | |
| static void | pushintosuper (struct alloc_cache *alloc, alloc_special_t *mem) |
| push mem and some more items to the super | |
| void | alloc_special_release (struct alloc_cache *alloc, alloc_special_t *mem) |
| Return special_t back to pool. | |
| void | alloc_stats (struct alloc_cache *alloc) |
| Print debug information (statistics). | |
| size_t | alloc_get_mem (struct alloc_cache *alloc) |
| Get memory size of alloc cache, alloc structure including special types. | |
| 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. | |
Variables | |
| size_t | unbound_mem_alloc = 0 |
| global debug value to keep track of total memory mallocs | |
| size_t | unbound_mem_freed = 0 |
| global debug value to keep track of total memory frees | |
This file contains memory allocation functions.
| #define THRNUM_SHIFT 48 |
number of bits for ID part of uint64, rest for number of threads.
Referenced by alloc_init(), and alloc_get_id().
| static void prealloc | ( | struct alloc_cache * | alloc | ) | [static] |
prealloc some entries in the cache.
To minimize contention. Result is 1 lock per alloc_max newly created entries.
| alloc,: | the structure to fill up. |
References ALLOC_SPECIAL_MAX, log_err(), alloc_setup_special(), alloc_set_special_next, alloc_cache::quar, and alloc_cache::num_quar.
Referenced by alloc_special_obtain().
| 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::super, alloc_cache::thread_num, alloc_cache::next_id, THRNUM_SHIFT, alloc_cache::last_id, alloc_cache::max_reg_blocks, alloc_cache::num_reg_blocks, alloc_cache::reg_list, alloc_cache::cleanup, alloc_cache::cleanup_arg, prealloc_blocks(), and alloc_cache::lock.
Referenced by daemon_init(), worker_init(), context_obtain_alloc(), ub_ctx_create(), alloc_test(), msgparse_test(), verifytest_file(), dstest_file(), and nsec3_hash_test().
| 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_cache::super, alloc_cache::lock, alloc_cache::quar, alloc_special_next, alloc_set_special_next, alloc_cache::num_quar, ub_packed_rrset_key::entry, lruhash_entry::lock, alloc_cache::reg_list, regional::next, and alloc_cache::num_reg_blocks.
Referenced by daemon_delete(), worker_delete(), ub_ctx_delete(), alloc_test(), msgparse_test(), verifytest_file(), dstest_file(), and nsec3_hash_test().
| 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::next_id, alloc_cache::last_id, log_warn(), fptr_ok, fptr_whitelist_alloc_cleanup(), alloc_cache::cleanup, alloc_cache::cleanup_arg, alloc_cache::thread_num, and THRNUM_SHIFT.
Referenced by rrset_update_id(), and alloc_special_obtain().
| alloc_special_t* alloc_special_obtain | ( | struct alloc_cache * | alloc | ) |
Get a new special_t element.
| alloc,: | where to alloc it. |
References log_assert, alloc_cache::quar, alloc_special_next, alloc_cache::num_quar, ub_packed_rrset_key::id, alloc_get_id(), alloc_cache::super, alloc_cache::lock, prealloc(), log_err(), and alloc_setup_special().
Referenced by move_into_cache(), store_rrset(), alloc_test(), repinfo_alloc_rrset_keys(), and packed_rrset_copy_alloc().
| 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 log_assert, alloc_cache::super, alloc_cache::lock, alloc_special_clean, alloc_cache::num_quar, ALLOC_SPECIAL_MAX, pushintosuper(), alloc_set_special_next, and alloc_cache::quar.
Referenced by store_rrset(), alloc_test(), ub_packed_rrset_parsedelete(), ub_rrset_key_delete(), and packed_rrset_copy_alloc().
| void alloc_stats | ( | struct alloc_cache * | alloc | ) |
Print debug information (statistics).
| alloc,: | on what alloc. |
References log_info(), alloc_cache::super, alloc_cache::num_quar, and alloc_cache::num_reg_blocks.
Referenced by alloc_test().
| 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_cache::super, alloc_cache::lock, alloc_cache::num_quar, alloc_cache::quar, alloc_special_next, ub_packed_rrset_key::entry, lruhash_entry::lock, alloc_cache::num_reg_blocks, and ALLOC_REG_SIZE.
Referenced by worker_mem_report().
| struct regional* alloc_reg_obtain | ( | struct alloc_cache * | alloc | ) | [read] |
Get a new regional for query states.
| alloc,: | where to alloc it. |
References alloc_cache::num_reg_blocks, alloc_cache::reg_list, regional::next, regional_create_custom(), and ALLOC_REG_SIZE.
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 alloc_cache::num_reg_blocks, alloc_cache::max_reg_blocks, regional_destroy(), regional_free_all(), log_assert, regional::next, and alloc_cache::reg_list.
Referenced by mesh_state_create(), and mesh_state_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.
| 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 worker_init(), and libworker_setup().