Bug 437469 - System Monitor disagrees with ksysguard and `free` regarding how much memory is used
Summary: System Monitor disagrees with ksysguard and `free` regarding how much memory ...
Status: RESOLVED INTENTIONAL
Alias: None
Product: plasma-systemmonitor
Classification: Applications
Component: general (show other bugs)
Version: 5.21.90
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KSysGuard Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-21 16:11 UTC by Nate Graham
Modified: 2021-05-21 17:23 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
They disagree on memory usage (768.74 KB, image/png)
2021-05-21 16:11 UTC, Nate Graham
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nate Graham 2021-05-21 16:11:38 UTC
Created attachment 138654 [details]
They disagree on memory usage

See attached screenshot. System Monitor says 7.8 GiB are used; KsysGuard says 5 GiB are used.

`free` seems to have numbers closer to ksysguard, not System Monitor. Is System Monitor adding used and shared together?

$ free
               total        used        free      shared  buff/cache   available
Mem:        16000340     5575520     1756448     2539232     8668372     7548948
Swap:       16777212       15616    16761596
Comment 1 Arjen Hiemstra 2021-05-21 16:41:37 UTC
plasma-systemmonitor (or actually, ksystemstats) uses `total - available` for the used amount, which should be the "correct" number, as available represents the amount of memory that is available to applications. From your example, 16000340 - 7548948 = 8451392 which, converted to GiB is 8.05987548828125 which is ... more than 7.8 GiB but a lot closer to that number.
Comment 2 Nate Graham 2021-05-21 16:44:46 UTC
Why does total minus available not equal free though? That doesn't make a lot of sense to me.
Comment 3 Arjen Hiemstra 2021-05-21 16:49:16 UTC
Note that this matches the behaviour of, among others, Gnome system monitor. In fact, we changed this behaviour to match that originally.

> Why does total minus available not equal free though? That doesn't make a lot of sense to me.

Which free? The one from "free" or the "free physical memory" from ksystemstats?
Comment 4 Nate Graham 2021-05-21 16:59:27 UTC
I mean used, not free. Sorry. Because 16000340 - 7548948 = 8451392, so if that's how much memory is used, then what does the "used" column in `free` (the CLI program) mean? I don't get how that number is 5575520, not 8451392.
Comment 5 Arjen Hiemstra 2021-05-21 17:14:53 UTC
From the "free" manpage:

> used   Used memory (calculated as total - free - buffers - cache)

vs:

> available     Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)

Or in other words, free does the same thing ksysguard did, which is actually an incorrect representation of the amount of memory used because as the free manual states, there are several things to consider when looking at the actual available memory.
Comment 6 Nate Graham 2021-05-21 17:23:37 UTC
Got it. Very interesting.