Swap memory is now available within openvz containers with RHEL6 series stable kernel. It is a good turn point of openvz containers. The latest kernels starting from 042stab035.1 now support swap within the containers. It is an entirely different memory management model for Openvz containers and this new swap model is called Vswap. Now you only need to take care of the following two parameters for configuring the memory physpages and swappages . These are the primary parameters . All others now become secondary
physpages : This parameter limits the physical memory (RAM) available to processes inside a container. The barrier is ignored, and the limit sets the limit.
swappages : This parameter limits the amount of swap space which can be used for processes inside a container. The barrier is ignored, and the limit sets the limit.
How to set SWAP on Openvz Vps ?
You can use the vzctl command interface to set the swap for the vps.
For example I need to set the swap to 1024 MB for a container 1000 , see below,
# vzctl set 1000 --swappages 0:1024M --save
See the swap result below,
[root@node ~]# vzctl exec 1000 free -m
total used free shared buffers cached
Mem: 4096 1814 2281 0 0 1814
-/+ buffers/cache: 0 4096
Swap: 1024 2 1021
When physpages limit is reached, memory pages belonging to the container are pushed out to so called virtual swap (vswap). The difference between normal swap and vswap is that with vswap no actual disk I/O usually occurs. Instead, a container is artificially slowed down, to emulate the effect of the real swapping.