提交 d94a14f8 编写于 作者: N Nikunj A. Dadhania 提交者: Eric Blake

memtune: Let virsh know the unlimited value for memory tunables

Display or set unlimited values for memory parameters. Unlimited is
represented by INT64_MAX in memory cgroup.
Signed-off-by: NNikunj A. Dadhania <nikunj@linux.vnet.ibm.com>
Reported-by: NJustin Clift <jclift@redhat.com>
上级 63dbc84a
......@@ -696,6 +696,7 @@ typedef enum {
*/
#define VIR_DOMAIN_MEMORY_FIELD_LENGTH 80
#define VIR_DOMAIN_MEMORY_PARAM_UNLIMITED (INT64_MAX >> 10)
/**
* VIR_DOMAIN_MEMORY_HARD_LIMIT:
......
......@@ -815,7 +815,7 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
int i;
virCgroupPtr cgroup = NULL;
virDomainObjPtr vm = NULL;
unsigned long val;
unsigned long long val;
int ret = -1;
int rc;
......
......@@ -7036,7 +7036,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
int i;
virCgroupPtr group = NULL;
virDomainObjPtr vm = NULL;
unsigned long val;
unsigned long long val;
int ret = -1;
int rc;
......
......@@ -355,8 +355,6 @@ static int virCgroupSetValueU64(virCgroupPtr group,
}
#if 0
/* This is included for completeness, but not yet used */
static int virCgroupSetValueI64(virCgroupPtr group,
int controller,
......@@ -376,6 +374,8 @@ static int virCgroupSetValueI64(virCgroupPtr group,
return rc;
}
#if 0
/* This is included for completeness, but not yet used */
static int virCgroupGetValueI64(virCgroupPtr group,
int controller,
const char *key,
......@@ -858,12 +858,22 @@ int virCgroupForDomain(virCgroupPtr driver ATTRIBUTE_UNUSED,
*
* Returns: 0 on success
*/
int virCgroupSetMemory(virCgroupPtr group, unsigned long kb)
int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb)
{
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.limit_in_bytes",
kb << 10);
unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
if (kb > maxkb)
return -EINVAL;
else if (kb == maxkb)
return virCgroupSetValueI64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.limit_in_bytes",
-1);
else
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.limit_in_bytes",
kb << 10);
}
/**
......@@ -894,7 +904,7 @@ int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb)
*
* Returns: 0 on success
*/
int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long kb)
int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb)
{
return virCgroupSetMemory(group, kb);
}
......@@ -907,7 +917,7 @@ int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long kb)
*
* Returns: 0 on success
*/
int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb)
int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb)
{
long long unsigned int limit_in_bytes;
int ret;
......@@ -915,7 +925,7 @@ int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb)
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.limit_in_bytes", &limit_in_bytes);
if (ret == 0)
*kb = (unsigned long) limit_in_bytes >> 10;
*kb = limit_in_bytes >> 10;
return ret;
}
......@@ -927,12 +937,22 @@ int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb)
*
* Returns: 0 on success
*/
int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long kb)
int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb)
{
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.soft_limit_in_bytes",
kb << 10);
unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
if (kb > maxkb)
return -EINVAL;
else if (kb == maxkb)
return virCgroupSetValueI64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.soft_limit_in_bytes",
-1);
else
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.soft_limit_in_bytes",
kb << 10);
}
......@@ -944,7 +964,7 @@ int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long kb)
*
* Returns: 0 on success
*/
int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long *kb)
int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb)
{
long long unsigned int limit_in_bytes;
int ret;
......@@ -952,7 +972,7 @@ int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long *kb)
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.soft_limit_in_bytes", &limit_in_bytes);
if (ret == 0)
*kb = (unsigned long) limit_in_bytes >> 10;
*kb = limit_in_bytes >> 10;
return ret;
}
......@@ -964,12 +984,22 @@ int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long *kb)
*
* Returns: 0 on success
*/
int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long kb)
int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long long kb)
{
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.memsw.limit_in_bytes",
kb << 10);
unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
if (kb > maxkb)
return -EINVAL;
else if (kb == maxkb)
return virCgroupSetValueI64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.memsw.limit_in_bytes",
-1);
else
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.memsw.limit_in_bytes",
kb << 10);
}
/**
......@@ -980,7 +1010,7 @@ int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long kb)
*
* Returns: 0 on success
*/
int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned long *kb)
int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned long long *kb)
{
long long unsigned int limit_in_bytes;
int ret;
......@@ -988,7 +1018,7 @@ int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned long *kb)
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.memsw.limit_in_bytes", &limit_in_bytes);
if (ret == 0)
*kb = (unsigned long) limit_in_bytes >> 10;
*kb = limit_in_bytes >> 10;
return ret;
}
......
......@@ -40,15 +40,15 @@ int virCgroupForDomain(virCgroupPtr driver,
int virCgroupAddTask(virCgroupPtr group, pid_t pid);
int virCgroupSetMemory(virCgroupPtr group, unsigned long kb);
int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb);
int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);
int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long kb);
int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb);
int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long kb);
int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long *kb);
int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long kb);
int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned long *kb);
int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb);
int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb);
int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb);
int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb);
int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long long kb);
int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned long long *kb);
int virCgroupDenyAllDevices(virCgroupPtr group);
......
......@@ -3007,8 +3007,11 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
params[i].value.l);
break;
case VIR_DOMAIN_MEMORY_PARAM_ULLONG:
vshPrint(ctl, "%-15s: %llu\n", params[i].field,
params[i].value.ul);
if (params[i].value.ul == VIR_DOMAIN_MEMORY_PARAM_UNLIMITED)
vshPrint(ctl, "%-15s: unlimited\n", params[i].field);
else
vshPrint(ctl, "%-15s: %llu kB\n", params[i].field,
params[i].value.ul);
break;
case VIR_DOMAIN_MEMORY_PARAM_DOUBLE:
vshPrint(ctl, "%-15s: %f\n", params[i].field,
......@@ -3059,6 +3062,10 @@ cmdMemtune(vshControl * ctl, const vshCmd * cmd)
sizeof(temp->field));
min_guarantee = 0;
}
/* If the user has passed -1, we interpret it as unlimited */
if (temp->value.ul == -1)
temp->value.ul = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
}
if (virDomainSetMemoryParameters(dom, params, nparams, 0) != 0)
vshError(ctl, "%s", _("Unable to change memory parameters"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册