3

According to the man page of vmstat, 'swpd' means the amount of virtual memory used. As my understanding, for most cases it should be zero unless the physical CPU is out of space.

However, I just found that the value of 'swpd' of my server is not zero.
enter image description here

I don't know why. Even if I have more than 700 processes, the CPUs are almost 100% unused.
enter image description here

In total, the swap is used about 190M. It's not that big comparing with its total size which is 250G.

So does it mean that some processes will use the virtual swap even if the CPUs are free?

1 Answer 1

7

Swap has nothing to with CPU utilization. Swap is memory that is written to disk.

The CPU can access normal RAM directly, and RAM is extremely fast compared to swap. That's why we have RAM - as a fast buffer for data the CPU needs to access.

Swap allows the kernel to write unused memory to disk, for retrieval when needed. This is a costly process, as disk is extremely slow compared to memory, but it also allows more memory use than the physical amount of memory.

In addition, some things may never be used, but yet have allocated memory space. Typically the kernel will swap out things that is not used.

190MB used SWAP is not a problem. The problem is if the computer has to write things out to swap, and retrieve it again.

My laptop has 445MB written to swap at the moment, and yet over 3GiB unused memory - obviously the kernel at some stage found something that was not used, and decided to swap it out.

In short: don't care about swap usage unless:

  1. You see frequent thrashing.
  2. free -m shows very low amount of available memory

A quick example of free -m from my laptop:

$ free -m
             total       used       free     shared    buffers     cached
Mem:          7702       7454        247        582        230       3477
-/+ buffers/cache:       3746       3955
Swap:         8191        445       7746

As we can see, there's 247MiB free. But this is not the whole story. In addition, there's over 3GiB of caches, that can be freed very quickly if the kernel needs more memory for something. Thus, the real amount of free memory is 3955MiB, shown in the second line under free. You also see the swap used.

In short: don't care about swap space usage unless you experience problems, like software responding very slowly - which is a good sign of thrashing.

To check for thrashing, you can run vmstat -s to display statistics. You'll see two lines, like this:

   174085 pages swapped in
   569123 pages swapped out

This is the numbers of pages written to swap and read from swap. As long as these numbers are not increasing fast, everything is just fine - and swap gives you more memory for real applications and caching that speeds up your system.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .