unbound: util/regional.c File Reference

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 regional * | regional_create (void)
| Create a new regional.
static void | regional_init (struct regional *r)
| init regional struct with first block
static struct regional * | regional_create_custom_large_object (size_t size, size_t large_object_size)
| Create a new region, with custom first block and large-object sizes.
struct regional * | regional_create_custom (size_t size)
| Create a new region, with custom settings.
struct regional * | regional_create_nochunk (size_t size)
| Create a new region, with custom settings, that will allocate everything outside the region chunk.
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.

## Function Documentation

## ◆ regional_create()

struct regional * regional_create | ( | void |  | ) |

Create a new regional.

Returns
  : newly allocated regional.

References REGIONAL_CHUNK_SIZE, and regional_create_custom().

Referenced by acl_list_create(), check_az_q_ans(), check_mod(), donotq_create(), dstest_file(), edns_strings_create(), log_dns_msg(), nsec3_hash_test(), perf_encode(), perftestpkt(), priv_create(), process_answer_detail(), respip_set_create(), specific_cases(), tcl_list_create(), testpkt(), verifytest_file(), zonemd_check_test(), zonemd_generate_test(), zonemd_offline_verify(), and zonemd_verify_test().

## ◆ regional_create_custom_large_object()

static struct regional * regional_create_custom_large_object | ( | size_t | size,
|  | size_t | large_object_size
| ) |  |
| static

Create a new region, with custom first block and large-object sizes.

Parameters

  size | length of first block.
  large_object_size | outside of chunk allocation threshold.

Returns
  : newly allocated regional.

References ALIGN_UP, ALIGNMENT, regional::first_size, regional::large_object_size, log_assert, and regional_init().

Referenced by regional_create_custom(), and regional_create_nochunk().

## ◆ regional_create_custom()

struct regional * regional_create_custom | ( | size_t | size | ) |

Create a new region, with custom settings.

Parameters

  size | length of first block.

Returns
  : newly allocated regional.

References regional_create_custom_large_object(), and REGIONAL_LARGE_OBJECT_SIZE.

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

## ◆ regional_create_nochunk()

struct regional * regional_create_nochunk | ( | size_t | size | ) |

Create a new region, with custom settings, that will allocate everything outside the region chunk.

Parameters

  size | length of first block.

Returns
  : newly allocated regional.

References regional_create_custom_large_object().

Referenced by local_zone_create().

## ◆ regional_free_all()

void regional_free_all | ( | struct regional * | r | ) |

Free all memory associated with regional.

Only keeps the first block with the regional inside it.

Parameters

  r | the region.

References regional::large_list, regional::next, and regional_init().

Referenced by acl_interface_init(), acl_list_apply_cfg(), alloc_reg_release(), auth_xfer_probe_lookup_callback(), auth_xfer_transfer_lookup_callback(), auth_zone_verify_zonemd(), auth_zone_verify_zonemd_key_with_ds(), auth_zone_zonemd_check_hash(), auth_zonemd_dnskey_lookup_callback(), autr_probe_timer(), burden_test(), chaos_trustanchor(), check_az_q_ans(), corner_cases(), donotq_apply_cfg(), dstest_entry(), dump_msg_lruhash(), edns_strings_apply_cfg(), handle_newq(), iter_indicates_dnssec(), libworker_attach_mesh(), libworker_fg(), load_msg(), load_rrset(), mesh_run(), perf_encode(), priv_apply_cfg(), regional_destroy(), reply_equal(), tcl_list_apply_cfg(), verifytest_entry(), worker_handle_request(), zonemd_get_dnskey_from_anchor(), zonemd_simple_rrset(), and zonemd_simple_rrsig().

## ◆ regional_destroy()

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_az_q_ans(), check_mod(), donotq_delete(), dstest_file(), edns_strings_delete(), libworker_delete_env(), local_zone_delete(), log_dns_msg(), nsec3_hash_test(), perf_encode(), perftestpkt(), priv_delete(), process_answer_detail(), respip_set_delete(), rpz_create(), rpz_delete(), specific_cases(), tcl_list_delete(), testpkt(), verifytest_file(), worker_delete(), zonemd_check_test(), zonemd_generate_test(), zonemd_offline_verify(), and zonemd_verify_test().

## ◆ regional_alloc()

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::large_object_size, regional::next, REGIONAL_CHUNK_SIZE, and regional::total_large.

Referenced by add_rr_to_rrset(), burden_test(), chaos_trustanchor(), compress_tree_newnode(), construct_reply_info_base(), corner_cases(), create_synth_cname(), createResponse(), delegpt_add_addr(), delegpt_add_ns(), delegpt_create(), dns64_adjust_a(), dns64_adjust_ptr(), dns64_inform_super(), dns64_operate(), dns_alloc_msg(), dns_copy_msg(), dns_msg_create(), donotq_insert(), ds_digest_match_dnskey(), edns_opt_list_append(), edns_opt_list_append_ede(), gen_dns_msg(), generate_sub_request(), handle_ipv6_ptr(), 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(), msg_create(), new_rrset(), nsec3_calc_hash(), nsec3_ce_wildcard(), nsec3_hash_name(), outnet_serviced_query(), packed_rrset_copy_region(), parse_copy_decompress_rrset(), parse_create_qinfo(), parse_reply_in_temp_region(), process_response(), processClassResponse(), read_addrs(), read_names(), regional_alloc_init(), regional_alloc_zero(), reply_info_alloc_rrset_keys(), reply_info_parse(), respip_copy_rrset(), rrset_array_unlock_touch(), rrset_canonical(), rrset_canonical_equal(), rrset_canonicalize_to_buffer(), rrset_insert_rr(), sock_list_insert(), synth_cname_rrset(), synth_dname_msg(), val_new(), val_new_getmsg(), worker_send_query(), and zonemd_simple_rrsig_allocs().

## ◆ regional_alloc_init()

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.

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

Parameters

  r | the region.
  init | to copy.
  size | number of bytes.

Returns
  : pointer to memory allocated.

References regional_alloc().

Referenced by acl_list_tags_cfg(), auth_zone_delegpt(), copy_msg(), corner_cases(), create_synth_cname(), delegpt_add_ns(), delegpt_set_name(), dns64_adjust_a(), dns_copy_msg(), dns_msg_create(), edns_opt_copy_region(), edns_opt_list_append(), gen_dns_msg(), generate_keytag_query(), iter_store_parentside_neg(), key_entry_copy_toregion(), key_entry_create_rrset(), key_entry_get_rrset(), key_entry_setup(), load_qinfo(), load_rr(), local_data_answer(), local_data_find_tag_datas(), lz_find_create_node(), mesh_state_add_reply(), mesh_state_create(), msg_create(), nsec3_calc_b32(), nsec3_hash_test_entry(), packed_rrset_copy_region(), prime_trust_anchor(), probe_anchor(), process_ds_response(), q_ans_parse(), read_names(), regional_strdup(), repinfo_copy_rrsets(), reply_equal(), respip_copy_rrset(), respip_operate(), rrset_canonical(), rrset_insert_rr(), serviced_callbacks(), serviced_create(), synth_dname_msg(), and val_new_getmsg().

## ◆ regional_alloc_zero()

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 acl_list_insert(), acl_list_tag_action_cfg(), acl_list_tag_data_cfg(), auth_zone_delegpt(), cfg_region_strlist_insert(), corner_cases(), create_synth_cname(), dns_msg_create(), iter_store_parentside_neg(), load_msg(), load_rrset(), local_data_answer(), local_data_find_tag_datas(), lz_enter_override(), lz_find_create_node(), mesh_serve_expired_init(), mesh_state_add_reply(), msg_create(), msg_grow_array(), new_cname_override(), new_local_rrset(), new_rrset(), parse_create_rrset(), populate_action_info(), q_ans_parse(), respip_copy_rrset(), respip_operate(), respip_sockaddr_find_or_create(), rpz_add_soa(), synth_dname_msg(), and tcl_list_insert().

## ◆ regional_strdup()

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 acl_list_tag_data_cfg(), algo_needs_reason(), corner_cases(), delegpt_add_addr(), delegpt_add_ns(), key_entry_copy_toregion(), key_entry_create_rrset(), and serviced_create().