On my Fedora 24, I executed two commands to examine the memory information, however, I got two different results about swap cache's size.

The first command is as follows:

[root@localhost ~]# vmstat -s
      4029004 K total memory
      1043700 K used memory
       742144 K active memory
       321916 K inactive memory
      2372500 K free memory
        63628 K buffer memory
       549176 K swap cache
      4063228 K total swap
            0 K used swap
      4063228 K free swap

The second command is as follows:

[root@localhost ~]# cat /proc/meminfo
MemTotal:        4029004 kB
MemFree:         2369712 kB
MemAvailable:    2690460 kB
Buffers:           63720 kB
Cached:           437460 kB
SwapCached:            0 kB

Please note: vmstat -s says 549176 K swap cache, while cat /proc/meminfo says SwapCached: 0 kB.

My question are:

  1. What does it mean by swap cache?
  2. What does it mean by SwapCached?
  3. Are they the same thing? If no, what's the difference between them?

In vmstat the field cache is the sum of cat /proc/meminfo fields Cached and Slab.

  • It means it's approximately file cache plus inode cache plus directory cache plus caches for extra objects.
  • The same field is called swap cache in vmstat -s.
  • The field has nothing, zero, nil to do with swap. A misnomer, as it often happens.
  • To calculate this from cat /proc/vmstat fields, use:

swap cache = nr_file_page + nr_slab_reclaimable + nr_slab_unreclaimable - meminfo_SwapCached

Looking at /proc/meminfo, the field SwapCached is unrelated; it has nothing to do with any disk cache or slab cache. It's how much of the swap is also present in the clean memory pages.

It seems the only counter which mixes up file cache with swap is the nr_file_page (it treats swap as any other another "cached" file; this terminology is totally incompatible with other counters/tools).

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.