Fix: exclude kernel threads from process enumeration to prevent RSS double-counting#3
Open
RobertoMaurizzi wants to merge 4 commits into
Open
Conversation
RobertoMaurizzi
force-pushed
the
fix_threads_counting_overflow
branch
from
July 25, 2026 06:25
7c6fe1c to
cadbeba
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Recent versions of sysinfo (0.30+) enumerates /proc/[pid]/task/[tid] entries as separate processes. On Linux each thread's /proc/[tid]/statm returns the full parent-process RSS (all threads share mm_struct), so a 30-thread browser inflates the per-process RSS sum 30×. This makes the treemap grouping denominator (total_value) far larger than actual physical memory, causing every entry to fall below group_threshold (default 1%) and collapse into a single "Other" tile.
The fix uses ProcessRefreshKind::without_tasks() on both the initial and refresh-specifics calls, which tells sysinfo to skip scanning /proc/[pid]/task/ entirely. This is both cleaner and more efficient than post-filtering — no thread entries are created, no wasted I/O reading their stat files.
Before the change
After the change
Validation
cargo fmt -- --checkcargo clippy --all-targets --all-features -- -D warningscargo testNotes
I'm not sure if there are cases where somebody might want to run actually counting threads: my main doubt that makes me think this is the right fix is that since each thread returns the whole RSS then there's no point trying to display them in a treemap showing memory usage distribution.
If you see a use for that, I might instead collect the threads but add a toggle about how they are managed.
I'm unable to test this on Windows or MacOS.