Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/util-mpm-hs-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ int SCHSCachePruneEvaluate(MpmConfig *mpm_conf, HashTable *inuse_caches)

struct dirent *ent;
char path[PATH_MAX];
uint32_t considered = 0, removed = 0;
uint32_t considered = 0, removed_by_age = 0, removed_by_version = 0;
const time_t cutoff = now - (time_t)mpm_conf->cache_max_age_seconds;
while ((ent = readdir(dir)) != NULL) {
const char *name = ent->d_name;
Expand Down Expand Up @@ -399,7 +399,10 @@ int SCHSCachePruneEvaluate(MpmConfig *mpm_conf, HashTable *inuse_caches)
/* coverity[toctou] */
int ret = unlink(path);
if (ret == 0 || (ret == -1 && errno == ENOENT)) {
removed++;
if (prune_by_version)
removed_by_version++;
else if (prune_by_age)
removed_by_age++;
SCLogDebug("File %s removed because of %s%s%s", path, prune_by_age ? "age" : "",
prune_by_age && prune_by_version ? " and " : "",
prune_by_version ? "incompatible version" : "");
Expand All @@ -411,7 +414,8 @@ int SCHSCachePruneEvaluate(MpmConfig *mpm_conf, HashTable *inuse_caches)

PatternDatabaseCache *pd_cache_stats = mpm_conf->cache_stats;
if (pd_cache_stats) {
pd_cache_stats->hs_dbs_cache_pruned_cnt = removed;
pd_cache_stats->hs_dbs_cache_pruned_by_age_cnt = removed_by_age;
pd_cache_stats->hs_dbs_cache_pruned_by_version_cnt = removed_by_version;
pd_cache_stats->hs_dbs_cache_pruned_considered_cnt = considered;
pd_cache_stats->hs_dbs_cache_pruned_cutoff = cutoff;
pd_cache_stats->cache_max_age_seconds = mpm_conf->cache_max_age_seconds;
Expand Down Expand Up @@ -448,17 +452,23 @@ void SCHSCacheStatsPrint(void *data)
}

if (pd_cache_stats->hs_cacheable_dbs_cnt) {
SCLogInfo("Rule group caching - loaded: %u newly cached: %u total cacheable: %u",
SCLogPerf("rule group caching - loaded: %u newly cached: %u total cacheable: %u",
pd_cache_stats->hs_dbs_cache_loaded_cnt, pd_cache_stats->hs_dbs_cache_saved_cnt,
pd_cache_stats->hs_cacheable_dbs_cnt);
}
if (pd_cache_stats->hs_dbs_cache_pruned_considered_cnt) {
SCLogInfo("Rule group cache pruning removed %u/%u of HS caches due to "
"version-incompatibility (not v%s) or "
"age (older than %s)",
pd_cache_stats->hs_dbs_cache_pruned_cnt,
pd_cache_stats->hs_dbs_cache_pruned_considered_cnt, HS_CACHE_FILE_VERSION,
time_str);
if (pd_cache_stats->hs_dbs_cache_pruned_by_version_cnt) {
SCLogInfo("rule group cache pruning removed %u/%u of HS caches due to "
"version-incompatibility (not v%s)",
pd_cache_stats->hs_dbs_cache_pruned_by_version_cnt,
pd_cache_stats->hs_dbs_cache_pruned_considered_cnt, HS_CACHE_FILE_VERSION);
}
if (pd_cache_stats->hs_dbs_cache_pruned_by_age_cnt) {
SCLogInfo("rule group cache pruning removed %u/%u of HS caches due to "
"age (older than %s)",
pd_cache_stats->hs_dbs_cache_pruned_by_age_cnt,
pd_cache_stats->hs_dbs_cache_pruned_considered_cnt, time_str);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/util-mpm-hs-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ typedef struct PatternDatabaseCache_ {
uint32_t hs_cacheable_dbs_cnt;
uint32_t hs_dbs_cache_loaded_cnt;
uint32_t hs_dbs_cache_saved_cnt;
uint32_t hs_dbs_cache_pruned_cnt;
uint32_t hs_dbs_cache_pruned_by_age_cnt;
uint32_t hs_dbs_cache_pruned_by_version_cnt;
uint32_t hs_dbs_cache_pruned_considered_cnt;
time_t hs_dbs_cache_pruned_cutoff;
uint64_t cache_max_age_seconds;
Expand Down
Loading