htop-dev / htop

htop - an interactive process viewer
https://htop.dev/
GNU General Public License v2.0
6.32k stars 427 forks source link

Wrong memory usage on BSD and derivatives. #955

Open dmilith opened 2 years ago

dmilith commented 2 years ago

So here's an example: https://s.verknowsys.com/1cfc4d97db733029aa928d94c78d0207.png

influxd is using over 48G of RSS, but total memory usage of the system in htop is 28G.

dmilith commented 2 years ago

Shouldn't htop count Total Memory as Active + Inactive + Laundry + Wired?

BenBE commented 2 years ago

What does vmstat report?

Which *BSD port exactly do you use? Or have you confirmed this issue with multiple platforms? If so, which?

dmilith commented 2 years ago

All BSDs (and MacOS too) will have a very similar (or the same) memory model, but I use FreeBSD 13.0 arm64/amd64 and MacOS 12.3 arm64.

The vmstat on that FreeBSD 13.0 host shows:

 procs    memory    page                      disks     faults       cpu
 r  b  w  avm  fre  flt  re  pi  po   fr   sr nv0 nv1   in   sy   cs us sy id
 1  0  1  27G 4.0G 2.2K 171  78   1 4.4K  14K   0 3212 5593  33K  30K 23 10 67

The top utility shows this:

Mem: 18G Active, 28G Inact, 2028K Laundry, 11G Wired, 4102M Free

(where htop shows "23.8G/63.7G" in Mem line)

grahamperrin commented 2 years ago

The Reddit post mentioned at https://github.com/htop-dev/htop/issues/1039#issuecomment-1157206516 includes this comment:

… think that it subtracts the arc cache from the actual memory usage when it updates, then it's wraps around backward all the way to the top. …

If the 16.0Z symptom in #1039 is not observable in this issue #955, it may be because I'm using L2ARC.

grahamperrin commented 2 years ago

If we're to compare with top(1) https://www.freebsd.org/cgi/man.cgi?query=top&sektion=1&manpath=FreeBSD, then a most significant difference might be the perception of what's free.

image

hstk30 commented 2 years ago

In my MacOS Monterey 12.4 with apple M1 pro, compare top and htop also have this problem.

image
haarp commented 1 year ago

On FreeBSD (OPNsense) I'm also seeing wrong memory counting.

Repro:

Thanks!