I have added vswap confguration samples to vzctl git. Basically, you set physpages and swappages and leave every other beancounter at unlimited. For example, this is how ve-vswap-256m-conf.sample looks like:
# UBC parameters (in form of barrier:limit) PHYSPAGES="0:256M" SWAPPAGES="0:512M" KMEMSIZE="unlimited" LOCKEDPAGES="unlimited" PRIVVMPAGES="unlimited" SHMPAGES="unlimited" NUMPROC="unlimited" VMGUARPAGES="unlimited" OOMGUARPAGES="unlimited" NUMTCPSOCK="unlimited" NUMFLOCK="unlimited" NUMPTY="unlimited" NUMSIGINFO="unlimited" TCPSNDBUF="unlimited" TCPRCVBUF="unlimited" OTHERSOCKBUF="unlimited" DGRAMRCVBUF="unlimited" NUMOTHERSOCK="unlimited" DCACHESIZE="unlimited" NUMFILE="unlimited" NUMIPTENT="unlimited" # Disk quota parameters (in form of softlimit:hardlimit) DISKSPACE="1G" DISKINODES="200000" QUOTATIME="0" # CPU fair scheduler parameter CPUUNITS="1000"
As you can see, physpages (ie RAM size) is set to 256 megabytes, while swappages (ie swap size) is set to 512 megabytes, all the other beancounters are unlimited. Wow, it's never been easier to configure your containers!
Now, we can utilize this stuff using RHEL6 based kernel. This is what we see from inside the container:
[root@localhost ~]# vzctl enter 103
entered into CT 103
[root@localhost /]# free
total used free shared buffers cached
Mem: 262144 23936 238208 0 0 10968
-/+ buffers/cache: 12968 249176
Swap: 524288 0 524288
[root@localhost /]# cat /proc/user_beancounters
Version: 2.5
uid resource held maxheld barrier limit failcnt
103: kmemsize 4722976 4853726 9223372036854775807 9223372036854775807 0
lockedpages 0 0 9223372036854775807 9223372036854775807 0
privvmpages 4296 13875 9223372036854775807 9223372036854775807 0
shmpages 31 31 9223372036854775807 9223372036854775807 0
dummy 0 0 0 0 0
numproc 33 33 9223372036854775807 9223372036854775807 0
physpages 5984 5985 0 65536 0
vmguarpages 0 0 9223372036854775807 9223372036854775807 0
oomguarpages 2696 2696 9223372036854775807 9223372036854775807 0
numtcpsock 4 4 9223372036854775807 9223372036854775807 0
numflock 5 6 9223372036854775807 9223372036854775807 0
numpty 1 1 9223372036854775807 9223372036854775807 0
numsiginfo 12 18 9223372036854775807 9223372036854775807 0
tcpsndbuf 69760 0 9223372036854775807 9223372036854775807 0
tcprcvbuf 65536 0 9223372036854775807 9223372036854775807 0
othersockbuf 2312 10768 9223372036854775807 9223372036854775807 0
dgramrcvbuf 0 0 9223372036854775807 9223372036854775807 0
numothersock 51 53 9223372036854775807 9223372036854775807 0
dcachesize 1172451 1172451 9223372036854775807 9223372036854775807 0
numfile 370 390 9223372036854775807 9223372036854775807 0
dummy 0 0 0 0 0
dummy 0 0 0 0 0
dummy 0 0 0 0 0
numiptent 14 14 9223372036854775807 9223372036854775807 0
[root@localhost /]# cat /proc/meminfo
MemTotal: 262144 kB
MemFree: 238208 kB
Cached: 10968 kB
Active: 16956 kB
Inactive: 1384 kB
Active(anon): 6352 kB
Inactive(anon): 1020 kB
Active(file): 10604 kB
Inactive(file): 364 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 524288 kB
SwapFree: 524288 kB
Dirty: 0 kB
AnonPages: 7364 kB
Mapped: 3416 kB
Shmem: 124 kB
Slab: 4012 kB
SReclaimable: 1088 kB
SUnreclaim: 2924 kB


Comments
i was trying this. It's showing the swap correctly, however, the ram amount (by just setting physpages) is displayed wrongly. Instead of using just 256M or 512M it's using the whole amount of RAM in the HN here.
total used free shared buffers cached
Mem: 3925 302 3623 0 0 0
-/+ buffers/cache: 302 3623
Swap: 512 0 512
I have to use privvmpages and set it to 256M:256M to get:
total used free shared buffers cached
Mem: 256 12 243 0 0 0
-/+ buffers/cache: 12 243
Swap: 1024 0 1024
(both times free -m, different VEs, one with 512M swap, one with 1G swap). Probably i'm doing something wrong. The used Kernel is 2.6.32 (with openvz patches applied) and vzctl i compiled from git.
/proc/user_beancounters for the VE where just setting physpages and swappages (and everything else to unlimited) looks like this:
101: kmemsize 837053 918135 9223372036854775807 9223372036854775807 0
lockedpages 0 6 9223372036854775807 9223372036854775807 0
privvmpages 73428 81582 9223372036854775807 9223372036854775807 0
shmpages 3901 3916 9223372036854775807 9223372036854775807 0
dummy 0 0 9223372036854775807 9223372036854775807 0
numproc 60 116 9223372036854775807 9223372036854775807 0
physpages 34015 40915 0 65536 0
vmguarpages 0 0 9223372036854775807 9223372036854775807 0
oomguarpages 34015 40915 9223372036854775807 9223372036854775807 0
numtcpsock 27 33 9223372036854775807 9223372036854775807 0
numflock 27 29 9223372036854775807 9223372036854775807 0
numpty 3 4 9223372036854775807 9223372036854775807 0
numsiginfo 0 18 9223372036854775807 9223372036854775807 0
tcpsndbuf 473192 850464 9223372036854775807 9223372036854775807 0
tcprcvbuf 509816 591736 9223372036854775807 9223372036854775807 0
othersockbuf 242232 297760 9223372036854775807 9223372036854775807 0
dgramrcvbuf 0 4360 9223372036854775807 9223372036854775807 0
numothersock 168 172 9223372036854775807 9223372036854775807 0
dcachesize 918687 931602 9223372036854775807 9223372036854775807 0
numfile 1773 2529 9223372036854775807 9223372036854775807 0
dummy 0 0 9223372036854775807 9223372036854775807 0
dummy 0 0 9223372036854775807 9223372036854775807 0
dummy 0 0 9223372036854775807 9223372036854775807 0
numiptent 20 20 9223372036854775807 9223372036854775807 0
Well, not really...
> The used Kernel is 2.6.32 (with openvz patches applied)
For 2.6.32, we have two branches -- rhel6 and 2.6.32. vswap is only supported by rhel6.
For each branch, we have versions; for example, latest rhel6 is 042test007.1.