[libvirt] [PATCH] memtune: Let virsh know the unlimited value for memory tunables

Nikunj A. Dadhania nikunj at linux.vnet.ibm.com
Tue Jan 11 05:18:27 UTC 2011


On Mon, 10 Jan 2011 12:02:36 -0700, Eric Blake <eblake at redhat.com> wrote:
> On 01/07/2011 12:09 AM, Nikunj A. Dadhania wrote:
> > From: Nikunj A. Dadhania <nikunj at linux.vnet.ibm.com>
> > 
> > Display unlimited when the memory cgroup settings says so. Unlimited is
> > represented by INT64_MAX in memory cgroup.
> > 
> > Signed-off-by: Nikunj A. Dadhania <nikunj at linux.vnet.ibm.com>
> > Reported-by: Justin Clift <jclift at redhat.com>
> > ---
> >  tools/virsh.c |   10 ++++++++--
> >  1 files changed, 8 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/virsh.c b/tools/virsh.c
> > index 55e2a68..bee875c 100644
> > --- a/tools/virsh.c
> > +++ b/tools/virsh.c
> > @@ -2987,9 +2987,15 @@ 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);
> > +                {
> > +                    unsigned long long max_kbytes = INT64_MAX >> 10;
> 
> Yuck - why do the clients have to know the magic value?  
Realised this but was late, and did not send a following patch :(

> Why not patch
> the source to actually return INT64_MAX rather than INT64_MAX>>10 when
> returning unlimited?
>
> Actually, due to the issue of cross-versioning between virsh and the
> actual libvirt running, we may have to check for both values.  But even
> having a constant (VIR_DOMAIN_MEMORY_PARAM_UNLIMITED) rather than making
> guests recompute things might be nice.
> 
I like this option of having a constant and here is the patch.

From: Nikunj A. Dadhania <nikunj at linux.vnet.ibm.com>

Display unlimited when the memory cgroup settings says so. Unlimited is
represented by INT64_MAX in memory cgroup.

Signed-off-by: Nikunj A. Dadhania <nikunj at linux.vnet.ibm.com>
Reported-by: Justin Clift <jclift at redhat.com>
---
 include/libvirt/libvirt.h.in |    1 +
 src/lxc/lxc_driver.c         |    2 +-
 src/qemu/qemu_driver.c       |    2 +-
 src/util/cgroup.c            |   27 +++++++++++++++++++++------
 src/util/cgroup.h            |    6 +++---
 tools/virsh.c                |    9 +++++++--
 6 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 3c6a54a..cb53f6b 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..c81ebba 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -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)
 {
     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;
+        else
+            *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
+    }
     return ret;
 }
 
@@ -944,7 +949,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 +957,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;
 }
 
@@ -980,7 +990,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 +998,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..2769676 100644
--- a/src/util/cgroup.h
+++ b/src/util/cgroup.h
@@ -44,11 +44,11 @@ int virCgroupSetMemory(virCgroupPtr group, unsigned long kb);
 int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);
 
 int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long kb);
-int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long *kb);
+int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb);
 int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long kb);
-int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long *kb);
+int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb);
 int virCgroupSetSwapHardLimit(virCgroupPtr group, unsigned long kb);
-int virCgroupGetSwapHardLimit(virCgroupPtr group, unsigned 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);




More information about the libvir-list mailing list