From 7c92aaeaa428a01292394e9a37de9a7ecda04078 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 18 Mar 2022 16:18:56 +0200 Subject: [PATCH] lib/blockcache: properly release memory occupied by deleted entries Proviously the deleted entries could remain referenced via lastAccessHeap for long time. This could lead to increased memory usage for the following caches starting from v1.73.0: * indexdb/indexBlocks * indexdb/dataBlocks * storage/indexBlocks Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2242 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2007 --- docs/CHANGELOG.md | 1 + lib/blockcache/blockcache.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index bd77728d32..e7815b06e6 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -23,6 +23,7 @@ The following tip changes can be tested by building VictoriaMetrics components f * BUGFIX: [Graphite Render API](https://docs.victoriametrics.com/#graphite-render-api-usage): return an additional point after `until` timestamp in the same way as Graphite does. Previously VictoriaMetrics didn't return this point, which could result in missing last point on the graph. * BUGFIX: properly locate series with the given `name` and without the given `label` when using the `name{label=~"foo|"}` series selector. Previously such series could be skipped. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2255). Thanks to @jduncan0000 for discovering and fixing the issue. +* BUGFIX: properly free up memory occupied by deleted cache entries for the following caches: `indexdb/dataBlocks`, `indexdb/indexBlocks`, `storage/indexBlocks`. This should reduce the increased memory usage starting from v1.73.0. See [this](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2242) and [this](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2007) issue. ## [v1.74.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.74.0) diff --git a/lib/blockcache/blockcache.go b/lib/blockcache/blockcache.go index 1737e0f3ca..86727e3534 100644 --- a/lib/blockcache/blockcache.go +++ b/lib/blockcache/blockcache.go @@ -396,6 +396,10 @@ func (lah *lastAccessHeap) Push(x interface{}) { func (lah *lastAccessHeap) Pop() interface{} { h := *lah e := h[len(h)-1] + + // Remove the reference to deleted entry, so Go GC could free up memory occupied by the deleted entry. + h[len(h)-1] = nil + *lah = h[:len(h)-1] return e }