Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

vzctl set: introduce --ram and --swap

These are just an easy aliases for --physpages and --swappages,
the differences being:

1. There is a single argument -- the limit (the barrier is set to 0).
2. The argument is in bytes (with optional K/M/G/T suffix).

While at it, document PHYSPAGES and SWAPPAGES in ctid.conf(5).

Signed-off-by: Kir Kolyshkin <>
  • Loading branch information...
1 parent 8c8d5cc commit 0535fe1eb35ed8e015c578b802a6ae39d0459bce @kolyshkin kolyshkin committed
2  include/vzctl_param.h
@@ -136,6 +136,8 @@
#define PARAM_PCI_ADD 365
#define PARAM_PCI_DEL 366
+#define PARAM_RAM 367
+#define PARAM_SWAP 368
#define PARAM_LINE "e:p:f:t:i:l:k:a:b:n:x:h"
4 man/ctid.conf.5
@@ -84,6 +84,10 @@ Corresponds to the \fB--dgramrcvbuf\fR option.
Corresponds to the \fB--dcachesize\fR option.
Corresponds to the \fB--numiptent\fR option.
+Corresponds to the \fB--physpages\fR or \fB--ram\fR option.
+Corresponds to the \fB--swappages\fR or \fB--swap\fR option.
Corresponds to the \fB--cpuunits\fR option.
.IP \fBDISK_QUOTA\fR="\fByes\fR|\fBno\fR"
50 man/vzctl.8
@@ -61,7 +61,7 @@ vzctl \- perform various operations on an OpenVZ container
.OP --host_mac hwaddr
.OP --bridge name
.OP --mac_filter \fBon\fR|\fBoff\fR]
-.\" Resource limits
+.\" User Beancounter limits
.OP --numproc items
.OP --numtcpsock items
.OP --numothersock items
@@ -83,6 +83,8 @@ vzctl \- perform various operations on an OpenVZ container
.OP --numiptent num
.OP --physpages pages
.OP --swappages pages
+.OP --ram bytes
+.OP --swap bytes
.\" CPU fair scheduler
.OP --cpuunits num
.OP --cpulimit num
@@ -294,9 +296,53 @@ and multicast packets);
By default, this functionality is enabled for all veth devices existing
inside the Container.
-.SS3 Resource limits
+.SS3 VSwap limits
+The following options sets memory and swap limits for VSwap-enabled kernels
+(kernel version 042stab042 or greater).
+Argument is in bytes, with an optional suffix. Available suffixes are:
+\fBT\fR, \fBt\fR
+\fBG\fR, \fBg\fR
+\fBM\fR, \fBm\fR
+\fBK\fR, \fBk\fR
+\fBP\fR, \fBp\fR
+memory pages (arch-specific).
+\fB--ram\fR \fIbytes\fR
+Sets physical memory (RAM) available to a container.
+Actually, the option is a shortcut for setting \fB--physpages\fR limit
+(the barrier is set to 0).
+\fB--swap\fR \fIbytes\fR
+Set swap space available to a container.
+Actually, the option is a shortcut for setting \fB--swappages\fR limit
+(the barrier is set to 0).
+Here is an example of setting container 777 to have
+512 megabytes of RAM and 1 gigabyte of swap:
+ vzctl set 777 --ram 512M --swap 1G --save
+.SS3 User Beancounter limits
The following options sets barrier and limit for various user beancounters.
+Note that for VSwap-enabled kernels (version 042stab042 or greater) these
+limits are optional, you must only set \fB--ram\fR and \fR--swap\fR
+(see above). For older kernels, these limits are obligatory.
Each option requires one or two arguments. In case of one argument,
\fBvzctl\fR sets barrier and limit to the same value. In case of
two colon-separated arguments, the first is a barrier,
45 src/lib/config.c
@@ -652,6 +652,47 @@ static int parse_ub(vps_param *vps_p, const char *val, int id, int divisor)
return ret;
+static int parse_vswap(ub_param *ub, const char *val, int id)
+ int ret;
+ ub_res res;
+ const char *tail;
+ unsigned long long tmp;
+ /* Translate from VSwap ('easy') to UBC parameter */
+ switch(id) {
+ case PARAM_RAM:
+ break;
+ case PARAM_SWAP:
+ break;
+ default:
+ return ERR_OTHER;
+ }
+ if (conf_get_by_id(config, id) == NULL)
+ return ERR_OTHER;
+ tail = parse_ul_sfx(val, &tmp, _page_size);
+ if (tail == NULL)
+ return ERR_INVAL;
+ if (*tail != '\0')
+ return ERR_INVAL;
+ if (tmp > LONG_MAX) {
+ tmp = LONG_MAX;
+ }
+ res.res_id = id;
+ res.limit[0] = 0;
+ res.limit[1] = tmp;
+ if (add_ub_param(ub, &res))
+ return ERR_NOMEM;
+ return ret;
static int store_ub(vps_param *old_p, vps_param *vps_p,
list_head_t *conf_h)
@@ -1932,6 +1973,10 @@ static int parse(envid_t veid, vps_param *vps_p, char *val, int id)
ret = parse_ub(vps_p, val, id, 1);
+ case PARAM_RAM:
+ case PARAM_SWAP:
+ ret = parse_vswap(&vps_p->res.ub, val, id);
+ break;
ret = parse_cap(val, &vps_p->res.cap);
4 src/vzctl-actions.c
@@ -137,6 +137,10 @@ static struct option set_opt[] = {
{"description", required_argument, NULL, PARAM_DESCRIPTION},
{"bootorder", required_argument, NULL, PARAM_BOOTORDER},
+ /* New "easy" VSwap parameters */
+ {"ram", required_argument, NULL, PARAM_RAM},
+ {"swap", required_argument, NULL, PARAM_SWAP},
{NULL, 0, NULL, 0}

0 comments on commit 0535fe1

Please sign in to comment.
Something went wrong with that request. Please try again.