mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 10:54:48 +08:00
vfs: fix excess CPU used by VFS cache cleaner looping
Before this change the VFS cache cleaner would loop indefinitely while the cache was above quota. This used up all the CPU. This fix prevents the cache cleaner from looping. It will be kicked on ENOSPACE and run in its scheduled time otherwise so this should be sufficient. See: https://forum.rclone.org/t/vfs-keeps-checking-same-files/32120
This commit is contained in:
parent
a07d376fb1
commit
2a817e21cb
|
@ -739,27 +739,17 @@ func (c *Cache) clean(kicked bool) {
|
|||
oldItems, oldUsed := len(c.item), fs.SizeSuffix(c.used)
|
||||
c.mu.Unlock()
|
||||
|
||||
// loop cleaning the cache until we reach below cache quota
|
||||
for {
|
||||
// Remove any files that are over age
|
||||
c.purgeOld(c.opt.CacheMaxAge)
|
||||
// Remove any files that are over age
|
||||
c.purgeOld(c.opt.CacheMaxAge)
|
||||
|
||||
if int64(c.opt.CacheMaxSize) <= 0 {
|
||||
break
|
||||
}
|
||||
|
||||
// Now remove files not in use until cache size is below quota starting from the
|
||||
// oldest first
|
||||
// If have a maximum cache size...
|
||||
if int64(c.opt.CacheMaxSize) > 0 {
|
||||
// Remove files not in use until cache size is below quota starting from the oldest first
|
||||
c.purgeOverQuota(int64(c.opt.CacheMaxSize))
|
||||
|
||||
// Remove cache files that are not dirty if we are still above the max cache size
|
||||
c.purgeClean(int64(c.opt.CacheMaxSize))
|
||||
c.retryFailedResets()
|
||||
|
||||
used := c.updateUsed()
|
||||
if used <= int64(c.opt.CacheMaxSize) && len(c.errItems) == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Was kicked?
|
||||
|
|
Loading…
Reference in New Issue
Block a user