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)
"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);
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;
}
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;
* */
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
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));
}
}
}
typedef int (*THashFormatFunc)(const void *in_data, char *output, size_t output_size);
typedef struct THashDataConfig_ {
- uint64_t memcap;
+ SC_ATOMIC_DECLARE(uint64_t, memcap);
uint32_t hash_rand;
uint32_t hash_size;
uint32_t prealloc;
* \retval 1 it fits
* \retval 0 no fit
*/
-#define THASH_CHECK_MEMCAP(ctx, size) \
- ((((uint64_t)SC_ATOMIC_GET((ctx)->memuse) + (uint64_t)(size)) <= (ctx)->config.memcap))
+#define THASH_CHECK_MEMCAP(ctx, size) \
+ ((((uint64_t)SC_ATOMIC_GET((ctx)->memuse) + (uint64_t)(size)) <= \
+ SC_ATOMIC_GET((ctx)->config.memcap)))
#define THashIncrUsecnt(h) \
(void)SC_ATOMIC_ADD((h)->use_cnt, 1)