Skip to content

Fix: exclude kernel threads from process enumeration to prevent RSS double-counting#3

Open
RobertoMaurizzi wants to merge 4 commits into
Vivallo04:mainfrom
RobertoMaurizzi:fix_threads_counting_overflow
Open

Fix: exclude kernel threads from process enumeration to prevent RSS double-counting#3
RobertoMaurizzi wants to merge 4 commits into
Vivallo04:mainfrom
RobertoMaurizzi:fix_threads_counting_overflow

Conversation

@RobertoMaurizzi

Copy link
Copy Markdown

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

image

After the change

image

Validation

  • cargo fmt -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test

Notes

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.

@RobertoMaurizzi
RobertoMaurizzi force-pushed the fix_threads_counting_overflow branch from 7c6fe1c to cadbeba Compare July 25, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant