Fix memory plateau after daily virus-database reload - #2
Merged
Conversation
Compiling a new engine while the previous one stayed live briefly doubled RSS; glibc then kept the old arenas mapped, so memory plateaued around 1.5x after daily.cvd published. Stream CVD verify/unpack from disk, pin Aho-Corasick to a contiguous NFA, switch Linux to jemalloc, and purge unused pages after each swap. Co-authored-by: Eldad A. Fux <eldadfux@users.noreply.github.com>
eldadfux
marked this pull request as ready for review
August 20, 2026 09:56
Greptile SummaryThe PR reduces peak and retained RSS during virus-database reloads by streaming CVD processing, limiting the Aho-Corasick representation, and using jemalloc reclamation on Linux.
Confidence Score: 5/5The PR appears safe to merge with no concrete blocking or independently actionable non-blocking defect identified. The changed download, verification, ingestion, swap, and allocator paths preserve existing signature support and installation ordering while reducing transient and retained memory. Important Files Changed
Reviews (1): Last reviewed commit: "Fix RSS step-up after daily CVD hot-relo..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The RSS chart (flat for hours, then a near-vertical jump that does not come back down) matches a daily
daily.cvdhot-reload, not a leak on the scan path.Default
DEFENDER_UPDATE_INTERVAL_SECSis 3600. When ClamAV publishes a new daily database (typically once a day), Defender:Enginewhile the previous one stays live (zero-downtime)ArcSwapPeak RSS is therefore about two engines plus unpack/compile scratch (~4.5 GiB from a ~2 GiB baseline). After the swap, glibc
malloccommonly does not return the old arenas to the OS, so RSS plateaus ~1.5× above the original baseline (the 3.55 GiB level in the screenshot).Changes
.tmpfiles are drained, not retained. PUA files are skipped whenDEFENDER_LOAD_PUAis off.ContiguousNFA. The default heuristic can pick a DFA that is many times larger and is a major contributor to the two-engine peak.ArcSwap, unused dirty pages are purged. Reload logsrss_before/rss_compiled/rss_after.A brief spike while both engines exist is still expected for zero-downtime updates. RSS should return near the pre-reload baseline once in-flight scans release the old
Arc.Verification
cargo test --locked --all-targetsOn a running instance, watch the reload line after a daily publish:
rss_aftershould be close torss_before, not stuck nearrss_compiled.