fix: use .PhysicalAvailableMemory instead of PhysicalFreeMemory

when showing memory usage, what you want to know is the used memory,
which doesn't include cached memory; cache memory can be claimed by
the kernel under memory pressure.

the Linux kernel will try to use as much cache as possible by default,
but that doesn't mean that the RAM is not available.

This PR fixes that and shows only the real used memory.
This commit is contained in:
Eduard Tolosa 2025-03-03 03:33:09 +00:00 committed by Jan De Dobbeleer
parent 5f4681e4ed
commit d6c1ff9518
7 changed files with 7 additions and 7 deletions

View file

@ -69,7 +69,7 @@
{
"foreground": "#94ffa2",
"style": "diamond",
"template": " <#ffffff>MEM:</> {{ round .PhysicalPercentUsed .Precision }}% ({{ (div ((sub .PhysicalTotalMemory .PhysicalFreeMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB)",
"template": " <#ffffff>MEM:</> {{ round .PhysicalPercentUsed .Precision }}% ({{ (div ((sub .PhysicalTotalMemory .PhysicalAvailableMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB)",
"type": "sysinfo"
}
],

View file

@ -46,7 +46,7 @@
{
"foreground": "#85C980",
"style": "diamond",
"template": "RAM:{{ (div ((sub .PhysicalTotalMemory .PhysicalFreeMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB ",
"template": "RAM:{{ (div ((sub .PhysicalTotalMemory .PhysicalAvailableMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB ",
"trailing_diamond": " ",
"type": "sysinfo"
},

View file

@ -79,7 +79,7 @@
{
"foreground": "#81ff91",
"style": "diamond",
"template": "<#cc7eda> \u007C </><#7eb8da>RAM:</> {{ (div ((sub .PhysicalTotalMemory .PhysicalFreeMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB",
"template": "<#cc7eda> \u007C </><#7eb8da>RAM:</> {{ (div ((sub .PhysicalTotalMemory .PhysicalAvailableMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB",
"type": "sysinfo"
},
{

View file

@ -44,7 +44,7 @@
"background": "#00c7fc",
"foreground": "#000000",
"style": "diamond",
"template": "RAM: {{ (div ((sub .PhysicalTotalMemory .PhysicalFreeMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB \ue266 ",
"template": "RAM: {{ (div ((sub .PhysicalTotalMemory .PhysicalAvailableMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB \ue266 ",
"trailing_diamond": "<transparent,#00c7fc>\ue0b2</>",
"type": "sysinfo"
},

View file

@ -12,7 +12,7 @@
{
"foreground": "#ff8800",
"style": "diamond",
"template": "{{ (div ((sub .PhysicalTotalMemory .PhysicalFreeMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB ",
"template": "{{ (div ((sub .PhysicalTotalMemory .PhysicalAvailableMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB ",
"type": "sysinfo"
}
],

View file

@ -31,7 +31,7 @@
{
"foreground": "#be9ddf",
"style": "diamond",
"template": "[<#ffffff>\ue266</> RAM: {{ (div ((sub .PhysicalTotalMemory .PhysicalFreeMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB]",
"template": "[<#ffffff>\ue266</> RAM: {{ (div ((sub .PhysicalTotalMemory .PhysicalAvailableMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB]",
"type": "sysinfo"
},
{

View file

@ -42,7 +42,7 @@
"background": "#516BEB",
"foreground": "#ffffff",
"style": "diamond",
"template": "RAM: {{ (div ((sub .PhysicalTotalMemory .PhysicalFreeMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB \ue266 ",
"template": "RAM: {{ (div ((sub .PhysicalTotalMemory .PhysicalAvailableMemory)|float64) 1073741824.0) }}/{{ (div .PhysicalTotalMemory 1073741824.0) }}GB \ue266 ",
"trailing_diamond": "<transparent,#516BEB>\ue0b2</>",
"type": "sysinfo"
},