Skip to contentSkip to conversation

More vNUMA fixes

PATCH In review Wei Liu 2 participants 8 messages Aug 17, 2015 – Aug 21, 2015

lore
Share & tools
lore
author
#1 lore raw

PATCH v3 1/3 xl: fix vNUMA vdistance parsing

In reply to Wei Liu

We should parse the output from splitting function, not the original string, otherwise the parsed result is wrong.

For example:

vnuma = [ [...,"vdistance=10,20",...],

          [...,"vdistance=20,10",...] ]

Before this change, vdistance from node 0 to all nodes (including itself) was 10 and vdistance from node 1 to all nodes was 20.

After this change, vdistance from node 0 to itself is 10, to node 1 is 20 and vdistance from node 1 to node 0 is 20, to itself is 10. That's the correct vdistance settings we expect.

---
v3: better commit message

---
 tools/libxl/xl_cmdimpl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/xl_cmdimpl.c +1 -1
index c6b0b68..44fff82 100644
@@ -1188,7 +1188,7 @@ static void parse_vnuma_config(const XLU_Config *config,
                     len = libxl_string_list_length(&vdist);
 
                     for (j = 0; j < len; j++) {
-                        val = parse_ulong(value);
+                        val = parse_ulong(vdist[j]);
                         p->distances[j] = val;
                     }
                     libxl_string_list_dispose(&vdist);
Signature · 1 line
2.1.4
author
#3 lore raw

PATCH v3 2/3 xl: error out if vNUMA specifies more vcpus than pcpus

In reply to Wei Liu

... but allow user to override that check by specifying maxvcpus= in xl configuration file.

Note that the code is constructed such that the fallout is dealt with after parsing. We can live with that because though it wastes a bit of cpu cycles but it is still functionally correct and I would like to have a clear split between parsing and dealing with fallouts.

---
 tools/libxl/xl_cmdimpl.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)
tools/libxl/xl_cmdimpl.c +28 -4
index 44fff82..ebbb9a5 100644
@@ -1175,6 +1175,14 @@ static void parse_vnuma_config(const XLU_Config *config,
                     for (j = 0; j < len; j++) {
                         parse_range(cpu_spec_list[j], &s, &e);
                         for (; s <= e; s++) {
+                            /*
+                             * Note that if we try to set a bit beyond
+                             * the size of bitmap, libxl_bitmap_set
+                             * has no effect. The resulted bitmap
+                             * doesn't reflect what user wants. The
+                             * fallout is dealt with later after
+                             * parsing.
+                             */
                             libxl_bitmap_set(&vcpu_parsed[i], s);
                             max_vcpus++;
                         }
@@ -1202,11 +1210,27 @@ static void parse_vnuma_config(const XLU_Config *config,
     }
 
     /* User has specified maxvcpus= */
-    if (b_info->max_vcpus != 0 &&  b_info->max_vcpus != max_vcpus) {
-        fprintf(stderr, "xl: vnuma vcpus and maxvcpus= mismatch\n");
-        exit(1);
-    } else
+    if (b_info->max_vcpus != 0) {
+        if (b_info->max_vcpus != max_vcpus) {
+            fprintf(stderr, "xl: vnuma vcpus and maxvcpus= mismatch\n");
+            exit(1);
+        }
+    } else {
+        int host_cpus = libxl_get_online_cpus(ctx);
+
+        if (host_cpus < 0) {
+            fprintf(stderr, "Failed to get online cpus\n");
+            exit(1);
+        }
+
+        if (host_cpus < max_vcpus) {
+            fprintf(stderr, "xl: vnuma specifies more vcpus than pcpus, "\
+                    "use maxvcpus= to override this check.\n");
+            exit(1);
+        }
+
         b_info->max_vcpus = max_vcpus;
+    }
 
     /* User has specified maxmem= */
     if (b_info->max_memkb != LIBXL_MEMKB_DEFAULT &&
Signature · 1 line
2.1.4
author
#5 lore raw

PATCH v3 3/3 libxc: fix vNUMA memory allocation

In reply to Wei Liu

Only 4KB allocation was using new_memflags. We should use new_memflags in for 2MB and 1GB allocation as well because that variable contains node information.

Without this patch, when creating a HVM guest with vNUMA, because the node information was not present in the flags passed to libxc, actual memory allocation didn't comply with what user specified. With this patch the behaviour is correct.

---
v3: better commit message

---
 tools/libxc/xc_hvm_build_x86.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/libxc/xc_hvm_build_x86.c +4 -2
index ec11f15..ea250dd 100644
@@ -486,7 +486,8 @@ static int setup_guest(xc_interface *xch,
 
                 done = xc_domain_populate_physmap(xch, dom, nr_extents,
                                                   SUPERPAGE_1GB_SHIFT,
-                                                  memflags, sp_extents);
+                                                  new_memflags,
+                                                  sp_extents);
 
                 if ( done > 0 )
                 {
@@ -526,7 +527,8 @@ static int setup_guest(xc_interface *xch,
 
                     done = xc_domain_populate_physmap(xch, dom, nr_extents,
                                                       SUPERPAGE_2MB_SHIFT,
-                                                      memflags, sp_extents);
+                                                      new_memflags,
+                                                      sp_extents);
 
                     if ( done > 0 )
                     {
Signature · 1 line
2.1.4

Wei Liu

author
#0 lore raw

v3 cover More vNUMA fixes

Wei Liu (3):
xl: fix vNUMA vdistance parsing
xl: error out if vNUMA specifies more vcpus than pcpus
libxc: fix vNUMA memory allocation

 tools/libxc/xc_hvm_build_x86.c |  6 ++++--
 tools/libxl/xl_cmdimpl.c       | 34 +++++++++++++++++++++++++++++-----
 2 files changed, 33 insertions(+), 7 deletions(-)
Signature · 1 line
2.1.4
Acked-by on v3 1/3
#2 lore raw

Re: [PATCH for-4.6 v3 1/3] xl: fix vNUMA vdistance parsing

In reply to Wei Liu
Quoted 11 lines · Wei Liu

We should parse the output from splitting function, not the original string, otherwise the parsed result is wrong.

For example:

vnuma = [ [...,"vdistance=10,20",...],

          [...,"vdistance=20,10",...] ]

Before this change, vdistance from node 0 to all nodes (including itself) was 10 and vdistance from node 1 to all nodes was 20.

Quoted 7 lines

After this change, vdistance from node 0 to itself is 10, to node 1 is
20 and vdistance from node 1 to node 0 is 20, to itself is 10. That's the correct vdistance settings we expect.

Acked-by on v3 3/3
#6 lore raw

Re: [PATCH for-4.6 v3 3/3] libxc: fix vNUMA memory allocation

In reply to Wei Liu
Quoted 10 lines · Wei Liu

Only 4KB allocation was using new_memflags. We should use new_memflags
in for 2MB and 1GB allocation as well because that variable contains node information.

Without this patch, when creating a HVM guest with vNUMA, because the node information was not present in the flags passed to libxc, actual memory allocation didn't comply with what user specified. With this patch the behaviour is correct.

Quoted 4 lines
Acked-by on v3 2/3
#4 lore raw

Re: [PATCH for-4.6 v3 2/3] xl: error out if vNUMA specifies more vcpus than pcpus

In reply to Wei Liu
Quoted 11 lines · Wei Liu

... but allow user to override that check by specifying maxvcpus= in xl
configuration file.

Note that the code is constructed such that the fallout is dealt with after parsing. We can live with that because though it wastes a bit of
cpu cycles but it is still functionally correct and I would like to have
a clear split between parsing and dealing with fallouts.

Quoted 2 lines
#7 lore raw
In reply to Wei Liu
Quoted 5 lines · Wei Liu

Wei Liu (3):
xl: fix vNUMA vdistance parsing
xl: error out if vNUMA specifies more vcpus than pcpus
libxc: fix vNUMA memory allocation

All applied, thanks.