mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 15:05:23 +00:00
include big mallocs in quota
This commit is contained in:
@@ -73,6 +73,7 @@ struct isc_mem {
|
|||||||
unsigned char * highest;
|
unsigned char * highest;
|
||||||
struct stats * stats;
|
struct stats * stats;
|
||||||
size_t quota;
|
size_t quota;
|
||||||
|
size_t total;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Forward. */
|
/* Forward. */
|
||||||
@@ -157,6 +158,7 @@ isc_mem_create(size_t init_max_size, size_t target_size,
|
|||||||
return (ISC_R_UNEXPECTED);
|
return (ISC_R_UNEXPECTED);
|
||||||
}
|
}
|
||||||
ctx->quota = 0;
|
ctx->quota = 0;
|
||||||
|
ctx->total = 0;
|
||||||
ctx->magic = MEM_MAGIC;
|
ctx->magic = MEM_MAGIC;
|
||||||
*ctxp = ctx;
|
*ctxp = ctx;
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
@@ -194,7 +196,7 @@ more_basic_blocks(isc_mem_t *ctx) {
|
|||||||
unsigned char *first, *last;
|
unsigned char *first, *last;
|
||||||
unsigned char **table;
|
unsigned char **table;
|
||||||
unsigned int table_size;
|
unsigned int table_size;
|
||||||
size_t total;
|
size_t increment;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Require: we hold the context lock. */
|
/* Require: we hold the context lock. */
|
||||||
@@ -202,12 +204,9 @@ more_basic_blocks(isc_mem_t *ctx) {
|
|||||||
/*
|
/*
|
||||||
* Did we hit the quota for this context?
|
* Did we hit the quota for this context?
|
||||||
*/
|
*/
|
||||||
if (ctx->quota != 0) {
|
increment = NUM_BASIC_BLOCKS * ctx->mem_target;
|
||||||
total = (size_t)(ctx->basic_table_count + 1) *
|
if (ctx->quota != 0 && ctx->total + increment > ctx->quota)
|
||||||
NUM_BASIC_BLOCKS * ctx->mem_target;
|
return;
|
||||||
if (total > ctx->quota)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
INSIST(ctx->basic_table_count <= ctx->basic_table_size);
|
INSIST(ctx->basic_table_count <= ctx->basic_table_size);
|
||||||
if (ctx->basic_table_count == ctx->basic_table_size) {
|
if (ctx->basic_table_count == ctx->basic_table_size) {
|
||||||
@@ -228,6 +227,7 @@ more_basic_blocks(isc_mem_t *ctx) {
|
|||||||
new = malloc(NUM_BASIC_BLOCKS * ctx->mem_target);
|
new = malloc(NUM_BASIC_BLOCKS * ctx->mem_target);
|
||||||
if (new == NULL)
|
if (new == NULL)
|
||||||
return;
|
return;
|
||||||
|
ctx->total += increment;
|
||||||
ctx->basic_table[ctx->basic_table_count] = new;
|
ctx->basic_table[ctx->basic_table_count] = new;
|
||||||
ctx->basic_table_count++;
|
ctx->basic_table_count++;
|
||||||
|
|
||||||
@@ -263,8 +263,13 @@ __isc_mem_get(isc_mem_t *ctx, size_t size) {
|
|||||||
|
|
||||||
if (size >= ctx->max_size || new_size >= ctx->max_size) {
|
if (size >= ctx->max_size || new_size >= ctx->max_size) {
|
||||||
/* memget() was called on something beyond our upper limit. */
|
/* memget() was called on something beyond our upper limit. */
|
||||||
|
if (ctx->quota != 0 && ctx->total + size > ctx->quota) {
|
||||||
|
ret = NULL;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
ret = malloc(size);
|
ret = malloc(size);
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
|
ctx->total += size;
|
||||||
ctx->stats[ctx->max_size].gets++;
|
ctx->stats[ctx->max_size].gets++;
|
||||||
ctx->stats[ctx->max_size].totalgets++;
|
ctx->stats[ctx->max_size].totalgets++;
|
||||||
}
|
}
|
||||||
@@ -341,6 +346,8 @@ __isc_mem_put(isc_mem_t *ctx, void *mem, size_t size) {
|
|||||||
free(mem);
|
free(mem);
|
||||||
INSIST(ctx->stats[ctx->max_size].gets != 0);
|
INSIST(ctx->stats[ctx->max_size].gets != 0);
|
||||||
ctx->stats[ctx->max_size].gets--;
|
ctx->stats[ctx->max_size].gets--;
|
||||||
|
INSIST(size <= ctx->total);
|
||||||
|
ctx->total -= size;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user