Add support for reading AnonHugePages from /proc/meminfo
This commit adds support for reading the `AnonHugePages` field from `/proc/meminfo`. The values in this field allow monitoring the [THP](https://www.kernel.org/doc/Documentation/vm/transhuge.txt) usage by systems that use this type of memory
This commit is contained in:
parent
faad806080
commit
7f4efa5358
|
@ -50,6 +50,7 @@ type VirtualMemoryStat struct {
|
|||
// https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s2-proc-meminfo.html
|
||||
// https://www.kernel.org/doc/Documentation/filesystems/proc.txt
|
||||
// https://www.kernel.org/doc/Documentation/vm/overcommit-accounting
|
||||
// https://www.kernel.org/doc/Documentation/vm/transhuge.txt
|
||||
Buffers uint64 `json:"buffers"`
|
||||
Cached uint64 `json:"cached"`
|
||||
WriteBack uint64 `json:"writeBack"`
|
||||
|
@ -78,6 +79,7 @@ type VirtualMemoryStat struct {
|
|||
HugePagesRsvd uint64 `json:"hugePagesRsvd"`
|
||||
HugePagesSurp uint64 `json:"hugePagesSurp"`
|
||||
HugePageSize uint64 `json:"hugePageSize"`
|
||||
AnonHugePages uint64 `json:"anonHugePages"`
|
||||
}
|
||||
|
||||
type SwapMemoryStat struct {
|
||||
|
|
|
@ -311,6 +311,12 @@ func fillFromMeminfoWithContext(ctx context.Context) (*VirtualMemoryStat, *Virtu
|
|||
return ret, retEx, err
|
||||
}
|
||||
ret.HugePageSize = t * 1024
|
||||
case "AnonHugePages":
|
||||
t, err := strconv.ParseUint(value, 10, 64)
|
||||
if err != nil {
|
||||
return ret, retEx, err
|
||||
}
|
||||
ret.AnonHugePages = t * 1024
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,6 +108,16 @@ var virtualMemoryTests = []struct {
|
|||
HugePageSize: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
"anonhugepages", &VirtualMemoryStat{
|
||||
Total: 260799420 * 1024,
|
||||
Available: 127880216 * 1024,
|
||||
Free: 119443248 * 1024,
|
||||
AnonHugePages: 50409472 * 1024,
|
||||
Used: 144748720128,
|
||||
UsedPercent: 54.20110673559013,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestVirtualMemoryLinux(t *testing.T) {
|
||||
|
|
|
@ -89,7 +89,7 @@ func TestVirtualMemoryStat_String(t *testing.T) {
|
|||
Free: 40,
|
||||
}
|
||||
t.Log(v)
|
||||
e := `{"total":10,"available":20,"used":30,"usedPercent":30.1,"free":40,"active":0,"inactive":0,"wired":0,"laundry":0,"buffers":0,"cached":0,"writeBack":0,"dirty":0,"writeBackTmp":0,"shared":0,"slab":0,"sreclaimable":0,"sunreclaim":0,"pageTables":0,"swapCached":0,"commitLimit":0,"committedAS":0,"highTotal":0,"highFree":0,"lowTotal":0,"lowFree":0,"swapTotal":0,"swapFree":0,"mapped":0,"vmallocTotal":0,"vmallocUsed":0,"vmallocChunk":0,"hugePagesTotal":0,"hugePagesFree":0,"hugePagesRsvd":0,"hugePagesSurp":0,"hugePageSize":0}`
|
||||
e := `{"total":10,"available":20,"used":30,"usedPercent":30.1,"free":40,"active":0,"inactive":0,"wired":0,"laundry":0,"buffers":0,"cached":0,"writeBack":0,"dirty":0,"writeBackTmp":0,"shared":0,"slab":0,"sreclaimable":0,"sunreclaim":0,"pageTables":0,"swapCached":0,"commitLimit":0,"committedAS":0,"highTotal":0,"highFree":0,"lowTotal":0,"lowFree":0,"swapTotal":0,"swapFree":0,"mapped":0,"vmallocTotal":0,"vmallocUsed":0,"vmallocChunk":0,"hugePagesTotal":0,"hugePagesFree":0,"hugePagesRsvd":0,"hugePagesSurp":0,"hugePageSize":0,"anonHugePages":0}`
|
||||
if e != fmt.Sprintf("%v", v) {
|
||||
t.Errorf("VirtualMemoryStat string is invalid: %v", v)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
MemTotal: 260799420 kB
|
||||
MemFree: 119443248 kB
|
||||
MemAvailable: 127880216 kB
|
||||
AnonHugePages: 50409472 kB
|
Loading…
Reference in New Issue