[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
This commit is contained in:
Tobias Witek 2018-05-01 10:01:36 +02:00
parent 7af362f5c3
commit 6cbf866b63

View file

@ -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"]),