htop icon indicating copy to clipboard operation
htop copied to clipboard

memory[bar] should display used+shared as the used memory

Open dragomang87 opened this issue 3 years ago • 2 comments

Shared memory accounts for memory in tmpfs among other things. If tmpfs is mounted in /tmp then adding a 1GB file will occupy 1GB of ram that is neither buffer or cache and cannot be freed by kernel on demand. However, htop's memory[bar] will only display the shared memory as purple bars but only write used/total in numbers at the end of the bar.

In case of a system running out of memory, the bar will look full but the number indicating the memory usage might be very low. memory[text] does not have this problem because it will display available memory, which will immediately show that the system is low on memory.

I think memory[bar] should display used+shared/total at the end of the bar to truly reflect the system state. An alternative would be to add an option to display available/total or to display used/used+shared/total.

(running htop 3.1.2 on Arch Linux)

Edit: corrected some confusion where I wrote free instead of `used' as pointed out by @kjbracey

dragomang87 avatar Dec 28 '21 20:12 dragomang87

Issue is misdescribed - it should be requesting used+shared/total rather than used/total.

htop 2.2.0 as packaged in my Ubuntu is working well, at least w.r.t tmpfs - it has used, buffers and cached, and Shmem has been subtracted from Cached, so tmpfs appears in used.

But since shared memory has been separated, the basic used is now less meaningful in isolation. I agree that the end-of-bar readout should be showing used+shared, and would also suggest that shared should be shown between used and buffers in the bar order.

kjbracey2 avatar Jan 09 '22 09:01 kjbracey2

Here's the history of the readout, as I figured it out:

  • Prior to 3.1.0, the shared memory was included in used, and the bar text showed used/total, so shared was counted.
  • In 3.1.0, the shared memory was separated (#558), and the bar showed (total-available)/total (#452). Shared memory was effectively counted via being not available - but the text was using a different information source to the bars.
  • In 3.1.1, the bar text went back to being used/total(#838), but that used now excluded shared memory. So this occurred for the first time in 3.1.1.

kjbracey2 avatar Jan 10 '22 15:01 kjbracey2

@kjbracey2 Maybe there is something wrong in my htop 3.2.1. Here is what I saw. The purple bar is obviously not included in used/total. img_v2_39f67730-d29a-420a-a03d-1acc9951c08g

cupen avatar Jul 15 '23 07:07 cupen

Yes, that's the issue being discussed. Since 3.1.1 the purple bar (shared) has not been included in the "used", despite it definitely being in use and not being reclaimable.

Note that the blue and orange (buffers + cache) are not counted either, but that makes sense as they are reclaimable, and will just occupy any unclaimed memory until someone claims it.

PR #913 would address this, and reorder the bars to put the green+purple (claimed) memory together, and show "claimed/total".

kjbracey2 avatar Jul 15 '23 11:07 kjbracey2

That PR has not been merged yet, because there was a related change scheduled that touched quite a bit of the same code. Also some details on the UI/UX will likely still need to be worked out.

BenBE avatar Jul 15 '23 11:07 BenBE