htop icon indicating copy to clipboard operation
htop copied to clipboard

Add PSS (proportional set size), Swap and SwapPSS calculation on Linux

Open ntninja opened this issue 5 years ago • 7 comments

I did not write this code and took a patch for this from https://github.com/linvinus/htop-mod. Please tell me about any improvements required.

While I can attest PSS to be a big improvement over RSS, there are some pain points about this:

  • /proc/<pid>/smaps is only readable by the (effective?) user of the given process. ~Since PSS calculation requires all memory mapping tables to be available for accurate calculation, this makes the PSS value somewhat useless htop runs as root.~ Actually this is not true making PSS data somewhat usable, but incomplete for users other than the current user, unless you're root. :slightly_frowning_face:
  • Greatly improved on Linux 4.14+ thanks to @himikof's suggestion! (Crunching the smaps data noticeably slows down htop – far from unusable, but slower.)

Original code was written by Craig M. Brandenburg for htop 1.0.2 Many performance improvements by GitHub user linvinus, ported to htop 2.0.2

ntninja avatar Oct 09 '18 20:10 ntninja

Maybe the code could be extended to try smaps_rollup if available (in kernel since 4.14)? The format is exactly the same, just less data to parse.

himikof avatar Oct 16 '18 16:10 himikof

@himikof: Thanks for the suggestion! I've implemented your suggestion and it does give quite a performance boost. Still not as quite snappy as when not reading any smaps file, but it stops the UI from feeling somewhat sluggish while PSS reporting is enabled.

ntninja avatar Oct 16 '18 18:10 ntninja

Thanks for the patch! I still need to take some time to give it a spin, but on first glance my initial comment is that we'll probably not want to enable PSS by default, given the performance concerns.

hishamhm avatar Oct 30 '18 20:10 hishamhm

I agree one that sentiment unfortunately. The original patch had it in by default, but given the speed on pre-4.14 kernels and the root requirement (that RSS and friends doesn't have) for complete reporting it is really a sane default currently. Let me know of any other things you notice and I'll apply the requested updates once there is more to do.

ntninja avatar Oct 30 '18 20:10 ntninja

@hishamhm: I have already explained why this is not a problem in the comment above. Mind considering a merge again?

ntninja avatar Dec 13 '18 21:12 ntninja

@hishamhm: Ping

ntninja avatar Mar 20 '19 16:03 ntninja

Merged here: htop-dev/htop@f9625ca

natoscott avatar Aug 19 '20 08:08 natoscott