Htop (btop) show 12 cpu > 60% but total mem usage at 30%

Probably a simple answer but I have calculations running where both htop and btop show all 12 cpus to be running above 60% simultaneously but the memory usage (total) that is being shown by both htop and btop is approximately 30% (10.5 gig out of 32 gig). The major calculation processes are being run in a vm if that is pertinent. Htop and btop data is from the host.

I am wondering why memory usage (total) does not show greater than than 60% also.

thanks for any insights, tom kosvic

A Linux system’s memory usage should not be directly comparable to CPU usage. They are important performance metrics, but they measure different aspects of your system - a high CPU usage does not necessarily mean you’d see a similar high memory usage, and vice versa.

For about 60 years, I always have assumed (apparently wrongly) that these were measures of the same thing. I do now see internet references that they are different. The articles are really superficial and merely reiterate that there is a difference with no real information.

I am curious now as to how memory usage is computed. Any references (beyond htop source code) would be appreciated.

thanks, tom kosvic

Computers and software are interesting creatures, and we all continue to learn something new about each. Me, being a software engineer with 35+ years experience, published author of 4 tech books (including a Linux book about 25 years ago), and retired 4 years ago … even with my experience, I continue to learn new things.

On a Linux system, experiencing high CPU usage while showing low memory usage can occur when a process is performing computationally intensive tasks, like complex calculations or heavy data processing, without needing to allocate large amounts of RAM, effectively bottlenecking the CPU while leaving most of the memory available.

There are CPU-intense apps known to perform heavy calculations like video encoding, scientific simulations, or large data analysis, but memory requirements are low.

At times, a kernel thread may run intensive operations that can lead to high CPU without significant memory usage.

An app might be using an inefficient algorithm which requires excessive CPU cycles to process data … even if the data itself is small.

A process executing frequent disk reads and writes can still heavily utilize the CPU, especially if the disk is slow.

Intensive network traffic can also lead to high CPU usage without significant memory consumption.

And let’s not forget … the opposite can happen … an app can be using huge amounts of memory without doing much CPU work.

Memory usage? Execute this:

:~> cat /proc/meminfo
1 Like

I am doing computational fluid dynamic calculations that are numerically intensive w/o much I/O. By your explanation that would account for what I see in htop.

Back in history, I started computing in about 1958 using basic and then FORTRAN. At that time careful control of numerically intense programs needed to be maintained to avoid memory caused crashes. Coding was needed to move processes into and out of memory to not exceed available memory. FORTRAN equivalence statements were very key. Fortunately all that is history.

I am still curious as to how memory-in-use is computed, i.e., what are the calculations done by meminfo.

I can think of 4 simple examples to illustrate the extremes.

  1. Examining a photo
    Say a 4000x6000 pixel at 64 bit per pixel means 192MB to store the original data, possibly another 192MB reserved for editing, some space for the editor code and the display driver etc. can easily add up to 1GB of memory in use; but as long as you just look at the image CPU load is near zero (High Memory, Low CPU usage).
  2. Editing that photo
    Now you want to darken your photo, add some blur effect and add some reddish tone.
    Memory usage may not change much, but CPU might shoot up to 100% for a few seconds until every pixel is changed to its new value (High Memory, High transient CPU usage).
  3. Transcoding and streaming a video
    Memory usage may be just enough to temporarily buffer a few seconds of the video stream, while CPU usage may be quite noticeable depending on the coding algorithm and the I/O bit rate of the stream (Low Memory, High CPU usage).
  4. Editing that full video
    A professional video editor might try to keep in memory the full video or a substantial part of it and reserve as much memory to store the edited version, possibly filling all the RAM available on the system. And while actually performing the editing CPU might keep near 100% for dozens of minutes (High Memory, High CPU usage).

None of the above was possible on my first “personal” machine, with 16 kB RAM and a 6502 CPU running at (maybe) 1 MHz. Fortunately all that is history too :laughing:

CPU usage is “how much work is the CPU actually doing”.

Memory usage is “how much active RAM is being used by the processes.”

If I create a program that just pushes the CPU to 100% (could be done probably in one line of code), but doesn’t do any data processing, the memory usage for that program is going to be very low, but the CPU would be pegged at 100%.

Total memory used (in htop, top, btop, or other similar programs) totals the amount of memory used by all executing processes in the system.

I have a system with a multicore/multithreaded CPU that htop registers as 36 CPUs (it’s 18 hyperthreaded cores). The system has 128 GB of RAM in it.

I tend to keep memory utilization around 30% (I have a lot of docker images running, virtual machines, Chrome open with about 300 tabs, etc).

Right now, I have 27% of my RAM in use by processes. Average utilization across all the reported CPUs in the system is < 10% because I’m reading the forums and not actively processing data or otherwise stressing the system.

Think of CPU as the exertion (like exercising), and memory as “keeping track of things” (like keeping things actively in your mind). If you’re out for a run, exertion is high, but maybe you’re doing it to “clear your mind”, so your “active memory” is essentially empty (because you’re “in the zone”). Not a perfect analogy, but good enough IMO. :slight_smile:

Start at man proc_meminfo

Why don’t you look at what you state.

(base) tom@mydesktop: ~ $ man proc_meminfo
No manual entry for proc_meminfo
(base) tom@mydesktop: ~ $ man meminfo
No manual entry for meminfo
(base) tom@mydesktop: ~ $

@tckosvic Hi, man-pages are probably too old in Leap 15.6 to have it…6.04 vs 6.9.1 in Tumbleweed… You will have to look online then…