Skip to content

filtering: remove debug.FreeOSMemory after engine rebuild - #8590

Open
ChenYun10 wants to merge 2 commits into
AdguardTeam:masterfrom
ChenYun10:fix/freeosmemory-io-spike
Open

filtering: remove debug.FreeOSMemory after engine rebuild#8590
ChenYun10 wants to merge 2 commits into
AdguardTeam:masterfrom
ChenYun10:fix/freeosmemory-io-spike

Conversation

@ChenYun10

@ChenYun10 ChenYun10 commented Sep 3, 2026

Copy link
Copy Markdown

Problem

Saving settings rebuilds the filtering engine, and initFiltering calls debug.FreeOSMemory afterwards. FreeOSMemory forces a full stop-the-world GC and returns all free memory to the OS, which causes a sudden CPU and I/O spike that can hang or crash the process right after a settings change — on any host (dedicated machines included), even with a small data volume.

Fix

Remove the debug.FreeOSMemory call and rely on the Go runtime scavenger, which returns memory to the OS gradually without the spike.

Notes

  • This was the only FreeOSMemory call in the codebase.
  • Verified: go build ./internal/filtering/ and go test ./internal/filtering/ pass.

Signed-off-by: Chen Yun ChenYun10@users.noreply.github.com

Calling debug.FreeOSMemory forces a full stop-the-world GC and returns all
free memory to the OS.  This causes a sudden I/O and CPU spike right after
saving settings (when the filtering engine is rebuilt), which on hosts with
limited disk I/O such as cloud VMs can make the process appear to hang.

Rely on the Go runtime scavenger, which returns memory to the OS gradually
without the spike.

Signed-off-by: Chen Yun <ChenYun10@users.noreply.github.com>
The forced GC and memory return can hang or crash the process on any
host, not just hosts with limited disk I/O.

Signed-off-by: Chen Yun <ChenYun10@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant