Operating System - Linux
1753428 Members
4836 Online
108793 Solutions
New Discussion юеВ

Re: why diff b/w output of "free/vmstat" & /proc/meminfo ?

 
Maaz
Valued Contributor

why diff b/w output of "free/vmstat" & /proc/meminfo ?

vmstat and free shows that swap used is "140 KB" while SwapCached(/proc/meminfo) is "100 KB" only.
why the difference b/w the output of "free/vmstat" and /proc/meminfo ?


# vmstat 3
procs -----------memory---------- ---swap-- -----io---- -system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 140 196692 23956 1522424 0 0 509 907 294 338 6 2 85 7 0
1 0 140 187056 24172 1530528 0 0 20 1621 504 736 33 2 58 7 0
1 0 140 166228 24172 1551848 0 0 1749 3105 532 718 45 1 44 10 0

# free
total used free shared buffers cached
Mem: 2067264 1953748 113516 0 24228 1586632
-/+ buffers/cache: 342888 1724376
Swap: 3100452 140 3100312

# cat /proc/meminfo
MemTotal: 2067264 kB
MemFree: 77316 kB
Buffers: 24908 kB
Cached: 1612472 kB
SwapCached: 100 kB
Active: 877428 kB
Inactive: 988284 kB
HighTotal: 1171264 kB
HighFree: 4340 kB
LowTotal: 896000 kB
LowFree: 72976 kB
SwapTotal: 3100452 kB
SwapFree: 3100312 kB
Dirty: 1128 kB
Writeback: 0 kB
AnonPages: 228184 kB
Mapped: 201276 kB
Slab: 49604 kB
CommitLimit: 4134084 kB
Committed_AS: 1110496 kB
PageTables: 5020 kB
VmallocTotal: 114680 kB
VmallocUsed: 11404 kB
VmallocChunk: 102516 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
Hugepagesize: 4096 kB

Regards
2 REPLIES 2
Court Campbell
Honored Contributor

Re: why diff b/w output of "free/vmstat" & /proc/meminfo ?

I think it is the difference in the total amount of swap versus how much swap is being cached in memory.

Per red hat docs the definition of SwapCached is:

The amount of swap, in kilobytes, used as cache memory.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Maaz
Valued Contributor

Re: why diff b/w output of "free/vmstat" & /proc/meminfo ?

I think i got the answer

When swapping pages out to the swap files, Linux avoids writing pages if it does not have to. There are times when a page is both in a swap file and in physical memory. This happens when a page that was swapped out of memory was then brought back into memory when it was again accessed by a process. So long as the page in memory is not written to, the copy in the swap file remains valid.

Linux uses the swap cache to track these pages. The swap cache is a list of page table entries, one per physical page in the system. This is a page table entry for a swapped out page and describes which swap file the page is being held in together with its location in the swap file. If a swap cache entry is non-zero, it represents a page which is being held in a swap file that has not been modified. If the page is subsequently modified (by being written to), its entry is removed from the swap cache.

When Linux needs to swap a physical page out to a swap file it consults the swap cache and, if there is a valid entry for this page, it does not need to write the page out to the swap file. This is because the page in memory has not been modified since it was last read from the swap file.

The entries in the swap cache are page table entries for swapped out pages. They are marked as invalid but contain information which allow Linux to find the right swap file and the right page within that swap file.

source:
http://www.linux-tutorial.info/modules.php?name=MContent&pageid=314