Skip to content

update mem info on every refresh on Solaris platform#1918

Merged
BenBE merged 1 commit intohtop-dev:mainfrom
ViryBe:main
Mar 6, 2026
Merged

update mem info on every refresh on Solaris platform#1918
BenBE merged 1 commit intohtop-dev:mainfrom
ViryBe:main

Conversation

@ViryBe
Copy link

@ViryBe ViryBe commented Mar 4, 2026

The bug

htop crashes on illumos when the cpu count changes.

Tested with latest main branch on an illumos system. I unfortunately don't have a Solaris machine to test on it, but according to the man pages the bug should be the same.

How to reproduce:

  1. Open htop in a terminal
  2. Disable CPU0:
# as root
psradm -f 0
# to re-enable CPU0
psradm -Fn 0

htop crashed in first terminal.

Issue and Fix

The memory info was previously read only once and kept in a static variable. However, the pointer to the memory info is invalidated when the kstat chain is updated, such as when the cpu count changes.

From the Illumos kstat_chain_update man page:

[...] any kstat_t structures retrieved by the
kstat_lookup(3KSTAT) function or data pointers obtained through the
kstat_data_lookup(3KSTAT) function are invalidated by a call to
kstat_chain_update(). [...]

So, re-reading the struct kstat_t on every memory scan ensure that the pointer meminfo is always valid.

Note that I also replace the 2 calls to kstat_open and kstat_close by a single kstat_chain_update.

@natoscott
Copy link
Member

@ViryBe thanks for looking into it.

I unfortunately don't have a Solaris machine to test on it

It'd be really good to test this no a Solaris machine before proceeding further - is there anyone out there who can help?

@ViryBe
Copy link
Author

ViryBe commented Mar 4, 2026

yeah, I'll try to install solaris in a VM to test the patch if I have some time in the following days

@BenBE BenBE added bug 🐛 Something isn't working Solaris Solaris, Illumos, OmniOS, OpenIndiana labels Mar 4, 2026
Copy link
Member

@BenBE BenBE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor stylistic note, apart from that the change looks reasonable. Testing on Solaris might be nice.

Use `kstat_chain_update` instead of 2 calls to `kstat_open` and `kstat_close`.

Furthemore, the memory info was previously read only once and kept in a static
variable. However, the pointer to the memory info is invalidated when the kstat
chain is updated, such as when the cpu count changes.

From the Illumos `kstat_chain_update` man page:

```
[...] any kstat_t structures retrieved by the
kstat_lookup(3KSTAT) function or data pointers obtained through the
kstat_data_lookup(3KSTAT) function are invalidated by a call to
kstat_chain_update(). [...]
```
@BenBE BenBE added this to the 3.5.0 milestone Mar 5, 2026
@ViryBe
Copy link
Author

ViryBe commented Mar 6, 2026

Thanks for the feedback @BenBE.

I tested in a Solaris 11.4 VM and I can confirm that the bug is also present and the fix works as intended.

@BenBE BenBE merged commit 3066c68 into htop-dev:main Mar 6, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐛 Something isn't working Solaris Solaris, Illumos, OmniOS, OpenIndiana

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants