6
free -m
            total       used        free    shared      buffers     cached
Mem:        15708       15539        168       124            6       6272
-/+ buffers/cache:       9260       6447
Swap:           0  1759218604          0

sysctl vm.swappiness
vm.swappiness = 0

grep Swap /proc/meminfo
SwapCached:    0 kB
SwapTotal:     0 kB
SwapFree:     36 kB

I have set vm.swappiness=0 to disable swap, but the output of free -m shows that swap cache is used 1759218604, a very huge number. I think used swap memory should be 0, why not 0?

centos version:6.7, Linux kernel:2.6

1
  • 3
    Just FYI, vm.swappiness=0 does not "disable swap", it just means that reclaiming file-backed pages will always be prioritized. Swap will still be used if that's the only way to free up some memory (before resorting to the OOM killer). If you really want to disable swap, just don't set up any swap files/devices. Note that disabling swap is typically a terrible idea, because it leads to thrashing on frequently used file-backed pages while lots of completely idle anonymous pages just sit there hogging RAM. – TooTea Jul 16 at 9:37
14

That's a very old RHEL/CentOS 6 kernel bug, you need to update to kernel-2.6.32-573.6.1.el6 (or newer). See this RH customer portal article (requires RH account) and this question on serverfault for more details.

I would also recommend upgrading your system, CentOS 6 is no longer supported and 6.7 is not even the latest minor version (last was 6.10).

9

Your system isn’t using any swap.

The kernel doesn’t directly track the amount of used swap, so free calculates it as the difference between total swap and free swap. For some reason (see Vojtech’s answer), your system’s kernel thinks that it has 36k of free swap out of 0k total, so free calculates that you have -36k used swap. That however is stored as an unsigned value, so it ends up being shown as a large integer (scaled by 1024 since you specified -m).

4
  • 4
    Well I don't have to ask who mmap()ed a disk device then. – Joshua Jul 15 at 17:40
  • I’m not getting the reference — how would that result in the symptoms shown in the question? – Stephen Kitt Jul 16 at 9:01
  • I recall a case awhile back where a very similar bug happened because mmap() would add to used swap but not total swap. – Joshua Jul 16 at 13:48
  • Ah right, thanks! – Stephen Kitt Jul 16 at 14:48

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.