From 0db5f3f2221ecff3a425fe33990eac0abf180f79 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Thu, 27 Sep 2018 18:44:31 -0700 Subject: [PATCH] Use MemAvailable for mem.free The current method of calculating the amount of free memory is incorrect. The linux kernel provides a method of getting this value, MemAvailable, which we can simply use directly --- widgets/mem_linux.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/widgets/mem_linux.lua b/widgets/mem_linux.lua index 4ff35d8..f167381 100644 --- a/widgets/mem_linux.lua +++ b/widgets/mem_linux.lua @@ -26,6 +26,7 @@ local function worker(format) for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+") do if k == "MemTotal" then _mem.total = math.floor(v/1024) elseif k == "MemFree" then _mem.buf.f = math.floor(v/1024) + elseif k == "MemAvailable" then _mem.buf.a = math.floor(v/1024) elseif k == "Buffers" then _mem.buf.b = math.floor(v/1024) elseif k == "Cached" then _mem.buf.c = math.floor(v/1024) elseif k == "SwapTotal" then _mem.swp.t = math.floor(v/1024) @@ -35,7 +36,7 @@ local function worker(format) end -- Calculate memory percentage - _mem.free = _mem.buf.f + _mem.buf.b + _mem.buf.c + _mem.free = _mem.buf.a _mem.inuse = _mem.total - _mem.free _mem.bcuse = _mem.total - _mem.buf.f _mem.usep = math.floor(_mem.inuse / _mem.total * 100)