Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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 <kir@openvz.org>
  • Loading branch information...
commit 0535fe1eb35ed8e015c578b802a6ae39d0459bce 1 parent 8c8d5cc
Kirill Kolyshkin kolyshkin authored
2  include/vzctl_param.h
View
@@ -136,6 +136,8 @@
#define PARAM_BOOTORDER 364
#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"
#endif
4 man/ctid.conf.5
View
@@ -84,6 +84,10 @@ Corresponds to the \fB--dgramrcvbuf\fR option.
Corresponds to the \fB--dcachesize\fR option.
.IP \fBNUMIPTENT\fR
Corresponds to the \fB--numiptent\fR option.
+.IP \fBPHYSPAGES\fR
+Corresponds to the \fB--physpages\fR or \fB--ram\fR option.
+.IP \fBSWAPPAGES\fR
+Corresponds to the \fB--swappages\fR or \fB--swap\fR option.
.IP \fBCPUUNITS\fR
Corresponds to the \fB--cpuunits\fR option.
.IP \fBDISK_QUOTA\fR="\fByes\fR|\fBno\fR"
50 man/vzctl.8
View
@@ -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
+.PP
+The following options sets memory and swap limits for VSwap-enabled kernels
+(kernel version 042stab042 or greater).
+.PP
+Argument is in bytes, with an optional suffix. Available suffixes are:
+.TP
+\fBT\fR, \fBt\fR
+terabytes;
+.TP
+\fBG\fR, \fBg\fR
+gigabytes;
+.TP
+\fBM\fR, \fBm\fR
+megabytes;
+.TP
+\fBK\fR, \fBk\fR
+kilobytes;
+.TP
+\fBP\fR, \fBp\fR
+memory pages (arch-specific).
+.PP
+.TP
+\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).
+.TP
+\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).
+.PP
+Here is an example of setting container 777 to have
+512 megabytes of RAM and 1 gigabyte of swap:
+.EX
+ vzctl set 777 --ram 512M --swap 1G --save
+.EE
+
+.SS3 User Beancounter limits
.PP
The following options sets barrier and limit for various user beancounters.
+.PP
+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.
+.PP
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
View
@@ -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:
+ id = PARAM_PHYSPAGES;
+ break;
+ case PARAM_SWAP:
+ id = PARAM_SWAPPAGES;
+ 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;
+ ret = ERR_LONG_TRUNC;
+ }
+
+ 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)
case PARAM_DCACHESIZE:
ret = parse_ub(vps_p, val, id, 1);
break;
+ case PARAM_RAM:
+ case PARAM_SWAP:
+ ret = parse_vswap(&vps_p->res.ub, val, id);
+ break;
case PARAM_CAP:
ret = parse_cap(val, &vps_p->res.cap);
break;
4 src/vzctl-actions.c
View
@@ -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}
};
Please sign in to comment.
Something went wrong with that request. Please try again.