Skip to content

Commit

Permalink
Fix a memory leak in inodesByTime (evicted inodes were not removed fr…
Browse files Browse the repository at this point in the history
…om the map)
  • Loading branch information
vitalif committed Dec 6, 2023
1 parent 950ddf5 commit d2dac73
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions internal/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,7 @@ func (inode *Inode) resetCache() {
inode.SetCacheState(ST_CACHED)
// Invalidate metadata entry
inode.SetAttrTime(time.Time{})
inode.SetExpireTime(time.Time{})
}

func (inode *Inode) FlushSmallObject() {
Expand Down
6 changes: 2 additions & 4 deletions internal/goofys.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,8 @@ func (fs *Goofys) MetaEvictor() {
}
// Try to keep the number of cached inodes under control %)
fs.mu.RLock()
toEvict := (len(fs.inodes)-fs.flags.EntryLimit)*2
totalInodes := len(fs.inodes)
toEvict := (totalInodes-fs.flags.EntryLimit)*2
if toEvict < 0 {
fs.mu.RUnlock()
retry = false
Expand Down Expand Up @@ -895,10 +896,7 @@ func (fs *Goofys) MetaEvictor() {
seen[id] = true
}
}
fs.mu.RLock()
totalInodes := len(fs.inodes)
retry = len(scan) >= toEvict && totalInodes > fs.flags.EntryLimit
fs.mu.RUnlock()
atomic.AddInt64(&fs.stats.evicts, int64(evicted))
if len(scan) > 0 {
log.Debugf("metadata cache: alive %v, scanned %v, evicted %v", totalInodes, len(scan), evicted)
Expand Down

0 comments on commit d2dac73

Please sign in to comment.