Copyright 2019 The Prometheus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

package procfs

import (
	
	
	
	
	
	

	
)
Meminfo represents memory statistics.
Total usable ram (i.e. physical ram minus a few reserved bits and the kernel binary code)
The sum of LowFree+HighFree
An estimate of how much memory is available for starting new applications, without swapping. Calculated from MemFree, SReclaimable, the size of the file LRU lists, and the low watermarks in each zone. The estimate takes into account that the system needs some page cache to function well, and that not all reclaimable slab will be reclaimable, due to items being in use. The impact of those factors will vary from system to system.
Relatively temporary storage for raw disk blocks shouldn't get tremendously large (20MB or so)
Memory that once was swapped out, is swapped back in but still also is in the swapfile (if memory is needed it doesn't need to be swapped out AGAIN because it is already in the swapfile. This saves I/O)
Memory that has been used more recently and usually not reclaimed unless absolutely necessary.
Memory which has been less recently used. It is more eligible to be reclaimed for other purposes
total amount of swap space available
Memory which has been evicted from RAM, and is temporarily on the disk
Memory which is waiting to get written back to the disk
Memory which is actively being written back to the disk
Non-file backed pages mapped into userspace page tables
files which have been mapped, such as libraries
in-kernel data structures cache
Part of Slab, that might be reclaimed, such as caches
Part of Slab, that cannot be reclaimed on memory pressure
amount of memory dedicated to the lowest level of page tables.
NFS pages sent to the server, but not yet committed to stable storage
Memory used for block device "bounce buffers"
Memory used by FUSE for temporary writeback buffers
Based on the overcommit ratio ('vm.overcommit_ratio'), this is the total amount of memory currently available to be allocated on the system. This limit is only adhered to if strict overcommit accounting is enabled (mode 2 in 'vm.overcommit_memory'). The CommitLimit is calculated with the following formula: CommitLimit = ([total RAM pages] - [total huge TLB pages]) * overcommit_ratio / 100 + [total swap pages] For example, on a system with 1G of physical RAM and 7G of swap with a `vm.overcommit_ratio` of 30 it would yield a CommitLimit of 7.3G. For more details, see the memory overcommit documentation in vm/overcommit-accounting.
The amount of memory presently allocated on the system. The committed memory is a sum of all of the memory which has been allocated by processes, even if it has not been "used" by them as of yet. A process which malloc()'s 1G of memory, but only touches 300M of it will show up as using 1G. This 1G is memory which has been "committed" to by the VM and can be used at any time by the allocating application. With strict overcommit enabled on the system (mode 2 in 'vm.overcommit_memory'),allocations which would exceed the CommitLimit (detailed above) will not be permitted. This is useful if one needs to guarantee that processes will not fail due to lack of memory once that memory has been successfully allocated.
total size of vmalloc memory area
amount of vmalloc area which is used
Meminfo returns an information about current kernel/system memory statistics. See https://www.kernel.org/doc/Documentation/filesystems/proc.txt
func ( FS) () (Meminfo, error) {
	,  := util.ReadFileNoStat(.proc.Path("meminfo"))
	if  != nil {
		return Meminfo{}, 
	}

	,  := parseMemInfo(bytes.NewReader())
	if  != nil {
		return Meminfo{}, fmt.Errorf("failed to parse meminfo: %v", )
	}

	return *, nil
}

func ( io.Reader) (*Meminfo, error) {
	var  Meminfo
	 := bufio.NewScanner()
Each line has at least a name and value; we ignore the unit.
		 := strings.Fields(.Text())
		if len() < 2 {
			return nil, fmt.Errorf("malformed meminfo line: %q", .Text())
		}

		,  := strconv.ParseUint([1], 0, 64)
		if  != nil {
			return nil, 
		}

		switch [0] {
		case "MemTotal:":
			.MemTotal = 
		case "MemFree:":
			.MemFree = 
		case "MemAvailable:":
			.MemAvailable = 
		case "Buffers:":
			.Buffers = 
		case "Cached:":
			.Cached = 
		case "SwapCached:":
			.SwapCached = 
		case "Active:":
			.Active = 
		case "Inactive:":
			.Inactive = 
		case "Active(anon):":
			.ActiveAnon = 
		case "Inactive(anon):":
			.InactiveAnon = 
		case "Active(file):":
			.ActiveFile = 
		case "Inactive(file):":
			.InactiveFile = 
		case "Unevictable:":
			.Unevictable = 
		case "Mlocked:":
			.Mlocked = 
		case "SwapTotal:":
			.SwapTotal = 
		case "SwapFree:":
			.SwapFree = 
		case "Dirty:":
			.Dirty = 
		case "Writeback:":
			.Writeback = 
		case "AnonPages:":
			.AnonPages = 
		case "Mapped:":
			.Mapped = 
		case "Shmem:":
			.Shmem = 
		case "Slab:":
			.Slab = 
		case "SReclaimable:":
			.SReclaimable = 
		case "SUnreclaim:":
			.SUnreclaim = 
		case "KernelStack:":
			.KernelStack = 
		case "PageTables:":
			.PageTables = 
		case "NFS_Unstable:":
			.NFSUnstable = 
		case "Bounce:":
			.Bounce = 
		case "WritebackTmp:":
			.WritebackTmp = 
		case "CommitLimit:":
			.CommitLimit = 
		case "Committed_AS:":
			.CommittedAS = 
		case "VmallocTotal:":
			.VmallocTotal = 
		case "VmallocUsed:":
			.VmallocUsed = 
		case "VmallocChunk:":
			.VmallocChunk = 
		case "HardwareCorrupted:":
			.HardwareCorrupted = 
		case "AnonHugePages:":
			.AnonHugePages = 
		case "ShmemHugePages:":
			.ShmemHugePages = 
		case "ShmemPmdMapped:":
			.ShmemPmdMapped = 
		case "CmaTotal:":
			.CmaTotal = 
		case "CmaFree:":
			.CmaFree = 
		case "HugePages_Total:":
			.HugePagesTotal = 
		case "HugePages_Free:":
			.HugePagesFree = 
		case "HugePages_Rsvd:":
			.HugePagesRsvd = 
		case "HugePages_Surp:":
			.HugePagesSurp = 
		case "Hugepagesize:":
			.Hugepagesize = 
		case "DirectMap4k:":
			.DirectMap4k = 
		case "DirectMap2M:":
			.DirectMap2M = 
		case "DirectMap1G:":
			.DirectMap1G = 
		}
	}

	return &, nil