-
Notifications
You must be signed in to change notification settings - Fork 0
/
bucket_vacuum.go
64 lines (55 loc) · 1.13 KB
/
bucket_vacuum.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cbytecache
import (
"math"
)
const (
VacuumRatioWeak = .25
VacuumRatioModerate = .5
VacuumRatioAggressive = .75
)
// Perform bilk vacuum operation.
func (b *bucket) bulkVacuum() error {
if err := b.checkStatus(); err != nil {
return err
}
var c int
b.svcLock()
defer func() {
if b.l() != nil {
b.l().Printf("bucket #%d: vacuum %d arenas", b.idx, c)
}
b.lastVac = b.nowT()
b.svcUnlock()
}()
// Run eviction before dump to evaluate number of arenas possible to vacuum.
if _, _, err := b.bulkEvictLF(true); err != nil {
return err
}
var t int
a := b.queue.act().next()
for a != nil {
if !a.released() {
t++
}
a = a.next()
}
r := int(math.Floor(float64(t) * b.config.VacuumRatio))
// Vacuum r arenas starting from tail.
a = b.queue.tail()
for c < r {
if !a.released() {
a.release()
b.mw().Release(b.ids, b.acap())
}
tail := a
a = a.prev()
tail.setNext(nil).setPrev(nil)
a.setNext(nil)
b.size.snap(snapRelease, b.acap())
c++
}
// Register last arena as tail.
b.queue.setTail(a)
return ErrOK
}
var _, _, _ = VacuumRatioWeak, VacuumRatioModerate, VacuumRatioAggressive