diff --git a/mem/mem.go b/mem/mem.go index ff960da..edaf268 100644 --- a/mem/mem.go +++ b/mem/mem.go @@ -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 { diff --git a/mem/mem_linux.go b/mem/mem_linux.go index 9353317..214a91e 100644 --- a/mem/mem_linux.go +++ b/mem/mem_linux.go @@ -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 } } diff --git a/mem/mem_linux_test.go b/mem/mem_linux_test.go index d830fbf..6b6fb78 100644 --- a/mem/mem_linux_test.go +++ b/mem/mem_linux_test.go @@ -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) { diff --git a/mem/mem_test.go b/mem/mem_test.go index 3be5656..79ddb0f 100644 --- a/mem/mem_test.go +++ b/mem/mem_test.go @@ -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) } diff --git a/mem/testdata/linux/virtualmemory/anonhugepages/proc/meminfo b/mem/testdata/linux/virtualmemory/anonhugepages/proc/meminfo new file mode 100644 index 0000000..d158c67 --- /dev/null +++ b/mem/testdata/linux/virtualmemory/anonhugepages/proc/meminfo @@ -0,0 +1,4 @@ +MemTotal: 260799420 kB +MemFree: 119443248 kB +MemAvailable: 127880216 kB +AnonHugePages: 50409472 kB \ No newline at end of file