|
|
|
@ -228,12 +228,15 @@ static int THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
|
|
|
|
|
GET_VAR(cnf_prefix, "memcap");
|
|
|
|
|
if ((ConfGet(varname, &conf_val)) == 1)
|
|
|
|
|
{
|
|
|
|
|
if (ParseSizeStringU64(conf_val, &ctx->config.memcap) < 0) {
|
|
|
|
|
uint64_t memcap;
|
|
|
|
|
if (ParseSizeStringU64(conf_val, &memcap) < 0) {
|
|
|
|
|
SCLogError("Error parsing %s "
|
|
|
|
|
"from conf file - %s. Killing engine",
|
|
|
|
|
varname, conf_val);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
SC_ATOMIC_INIT(ctx->config.memcap);
|
|
|
|
|
SC_ATOMIC_SET(ctx->config.memcap, memcap);
|
|
|
|
|
}
|
|
|
|
|
GET_VAR(cnf_prefix, "hash-size");
|
|
|
|
|
if ((ConfGet(varname, &conf_val)) == 1)
|
|
|
|
@ -261,7 +264,7 @@ static int THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
|
|
|
|
|
"Memcap: %" PRIu64 ", Hash table size %" PRIu64 ". Calculate "
|
|
|
|
|
"total hash size by multiplying \"hash-size\" with %" PRIuMAX ", "
|
|
|
|
|
"which is the hash bucket size.",
|
|
|
|
|
ctx->config.memcap, hash_size, (uintmax_t)sizeof(THashHashRow));
|
|
|
|
|
SC_ATOMIC_GET(ctx->config.memcap), hash_size, (uintmax_t)sizeof(THashHashRow));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
ctx->array = SCMallocAligned(ctx->config.hash_size * sizeof(THashHashRow), CLS);
|
|
|
|
@ -283,7 +286,7 @@ static int THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
|
|
|
|
|
SCLogError("preallocating data failed: "
|
|
|
|
|
"max thash memcap reached. Memcap %" PRIu64 ", "
|
|
|
|
|
"Memuse %" PRIu64 ".",
|
|
|
|
|
ctx->config.memcap,
|
|
|
|
|
SC_ATOMIC_GET(ctx->config.memcap),
|
|
|
|
|
((uint64_t)SC_ATOMIC_GET(ctx->memuse) + THASH_DATA_SIZE(ctx)));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
@ -323,12 +326,12 @@ THashTableContext *THashInit(const char *cnf_prefix, size_t data_size,
|
|
|
|
|
unless defined by the rule keyword */
|
|
|
|
|
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
|
|
|
|
// limit memcap size to default when fuzzing
|
|
|
|
|
ctx->config.memcap = THASH_DEFAULT_MEMCAP;
|
|
|
|
|
SC_ATOMIC_SET(ctx->config.memcap, THASH_DEFAULT_MEMCAP);
|
|
|
|
|
#else
|
|
|
|
|
if (memcap > 0) {
|
|
|
|
|
ctx->config.memcap = memcap;
|
|
|
|
|
SC_ATOMIC_SET(ctx->config.memcap, memcap);
|
|
|
|
|
} else {
|
|
|
|
|
ctx->config.memcap = reset_memcap ? UINT64_MAX : THASH_DEFAULT_MEMCAP;
|
|
|
|
|
SC_ATOMIC_SET(ctx->config.memcap, reset_memcap ? UINT64_MAX : THASH_DEFAULT_MEMCAP);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
ctx->config.prealloc = THASH_DEFAULT_PREALLOC;
|
|
|
|
@ -349,8 +352,9 @@ THashTableContext *THashInit(const char *cnf_prefix, size_t data_size,
|
|
|
|
|
* */
|
|
|
|
|
void THashConsolidateMemcap(THashTableContext *ctx)
|
|
|
|
|
{
|
|
|
|
|
ctx->config.memcap = MAX(SC_ATOMIC_GET(ctx->memuse), ctx->config.memcap);
|
|
|
|
|
SCLogDebug("memcap after load set to: %" PRIu64, ctx->config.memcap);
|
|
|
|
|
SC_ATOMIC_SET(
|
|
|
|
|
ctx->config.memcap, MAX(SC_ATOMIC_GET(ctx->memuse), SC_ATOMIC_GET(ctx->config.memcap)));
|
|
|
|
|
SCLogDebug("memcap after load set to: %" PRIu64, SC_ATOMIC_GET(ctx->config.memcap));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief shutdown the flow engine
|
|
|
|
@ -598,7 +602,7 @@ static THashData *THashDataGetNew(THashTableContext *ctx, void *data)
|
|
|
|
|
SC_ATOMIC_SET(ctx->memcap_reached, true);
|
|
|
|
|
}
|
|
|
|
|
SCLogError("Adding data will exceed memcap: %" PRIu64 ", current memuse: %" PRIu64,
|
|
|
|
|
(ctx)->config.memcap, SC_ATOMIC_GET(ctx->memuse));
|
|
|
|
|
SC_ATOMIC_GET((ctx)->config.memcap), SC_ATOMIC_GET(ctx->memuse));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|