SAR内存输出与free命令的关联及数值不符问题咨询
SAR内存输出与free命令的关联及数值不符问题咨询
Hey there! Let's dig into why you might notice mismatches between sar's memory stats and what free -h shows, plus how these two tools actually connect.
First, let's clarify core differences between the two tools
free -htakes a real-time snapshot of your server's memory at the exact moment you run it.- When you use
sar -f /var/log/sa/sa04 -r, you're looking at historical sampled data: either individual time-point snapshots (like the10:15:01 AMentry in your output) or an average of all samples for the period (theAverage:line). Comparing an average to a real-time snapshot will almost always show discrepancies—make sure you're comparing apples to apples!
Field-by-field mapping (and where discrepancies often pop up)
Let's match up your sar -r fields to free output, using your CentOS 7 kernel (3.10.0-1062.el7) as context:
kbmemfree(sar) ↔freecolumn infree -hkbmemused(sar) ↔usedcolumn infree -h(both include buffers and cached memory by default)kbbuffers(sar) ↔bufferscolumn infree -hkbcached(sar) ↔cachedcolumn infree -h
Common mismatch causes for your kernel version:
- Slab memory inclusion: In older
sysstatversions (the package that providessar),kbcachedmight not include Slab memory, butfree'scachedcolumn does. This can lead to a noticeable gap between the two cached values. - Kernel/sysstat version differences: The referenced website might describe behavior from a newer kernel or
sysstatrelease. CentOS 7 uses a relatively old kernel andsysstatpackage, so some field calculations might differ slightly from newer distributions. - Commit vs actual memory:
sarincludeskbcommitand%commit—these measure the total memory that's been committed (including potential swap usage), not actual used memory.freedoesn't have a direct equivalent, so don't confuse these with your real RAM utilization.
How to verify and troubleshoot
- Compare real-time samples: Run
sar -r 1 1(takes 1 sample, 1 second apart) andfree -b(uses bytes to avoid unit conversion errors) at the same time. The numbers should align closely if there's no underlying issue. - Check your sysstat version: Run
sar -V—if you're on an older version, updating thesysstatpackage (yum update sysstatfor CentOS 7) might resolve minor calculation inconsistencies. - Focus on matching time points: When checking historical
sardata, find a specific time entry (like10:15:01 AM) and compare it to afreesnapshot taken at that exact moment (if you have logs or can replicate the timing).
备注:内容来源于stack exchange,提问作者iostrym
相关产品推荐
相关产品推荐

