From c25b839078eaa6d8f4b8ac491223b7283e6aef13 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 1 Jul 2021 11:49:16 +0300 Subject: [PATCH] lib/workingsetcache: reset the cache mode when the cache is reset This should reduce memory usage if the working set is reduced after the cache reset. --- docs/CHANGELOG.md | 2 ++ lib/workingsetcache/cache.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 5cdf685fe..4ba8aff55 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,6 +6,8 @@ sort: 15 ## tip +* FEATURE: reduce memory usage when performing heavy queries over high number of time series. + * BUGFIX: remove `{ %space %}` typo in `/targets` output. The typo has been introduced in v1.62.0. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1408). diff --git a/lib/workingsetcache/cache.go b/lib/workingsetcache/cache.go index c21a331bd..03d1ce1d8 100644 --- a/lib/workingsetcache/cache.go +++ b/lib/workingsetcache/cache.go @@ -218,6 +218,8 @@ func (c *Cache) Reset() { prev.Reset() curr := c.curr.Load().(*fastcache.Cache) curr.Reset() + // Reset the mode to `split` in the hope the working set size becomes smaller after the reset. + atomic.StoreUint64(&c.mode, split) } // UpdateStats updates fcs with cache stats.