mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/blockcache: properly remove references to deleted parts
Previously references to deleted parts may remain active as cache.m keys.
This could prevent from proper memory de-allocation.
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
This is a follow-up for 88605a7ea2
This commit is contained in:
parent
2ae3a9a8a3
commit
e3a10b327c
1 changed files with 16 additions and 11 deletions
|
@ -265,14 +265,10 @@ func (c *cache) cleanByTimeout() {
|
|||
defer c.mu.Unlock()
|
||||
|
||||
for len(c.lah) > 0 {
|
||||
e := c.lah[0]
|
||||
if lastAccessTime < e.lastAccessTime {
|
||||
if lastAccessTime < c.lah[0].lastAccessTime {
|
||||
break
|
||||
}
|
||||
c.updateSizeBytes(-e.b.SizeBytes())
|
||||
pes := c.m[e.k.Part]
|
||||
delete(pes, e.k.Offset)
|
||||
heap.Pop(&c.lah)
|
||||
c.removeLeastRecentlyAccessedItem()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,12 +329,21 @@ func (c *cache) PutBlock(k Key, b Block) {
|
|||
c.updateSizeBytes(e.b.SizeBytes())
|
||||
maxSizeBytes := c.getMaxSizeBytes()
|
||||
for c.SizeBytes() > maxSizeBytes && len(c.lah) > 0 {
|
||||
c.removeLeastRecentlyAccessedItem()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cache) removeLeastRecentlyAccessedItem() {
|
||||
e := c.lah[0]
|
||||
c.updateSizeBytes(-e.b.SizeBytes())
|
||||
pes := c.m[e.k.Part]
|
||||
p := e.k.Part
|
||||
pes := c.m[p]
|
||||
delete(pes, e.k.Offset)
|
||||
heap.Pop(&c.lah)
|
||||
if len(pes) == 0 {
|
||||
// Remove reference to p from c.m in order to free up memory occupied by p.
|
||||
delete(c.m, p)
|
||||
}
|
||||
heap.Pop(&c.lah)
|
||||
}
|
||||
|
||||
func (c *cache) Len() int {
|
||||
|
|
Loading…
Reference in a new issue