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?

Fela Maslen
  • 1,183
  • 2
  • 11
  • 19
  • 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 '19 at 13:35
  • The processes running on my server are irrelevant to the question. – Fela Maslen Nov 02 '19 at 14:16

1 Answers1

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.

John Mahowald
  • 30,009
  • 1
  • 17
  • 32