From c45dedb0e83f20d2ea989ddefffbe542fdacfd5b Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Tue, 1 May 2018 10:01:36 +0200 Subject: [PATCH] [modules/memory] Use MemAvailable, if present If the kernel supports it, MemAvailable contains an estimation of the memory available for usage. Use this to calculate the amount of free memory (as this seems to closely match the output of gnome-system-monitor). fixes #253 --- bumblebee/modules/memory.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bumblebee/modules/memory.py b/bumblebee/modules/memory.py index 9df990f..1ff2f25 100644 --- a/bumblebee/modules/memory.py +++ b/bumblebee/modules/memory.py @@ -50,7 +50,10 @@ class Module(bumblebee.engine.Module): if tmp[2] == "mB": value = value*1024*1024 if tmp[2] == "gB": value = value*1024*1024*1024 data[tmp[0]] = value - used = data["MemTotal"] - data["MemFree"] - data["Buffers"] - data["Cached"] - data["Slab"] + if "MemAvailable" in data: + used = data["MemTotal"] - data["MemAvailable"] + else: + used = data["MemTotal"] - data["MemFree"] - data["Buffers"] - data["Cached"] - data["Slab"] self._mem = { "total": bumblebee.util.bytefmt(data["MemTotal"]), "available": bumblebee.util.bytefmt(data["MemAvailable"]),