This repository was archived by the owner on Dec 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdm-cache.go
More file actions
69 lines (57 loc) · 2.56 KB
/
dm-cache.go
File metadata and controls
69 lines (57 loc) · 2.56 KB
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
65
66
67
68
69
// Copyright 2017-18 Daniel Swarbrick. All rights reserved.
// Use of this source code is governed by a GPL license that can be found in the LICENSE file.
// dm-cache Statistics Parser.
// See dm-cache documentation at: https://www.kernel.org/doc/Documentation/device-mapper/cache.txt
package devmapper
import "fmt"
type dmCacheStatus struct {
mdataBlockSize int // Fixed block size for each metadata block in sectors
mdataUsedBlocks int // Number of metadata blocks used
mdataTotalBlocks int // Total number of metadata blocks
cacheBlockSize int // Configurable block size for the cache device in sectors
cacheUsedBlocks int // Number of blocks resident in the cache
cacheTotalBlocks int // Total number of cache blocks
readHits int // Number of times a READ bio has been mapped to the cache
readMisses int // Number of times a READ bio has been mapped to the origin
writeHits int // Number of times a WRITE bio has been mapped to the cache
writeMisses int // Number of times a WRITE bio has been mapped to the origin
demotions int // Number of times a block has been removed from the cache
promotions int // Number of times a block has been moved to the cache
dirty int // Number of blocks in the cache that differ from the origin
}
// cacheUsedPerc returns the percentage of cache blocks used
func (d *dmCacheStatus) cacheUsedPerc() float64 {
return float64(d.cacheUsedBlocks) / float64(d.cacheTotalBlocks) * 100
}
// mdataUsedPerc returns the percentage of metadata blocks used
func (d *dmCacheStatus) mdataUsedPerc() float64 {
return float64(d.mdataUsedBlocks) / float64(d.mdataTotalBlocks) * 100
}
// readHitRatio returns the cache read hit ratio (0.0 - 1.0)
func (d *dmCacheStatus) readHitRatio() float64 {
if d.readHits > 0 {
return float64(d.readHits) / float64(d.readHits+d.readMisses)
} else {
return 0
}
}
// writeHitRatio returns the cache write hit ratio (0.0 - 1.0)
func (d *dmCacheStatus) writeHitRatio() float64 {
if d.writeHits > 0 {
return float64(d.writeHits) / float64(d.writeHits+d.writeMisses)
} else {
return 0
}
}
func unmarshallParams(params string) dmCacheStatus {
var s dmCacheStatus
fmt.Sscanf(params, "%d %d/%d %d %d/%d %d %d %d %d %d %d %d",
&s.mdataBlockSize, &s.mdataUsedBlocks, &s.mdataTotalBlocks,
&s.cacheBlockSize, &s.cacheUsedBlocks, &s.cacheTotalBlocks,
&s.readHits, &s.readMisses,
&s.writeHits, &s.writeMisses,
&s.demotions, &s.promotions, &s.dirty)
// Remainder of table data needs to be handled token by token, e.g.:
// tokens := strings.Fields(params)[11:]
return s
}