From 0c2313dcdde8ec1aba2c8dadc5273aa2fcbe7381 Mon Sep 17 00:00:00 2001 From: Andreas Geisenhainer Date: Wed, 14 Mar 2018 19:15:09 +0100 Subject: [PATCH] mem: adds information about used memory without freeable parts * used memory (values 1 and 2) are: everything but free+cache * laundry is counted as freeable, but not free. ** "notfreeable memory" (values 11 and 12) are: active+inactive+wired --- README.md | 10 ++++++---- widgets/mem_freebsd.lua | 17 ++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e0d4e56..d47dab2 100644 --- a/README.md +++ b/README.md @@ -323,8 +323,10 @@ Supported platforms: Linux, FreeBSD. total system memory, 4th as free memory, 5th as swap usage in percent, 6th as swap usage, 7th as total system swap, 8th as free swap and 9th as memory usage with buffers and cache - * FreeBSD: see above, but there are two more values: the 9th value is wired memory - in percent and the 10th value giving wired memory + * FreeBSD: see above, but there are four more values: the 9th value is wired memory + in percent, the 10th value is wired memory. The 11th and 12th value return + 'not freeable memory' (basically active+inactive+wired) in percent and megabytes, + respectively. **vicious.widgets.mpd** @@ -804,8 +806,8 @@ Format functions can be used as well: naughty.notify({ title = "Battery indicator", text = vicious.call(vicious.widgets.bat, function(widget, args) return string.format("%s: %10sh\n%s: %14d%%\n%s: %12dW", - "Remaining time", args[3], - "Wear level", args[4], + "Remaining time", args[3], + "Wear level", args[4], "Present rate", args[5]) end, "0") }) end) diff --git a/widgets/mem_freebsd.lua b/widgets/mem_freebsd.lua index 81ea146..b3c1fae 100644 --- a/widgets/mem_freebsd.lua +++ b/widgets/mem_freebsd.lua @@ -31,12 +31,15 @@ local function worker(format) _mem.buf.wired = math.floor(_mem.buf.wired/1048576) -- Calculate memory percentage - _mem.free = _mem.buf.free + _mem.buf.cache + _mem.buf.laundry + _mem.free = _mem.buf.free + _mem.buf.cache -- used memory basically consists of active+inactive+wired _mem.inuse = _mem.total - _mem.free + _mem.notfreeable = _mem.inuse - _mem.buf.laundry _mem.wire = _mem.buf.wired + _mem.usep = math.floor(_mem.inuse / _mem.total * 100) _mem.wirep = math.floor(_mem.wire / _mem.total * 100) + _mem.notfreeablep = math.floor(_mem.notfreeable / _mem.total * 100) -- Get swap states local vm_swap_total = tonumber(helpers.sysctl("vm.swap_total")) @@ -46,23 +49,23 @@ local function worker(format) if vm_swap_enabled == 1 and vm_swap_total > 0 then -- Get swap space in bytes _swp.total = vm_swap_total - _swp.buf.f = _swp.total - tonumber(vm_stats.v_swapin) + _swp.buf.free = _swp.total - tonumber(vm_stats.v_swapin) -- Rework into megabytes _swp.total = math.floor(_swp.total/1048576) - _swp.buf.f = math.floor(_swp.buf.f/1048576) + _swp.buf.free = math.floor(_swp.buf.free/1048576) -- Calculate percentage - _swp.inuse = _swp.total - _swp.buf.f + _swp.inuse = _swp.total - _swp.buf.free _swp.usep = math.floor(_swp.inuse / _swp.total * 100) else _swp.usep = -1 _swp.inuse = -1 _swp.total = -1 - _swp.buf.f = -1 + _swp.buf.free = -1 end return { _mem.usep, _mem.inuse, _mem.total, _mem.free, - _swp.usep, _swp.inuse, _swp.total, _swp.buf.f, - _mem.wirep, _mem.wire } + _swp.usep, _swp.inuse, _swp.total, _swp.buf.free, + _mem.wirep, _mem.wire, _mem.notfreeablep, _mem.notfreeable } end return setmetatable(mem_freebsd, { __call = function(_, ...) return worker(...) end })