On Tue, 11 Jan 2011 08:19:30 -0700, Eric Blake <eblake(a)redhat.com> wrote:
On 01/10/2011 10:18 PM, Nikunj A. Dadhania wrote:
[snip]
> @@ -907,7 +907,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)
So why is Get changed to ull, but Set remains with just unsigned long?
This patch is still incomplete. I think you need to touch both
functions, and also virCgroupSetMemory. Also, in virCgroupSetMemory,
you need to check for overflow, and fail if someone requests an
impossible amount of kb.
> {
> long long unsigned int limit_in_bytes;
> int ret;
> @@ -915,7 +915,12 @@ 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;
> + {
> + if (limit_in_bytes != INT64_MAX)
> + *kb = (unsigned long long) limit_in_bytes >> 10;
This cast is not necessary, since limit_in_bytes is already ull.
Hi Eric,
Thanks for reviewing.
Here is the patch, now the set calls are also ull.
Still virCgroupGetMemoryUsage is not changed, this will require changes
in virDomainInfoPtr (info->memory). I am not sure if I should have them
in this patch.
From: Nikunj A. Dadhania <nikunj(a)linux.vnet.ibm.com>
Display unlimited when the memory cgroup settings says so. Unlimited is
represented by INT64_MAX in memory cgroup.
v3: Make virCgroupSet memory call ull
Signed-off-by: Nikunj A. Dadhania <nikunj(a)linux.vnet.ibm.com>
Reported-by: Justin Clift <jclift(a)redhat.com>
---
include/libvirt/libvirt.h.in | 1 +
src/lxc/lxc_driver.c | 2 +-
src/qemu/qemu_driver.c | 2 +-
src/util/cgroup.c | 45 +++++++++++++++++++++++++++++++++---------
src/util/cgroup.h | 14 +++++++------
tools/virsh.c | 9 +++++++-
6 files changed, 52 insertions(+), 21 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 3c6a54a..6475936 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -696,6 +696,7 @@ typedef enum {
*/
#define VIR_DOMAIN_MEMORY_FIELD_LENGTH 80
+#define VIR_DOMAIN_MEMORY_PARAM_UNLIMITED UINT64_MAX
/**
* VIR_DOMAIN_MEMORY_HARD_LIMIT:
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index eb58086..2db9954 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -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;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e915705..6648c6a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7077,7 +7077,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;
diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index 3ba6325..f8991cf 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -858,8 +858,11 @@ 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)
{
+ if (kb > (VIR_DOMAIN_MEMORY_PARAM_UNLIMITED >> 10))
+ return -EINVAL;
+
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.limit_in_bytes",
@@ -883,6 +886,7 @@ int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb)
"memory.usage_in_bytes", &usage_in_bytes);
if (ret == 0)
*kb = (unsigned long) usage_in_bytes >> 10;
+
return ret;
}
@@ -894,7 +898,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 +911,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 +919,12 @@ 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;
+ {
+ if (limit_in_bytes != INT64_MAX)
+ *kb = (unsigned long long) limit_in_bytes >> 10;
+ else
+ *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
+ }
return ret;
}
@@ -927,8 +936,11 @@ 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)
{
+ if (kb > (VIR_DOMAIN_MEMORY_PARAM_UNLIMITED >> 10))
+ return -EINVAL;
+
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.soft_limit_in_bytes",
@@ -944,7 +956,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 +964,12 @@ 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;
+ {
+ if (limit_in_bytes != INT64_MAX)
+ *kb = (unsigned long long) limit_in_bytes >> 10;
+ else
+ *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
+ }
return ret;
}
@@ -964,8 +981,11 @@ 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)
{
+ if (kb > (VIR_DOMAIN_MEMORY_PARAM_UNLIMITED >> 10))
+ return -EINVAL;
+
return virCgroupSetValueU64(group,
VIR_CGROUP_CONTROLLER_MEMORY,
"memory.memsw.limit_in_bytes",
@@ -980,7 +1000,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 +1008,12 @@ 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;
+ {
+ if (limit_in_bytes != INT64_MAX)
+ *kb = (unsigned long long) limit_in_bytes >> 10;
+ else
+ *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
+ }
return ret;
}
diff --git a/src/util/cgroup.h b/src/util/cgroup.h
index 9e1c61f..964da7a 100644
--- a/src/util/cgroup.h
+++ b/src/util/cgroup.h
@@ -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);
diff --git a/tools/virsh.c b/tools/virsh.c
index 55e2a68..2fff9f4 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2987,9 +2987,14 @@ 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\n", params[i].field,
+ params[i].value.ul);
break;
+ }
case VIR_DOMAIN_MEMORY_PARAM_DOUBLE:
vshPrint(ctl, "%-15s: %f\n", params[i].field,
params[i].value.d);