mirror of
https://git.proxmox.com/git/proxmox
synced 2025-07-22 19:02:11 +00:00
![]() The old code was wrong and overestimated the memory used because it did not take into account things like "SReclaimable", a part of slab (in-kernel memory allocator) describing things like caches that can be reclaimed, plus the memory for "Active(file)" and "Inactive(file)", and other internal kernel things that even though small for each one, can add up quickly. Most of these metrics are exposed and could be included in the calculation, but this will simply become obsolete in the future as the kernel changes how it does things and how it calculates such available memory, as it has done many times in the past. To solve this problem for the long term, the MemAvailable field was added to /proc/meminfo as of kernel 3.14. It describes "the amount of memory available for a new workload without pushing the system into swap". While it is only an estimate, it is as good as it gets, and since it comes from the kernel, we can always assume that it is correct for the currently booted kernel. So, switch over to this metric for calculating the used memory by subtracting MemAvailable from MemTotal. Also adds a simple test case for the parser. This commit is based on a patch from Dietmar [1]. [0]: https://git.kernel.org/torvalds/c/34e431b0ae398fc54ea69ff85ec700722c9da773 [1]: https://lore.proxmox.com/all/20250313114535.99912-2-dietmar@proxmox.com/ Originally-by: Dietmar Maurer <dietmar@proxmox.com> [TL: rewrite comments and commit message from scratch] Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> |
||
---|---|---|
.. | ||
debian | ||
src | ||
tests | ||
Cargo.toml |