-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mem widget reports wrong(?) amount of memory used and it's frozen #271
Comments
~150 higher to be precise |
First, your widget is wrong: it sets statically the my_mem = wibox.container.margin(
wibox.widget{
align = "center",
valign = "center",
widget = lain.widgets.mem{
settings = function()
widget:set_text(mem_now.used)
end
},
-- margins
--left = 1,
--right = 1,
--top = 1,
--bottom = 1
}) Second, don't rely on --- a/mem.lua
+++ b/mem.lua
@@ -29,17 +29,18 @@
mem_now = {}
for line in io.lines("/proc/meminfo") do
for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+") do
if k == "MemTotal" then mem_now.total = math.floor(v / 1024)
elseif k == "MemFree" then mem_now.free = math.floor(v / 1024)
elseif k == "Buffers" then mem_now.buf = math.floor(v / 1024)
elseif k == "Cached" then mem_now.cache = math.floor(v / 1024)
elseif k == "SwapTotal" then mem_now.swap = math.floor(v / 1024)
elseif k == "SwapFree" then mem_now.swapf = math.floor(v / 1024)
+ elseif k == "PageTables" then mem_now.paget = math.floor(v / 1024)
end
end
end
- mem_now.used = mem_now.total - (mem_now.free + mem_now.buf + mem_now.cache)
+ mem_now.used = mem_now.total - mem_now.free - mem_now.buf - mem_now.cache - mem_now.paget
mem_now.swapused = mem_now.swap - mem_now.swapf
mem_now.perc = math.floor(mem_now.used / mem_now.total * 100) |
Hey! Thanks for the code! It was a stupid mistake. |
Cached+Buffer from /proc/meminfo != buff/cached from top for some reason |
I used SReclaimable instead of PageTables. Also top uses roundup instead of rounddown (as it implemented in mem.lua)
Considering these changes in mem.lua the widget shows the same numbers with top and they are in MiB. htop uses MB so they differs. |
We're now aligned to |
Right shift by 10 can be understood as integer division by 2^10. So the above does: Oh and: If the goal is to match top's behaviour, then 23318f8 is still wrong, since it rounds up instead of to-nearest. /me was just randomly browsing around and leaves again... |
Or even one more alternative: |
Cached includes tmpfs & shmem. ref: 1. neofetch get_memory() 2. kernel Documentation/filesystems/proc.rst 3. lcpz/lain#271
As Cached includes tmpfs & shmem, see proc.rst, so after
After adding |
Hi guys!
I've found that lain.widgets.mem shows wrong (differs with htop and free -h) number of memory used and it is not being refreshed. I use this code to configure the widget.
And it gets ~200Mb higher I see in htop or free.
The text was updated successfully, but these errors were encountered: