0

See the following screenshot:

htop vs free

The "total" amount of memory is reported at 8GB by both htop and free, but while free reports that only 2.7GB is "used", htop reports that 7.53GB is used. free reports that 5GB is buffers/cache, while htop reports this as 100MB.

I think htop is correct here, because the system is sluggish and kswapd0 has high CPU usage.

What is the reason for this mismatch?

  • While I'm sure you are torrenting free software, some explanation of your business case for torrents and media server would keep this on Severfault and not Superuser. – John Mahowald Oct 14 at 13:35
  • The processes running on my server are irrelevant to the question. – Fela Maslen Nov 2 at 14:16
2

https://www.linuxatemyram.com/

Classic confusion on cached versus used. htop is counting cached as used but free is not. As this is Linux, read /proc/meminfo yourself and see how the counters relate to each other.

Edit: you asked specifically about the difference in cached.

free from procps apparently does page cache plus slab reclaimable. From proc/sysinfo.c

  kb_main_cached = kb_page_cache + kb_slab_reclaimable;

htop is page cache plus slab reclaim minus shared memory. linux/LinuxProcessList.c

   this->cachedMem = this->cachedMem + sreclaimable - shmem;

Honestly, on modern Linux, I would look at MemAvailable and some other counters in /proc/meminfo directly. If I cared about the numbers.


Performance tools, while very useful, can be misleading, confusing, and poorly documented. Do not assume different tools calculate a similarly named thing with the same algorithm.


Sluggish and slow response times could be anything. Storage IOPS limits or response times, memory page ins from slow storage, high CPU utilization (maybe not at the instant you took this screenshot), slow network, poorly written applications, and so on.

Quantify what is being slow and how much. You have many applications running: μTorrent Server, mysql, mongo, plex, some other containers. Turn on slow query logs. Profile applications. Log every performance metrics you can into a time series database and look at the graphs.

  • htop reports buffers/cache as 4M/105M (respectively), while free reports this as 5G. What would be the reason for this particular mismatch? – Fela Maslen Nov 2 at 14:20
  • They compute it differently. See edit. – John Mahowald Nov 4 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.