2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 22:45:39 +00:00

Make the memory and mempool counters to be stdatomic types

This is yet another step into unlocking some parts of the memory
contexts.  All the regularly updated variables has been turned into
atomic types, so we can later remove the locks when updating various
counters.

Also unlock as much code as possible without breaking anything.
This commit is contained in:
Ondřej Surý
2021-02-04 21:56:49 +01:00
committed by Ondřej Surý
parent 0f44139145
commit b09106e93a
3 changed files with 394 additions and 508 deletions

View File

@@ -250,6 +250,19 @@ isc_mem_total(isc_mem_t *mctx);
* not yet used. * not yet used.
*/ */
size_t
isc_mem_malloced(isc_mem_t *ctx);
/*%<
* Get an estimate of the amount of memory allocated in 'mctx', in bytes.
*/
size_t
isc_mem_maxmalloced(isc_mem_t *ctx);
/*%<
* Get an estimate of the largest amount of memory that has been
* allocated in 'mctx' at any time.
*/
bool bool
isc_mem_isovermem(isc_mem_t *mctx); isc_mem_isovermem(isc_mem_t *mctx);
/*%< /*%<
@@ -265,13 +278,13 @@ isc_mem_setwater(isc_mem_t *mctx, isc_mem_water_t water, void *water_arg,
* Set high and low water marks for this memory context. * Set high and low water marks for this memory context.
* *
* When the memory usage of 'mctx' exceeds 'hiwater', * When the memory usage of 'mctx' exceeds 'hiwater',
* '(water)(water_arg, #ISC_MEM_HIWATER)' will be called. 'water' needs to * '(water)(water_arg, #ISC_MEM_HIWATER)' will be called. 'water' needs
* call isc_mem_waterack() with #ISC_MEM_HIWATER to acknowledge the state *to call isc_mem_waterack() with #ISC_MEM_HIWATER to acknowledge the
* change. 'water' may be called multiple times. *state change. 'water' may be called multiple times.
* *
* When the usage drops below 'lowater', 'water' will again be called, this * When the usage drops below 'lowater', 'water' will again be called,
* time with #ISC_MEM_LOWATER. 'water' need to calls isc_mem_waterack() with *this time with #ISC_MEM_LOWATER. 'water' need to calls
* #ISC_MEM_LOWATER to acknowledge the change. *isc_mem_waterack() with #ISC_MEM_LOWATER to acknowledge the change.
* *
* static void * static void
* water(void *arg, int mark) { * water(void *arg, int mark) {
@@ -396,7 +409,8 @@ isc_mempool_destroy(isc_mempool_t **mpctxp);
void void
isc_mempool_setname(isc_mempool_t *mpctx, const char *name); isc_mempool_setname(isc_mempool_t *mpctx, const char *name);
/*%< /*%<
* Associate a name with a memory pool. At most 15 characters may be used. * Associate a name with a memory pool. At most 15 characters may be
*used.
* *
* Requires: * Requires:
*\li mpctx is a valid pool. *\li mpctx is a valid pool.
@@ -408,15 +422,15 @@ isc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock);
/*%< /*%<
* Associate a lock with this memory pool. * Associate a lock with this memory pool.
* *
* This lock is used when getting or putting items using this memory pool, * This lock is used when getting or putting items using this memory
* and it is also used to set or get internal state via the isc_mempool_get*() *pool, and it is also used to set or get internal state via the
* and isc_mempool_set*() set of functions. *isc_mempool_get*() and isc_mempool_set*() set of functions.
* *
* Multiple pools can each share a single lock. For instance, if "manager" * Multiple pools can each share a single lock. For instance, if
* type object contained pools for various sizes of events, and each of *"manager" type object contained pools for various sizes of events, and
* these pools used a common lock. Note that this lock must NEVER be used *each of these pools used a common lock. Note that this lock must
* by other than mempool routines once it is given to a pool, since that can *NEVER be used by other than mempool routines once it is given to a
* easily cause double locking. *pool, since that can easily cause double locking.
* *
* Requires: * Requires:
* *
@@ -426,19 +440,19 @@ isc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock);
* *
*\li No previous lock is assigned to this pool. *\li No previous lock is assigned to this pool.
* *
*\li The lock is initialized before calling this function via the normal *\li The lock is initialized before calling this function via the
* means of doing that. *normal means of doing that.
*/ */
/* /*
* The following functions get/set various parameters. Note that due to * The following functions get/set various parameters. Note that due to
* the unlocked nature of pools these are potentially random values unless * the unlocked nature of pools these are potentially random values
* the imposed externally provided locking protocols are followed. *unless the imposed externally provided locking protocols are followed.
* *
* Also note that the quota limits will not always take immediate effect. * Also note that the quota limits will not always take immediate
* For instance, setting "maxalloc" to a number smaller than the currently *effect. For instance, setting "maxalloc" to a number smaller than the
* allocated count is permitted. New allocations will be refused until *currently allocated count is permitted. New allocations will be
* the count drops below this threshold. *refused until the count drops below this threshold.
* *
* All functions require (in addition to other requirements): * All functions require (in addition to other requirements):
* mpctx is a valid memory pool * mpctx is a valid memory pool
@@ -486,8 +500,8 @@ isc_mempool_getallocated(isc_mempool_t *mpctx);
unsigned int unsigned int
isc_mempool_getfillcount(isc_mempool_t *mpctx); isc_mempool_getfillcount(isc_mempool_t *mpctx);
/*%< /*%<
* Returns the number of items allocated as a block from the parent memory * Returns the number of items allocated as a block from the parent
* context when the free list is empty. * memory context when the free list is empty.
*/ */
void void

File diff suppressed because it is too large Load Diff

View File

@@ -370,7 +370,9 @@ isc_mem_detach
isc_mem_getname isc_mem_getname
isc_mem_inuse isc_mem_inuse
isc_mem_isovermem isc_mem_isovermem
isc_mem_malloced
isc_mem_maxinuse isc_mem_maxinuse
isc_mem_maxmalloced
isc_mem_references isc_mem_references
@IF NOTYET @IF NOTYET
isc_mem_renderjson isc_mem_renderjson