Description
The current Linux memory states provided by the hostmetricsreceiver
might be not the most appropriate ones for an end user. The available memory states for Linux are:
[buffered, cached, free, slab_reclaimable, slab_unreclaimable, used]
All of those values are retrieved with gopsutil, which gets them from /proc/meminfo
file.
A user might think that the free
value represents the amount of memory that the system can use, but free (MemFree) is a count of how many pages are free in the buddy allocator, however there are a lot of ways pages can be returned to the buddy allocator in time of need. The latest is provided by the Linux kernel (>3.16) as MemAvailable
in /proc/meminfo
.
Can we get MemAvailable field from current states?
No, it is an independent field not computed with the current values. Gopsutils provides this value regardless the kernel version as it can be estimated from MemFree, Active(file), Inactive(file), and SReclaimable, as well as the "low" watermarks from /proc/zoneinfo.
Repercussion
The user will be able to know the actual available memory of the system.
- Will it break the assumption that the sum of all metrics states should be equal to the limit (total memory)? https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/README.md#instrument-naming
It is already broken and quite difficult to achieve it as some of the memory state values are inclusive, for example the cached state. The assumption would be defined as:
total = buffered + cached + free + used + slab_reclaimable + slab_unreclaimable
But the used
value is computed by gopsutils as: total - free - buffered - cached
Then:
total = buffered + cached + free + (total - free - buffered - cached) + slab_reclaimable + slab_unreclaimable
total = total + slab_reclaimable + slab_unreclaimable
The sum(state) will always be higher than the total.
(The following proposals do not solve the sum assumption, they only add more memory information for the user)
Proposal 1
Add a new memory state for Linux to provide the available memory. State name: avaialble
Proposal 2
Change used
state for: total - available
This proposal requires to add the memory.limit metric as we won't be able to compute the total memory from the states. Currently, we can get the total amount of memory with the following promQL query: scalar(sum without (state) (system_memory_usage{state =~ "free|used|cached|buffered"}))
Metadata
Metadata
Assignees
Labels
Type
Projects
Status