大网数据广告活动
服务器运维问答

free and htop report totally different numbers

· 52CE 我爱测

See the following screenshot: 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, whi…

问题原文

原帖链接 · Fela Maslen · CC BY-SA 4.0

See the following screenshot:

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?

已采纳解答

原帖链接 · John Mahowald · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-10-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。