Skip to content

Commit

Permalink
fix(tmo): modify calculation algorithm
Browse files Browse the repository at this point in the history
Signed-off-by: linzhecheng <[email protected]>
  • Loading branch information
cheney-lin committed Sep 23, 2024
1 parent d1dc9d9 commit 3e1e59d
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ const (
)

const (
InactiveProbe = 0.1
OffloadingSizeScaleCoeff = 1.05
CacheMappedCoeff = 2
InactiveProbe = 0.1
OffloadingSizeScaleCoeff = 1.25
CacheMappedCoeff = 2
MinReclaimSize = 256 << 10 // 256 KiB
IndependentRefaultThreshold = 1000
)

const (
Expand Down Expand Up @@ -118,16 +120,18 @@ func refaultPolicyFunc(lastStats TmoStats, currStats TmoStats, conf *tmoconf.TMO
if pgstealDelta > 0 && pgscanDelta > 0 {
reclaimAccuracyRatio = 1 - refaultDelta/pgstealDelta
reclaimScanEfficiencyRatio = pgstealDelta / pgscanDelta
} else if refaultDelta > IndependentRefaultThreshold {
reclaimAccuracyRatio = 0
}

var result float64
if reclaimAccuracyRatio < conf.RefaultPolicyConf.ReclaimAccuracyTarget || reclaimScanEfficiencyRatio < conf.RefaultPolicyConf.ReclaimScanEfficiencyTarget {
// Decrease offloading size if detecting the reclaim accuracy or scan efficiency is below the targets
result = math.Max(0, lastStats.offloadingTargetSize*reclaimAccuracyRatio)
result = math.Max(0.25, reclaimAccuracyRatio) * lastStats.offloadingTargetSize
} else {
// Try to increase offloading size but make sure not exceed the max probe of memory usage and 10% of inactive memory when the target size of last round is relatively small,
// which means reclaim accuracy and reclaim scan efficiency is low.
result = math.Min(math.Max(lastStats.offloadingTargetSize*OffloadingSizeScaleCoeff, currStats.memInactive*InactiveProbe), currStats.memUsage*conf.RefaultPolicyConf.MaxProbe)
result = math.Min(math.Max(lastStats.offloadingTargetSize*OffloadingSizeScaleCoeff, MinReclaimSize), math.Min(currStats.memInactive*InactiveProbe, currStats.memUsage*conf.RefaultPolicyConf.MaxProbe))
}
general.InfoS("refault info", "obj", currStats.obj, "reclaimAccuracyRatio", reclaimAccuracyRatio, "ReclaimAccuracyTarget", conf.RefaultPolicyConf.ReclaimAccuracyTarget,
"reclaimScanEfficiencyRatio", reclaimScanEfficiencyRatio, "ReclaimScanEfficiencyTarget", conf.RefaultPolicyConf.ReclaimScanEfficiencyTarget,
Expand Down

0 comments on commit 3e1e59d

Please sign in to comment.