-
Notifications
You must be signed in to change notification settings - Fork 1.6k
HS: Prune stale cache files from disk v4.1 #14516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
To have a system-level overview of when was the last time the file was used, update the file modification timestamp to to the current time. This is needed to remove stale cache files of the system. Access time is not used as it may be, on the system level, disabled. Ticket: 7830
Ticket: 7830
Hyperscan MPM can cache the compiled contexts to files. This however grows as rulesets change and leads to bloating the system. This addition prunes the stale cache files based on their modified file timestamp. Part of this work incorporates new model for MPM cache stats to split it out from the cache save function and aggregate cache-related stats in one place (newly added pruning). Ticket: 7830
This is especially relevant for multi-instance simultaneous setups as we might risk read/write races.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #14516 +/- ##
==========================================
- Coverage 82.11% 82.10% -0.01%
==========================================
Files 1013 1013
Lines 262297 262495 +198
==========================================
+ Hits 215380 215532 +152
- Misses 46917 46963 +46
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 18 out of 41 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| PatternDatabaseCache *pd_cache_stats = mpm_conf->cache_stats; | ||
| pd_cache_stats->hs_dbs_cache_pruned_cnt = removed; | ||
| 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; |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In SCHSCachePrune, mpm_conf->cache_stats is dereferenced without checking if it's NULL. If CacheStatsInit is not implemented or returns NULL for some reason but CachePrune is implemented, this will cause a null pointer dereference. Add a null check before accessing cache_stats.
| { | ||
| uint32_t hash[2] = { 0 }; | ||
| hashword2(&pd->pattern_cnt, 1, &hash[0], &hash[1]); | ||
| SCSha256 *hasher = SCSha256New(); |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SCSha256New() is called without checking if it returns NULL. While Box::new in Rust will panic on allocation failure rather than returning NULL, it's good practice to check the return value when crossing FFI boundaries to make the code more defensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree here
|
Information: QA ran without warnings. Pipeline = 28848 |
| } | ||
|
|
||
| if (!SCSha256FinalizeToHex(hasher, hash, hash_len)) { | ||
| hasher = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this set to NULL here and not in the success case?
|
For a bigger and more complex PR like this, please don't include doc space cleanup commits. Those can go into their own PR to ease review. |
|
In my MT setup, the old files are removed as expected, but I do get lots of warnings |
Follow-up of #14512
Link to ticket: https://redmine.openinfosecfoundation.org/issues/7830
Describe changes:
v4.1:
v4.0:
v3.3:
v3:
v2:
v1:
The logic to determine a stale file is currently based on the modification timestamp in the file systems. The accessed time stamp was not used as it may be switched off. Alternatively, we could use a local DB/notekeeping file of the last used files/caches but this approach seemed simpler.
I can also add GitHub CI tests, I thought of some scenarios.