mem.c File Reference

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <limits.h>
#include <isc/bind9.h>
#include <isc/json.h>
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/msgs.h>
#include <isc/once.h>
#include <isc/ondestroy.h>
#include <isc/string.h>
#include <isc/mutex.h>
#include <isc/print.h>
#include <isc/util.h>
#include <isc/xml.h>

Go to the source code of this file.

Data Structures

struct  element
struct  size_info
struct  stats
struct  isc__mempool
struct  isc__memmethods
struct  isc__mempoolmethods

Defines

#define MCTXLOCK(m, l)   if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) LOCK(l)
#define MCTXUNLOCK(m, l)   if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) UNLOCK(l)
#define ISC_MEM_DEBUGGING   0
#define DEF_MAX_SIZE   1100
#define DEF_MEM_TARGET   4096
#define ALIGNMENT_SIZE   8U
 must be a power of 2
#define NUM_BASIC_BLOCKS   64
 must be > 1
#define TABLE_INCREMENT   1024
#define DEBUGLIST_COUNT   1024
#define FLARG_PASS
#define FLARG
#define MEM_MAGIC   ISC_MAGIC('M', 'e', 'm', 'C')
#define VALID_CONTEXT(c)   ISC_MAGIC_VALID(c, MEM_MAGIC)
#define MEMPOOL_MAGIC   ISC_MAGIC('M', 'E', 'M', 'p')
#define VALID_MEMPOOL(c)   ISC_MAGIC_VALID(c, MEMPOOL_MAGIC)
#define ADD_TRACE(a, b, c, d, e)
#define DELETE_TRACE(a, b, c, d, e)
#define ISC_MEMFUNC_SCOPE

Typedefs

typedef struct isc__mem isc__mem_t
typedef struct isc__mempool isc__mempool_t
typedef struct element element

Functions

static ISC_LIST (isc__mem_t)
static size_t rmsize (size_t size)
static size_t quantize (size_t size)
static isc_boolean_t more_basic_blocks (isc__mem_t *ctx)
static isc_boolean_t more_frags (isc__mem_t *ctx, size_t new_size)
static void * mem_getunlocked (isc__mem_t *ctx, size_t size)
static void mem_putunlocked (isc__mem_t *ctx, void *mem, size_t size)
static void * mem_get (isc__mem_t *ctx, size_t size)
static void mem_put (isc__mem_t *ctx, void *mem, size_t size)
static void mem_getstats (isc__mem_t *ctx, size_t size)
static void mem_putstats (isc__mem_t *ctx, void *ptr, size_t size)
static void * default_memalloc (void *arg, size_t size)
static void default_memfree (void *arg, void *ptr)
static void initialize_action (void)
isc_result_t isc_mem_createx (size_t init_max_size, size_t target_size, isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg, isc_mem_t **ctxp)
isc_result_t isc_mem_createx2 (size_t init_max_size, size_t target_size, isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg, isc_mem_t **ctxp, unsigned int flags)
 Create a memory context.
static void destroy (isc__mem_t *ctx)
void isc__mem_attach (isc_mem_t *source0, isc_mem_t **targetp)
void isc__mem_detach (isc_mem_t **ctxp)
void isc___mem_putanddetach (isc_mem_t **ctxp, void *ptr, size_t size FLARG)
void isc__mem_destroy (isc_mem_t **ctxp)
isc_result_t isc_mem_ondestroy (isc_mem_t *ctx0, isc_task_t *task, isc_event_t **event)
 Request to be notified with an event when a memory context has been successfully destroyed.
void * isc___mem_get (isc_mem_t *ctx0, size_t size FLARG)
void isc___mem_put (isc_mem_t *ctx0, void *ptr, size_t size FLARG)
void isc__mem_waterack (isc_mem_t *ctx0, int flag)
void isc_mem_stats (isc_mem_t *ctx0, FILE *out)
 Print memory usage statistics for 'mctx' on the stream 'out'.
static void * mem_allocateunlocked (isc_mem_t *ctx0, size_t size)
void * isc___mem_allocate (isc_mem_t *ctx0, size_t size FLARG)
void * isc___mem_reallocate (isc_mem_t *ctx0, void *ptr, size_t size FLARG)
void isc___mem_free (isc_mem_t *ctx0, void *ptr FLARG)
char * isc___mem_strdup (isc_mem_t *mctx0, const char *s FLARG)
void isc__mem_setdestroycheck (isc_mem_t *ctx0, isc_boolean_t flag)
void isc_mem_setquota (isc_mem_t *ctx0, size_t quota)
size_t isc_mem_getquota (isc_mem_t *ctx0)
 Set/get the memory quota of 'mctx'. This is a hard limit on the amount of memory that may be allocated from mctx; if it is exceeded, allocations will fail.
size_t isc__mem_inuse (isc_mem_t *ctx0)
size_t isc__mem_maxinuse (isc_mem_t *ctx0)
size_t isc__mem_total (isc_mem_t *ctx0)
void isc__mem_setwater (isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg, size_t hiwater, size_t lowater)
isc_boolean_t isc__mem_isovermem (isc_mem_t *ctx0)
void isc_mem_setname (isc_mem_t *ctx0, const char *name, void *tag)
 Name 'ctx'.
const char * isc_mem_getname (isc_mem_t *ctx0)
 Get the name of 'ctx', as previously set using isc_mem_setname().
void * isc_mem_gettag (isc_mem_t *ctx0)
 Get the tag value for 'task', as previously set using isc_mem_setname().
isc_result_t isc__mempool_create (isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp)
void isc__mempool_setname (isc_mempool_t *mpctx0, const char *name)
void isc__mempool_destroy (isc_mempool_t **mpctxp)
void isc__mempool_associatelock (isc_mempool_t *mpctx0, isc_mutex_t *lock)
void * isc___mempool_get (isc_mempool_t *mpctx0 FLARG)
void isc___mempool_put (isc_mempool_t *mpctx0, void *mem FLARG)
void isc__mempool_setfreemax (isc_mempool_t *mpctx0, unsigned int limit)
unsigned int isc_mempool_getfreemax (isc_mempool_t *mpctx0)
 Returns the maximum allowed size of the free list.
unsigned int isc_mempool_getfreecount (isc_mempool_t *mpctx0)
 Returns current size of the free list.
void isc__mempool_setmaxalloc (isc_mempool_t *mpctx0, unsigned int limit)
unsigned int isc_mempool_getmaxalloc (isc_mempool_t *mpctx0)
unsigned int isc__mempool_getallocated (isc_mempool_t *mpctx0)
void isc__mempool_setfillcount (isc_mempool_t *mpctx0, unsigned int limit)
unsigned int isc_mempool_getfillcount (isc_mempool_t *mpctx0)
 Returns the number of items allocated as a block from the parent memory context when the free list is empty.
isc_result_t isc__mem_register (void)
 A short cut function that specifies the memory management module in the ISC library for isc_mem_register(). An application that uses the ISC library usually do not have to care about this function: it would call isc_lib_register(), which internally calls this function.
void isc__mem_printactive (isc_mem_t *ctx0, FILE *file)
void isc_mem_printallactive (FILE *file)
 Print to 'file' all active memory in all contexts.
void isc_mem_checkdestroyed (FILE *file)
 Check that all memory contexts have been destroyed. Prints out those that have not been. Fatally fails if there are still active contexts.
unsigned int isc_mem_references (isc_mem_t *ctx0)
 Return the current reference count.
isc_result_t isc_mem_register (isc_memcreatefunc_t createfunc)
 Register a new memory management implementation and add it to the list of supported implementations. This function must be called when a different memory management library is used than the one contained in the ISC library.
isc_result_t isc__mem_create2 (size_t init_max_size, size_t target_size, isc_mem_t **mctxp, unsigned int flags)
isc_result_t isc_mem_create (size_t init_max_size, size_t target_size, isc_mem_t **mctxp)
isc_result_t isc_mem_create2 (size_t init_max_size, size_t target_size, isc_mem_t **mctxp, unsigned int flags)
void isc_mem_attach (isc_mem_t *source, isc_mem_t **targetp)
void isc_mem_detach (isc_mem_t **mctxp)
 Attach to / detach from a memory context.
void isc_mem_destroy (isc_mem_t **mctxp)
 Destroy a memory context.
void isc_mem_setdestroycheck (isc_mem_t *mctx, isc_boolean_t flag)
 If 'on' is ISC_TRUE, 'mctx' will check for memory leaks when destroyed and abort the program if any are present.
void isc_mem_setwater (isc_mem_t *ctx, isc_mem_water_t water, void *water_arg, size_t hiwater, size_t lowater)
 Set high and low water marks for this memory context.
void isc_mem_waterack (isc_mem_t *ctx, int flag)
 Called to acknowledge changes in signaled by calls to 'water'.
size_t isc_mem_inuse (isc_mem_t *mctx)
 Get an estimate of the amount of memory in use in 'mctx', in bytes. This includes quantization overhead, but does not include memory allocated from the system but not yet used.
size_t isc_mem_maxinuse (isc_mem_t *mctx)
 Get an estimate of the largest amount of memory that has been in use in 'mctx' at any time.
size_t isc_mem_total (isc_mem_t *mctx)
 Get the total amount of memory in 'mctx', in bytes, including memory not yet used.
isc_boolean_t isc_mem_isovermem (isc_mem_t *mctx)
 Return true iff the memory context is in "over memory" state, i.e., a hiwater mark has been set and the used amount of memory has exceeds the mark.
isc_result_t isc_mempool_create (isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp)
 Create a memory pool.
void isc_mempool_destroy (isc_mempool_t **mpctxp)
 Destroy a memory pool.
unsigned int isc_mempool_getallocated (isc_mempool_t *mpctx)
 Returns the number of items allocated from this pool.
void isc_mempool_setmaxalloc (isc_mempool_t *mpctx, unsigned int limit)
 Sets the maximum allowed number of allocations.
void isc_mempool_setfreemax (isc_mempool_t *mpctx, unsigned int limit)
 Sets the maximum allowed size of the free list.
void isc_mempool_setname (isc_mempool_t *mpctx, const char *name)
 Associate a name with a memory pool. At most 15 characters may be used.
void isc_mempool_associatelock (isc_mempool_t *mpctx, isc_mutex_t *lock)
 Associate a lock with this memory pool.
void isc_mempool_setfillcount (isc_mempool_t *mpctx, unsigned int limit)
 Sets the fillcount.
void * isc__mem_get (isc_mem_t *mctx, size_t size FLARG)
void isc__mem_put (isc_mem_t *mctx, void *ptr, size_t size FLARG)
void isc__mem_putanddetach (isc_mem_t **mctxp, void *ptr, size_t size FLARG)
void * isc__mem_allocate (isc_mem_t *mctx, size_t size FLARG)
void * isc__mem_reallocate (isc_mem_t *mctx, void *ptr, size_t size FLARG)
char * isc__mem_strdup (isc_mem_t *mctx, const char *s FLARG)
void isc__mem_free (isc_mem_t *mctx, void *ptr FLARG)
void * isc__mempool_get (isc_mempool_t *mpctx FLARG)
void isc__mempool_put (isc_mempool_t *mpctx, void *mem FLARG)

Variables

LIBISC_EXTERNAL_DATA unsigned int isc_mem_debugging = ISC_MEM_DEBUGGING
LIBISC_EXTERNAL_DATA unsigned int isc_mem_defaultflags = ISC_MEMFLAG_DEFAULT
static struct isc__memmethods memmethods
static struct isc__mempoolmethods mempoolmethods
static isc_memcreatefunc_t mem_createfunc = NULL


Detailed Description

Definition in file mem.c.


Define Documentation

#define MCTXLOCK ( m,
 )     if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) LOCK(l)

Definition at line 41 of file mem.c.

Referenced by isc___mem_putanddetach(), isc___mempool_put(), isc__mempool_create(), isc_mem_setquota(), and isc_mem_stats().

#define MCTXUNLOCK ( m,
 )     if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) UNLOCK(l)

Definition at line 42 of file mem.c.

Referenced by isc___mem_putanddetach(), isc___mempool_put(), isc__mempool_create(), isc_mem_setquota(), and isc_mem_stats().

#define ISC_MEM_DEBUGGING   0

Definition at line 45 of file mem.c.

#define DEF_MAX_SIZE   1100

Definition at line 54 of file mem.c.

#define DEF_MEM_TARGET   4096

Definition at line 55 of file mem.c.

#define ALIGNMENT_SIZE   8U

must be a power of 2

Definition at line 56 of file mem.c.

Referenced by isc___mem_putanddetach(), mem_allocateunlocked(), and rmsize().

#define NUM_BASIC_BLOCKS   64

must be > 1

Definition at line 57 of file mem.c.

#define TABLE_INCREMENT   1024

Definition at line 58 of file mem.c.

#define DEBUGLIST_COUNT   1024

Definition at line 59 of file mem.c.

#define FLARG_PASS

Definition at line 81 of file mem.c.

Referenced by isc___mem_putanddetach().

#define FLARG

Definition at line 82 of file mem.c.

#define MEM_MAGIC   ISC_MAGIC('M', 'e', 'm', 'C')

Definition at line 108 of file mem.c.

#define VALID_CONTEXT (  )     ISC_MAGIC_VALID(c, MEM_MAGIC)

Definition at line 109 of file mem.c.

#define MEMPOOL_MAGIC   ISC_MAGIC('M', 'E', 'M', 'p')

Definition at line 175 of file mem.c.

Referenced by isc__mempool_create().

#define VALID_MEMPOOL (  )     ISC_MAGIC_VALID(c, MEMPOOL_MAGIC)

Definition at line 176 of file mem.c.

Referenced by isc___mempool_put(), and isc__mempool_setfreemax().

#define ADD_TRACE ( a,
b,
c,
d,
 ) 

Definition at line 206 of file mem.c.

#define DELETE_TRACE ( a,
b,
c,
d,
 ) 

Definition at line 207 of file mem.c.

Referenced by isc___mem_putanddetach(), and isc___mempool_put().

#define ISC_MEMFUNC_SCOPE

Definition at line 208 of file mem.c.


Typedef Documentation

typedef struct isc__mem isc__mem_t

Definition at line 64 of file mem.c.

typedef struct isc__mempool isc__mempool_t

Definition at line 65 of file mem.c.

typedef struct element element

Definition at line 85 of file mem.c.


Function Documentation

static ISC_LIST ( isc__mem_t   )  [static]

Definition at line 117 of file mem.c.

References arg, inuse(), ISC_LINK, ISC_LIST, name, references, and water().

static size_t rmsize ( size_t  size  )  [inline, static]

Definition at line 492 of file mem.c.

References ALIGNMENT_SIZE.

static size_t quantize ( size_t  size  )  [inline, static]

Round up the result in order to get a size big enough to satisfy the request and be aligned on ALIGNMENT_SIZE byte boundaries.

Definition at line 500 of file mem.c.

Referenced by mem_putunlocked().

static isc_boolean_t more_basic_blocks ( isc__mem_t ctx  )  [inline, static]

Definition at line 513 of file mem.c.

static isc_boolean_t more_frags ( isc__mem_t ctx,
size_t  new_size 
) [inline, static]

Try to get more fragments by chopping up a basic block.

Definition at line 583 of file mem.c.

static void* mem_getunlocked ( isc__mem_t ctx,
size_t  size 
) [inline, static]

Definition at line 645 of file mem.c.

Referenced by mem_allocateunlocked().

static void mem_putunlocked ( isc__mem_t ctx,
void *  mem,
size_t  size 
) [inline, static]

Definition at line 727 of file mem.c.

References INSIST, inuse(), and quantize().

Referenced by isc___mem_putanddetach(), and isc___mempool_put().

static void* mem_get ( isc__mem_t ctx,
size_t  size 
) [inline, static]

Perform a malloc, doing memory filling and overrun detection as necessary.

Definition at line 774 of file mem.c.

Referenced by mem_allocateunlocked().

static void mem_put ( isc__mem_t ctx,
void *  mem,
size_t  size 
) [inline, static]

Perform a free, doing memory filling and overrun detection as necessary.

Definition at line 803 of file mem.c.

References INSIST, and UNUSED.

Referenced by isc___mem_putanddetach(), and isc___mempool_put().

static void mem_getstats ( isc__mem_t ctx,
size_t  size 
) [inline, static]

Update internal counters after a memory get.

Definition at line 819 of file mem.c.

static void mem_putstats ( isc__mem_t ctx,
void *  ptr,
size_t  size 
) [inline, static]

Update internal counters after a memory put.

Definition at line 836 of file mem.c.

References INSIST, and UNUSED.

Referenced by isc___mem_putanddetach(), and isc___mempool_put().

static void* default_memalloc ( void *  arg,
size_t  size 
) [static]

Definition at line 856 of file mem.c.

References UNUSED.

Referenced by ATF_TC_BODY(), and dst_lib_init2().

static void default_memfree ( void *  arg,
void *  ptr 
) [static]

Definition at line 864 of file mem.c.

Referenced by ATF_TC_BODY(), and dst_lib_init2().

static void initialize_action ( void   )  [static]

Definition at line 870 of file mem.c.

Referenced by dns_acl_isinsecure(), initialize(), and isc_mem_register().

isc_result_t isc_mem_createx ( size_t  init_max_size,
size_t  target_size,
isc_memalloc_t  memalloc,
isc_memfree_t  memfree,
void *  arg,
isc_mem_t **  ctxp 
)

Definition at line 882 of file mem.c.

References isc_mem_createx2(), and isc_mem_defaultflags.

isc_result_t isc_mem_createx2 ( size_t  max_size,
size_t  target_size,
isc_memalloc_t  memalloc,
isc_memfree_t  memfree,
void *  arg,
isc_mem_t **  mctxp,
unsigned int  flags 
)

Create a memory context.

'max_size' and 'target_size' are tuning parameters. When ISC_MEMFLAG_INTERNAL is set, allocations smaller than 'max_size' will be satisfied by getting blocks of size 'target_size' from the system allocator and breaking them up into pieces; larger allocations will use the system allocator directly. If 'max_size' and/or 'target_size' are zero, default values will be * used. When ISC_MEMFLAG_INTERNAL is not set, 'target_size' is ignored.

'max_size' is also used to size the statistics arrays and the array used to record active memory when ISC_MEM_DEBUGRECORD is set. Setting 'max_size' too low can have detrimental effects on performance.

A memory context created using isc_mem_createx() will obtain memory from the system by calling 'memalloc' and 'memfree', passing them the argument 'arg'. A memory context created using isc_mem_create() will use the standard library malloc() and free().

If ISC_MEMFLAG_NOLOCK is set in 'flags', the corresponding memory context will be accessed without locking. The user who creates the context must ensure there be no race. Since this can be a source of bug, it is generally inadvisable to use this flag unless the user is very sure about the race condition and the access to the object is highly performance sensitive.

Requires: mctxp != NULL && *mctxp == NULL

Definition at line 892 of file mem.c.

Referenced by ATF_TC_BODY(), dst_lib_init2(), and isc_mem_createx().

static void destroy ( isc__mem_t ctx  )  [static]

Definition at line 1026 of file mem.c.

void isc__mem_attach ( isc_mem_t source0,
isc_mem_t **  targetp 
)

Definition at line 1101 of file mem.c.

void isc__mem_detach ( isc_mem_t **  ctxp  ) 

Definition at line 1115 of file mem.c.

void isc___mem_putanddetach ( isc_mem_t **  ctxp,
void *  ptr,
size_t size  FLARG 
)

Definition at line 1147 of file mem.c.

References ALIGNMENT_SIZE, DELETE_TRACE, destroy(), FLARG_PASS, INSIST, isc__mem_free(), ISC_FALSE, ISC_MEM_DEBUGCTX, isc_mem_debugging, ISC_MEM_DEBUGSIZE, ISC_TRUE, MCTXLOCK, MCTXUNLOCK, mem_put(), mem_putstats(), mem_putunlocked(), REQUIRE, size_info::size, size_info::u, and VALID_CONTEXT.

void isc__mem_destroy ( isc_mem_t **  ctxp  ) 

Definition at line 1208 of file mem.c.

isc_result_t isc_mem_ondestroy ( isc_mem_t ctx0,
isc_task_t task,
isc_event_t **  event 
)

Request to be notified with an event when a memory context has been successfully destroyed.

Definition at line 1235 of file mem.c.

void* isc___mem_get ( isc_mem_t ctx0,
size_t size  FLARG 
)

Definition at line 1247 of file mem.c.

void isc___mem_put ( isc_mem_t ctx0,
void *  ptr,
size_t size  FLARG 
)

Definition at line 1289 of file mem.c.

void isc__mem_waterack ( isc_mem_t ctx0,
int  flag 
)

Definition at line 1339 of file mem.c.

void isc_mem_stats ( isc_mem_t ctx0,
FILE *  out 
)

Print memory usage statistics for 'mctx' on the stream 'out'.

Definition at line 1397 of file mem.c.

References stats::blocks, stats::freefrags, stats::gets, ISC_LIST_HEAD, ISC_LIST_NEXT, ISC_MEMPOOL_NAMES, ISC_MSG_POOLALLOCATED, ISC_MSG_POOLFILLCOUNT, ISC_MSG_POOLFREECOUNT, ISC_MSG_POOLFREEMAX, ISC_MSG_POOLGETS, ISC_MSG_POOLMAXALLOC, ISC_MSG_POOLNAME, ISC_MSG_POOLSIZE, ISC_MSG_POOLSTATS, isc_msgcat_get(), ISC_MSGSET_MEM, isc__mempool::lock, MCTXLOCK, MCTXUNLOCK, REQUIRE, s, stats::totalgets, and VALID_CONTEXT.

Referenced by cleanup(), destroy_libs(), exit_check(), and main().

static void* mem_allocateunlocked ( isc_mem_t ctx0,
size_t  size 
) [static]

Definition at line 1479 of file mem.c.

References ALIGNMENT_SIZE, size_info::ctx, ISC_MEM_DEBUGCTX, isc_mem_debugging, mem_get(), mem_getunlocked(), size_info::size, and size_info::u.

void* isc___mem_allocate ( isc_mem_t ctx0,
size_t size  FLARG 
)

Definition at line 1503 of file mem.c.

void* isc___mem_reallocate ( isc_mem_t ctx0,
void *  ptr,
size_t size  FLARG 
)

Definition at line 1544 of file mem.c.

void isc___mem_free ( isc_mem_t ctx0,
void *ptr  FLARG 
)

Definition at line 1583 of file mem.c.

char* isc___mem_strdup ( isc_mem_t mctx0,
const char *s  FLARG 
)

Definition at line 1641 of file mem.c.

References isc__mem_allocate(), REQUIRE, s, and VALID_CONTEXT.

void isc__mem_setdestroycheck ( isc_mem_t ctx0,
isc_boolean_t  flag 
)

Definition at line 1660 of file mem.c.

void isc_mem_setquota ( isc_mem_t ctx0,
size_t  quota 
)

Definition at line 1676 of file mem.c.

References MCTXLOCK, MCTXUNLOCK, REQUIRE, and VALID_CONTEXT.

size_t isc_mem_getquota ( isc_mem_t ctx0  ) 

Set/get the memory quota of 'mctx'. This is a hard limit on the amount of memory that may be allocated from mctx; if it is exceeded, allocations will fail.

Definition at line 1688 of file mem.c.

size_t isc__mem_inuse ( isc_mem_t ctx0  ) 

Definition at line 1703 of file mem.c.

size_t isc__mem_maxinuse ( isc_mem_t ctx0  ) 

Definition at line 1718 of file mem.c.

size_t isc__mem_total ( isc_mem_t ctx0  ) 

Definition at line 1733 of file mem.c.

void isc__mem_setwater ( isc_mem_t ctx0,
isc_mem_water_t  water,
void *  water_arg,
size_t  hiwater,
size_t  lowater 
)

Definition at line 1748 of file mem.c.

isc_boolean_t isc__mem_isovermem ( isc_mem_t ctx0  ) 

Definition at line 1785 of file mem.c.

void isc_mem_setname ( isc_mem_t ctx,
const char *  name,
void *  tag 
)

Name 'ctx'.

Notes:

Requires:

Definition at line 1799 of file mem.c.

Referenced by configure_view(), dns_resolver_create(), dns_view_createresolver(), dst_lib_init2(), get_clientmctx(), main(), mctxinit(), and setup_libs().

const char* isc_mem_getname ( isc_mem_t ctx  ) 

Get the name of 'ctx', as previously set using isc_mem_setname().

Requires:

Returns:

Definition at line 1812 of file mem.c.

void* isc_mem_gettag ( isc_mem_t ctx  ) 

Get the tag value for 'task', as previously set using isc_mem_setname().

Requires:

Notes: Requires:

Definition at line 1824 of file mem.c.

isc_result_t isc__mempool_create ( isc_mem_t mctx0,
size_t  size,
isc_mempool_t **  mpctxp 
)

Definition at line 1837 of file mem.c.

References isc__mempool::common, isc_mempool::impmagic, ISC_LIST_INITANDAPPEND, isc_mem_get, ISC_R_NOMEMORY, ISC_R_SUCCESS, ISCAPI_MPOOL_MAGIC, isc__mempool::lock, isc_mempool::magic, isc__mempool::mctx, MCTXLOCK, MCTXUNLOCK, MEMPOOL_MAGIC, mempoolmethods, isc_mempool::methods, REQUIRE, and VALID_CONTEXT.

void isc__mempool_setname ( isc_mempool_t mpctx0,
const char *  name 
)

Definition at line 1881 of file mem.c.

void isc__mempool_destroy ( isc_mempool_t **  mpctxp  ) 

Definition at line 1903 of file mem.c.

void isc__mempool_associatelock ( isc_mempool_t mpctx0,
isc_mutex_t lock 
)

Definition at line 1967 of file mem.c.

void* isc___mempool_get ( isc_mempool_t *mpctx0  FLARG  ) 

Definition at line 1978 of file mem.c.

void isc___mempool_put ( isc_mempool_t mpctx0,
void *mem  FLARG 
)

Definition at line 2062 of file mem.c.

References DELETE_TRACE, INSIST, LOCK, isc__mempool::lock, isc__mempool::mctx, MCTXLOCK, MCTXUNLOCK, mem_put(), mem_putstats(), mem_putunlocked(), element::next, REQUIRE, UNLOCK, and VALID_MEMPOOL.

void isc__mempool_setfreemax ( isc_mempool_t mpctx0,
unsigned int  limit 
)

Definition at line 2118 of file mem.c.

References LOCK, isc__mempool::lock, REQUIRE, UNLOCK, and VALID_MEMPOOL.

unsigned int isc_mempool_getfreemax ( isc_mempool_t mpctx0  ) 

Returns the maximum allowed size of the free list.

Definition at line 2133 of file mem.c.

unsigned int isc_mempool_getfreecount ( isc_mempool_t mpctx0  ) 

Returns current size of the free list.

Definition at line 2151 of file mem.c.

void isc__mempool_setmaxalloc ( isc_mempool_t mpctx0,
unsigned int  limit 
)

Definition at line 2169 of file mem.c.

unsigned int isc_mempool_getmaxalloc ( isc_mempool_t mpctx  ) 

Returns the maximum allowed number of allocations.

Definition at line 2186 of file mem.c.

unsigned int isc__mempool_getallocated ( isc_mempool_t mpctx0  ) 

Definition at line 2204 of file mem.c.

void isc__mempool_setfillcount ( isc_mempool_t mpctx0,
unsigned int  limit 
)

Definition at line 2222 of file mem.c.

unsigned int isc_mempool_getfillcount ( isc_mempool_t mpctx0  ) 

Returns the number of items allocated as a block from the parent memory context when the free list is empty.

Definition at line 2238 of file mem.c.

isc_result_t isc__mem_register ( void   ) 

A short cut function that specifies the memory management module in the ISC library for isc_mem_register(). An application that uses the ISC library usually do not have to care about this function: it would call isc_lib_register(), which internally calls this function.

Definition at line 2257 of file mem.c.

Referenced by do_register().

void isc__mem_printactive ( isc_mem_t ctx0,
FILE *  file 
)

Definition at line 2262 of file mem.c.

void isc_mem_printallactive ( FILE *  file  ) 

Print to 'file' all active memory in all contexts.

Requires ISC_MEM_DEBUGRECORD to have been set.

Definition at line 2277 of file mem.c.

Referenced by isc__taskmgr_destroy().

void isc_mem_checkdestroyed ( FILE *  file  ) 

Check that all memory contexts have been destroyed. Prints out those that have not been. Fatally fails if there are still active contexts.

Definition at line 2296 of file mem.c.

Referenced by main().

unsigned int isc_mem_references ( isc_mem_t ctx0  ) 

Return the current reference count.

Definition at line 2322 of file mem.c.

Referenced by exit_check().

isc_result_t isc_mem_register ( isc_memcreatefunc_t  createfunc  ) 

Register a new memory management implementation and add it to the list of supported implementations. This function must be called when a different memory management library is used than the one contained in the ISC library.

Definition at line 2670 of file mem.c.

References createlock, initialize_action(), isc_once_do, ISC_R_EXISTS, ISC_R_SUCCESS, LOCK, once, RUNTIME_CHECK, and UNLOCK.

isc_result_t isc__mem_create2 ( size_t  init_max_size,
size_t  target_size,
isc_mem_t **  mctxp,
unsigned int  flags 
)

Definition at line 2687 of file mem.c.

isc_result_t isc_mem_create ( size_t  init_max_size,
size_t  target_size,
isc_mem_t **  mctxp 
)

Definition at line 2703 of file mem.c.

Referenced by add(), ATF_TC_BODY(), configure_view(), dns_client_create(), dns_resolver_create(), dns_test_begin(), dns_view_createresolver(), get_clientmctx(), initialize(), isc_test_begin(), main(), mctxinit(), random_test(), and setup_libs().

isc_result_t isc_mem_create2 ( size_t  init_max_size,
size_t  target_size,
isc_mem_t **  mctxp,
unsigned int  flags 
)

Definition at line 2722 of file mem.c.

void isc_mem_attach ( isc_mem_t source,
isc_mem_t **  targetp 
)

Definition at line 2736 of file mem.c.

Referenced by _new_prefix(), add_listener(), alloc_pool(), axfr_rrstream_create(), cfg_aclconfctx_create(), cfg_parser_create(), compound_rrstream_create(), create_stats(), dns_acache_create(), dns_acl_create(), dns_adb_create(), dns_badcache_init(), dns_byaddr_create(), dns_cache_create3(), dns_client_createx2(), dns_client_updaterec(), dns_db_register(), dns_dbtable_create(), dns_difftuple_create(), dns_dispatchmgr_create(), dns_dispatchset_create(), dns_dlzcreate(), dns_dlzregister(), dns_dns64_create(), dns_ecdb_create(), dns_fwdtable_create(), dns_iptable_create(), dns_keytable_create(), dns_lookup_create(), dns_message_create(), dns_order_create(), dns_portlist_create(), dns_rbt_create(), dns_rbtdb_create(), dns_requestmgr_create(), dns_resolver_create(), dns_resolver_createfetch3(), dns_rpz_new_zones(), dns_rrl_init(), dns_sdb_create(), dns_sdb_register(), dns_sdlzcreateDBP(), dns_sdlzregister(), dns_ssutable_create(), dns_tkeyctx_create(), dns_tsigkey_createfromkey(), dns_tsigkeyring_create(), dns_view_create(), dns_zone_create(), dns_zone_forwardupdate(), dns_zonemgr_create(), dns_zonemgr_createzone(), dns_zt_create(), dst_lib_init2(), dumpctx_create(), fctx_create(), get_clientmctx(), get_key_struct(), isc__taskmgr_create(), isc__timermgr_create(), isc_counter_create(), isc_entropy_create(), isc_hash_ctxcreate(), isc_heap_create(), isc_httpdmgr_create(), isc_log_create(), isc_radix_create(), isc_rng_create(), isc_symtab_create(), ixfr_rrstream_create(), journal_open(), keyfetch_done(), listener_create(), loadctx_create(), loadctx_destroy(), new_request(), notify_create(), ns_interfacemgr_create(), ns_lwdmanager_create(), ns_lwsearchlist_create(), pk11_initialize(), setup_newzones(), soa_rrstream_create(), xfrin_create(), xfrout_ctx_create(), and zone_startload().

void isc_mem_detach ( isc_mem_t **   ) 

Attach to / detach from a memory context.

This is intended for applications that use multiple memory contexts in such a way that it is not obvious when the last allocations from a given context has been freed and destroying the context is safe.

Most applications do not need to call these functions as they can simply create a single memory context at the beginning of main() and destroy it at the end of main(), thereby guaranteeing that it is not destroyed while there are outstanding allocations.

Definition at line 2749 of file mem.c.

Referenced by ATF_TC_BODY(), cache_free(), client_create(), clientmgr_destroy(), configure_view(), destroy(), destroy_mgr(), dns_acache_create(), dns_cache_create3(), dns_client_create(), dns_db_unregister(), dns_difftuple_free(), dns_dispatchmgr_create(), dns_dispatchset_create(), dns_dlzdestroy(), dns_dlzunregister(), dns_fwdtable_destroy(), dns_lib_shutdown(), dns_name_destroy(), dns_resolver_create(), dns_sdb_create(), dns_sdb_unregister(), dns_sdlzregister(), dns_sdlzunregister(), dns_tkeyctx_destroy(), dns_view_createresolver(), dns_zonemgr_create(), dns_zonemgr_createzone(), dst_lib_destroy(), free_rbtdb(), initialize(), isc__timermgr_create(), isc__timermgr_destroy(), isc_httpdmgr_create(), keyfetch_done(), loadctx_destroy(), manager_free(), mctxfree(), mgr_destroy(), notify_destroy(), ns_lwdmanager_create(), ns_lwdmanager_detach(), ns_lwreslistener_detach(), ns_lwsearchlist_detach(), pk11_finalize(), req_destroy(), zone_free(), zone_startload(), and zonemgr_free().

void isc_mem_destroy ( isc_mem_t **  mctxp  ) 

Destroy a memory context.

Definition at line 2761 of file mem.c.

Referenced by ATF_TC_BODY(), cleanup(), destroy_libs(), dns_test_end(), isc_test_end(), and main().

void isc_mem_setdestroycheck ( isc_mem_t mctx,
isc_boolean_t  flag 
)

If 'on' is ISC_TRUE, 'mctx' will check for memory leaks when destroyed and abort the program if any are present.

Definition at line 2773 of file mem.c.

Referenced by dst_lib_init2().

void isc_mem_setwater ( isc_mem_t mctx,
isc_mem_water_t  water,
void *  water_arg,
size_t  hiwater,
size_t  lowater 
)

Set high and low water marks for this memory context.

When the memory usage of 'mctx' exceeds 'hiwater', '(water)(water_arg, ISC_MEM_HIWATER)' will be called. 'water' needs to call isc_mem_waterack() with ISC_MEM_HIWATER to acknowledge the state change. 'water' may be called multiple times.

When the usage drops below 'lowater', 'water' will again be called, this time with ISC_MEM_LOWATER. 'water' need to calls isc_mem_waterack() with ISC_MEM_LOWATER to acknowledge the change.

static void water(void *arg, int mark) { struct foo *foo = arg;

LOCK(&foo->marklock); if (foo->mark != mark) { foo->mark = mark; .... isc_mem_waterack(foo->mctx, mark); } UNLOCK(&foo->marklock); }

If 'water' is NULL then 'water_arg', 'hi_water' and 'lo_water' are ignored and the state is reset.

Requires:

'water' is not NULL. hi_water >= lo_water

Definition at line 2780 of file mem.c.

Referenced by cache_free(), destroy(), dns_acache_setcachesize(), dns_acache_shutdown(), dns_adb_setadbsize(), dns_adb_shutdown(), and dns_cache_setcachesize().

void isc_mem_waterack ( isc_mem_t ctx,
int  flag 
)

Called to acknowledge changes in signaled by calls to 'water'.

Definition at line 2792 of file mem.c.

Referenced by water().

size_t isc_mem_inuse ( isc_mem_t mctx  ) 

Get an estimate of the amount of memory in use in 'mctx', in bytes. This includes quantization overhead, but does not include memory allocated from the system but not yet used.

Definition at line 2802 of file mem.c.

Referenced by acache_incremental_cleaning_action(), ATF_TC_BODY(), ATF_TP_ADD_TCS(), begin_cleaning(), dns_cache_dumpstats(), end_cleaning(), incremental_cleaning_action(), and water().

size_t isc_mem_maxinuse ( isc_mem_t mctx  ) 

Get an estimate of the largest amount of memory that has been in use in 'mctx' at any time.

Definition at line 2812 of file mem.c.

Referenced by dns_cache_dumpstats().

size_t isc_mem_total ( isc_mem_t mctx  ) 

Get the total amount of memory in 'mctx', in bytes, including memory not yet used.

Definition at line 2822 of file mem.c.

Referenced by ATF_TC_BODY(), ATF_TP_ADD_TCS(), and dns_cache_dumpstats().

isc_boolean_t isc_mem_isovermem ( isc_mem_t mctx  ) 

Return true iff the memory context is in "over memory" state, i.e., a hiwater mark has been set and the used amount of memory has exceeds the mark.

Definition at line 2832 of file mem.c.

Referenced by addrdataset(), check_stale_name(), clean_namehooks(), dns_adb_destroyfind(), dns_adb_freeaddrinfo(), expirenode(), and link_entry().

isc_result_t isc_mempool_create ( isc_mem_t mctx,
size_t  size,
isc_mempool_t **  mpctxp 
)

Create a memory pool.

Requires:

Defaults: Returns:

Definition at line 2843 of file mem.c.

Referenced by dispatch_createudp(), dns_dispatchmgr_create(), dns_dispatchmgr_setudp(), dns_message_create(), and setup_libs().

void isc_mempool_destroy ( isc_mempool_t **  mpctxp  ) 

Destroy a memory pool.

Requires:

Definition at line 2850 of file mem.c.

Referenced by destroy(), destroy_disp(), destroy_libs(), destroy_mgr(), dispatch_createudp(), dispatch_free(), dns_adb_create(), dns_dispatchmgr_create(), dns_dispatchmgr_setudp(), dns_message_create(), and dns_message_destroy().

unsigned int isc_mempool_getallocated ( isc_mempool_t mpctx  ) 

Returns the number of items allocated from this pool.

Definition at line 2862 of file mem.c.

Referenced by destroy_mgr_ok(), dns_adb_whenshutdown(), dump_adb(), and msgreset().

void isc_mempool_setmaxalloc ( isc_mempool_t mpctx,
unsigned int  limit 
)

Sets the maximum allowed number of allocations.

Additional requirements:

Definition at line 2872 of file mem.c.

Referenced by dispatch_createudp(), dns_dispatchmgr_create(), and dns_dispatchmgr_setudp().

void isc_mempool_setfreemax ( isc_mempool_t mpctx,
unsigned int  limit 
)

Sets the maximum allowed size of the free list.

Definition at line 2882 of file mem.c.

Referenced by dispatch_createudp(), dns_dispatchmgr_create(), dns_dispatchmgr_setudp(), dns_message_create(), and setup_libs().

void isc_mempool_setname ( isc_mempool_t mpctx,
const char *  name 
)

Associate a name with a memory pool. At most 15 characters may be used.

Requires:

Definition at line 2892 of file mem.c.

Referenced by dispatch_createudp(), dns_dispatchmgr_create(), dns_dispatchmgr_setudp(), dns_message_create(), and setup_libs().

void isc_mempool_associatelock ( isc_mempool_t mpctx,
isc_mutex_t lock 
)

Associate a lock with this memory pool.

This lock is used when getting or putting items using this memory pool, and it is also used to set or get internal state via the isc_mempool_get*() and isc_mempool_set*() set of functions.

Multiple pools can each share a single lock. For instance, if "manager" type object contained pools for various sizes of events, and each of these pools used a common lock. Note that this lock must NEVER be used by other than mempool routines once it is given to a pool, since that can easily cause double locking.

Requires:

Definition at line 2902 of file mem.c.

Referenced by dispatch_createudp(), dns_dispatchmgr_create(), and dns_dispatchmgr_setudp().

void isc_mempool_setfillcount ( isc_mempool_t mpctx,
unsigned int  limit 
)

Sets the fillcount.

Additional requirements:

Definition at line 2912 of file mem.c.

Referenced by dispatch_createudp(), dns_dispatchmgr_create(), dns_dispatchmgr_setudp(), and setup_libs().

void* isc__mem_get ( isc_mem_t mctx,
size_t size  FLARG 
)

Definition at line 2922 of file mem.c.

void isc__mem_put ( isc_mem_t mctx,
void *  ptr,
size_t size  FLARG 
)

Definition at line 2933 of file mem.c.

void isc__mem_putanddetach ( isc_mem_t **  mctxp,
void *  ptr,
size_t size  FLARG 
)

Definition at line 2943 of file mem.c.

void* isc__mem_allocate ( isc_mem_t mctx,
size_t size  FLARG 
)

Definition at line 2958 of file mem.c.

Referenced by isc___mem_strdup().

void* isc__mem_reallocate ( isc_mem_t mctx,
void *  ptr,
size_t size  FLARG 
)

Definition at line 2968 of file mem.c.

char* isc__mem_strdup ( isc_mem_t mctx,
const char *s  FLARG 
)

Definition at line 2978 of file mem.c.

void isc__mem_free ( isc_mem_t mctx,
void *ptr  FLARG 
)

Definition at line 2988 of file mem.c.

Referenced by isc___mem_putanddetach().

void* isc__mempool_get ( isc_mempool_t *mpctx  FLARG  ) 

Definition at line 2998 of file mem.c.

void isc__mempool_put ( isc_mempool_t mpctx,
void *mem  FLARG 
)

Definition at line 3008 of file mem.c.


Variable Documentation

LIBISC_EXTERNAL_DATA unsigned int isc_mem_debugging = ISC_MEM_DEBUGGING

Definition at line 47 of file mem.c.

Referenced by ATF_TC_BODY(), dns_test_begin(), isc___mem_putanddetach(), isc_test_begin(), load_configuration(), main(), mem_allocateunlocked(), parse_command_line(), pre_parse_args(), and preparse_args().

LIBISC_EXTERNAL_DATA unsigned int isc_mem_defaultflags = ISC_MEMFLAG_DEFAULT

Definition at line 48 of file mem.c.

Referenced by isc_mem_createx(), and parse_command_line().

struct isc__memmethods memmethods [static]

struct isc__mempoolmethods mempoolmethods [static]

Referenced by isc__mempool_create().

isc_memcreatefunc_t mem_createfunc = NULL [static]

Definition at line 2667 of file mem.c.


Generated on Tue Apr 28 17:41:18 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha