From f350953a19c0efd1e02c21ecb24ee884942096ba Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Fri, 3 Mar 2023 12:32:22 +0800 Subject: [PATCH] calculate disk cache usage percent accurately (#16740) --- cmd/disk-cache.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/disk-cache.go b/cmd/disk-cache.go index 904c7407a..2c0e14e1a 100644 --- a/cmd/disk-cache.go +++ b/cmd/disk-cache.go @@ -25,7 +25,6 @@ import ( "strconv" "strings" "sync" - "sync/atomic" "time" objectlock "github.com/minio/minio/internal/bucket/object/lock" @@ -893,8 +892,16 @@ func newServerCacheObjects(ctx context.Context, config cache.Config) (CacheObjec cacheDiskStats[i].UsageSize = info.Used cacheDiskStats[i].TotalCapacity = info.Total cacheDiskStats[i].Dir = dcache.stats.Dir - atomic.StoreInt32(&cacheDiskStats[i].UsageState, atomic.LoadInt32(&dcache.stats.UsageState)) - atomic.StoreUint64(&cacheDiskStats[i].UsagePercent, atomic.LoadUint64(&dcache.stats.UsagePercent)) + if info.Total != 0 { + // UsageState + gcTriggerPct := dcache.quotaPct * dcache.highWatermark / 100 + usedPercent := float64(info.Used) * 100 / float64(info.Total) + if usedPercent >= float64(gcTriggerPct) { + cacheDiskStats[i].UsageState = 1 + } + // UsagePercent + cacheDiskStats[i].UsagePercent = uint64(usedPercent) + } } } return cacheDiskStats