Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

VSwap

2,248 bytes added, 15:57, 17 July 2020
vswap in vz7 details added
'''New [[Download/kernel/rhel6|RHEL6-based OpenVZ]] kernel''' has a new memory management model, which supersedes [[UBC|User beancounters]]. It is called '''VSwap'''.
 
== Primary parameters ==
With VSwap, there are two required parameters: <code>ram</code> and <code>swap</code> (a.k.a. <code>physpages</code> and <code>swappages</code>). All the other beancounters become optional.
Since vzctl 4.6, if some optional beancounters are not set, vzctl sets them implicitly,
using based on '''ram ''' and swap and, in case of privvmpages, a new parameter called '''VM overcommitswap'''settings.
The following formulae are used:
<math>vmguarpages_{bar} = vmguarpages_{lim} = ram + swap</math>
Also==== VM overcommit and privvmpages ==== vzctl 4.6 adds a new parameter, if <code>--vm_overcommit</code>.Its only purpose is to be used in privvmpages calculation,in case VSwap is used and there is no explicit settingfor privvmpages. If <math>vm\_overcommit</math> is set to non-zero:
: <math>privvmpages_{bar} = privvmpages_{lim} = (ram + swap) \times vm\_overcommit</math>
otherwiseIf it is not set:
: <math>privvmpages_{bar} = privvmpages_{lim} = \infty</math>
# Add PHYSPAGES and SWAPPAGES parameters to config. Easiest way is to use <code>vzctl set $CTID --ram N --swap M --save</code>
Now your config is vswap enabled, and when you (re)start it(or use <code>--reset_ub</code>), vswap mechanism will be used by the kernel for this CT. Here is an example of the above steps:  CTID=123 RAM=1G SWAP=2G CFG=/etc/vz/conf/${CTID}.conf cp $CFG $CFG.pre-vswap grep -Ev '^(KMEMSIZE|LOCKEDPAGES|PRIVVMPAGES|SHMPAGES|NUMPROC|PHYSPAGES|VMGUARPAGES|OOMGUARPAGES|NUMTCPSOCK|NUMFLOCK|NUMPTY|NUMSIGINFO|TCPSNDBUF|TCPRCVBUF|OTHERSOCKBUF|DGRAMRCVBUF|NUMOTHERSOCK|DCACHESIZE|NUMFILE|AVNUMPROC|NUMIPTENT|ORIGIN_SAMPLE|SWAPPAGES)=' > $CFG < $CFG.pre-vswap vzctl set $CTID --ram $RAM --swap $SWAP --save vzctl set $CTID --reset_ub
== How to distinguish between vswap and non-vswap configs? ==
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.
 
== Details about vSwap implementation in Virtuozzo 7 ==
 
The Container swapping process is similar to that on a standalone computer.<br>
This means in particular that some pages may get into the swap even if there is some free memory reported in the Container.<br>
This may validly happen in case kernel memory management system detects some anonymous memory which is not touched for a long time by Container processes and decides that it's more
efficient to put these anonymous pages into the swap and use more caches in a Container instead.
The Container swap space resides in physical node swap file.<br>
When the swap-out for a Container starts, appropriate number of pages are allocated in physical swap on the host. Next
# if there is no free memory on the host, the real swap-out of Container's memory to physical swap happens
# if there is free memory on the host, the Container's memory is saved in a special swap cache in host's RAM and no real write to host's physical swap occurs
{{Note|The physical swap space is allocated in both cases anyway, this guarantees all amount of host's swap cache for Containers memory can be written into physical swap on host in case the host gets short of RAM.}}
* '''Consequence 1''': without any configured node swap file the Container's `SWAPPAGES` parameter will be ignored.
* '''Consequence 2''': if node's swap size is less than sum of all Containers' swap sizes on the node, Containers won't be able to use 100% of their swap simultaneously - similar to RAM settings.
== See also ==