unbound  0.1
Macros | Functions
regional.c File Reference

Regional allocator. More...

#include "config.h"
#include "util/log.h"
#include "util/regional.h"

Macros

#define ALIGN_UP(x, s)   (((x) + s - 1) & (~(s - 1)))
 increase size until it fits alignment of s bytes
#define ALIGNMENT   (sizeof(uint64_t))
 what size to align on; make sure a char* fits in it.
#define REGIONAL_CHUNK_SIZE   8192
 Default reasonable size for chunks.
#define REGIONAL_LARGE_OBJECT_SIZE   2048
 Default size for large objects - allocated outside of chunks.

Functions

struct regionalregional_create (void)
 Create a new regional.
static void regional_init (struct regional *r)
 init regional struct with first block
struct regionalregional_create_custom (size_t size)
 Create a new region, with custom settings.
void regional_free_all (struct regional *r)
 Free all memory associated with regional.
void regional_destroy (struct regional *r)
 Destroy regional.
void * regional_alloc (struct regional *r, size_t size)
 Allocate size bytes of memory inside regional.
void * regional_alloc_init (struct regional *r, const void *init, size_t size)
 Allocate size bytes of memory inside regional and copy INIT into it.
void * regional_alloc_zero (struct regional *r, size_t size)
 Allocate size bytes of memory inside regional that are initialized to 0.
char * regional_strdup (struct regional *r, const char *string)
 Duplicate string and allocate the result in regional.
static size_t count_chunks (struct regional *r)
 reasonably slow, but stats and get_mem are not supposed to be fast count the number of chunks in use
static size_t count_large (struct regional *r)
 also reasonably slow, counts the number of large objects
void regional_log_stats (struct regional *r)
 Debug print regional statistics to log.
size_t regional_get_mem (struct regional *r)
 get total memory size in use by region

Detailed Description

Regional allocator.

Allocates small portions of of larger chunks.

Macro Definition Documentation

#define ALIGNMENT   (sizeof(uint64_t))

what size to align on; make sure a char* fits in it.

Referenced by regional_alloc(), regional_init(), and regional_log_stats().

#define REGIONAL_LARGE_OBJECT_SIZE   2048

Default size for large objects - allocated outside of chunks.

Referenced by regional_alloc(), and regional_log_stats().

Function Documentation

struct regional* regional_create ( void  )
read
struct regional* regional_create_custom ( size_t  size)
read

Create a new region, with custom settings.

Parameters
size,:length of first block.
Returns
: newly allocated regional.

References regional::first_size, log_assert, and regional_init().

Referenced by alloc_reg_obtain(), burden_test(), libworker_setup(), prealloc_blocks(), regional_create(), specific_cases(), and worker_init().

void regional_free_all ( struct regional r)
void regional_destroy ( struct regional r)

Destroy regional.

All memory associated with regional is freed as if regional_free_all was called, as well as destroying the regional struct.

Parameters
r,:to delete.

References regional_free_all().

Referenced by acl_list_delete(), alloc_reg_release(), burden_test(), check_mod(), donotq_delete(), dstest_file(), libworker_delete(), local_zone_delete(), log_dns_msg(), nsec3_hash_test(), perf_encode(), perftestpkt(), priv_delete(), process_answer_detail(), specific_cases(), testpkt(), verifytest_file(), and worker_delete().

void* regional_alloc ( struct regional r,
size_t  size 
)

Allocate size bytes of memory inside regional.

The memory is deallocated when region_free_all is called for this region.

Parameters
r,:the region.
size,:number of bytes.
Returns
: pointer to memory allocated.

References ALIGN_UP, ALIGNMENT, regional::available, regional::data, regional::large_list, regional::next, REGIONAL_CHUNK_SIZE, REGIONAL_LARGE_OBJECT_SIZE, and regional::total_large.

Referenced by acl_list_insert(), add_rr_to_rrset(), burden_test(), compress_tree_newnode(), construct_reply_info_base(), corner_cases(), createResponse(), delegpt_add_addr(), delegpt_add_ns(), delegpt_create(), dns_alloc_msg(), dns_copy_msg(), dns_msg_create(), donotq_insert(), ds_digest_match_dnskey(), errinf(), gen_dns_msg(), generate_sub_request(), insert_rr(), iter_add_prepend_answer(), iter_add_prepend_auth(), iter_new(), iter_prepend(), iter_store_parentside_neg(), key_entry_get_rrset(), key_entry_setup(), libworker_send_query(), mesh_state_add_cb(), mesh_state_add_reply(), mesh_state_attachment(), mesh_state_create(), moveover_rrsigs(), new_rrset(), nsec3_calc_hash(), nsec3_ce_wildcard(), nsec3_hash_name(), packed_rrset_copy_region(), parse_copy_decompress_rrset(), parse_create_qinfo(), parse_create_rrset(), parse_reply(), process_response(), processClassResponse(), read_addrs(), read_names(), regional_alloc_init(), regional_alloc_zero(), repinfo_alloc_rrset_keys(), reply_info_parse(), rrset_array_unlock_touch(), rrset_canonical(), sock_list_insert(), synth_cname_rrset(), synth_dname_msg(), val_dlv_init(), val_new(), val_new_getmsg(), and worker_send_query().

void* regional_alloc_init ( struct regional r,
const void *  init,
size_t  size 
)
void* regional_alloc_zero ( struct regional r,
size_t  size 
)

Allocate size bytes of memory inside regional that are initialized to 0.

The memory is deallocated when region_free_all is called for this region.

Parameters
r,:the region.
size,:number of bytes.
Returns
: pointer to memory allocated.

References regional_alloc().

Referenced by corner_cases(), dns_msg_create(), iter_store_parentside_neg(), load_msg(), load_rrset(), lz_find_create_node(), new_local_rrset(), and synth_dname_msg().

char* regional_strdup ( struct regional r,
const char *  string 
)

Duplicate string and allocate the result in regional.

Parameters
r,:the region.
string,:null terminated string.
Returns
: pointer to memory allocated.

References regional_alloc_init().

Referenced by algo_needs_reason(), corner_cases(), errinf(), key_entry_copy_toregion(), and key_entry_create_rrset().