htop-dev / htop

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

htop 3.2.2 wrong cpu count in LXC container with cgroup limits #1332

Closed Napsty closed 9 months ago

Napsty commented 10 months ago

First of all thanks for htop. Been using it for years and it's an enormous helper!

Today I've used htop the first time in a Debian 12 (Bookworm) running as a LXC container. I was surprised to see the full amount of physical cores in the htop output:

image

At first I suspected a problem in LXC, that the cgroup limits don't work anymore in a Bookworm container (see https://discuss.linuxcontainers.org/t/cgroup2-cpu-limit-no-longer-working-after-lxc-container-upgraded-to-debian-12) but then realized that it might be a htop problem.

After manually compiling htop 3.2.1, I can actually confirm this. Here's the htop 3.2.1 output on the very same LXC container:

image

Here we get to see two CPUs in the output, which represents the cgroup limit defined on the host.

(Available memory is correctly shown in both htop versions by the way).

I noticed the following line in the changelog:

https://github.com/htop-dev/htop/blob/main/ChangeLog#L22C3-L22C64

On Linux, improvements to cgroup and container identification

Maybe that's where this comes from?

BenBE commented 10 months ago

I think there was a change regarding CPU handling between 3.2.1 and 3.2.2 that @fasterit can shed some more light onto.

May be something related to: #993, #995, #1004, #1197, …

Napsty commented 10 months ago

Maybe duplicate of or at least related to https://github.com/htop-dev/htop/issues/1020

Napsty commented 9 months ago

Actually I'm mistaken! htop 3.2.2 compiled from source looks similar to the output of 3.2.1. This is with htop 3.2.2 compiled from the release htop-3.2.2.tar.xz:

root@bookworm:~/htop-3.2.2# ./htop --version
htop 3.2.2

image

The problem with the wrong cpu count seems to come from the htop package in the Debian repositories. There was a manual patch added in the package:

image

The patch in question:

image

That patch is the same as the PR #1197. Manually applying PR 1197 on htop 3.2.2 source code leads to the same wrong cpu count. If I see this correctly, htop 3.3.0 (milestone) would contain this problem again.