Difference between revisions of "VSwap"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
(How to distinguish between vswap and non-vswap configs?)
(improved)
Line 1: Line 1:
 
'''New [[Download/kernel/rhel6|RHEL6-based OpenVZ]] kernel''' has a new memory management model, which supersedes [[UBC|User beancounters]]. It is called '''VSwap'''.
 
'''New [[Download/kernel/rhel6|RHEL6-based OpenVZ]] kernel''' has a new memory management model, which supersedes [[UBC|User beancounters]]. It is called '''VSwap'''.
  
Now you can set two primary parameters: <code>physpages</code> and <code>swappages</code>, while all the other beancounters become secondary and optional.
+
Now you can set two primary parameters: <code>ram</code> and <code>swap</code> (a.k.a. <code>physpages</code> and <code>swappages</code>), while all the other beancounters become secondary and optional.
  
 
* '''physpages'''
 
* '''physpages'''
: This parameter limits the physical memory (RAM) available to processes inside a container.
+
: This parameter sets the amount of fast physical memory (RAM) available to processes inside a container, in memory pages.
 
: The <code>barrier</code> is ignored and should be set to 0, and the <code>limit</code> sets the limit.
 
: The <code>barrier</code> is ignored and should be set to 0, and the <code>limit</code> sets the limit.
 
: Currently (as of >= 042stab042) the user memory, the kernel memory and the page cache are accounted into <code>physpages</code>.
 
: Currently (as of >= 042stab042) the user memory, the kernel memory and the page cache are accounted into <code>physpages</code>.
 +
 +
* '''ram'''
 +
: is an easy shortcut for physpages.limit, and is measured in bytes
  
 
* '''swappages'''
 
* '''swappages'''
: This parameter limits the amount of swap space which can be used for processes inside a container.
+
: This parameter sets the amount of "slower memory" (vswap) available to processes inside a container, in memory pages.
 
: The <code>barrier</code> is ignored and should be set to 0, and the <code>limit</code> sets the limit.
 
: The <code>barrier</code> is ignored and should be set to 0, and the <code>limit</code> sets the limit.
 +
 +
* '''swap'''
 +
: is an easy shortcut for swappages.limit, and is measured in bytes
  
 
The sum of <code>physpages.limit</code> and <code>swappages.limit</code> limits the maximum amount
 
The sum of <code>physpages.limit</code> and <code>swappages.limit</code> limits the maximum amount
of allocated memory which can be used by a container. When physpages limit
+
of memory which can be used by a container. When physpages limit
 
is reached, memory pages belonging to the container are pushed out to
 
is reached, memory pages belonging to the container are pushed out to
 
so called virtual swap (''vswap''). The difference between normal swap
 
so called virtual swap (''vswap''). The difference between normal swap
Line 20: Line 26:
 
swapping. Actual swap out occurs only if there is a global memory shortage
 
swapping. Actual swap out occurs only if there is a global memory shortage
 
on the system.
 
on the system.
 +
 +
{{Note|swap used by a container can exceed <code>swappages.limit</code>, but is always within sum of <code>physpages.limit</code> and <code>swappages.limit</code>.}}
  
 
== Setting ==
 
== Setting ==
Line 28: Line 36:
 
   
 
   
 
  vzctl set 777 --ram 512M --swap 1G --save
 
  vzctl set 777 --ram 512M --swap 1G --save
 
If you are converting an existing CT from old (non-vswap) configuration, you can either
 
* leave all the other UBC parameters as-is,
 
* or set those to 'unlimited',
 
* or remove those from configuration file.
 
  
 
== Convert non-vswap CT to Vswap ==
 
== Convert non-vswap CT to Vswap ==
Line 46: Line 49:
 
== How to distinguish between vswap and non-vswap configs? ==
 
== How to distinguish between vswap and non-vswap configs? ==
  
Both <code>vzctl</code> and the kernel treats a configuration file as vswap one if PHYSPAGES limit is '''not''' set to <code>unlimited</code> (a.k.a. [[LONG_MAX]]).
+
Both <code>vzctl</code> and the kernel treats a configuration file as vswap one if PHYSPAGES limit is '''not''' set to <code>unlimited</code> (a.k.a. [[LONG_MAX]]). You can also use the following command:
 +
 
 +
# vzlist -o vswap $CTID
  
 
In addition, vzctl checks if kernel support vswap, and refuses to start a vswap-enabled container on a non vswap capable kernel. The check is presence of <code>/proc/vz/vswap</code> file.
 
In addition, vzctl checks if kernel support vswap, and refuses to start a vswap-enabled container on a non vswap capable kernel. The check is presence of <code>/proc/vz/vswap</code> file.

Revision as of 01:00, 18 June 2013

New RHEL6-based OpenVZ kernel has a new memory management model, which supersedes User beancounters. It is called VSwap.

Now you can set two primary parameters: ram and swap (a.k.a. physpages and swappages), while all the other beancounters become secondary and optional.

  • physpages
This parameter sets the amount of fast physical memory (RAM) available to processes inside a container, in memory pages.
The barrier is ignored and should be set to 0, and the limit sets the limit.
Currently (as of >= 042stab042) the user memory, the kernel memory and the page cache are accounted into physpages.
  • ram
is an easy shortcut for physpages.limit, and is measured in bytes
  • swappages
This parameter sets the amount of "slower memory" (vswap) available to processes inside a container, in memory pages.
The barrier is ignored and should be set to 0, and the limit sets the limit.
  • swap
is an easy shortcut for swappages.limit, and is measured in bytes

The sum of physpages.limit and swappages.limit limits the maximum amount of memory which can be used by a container. 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. Actual swap out occurs only if there is a global memory shortage on the system.

Yellowpin.svg Note: swap used by a container can exceed swappages.limit, but is always within sum of physpages.limit and swappages.limit.

Setting

Yellowpin.svg Note: for VSwap, you need vswap-enabled kernel, ie RHEL6-based OpenVZ kernel.

Since vzctl 3.0.30, you can use --ram and --swap parameters, like this:

vzctl set 777 --ram 512M --swap 1G --save

Convert non-vswap CT to Vswap

If you have an existing container with usual UBC parameters set, and you want to convert this one into VSwap enabled config, here's what you need to do.

  1. Decide on how much RAM and swap you want this CT to have. Generally, sum of your new RAM+swap should be more or less equal to sum of old PRIVVMPAGES and KMEMSIZE.
  2. Manually remove all UBC parameters from config. This is optional, you can still have UBC limits applied if you want.
  3. Add PHYSPAGES and SWAPPAGES parameters to config. Easiest way is to use vzctl set $CTID --ram N --swap M --save

Now your config is vswap enabled, and when you (re)start it, vswap mechanism will be used by the kernel for this CT.

How to distinguish between vswap and non-vswap configs?

Both vzctl and the kernel treats a configuration file as vswap one if PHYSPAGES limit is not set to unlimited (a.k.a. LONG_MAX). You can also use the following command:

# vzlist -o vswap $CTID

In addition, vzctl checks if kernel support vswap, and refuses to start a vswap-enabled container on a non vswap capable kernel. The check is presence of /proc/vz/vswap file.

See also