Skip to contentSkip to conversation

xen balloon driver numa support, libxl interface

RFC PATCH In review Yechen Li 4 participants 14 messages Aug 12, 2013 – Aug 13, 2013

lore
Share & tools
lore

Yechen Li

author
#0 lore raw

RFC PATCH 1/1 xen balloon driver numa support, libxl interface

---

This small patch implements a numa support of memory operation for libxl The command is: xl mem-set-numa [-e] vmid memorysize nodeid
To pass the parameters to balloon driver in kernel, I add a file of xen-store
as /local/domain/(id)/memory/target_nid, hoping this is ok....

It's my first time submitting a patch, please point out the problems so that
I could work better in future, thanks very much!

 tools/libxl/libxl.c       | 14 ++++++++++++--
 tools/libxl/libxl.h       |  1 +
 tools/libxl/xl.h          |  1 +
 tools/libxl/xl_cmdimpl.c  | 45 +++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/xl_cmdtable.c |  7 +++++++
 5 files changed, 66 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +12 -2
index 81785df..f027d59 100644
@@ -3642,10 +3642,17 @@ retry:
     }
     return 0;
 }
-
 int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid,
         int32_t target_memkb, int relative, int enforce)
 {
+    return libxl_set_memory_target_numa(ctx, domid, target_memkb, relative,
+                enforce, -1, 0);
+}
+
+int libxl_set_memory_target_numa(libxl_ctx *ctx, uint32_t domid,
+        int32_t target_memkb, int relative, int enforce,
+        int node_specify, bool nodeexact)
+{
     GC_INIT(ctx);
     int rc = 1, abort_transaction = 0;
     uint32_t memorykb = 0, videoram = 0;
@@ -3754,7 +3761,10 @@ retry_transaction:
         abort_transaction = 1;
         goto out;
     }
-
+    //lcc:
+    LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "target_nid = %d focus= %d", node_specify, (int) nodeexact);
+    libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target_nid",
+                dompath), "%"PRId32" %"PRId32, node_specify, (int)nodeexact);
     libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target",
                 dompath), "%"PRIu32, new_target_memkb);
     rc = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
tools/libxl/libxl.h +1 -0
index be19bf5..e21d8c3 100644
@@ -628,6 +628,7 @@ int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid,
 
 int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb);
 int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, int32_t target_memkb, int relative, int enforce);
+int libxl_set_memory_target_numa(libxl_ctx *ctx, uint32_t domid, int32_t target_memkb, int relative, int enforce, int node_specify, bool nodeexact);
 int libxl_get_memory_target(libxl_ctx *ctx, uint32_t domid, uint32_t *out_target);
 
 
tools/libxl/xl.h +1 -0
index e72a7d2..6e5873d 100644
@@ -62,6 +62,7 @@ int main_vcpupin(int argc, char **argv);
 int main_vcpuset(int argc, char **argv);
 int main_memmax(int argc, char **argv);
 int main_memset(int argc, char **argv);
+int main_memset_numa(int argc, char **argv);
 int main_sched_credit(int argc, char **argv);
 int main_sched_credit2(int argc, char **argv);
 int main_sched_sedf(int argc, char **argv);
tools/libxl/xl_cmdimpl.c +45 -0

51 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +7 -0
index 326a660..ab918c0 100644
@@ -199,6 +199,13 @@ struct cmd_spec cmd_table[] = {
       "Set the current memory usage for a domain",
       "<Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]>",
     },
+    { "mem-set-numa",
+        &main_memset_numa, 0, 1,
+        "Set the current memory usage for a domain, with numa node specified",
+        "[-e] <Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]> <nid>",
+        "-e, --exact: operatrion will force on this node exactly"
+        "nid: the machine(physical) node id\n"
+    },
     { "button-press",
       &main_button_press, 0, 1,
       "Indicate an ACPI button press to the domain",
Signature · 1 line
1.8.1.4
#1 lore raw
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Yechen Li

This small patch implements a numa support of memory operation for libxl The command is: xl mem-set-numa [-e] vmid memorysize nodeid To pass the parameters to balloon driver in kernel, I add a file of
xen-store
as /local/domain/(id)/memory/target_nid, hoping this is ok....

It's my first time submitting a patch, please point out the problems so
that I could work better in future, thanks very much!

The main problem here is the lack of a consumer of this ...

tools/libxl/libxl.c retry_transaction: · line 3767

Quoted 9 lines
tools/libxl/libxl.c +4 -1
@@ -3754,7 +3761,10 @@ retry_transaction:
         abort_transaction = 1;
         goto out;
     }
-
+    //lcc:
+    LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "target_nid = %d focus= %d", node_specify, (int) nodeexact);
+    libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target_nid",
+                dompath), "%"PRId32" %"PRId32, node_specify, (int)nodeexact);

... new Xenbus node. Without (so far) a true view into the host topology, even if you added a respective consumer to the balloon driver, how would that driver honor such a request? And even if it knew about host topology, unless the virtual topology in the subject domain sufficiently closely resembled the host's, it would - afaict - still have no way of obtaining suitable memory from the page allocator.

Jan

author
#2 lore raw

HI Jan,

Quoted 8 lines

... new Xenbus node. Without (so far) a true view into the host topology, even if you added a respective consumer to the balloon driver, how would that driver honor such a request? And even if it knew about host topology, unless the virtual topology in the subject domain sufficiently closely resembled the host's, it would - afaict - still have no way of obtaining suitable memory from the page allocator.

Do you mean the kernel part?
The modification of kernel is here:
http://lists.xenproject.org/archives/html/xen-devel/2013-08/msg01179.html
I still haven't find out how to generate two patches in one time....So I have to send two email, sorry

Quoted 36 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · Yechen Li

This small patch implements a numa support of memory operation for

libxl

Quoted 7 lines

The command is: xl mem-set-numa [-e] vmid memorysize nodeid To pass the parameters to balloon driver in kernel, I add a file of
xen-store
as /local/domain/(id)/memory/target_nid, hoping this is ok....

It's my first time submitting a patch, please point out the problems so
that I could work better in future, thanks very much!

The main problem here is the lack of a consumer of this ...

tools/libxl/libxl.c retry_transaction: · line 3765

Quoted 7 lines
tools/libxl/libxl.c +2 -1
@@ -3754,7 +3761,10 @@ retry_transaction:
         abort_transaction = 1;
         goto out;
     }
-
+    //lcc:
+    LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "target_nid = %d focus= %d",

node_specify, (int) nodeexact);

Review retry_transaction: · line 3767

Quoted 2 lines
(quoted diff) +2 -0
+    libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target_nid",
+                dompath), "%"PRId32" %"PRId32, node_specify,

(int)nodeexact);

... new Xenbus node. Without (so far) a true view into the host topology, even if you added a respective consumer to the balloon driver, how would that driver honor such a request? And even if it knew about host topology, unless the virtual topology in the subject domain sufficiently closely resembled the host's, it would - afaict - still have no way of obtaining suitable memory from the page allocator.

Jan

Signature · 8 lines
Yechen Li

Team of System Virtualization and Cloud Computing
School of Electronic Engineering  and Computer Science,
Peking University, China

Nothing is impossible because impossible itself  says: " I'm possible "
lccycc From PKU

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · Li Yechen

HI Jan,

Quoted 8 lines

... new Xenbus node. Without (so far) a true view into the host topology, even if you added a respective consumer to the balloon driver, how would that driver honor such a request? And even if it knew about host topology, unless the virtual topology in the subject domain sufficiently closely resembled the host's, it would - afaict - still have no way of obtaining suitable memory from the page allocator.

Quoted 5 lines

Do you mean the kernel part?
The modification of kernel is here:
http://lists.xenproject.org/archives/html/xen-devel/2013-08/msg01179.html
I still haven't find out how to generate two patches in one time....So I have to send two email, sorry

Sending two mails is fine - you just should have referred to the other one in the description.

But that kernel change is very bogus; first of all you need to clean it up to undo all the restoration of code that 3.11-rc changed. And then you'll need to explain what the correlation between virtual and physical node IDs is.

Jan

author
#4 lore raw
Quoted 5 lines

But that kernel change is very bogus; first of all you need to clean it up to undo all the restoration of code that 3.11-rc changed. And then you'll need to explain what the correlation between virtual and physical node IDs is.

Oh no! Acturally I start this work from 3.9 and do not notice that the code changes a little.....
Thank you very much I'll merge it right now.....
The relation between virtual and physical node IDs is belong to another guy's work, I think we could see her email soon.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#5 lore raw

OK...The different from 3.9 to 3.11 is only a litte log print....I have merge the code, it does not affect this patch...

Quoted 11 lines · Li Yechen

But that kernel change is very bogus; first of all you need

Quoted 3 lines

to clean it up to undo all the restoration of code that 3.11-rc changed. And then you'll need to explain what the correlation between virtual and physical node IDs is.

Oh no! Acturally I start this work from 3.9 and do not notice that the code changes a little.....
Thank you very much I'll merge it right now.....
The relation between virtual and physical node IDs is belong to another guy's work, I think we could see her email soon.

Signature · 8 lines
Yechen Li

Team of System Virtualization and Cloud Computing
School of Electronic Engineering  and Computer Science,
Peking University, China

Nothing is impossible because impossible itself  says: " I'm possible "
lccycc From PKU

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#6 lore raw
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Li Yechen

OK...The different from 3.9 to 3.11 is only a litte log print....I have merge the code, it does not affect this patch...

No - the patch you sent re-added things like explicit updating of totalram_pages and totalhigh_pages. This needs to be dropped; only then will it make sense to actually look at the patch.

Jan

#7 lore raw
In reply to Li Yechen

Hey, Yechen... Could you please switch to text-only e-mails? That would be much more respectful of the actual list etiquette, but most important it will all look a lot better looking when replying...

Quoted 9 lines · Li Yechen

But that kernel change is very bogus; first of all you need to clean it up to undo all the restoration of code that 3.11-rc
changed. And then you'll need to explain what the correlation between virtual and physical node IDs is.

The relation between virtual and physical node IDs is belong to another guy's work, I think we could see her email soon.

Well, although that's mostly true, I think it would not have harmed to have some sort of high level description of the overall design, trying to explain what the final goal is, who all the involved actors are, what role they play, etc.

Of course, I know all these kind of stuff, since you sent me in a private e-mail already, but can I ask you to come up with a summary of that, and attach it somehow to the public submission (a 0/xx message, even if this just a single patch, would have been great).

Thanks and Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#10 lore raw
In reply to Jan Beulich
Quoted 15 lines · Jan Beulich

tools/libxl/libxl.c retry_transaction: · line 3767

Quoted 10 lines
Quoted 1 line
Quoted 1 line · Yechen Li
tools/libxl/libxl.c +4 -1
@@ -3754,7 +3761,10 @@ retry_transaction:
         abort_transaction = 1;
         goto out;
     }
-
+    //lcc:
+    LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "target_nid = %d focus= %d", node_specify, (int) nodeexact);
+    libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target_nid",
+                dompath), "%"PRId32" %"PRId32, node_specify, (int)nodeexact);

... new Xenbus node. Without (so far) a true view into the host topology, even if you added a respective consumer to the balloon driver, how would that driver honor such a request?

Right. So, as I asked in another e-mail, Yechen, could you provide (either here or when submitting an new/updated version of the patch) some more details about the overall design, so that people wanting to review the patch could have an insight of the big picture? :-)

Really quickly, Jan, this is meant to be effective once:
1. we will have a way to specify and build a virtual NUMA topology for

    the guests;

2. we will have a way for a virtual NUMA enabled guest to figure out what physical host NUMA node X has the pages of its virtual NUMA node Y.

As Yechen said, Elena is working on the PV side of 1., while Matt has something for the HVM side of it. Once we will have both in place, we can figure out 2., and then have Yechen's work integrate with that all.

Yes, I know, sending this patch as the first item _is_ a bit confusing, but we thought that, since this involves new interfaces (e.g., the new xenstore node), it could be useful to start gathering some early feedback. :-)

Hope Yechen can explain the problem better, and make things even more clear.

Quoted 5 lines

And even if it knew about host topology, unless the virtual topology in the subject domain sufficiently closely resembled the host's, it would - afaict - still have no way of obtaining suitable memory from the page allocator.

Not sure I get entirely what you mean... Are you saying that, if the pages for a guest virtual NUMA node X come from multiple host nodes (instead than from just one single host NUMA node Y), this won't work properly?

If yes, well, I agree. In that case, we'll more or less fall back on what we have right now (and if that is not the case in the code, well, we should make it so), so no better, no worse, right? However, what about the case in which we do manage in putting a guest's virtual node onto a host's virtual node? That should work a lot better (than now), right?

In summary, this is meant at being a performance and resource optimization, for all the cases and setups where a specific set of conditions can be satisfied. I think this is the case for most performance and resource optimization, and I think this would be a nice one to have.

Thanks for your feedback and Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#11 lore raw
In reply to Yechen Li

Hello Yechen, nice to see you and your code here!! :-)

That's already a nice job as a first submission. See some comments about both the code and "the process" below and inline.

First of all, both xen-devel and LKML are very busy lists. One could think that people just read all the messages that come across, but, as a matter of fact, that is hardly the case. That's why you usually do not just send the e-mail(s) with the patch (series) to the list, but you also put the relevant people you want and need feedback from on Cc.

These "relevant people" are at least the maintainers of the subsystem you're modifying with your patches. In this case, your changes affects bits of the Xen toolsack, i.e., xl and libxl, so you should at least have the toolstack maintainers in Cc.

To figure out who they are, most projects have a MAINTAINERS file (both Xen and Linux does). If you look there you will fin out this entry:

TOOLSTACK

M:      Ian Jackson <ian_DOT_jackson_AT_eu.citrix.com>
M:      Stefano Stabellini <stefano_DOT_stabellini_AT_eu.citrix.com>
M:      Ian Campbell <ian_DOT_campbell_AT_citrix.com>
S:      Supported
F:      tools/

Meaning that what is under the 'tools/' directory, is under the responsibility of those three people, which are the ones you should have in the Cc list.

You may well put other people there too (provided you do not exaggerate! :-P). For instance, I'm taking care of NUMA in Xen, so you should have me there. Also, this patch couples with the other one for Linux, so you can have the Linux maintainers (that you will/would Cc to that one, and that would be Konrad) in Cc as well.

For this time, I did this for you (by replying to your e-mail and adding those people). Next time, don't forget to put them there yourself.

Quoted 2 lines · Yechen Li

---

That's weird... This really should not be here. Usually, what you have is:
- the changelog
- the "---"
- the diffstat.

Check out other submissions to xen-devel to see what I mean (e.g.,
http://comments.gmane.org/gmane.comp.emulators.xen.devel/165396 )

Perhaps something is not completely right with your git-format-patch/git-send-email settings or parameters?

Regarding the changelog here below, formatting is important, and you usually do not want any indentation (tools like git-log will put it there themselves), and you want lines there to be even shorter that 80 characters (for the exact same reason! :-D).

About the content:

Quoted 2 lines

This small patch implements a numa support of memory operation for libxl

Perhaps something like "This patch adds NUMA support to setting the memory target from libxl and xl"

Quoted 4 lines

The command is: xl mem-set-numa [-e] vmid memorysize nodeid
To pass the parameters to balloon driver in kernel, I add a file of xen-store
as /local/domain/(id)/memory/target_nid, hoping this is ok....

Although stuff like "hoping is ok" is fair for RFC patches or series, just make sure that, in future versions, that will no longer be RFCs, you do not put those kind of stuff in the actual changelogs, ok? :-P

Quoted 3 lines

It's my first time submitting a patch, please point out the problems so that
I could work better in future, thanks very much!

And the same applies to this hunk here. It is not at all required, but personally, when it comes to RFC, I always include a 0/XX message, right for hosting this kind of comments.

Not to mention that, as I said already in my other e-mail (while replying to Jan), you could have used it to specify some more details about the design, the final goal, etc., too.

Anyway: "please point out the problems so that I could work better in future" that's the right attitude, I really appreciate this!! :-P :-P

Quoted 7 lines
tools/libxl/libxl.c       | 14 ++++++++++++--
tools/libxl/libxl.h       |  1 +
tools/libxl/xl.h          |  1 +
tools/libxl/xl_cmdimpl.c  | 45 +++++++++++++++++++++++++++++++++++++++++++++
tools/libxl/xl_cmdtable.c |  7 +++++++
5 files changed, 66 insertions(+), 2 deletions(-)

About the splitting of this patch in an easier to review and to understand patch series, what about having two patches, one (the first in the series) modifying libxl, and another one modifying xl?

tools/libxl/libxl.c retry: · line 3645

Quoted 10 lines
tools/libxl/libxl.c +0 -1
index 81785df..f027d59 100644
@@ -3642,10 +3642,17 @@ retry:
     }
     return 0;
 }
-
 

Removing a white space could be a good thing, if having them there violates the coding style.

However, I don't think this is the case (i.e., this particular white space is fine where it is).

Also, even if it was the case, you do not want to mix coding style fixes with actual bug fixing or new features implementation.

tools/libxl/libxl.c retry:

Quoted 12 lines
tools/libxl/libxl.c +8 -0
 int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid,
         int32_t target_memkb, int relative, int enforce)
 {
+    return libxl_set_memory_target_numa(ctx, domid, target_memkb, relative,
+                enforce, -1, 0);
+}
+
+int libxl_set_memory_target_numa(libxl_ctx *ctx, uint32_t domid,
+        int32_t target_memkb, int relative, int enforce,
+        int node_specify, bool nodeexact)
+{
 

'node_specify' can probably be just 'node'. Actually, I'd probably change the name of the function itself to 'libxl_set_memory_target_node' instead of '_numa'.

Regarding 'nodeexact', see below.

tools/libxl/libxl.c retry_transaction: · line 3765

Quoted 10 lines
tools/libxl/libxl.c +0 -0
     GC_INIT(ctx);
     int rc = 1, abort_transaction = 0;
     uint32_t memorykb = 0, videoram = 0;
tools/libxl/libxl.c +1 -1
@@ -3754,7 +3761,10 @@ retry_transaction:
         abort_transaction = 1;
         goto out;
     }
-
+    //lcc:
 

Again, do not remove white spaces. Also, comments done via "//" are not welcome. I know this is an RFC, so no need to worry too much, this is just me trying to help you as much as I can to get next version in a better shape, ok? :-)

tools/libxl/libxl.c retry_transaction: · line 3767

Quoted 2 lines
tools/libxl/libxl.c +1 -0
+    LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "target_nid = %d focus= %d", node_specify, (int) nodeexact);
 

Casts are bad. They hide errors at either design and/or implementation level. There probably are cases where you can't avoid them (and you should document things being like that somehow, e.g., in code comments), but in general, you should think twice before introducing one, and see if you really can't accomplish the same without it.

Regarding this nodeexact thing, I wonder whether we could turn it into some kind of flag that you can || to 'node_specify' (or 'node'), similarly to what actually happens in Xen with MEMF_exact_node.

Notice that this is not because Xen's and libxl's interface needs to have these kinds of correlations and dependencies... It's just I think I'd like it better that way. :-)

tools/libxl/libxl.c retry_transaction:

Quoted 3 lines
tools/libxl/libxl.c +2 -0
+    libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target_nid",
+                dompath), "%"PRId32" %"PRId32, node_specify, (int)nodeexact);
 

Casts here too.

tools/libxl/libxl.h int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid, · line 632

Quoted 8 lines
tools/libxl/libxl.h +1 -0
@@ -628,6 +628,7 @@ int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid,
 
 int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb);
 int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, int32_t target_memkb, int relative, int enforce);
+int libxl_set_memory_target_numa(libxl_ctx *ctx, uint32_t domid, int32_t target_memkb, int relative, int enforce, int node_specify, bool nodeexact);
 

About names, see above. Also, this is a very long line. In general we want lines to break at (well, before!) 80 characters. I appreciate that this files have long lines already, but that does not mean that new code should make the situation worse! :-P

tools/libxl/xl.h int main_vcpupin(int argc, char **argv); · line 66

Quoted 13 lines
tools/libxl/libxl.h +0 -0
 int libxl_get_memory_target(libxl_ctx *ctx, uint32_t domid, uint32_t *out_target);
 
tools/libxl/xl.h +1 -0
index e72a7d2..6e5873d 100644
@@ -62,6 +62,7 @@ int main_vcpupin(int argc, char **argv);
 int main_vcpuset(int argc, char **argv);
 int main_memmax(int argc, char **argv);
 int main_memset(int argc, char **argv);
+int main_memset_numa(int argc, char **argv);
 

So, you are introducing a new command... Why not just add a "NUMA option"(something like '-n'/'--numa') to mem-set?

Either way, look at the docs/man directory in the source tree. You'll find a file called xl.pod.1, which hosts the manual page for `xl', in markdown format. When adding or changing something (and that applies to both the cases where you add a new command or a new option), you should update that file too, to account for the new feature (or reflect the new behavior).

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +4 -0
@@ -2523,6 +2523,51 @@ int main_memset(int argc, char **argv)
     return 0;
 }
 
+static void set_memory_target_numa(uint32_t domid, const char *mem, int mnid, bool nodeexact)
+{
+    long long int memorykb;
+

tools/libxl/xl_cmdimpl.c int main_memset(int argc, char **argv) · line 2539

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +9 -0
+    memorykb = parse_mem_size_kb(mem);
+    if (memorykb == -1)  {
+        fprintf(stderr, "invalid memory size: %s\n", mem);
+        exit(3);
+    }
+
+    libxl_set_memory_target_numa(ctx, domid, memorykb, 0, /* enforce */ 1, mnid, nodeexact);
+}
+
 

This is really similar to set_memory_target. Merging the two will avoid code duplication.

Quoted 18 lines
tools/libxl/xl_cmdimpl.c +18 -0
+int main_memset_numa(int argc, char **argv)
+{
+    uint32_t domid;
+    int opt = 0;
+    int mnid = -1;
+    const char *mem;
+    bool nodeexact = false;
+    static const struct option opts[] = {
+        {"exact", 0, 0, 'e'},
+        COMMON_LONG_OPTS,
+        {0, 0, 0, 0}
+    };
+
+    SWITCH_FOREACH_OPT(opt, "e", opts, "mem-set-numa", 1) {
+    case 'e':
+        nodeexact = true;
+        break;
+    }

tools/libxl/xl_cmdimpl.c int main_memset(int argc, char **argv)

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +9 -0
+    if (argc < optind + 3){
+        help("mem-set-numa");
+        return 2;
+    }
+    domid = find_domain(argv[optind]);
+    mem = argv[optind + 1];
+    if (sscanf(argv[optind + 2], "%d", &mnid) != 1){
+        fprintf(stderr, "invalid node id");
+    }
 

If you make this all a mode of operation of the existing mem-set, this will get easier and prettier, as you may rely on the option handling machinery to retrieve the node-ID argument, instead of having to manually fidle with optind, argv, sscanf, etc.

tools/libxl/xl_cmdimpl.c int main_memset(int argc, char **argv) · line 2569

Quoted 2 lines
tools/libxl/xl_cmdimpl.c +1 -0
+    fprintf(stderr, "nodeexact = %d domid = %d mem = %s mnid = %d\n", nodeexact, domid, mem, mnid);
 

This 'fprintf' is debug output, right? Make sure that future non-RFC versions does not have this, or that you gate it properly.

So, you tell me now... Was the feedback useful? :-D

Anyway, thanks a lot for doing and sharing this. I know it's a bit hard the first times, but if you keep going, you'll get used to it soon enough!

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#12 lore raw
In reply to Yechen Li

[Adding potentially interested people in Cc: the Ian-s are the toolstack maintainers, Elena is there because her work on PV-NUMA is somewhat related, Konrad is there because of the Linux implications of this]

Quoted 150 lines · Yechen Li

---

This small patch implements a numa support of memory operation for libxl The command is: xl mem-set-numa [-e] vmid memorysize nodeid
To pass the parameters to balloon driver in kernel, I add a file of xen-store
as /local/domain/(id)/memory/target_nid, hoping this is ok....

It's my first time submitting a patch, please point out the problems so that
I could work better in future, thanks very much!

 tools/libxl/libxl.c       | 14 ++++++++++++--
 tools/libxl/libxl.h       |  1 +
 tools/libxl/xl.h          |  1 +
 tools/libxl/xl_cmdimpl.c  | 45 +++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/xl_cmdtable.c |  7 +++++++
 5 files changed, 66 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +12 -2
index 81785df..f027d59 100644
@@ -3642,10 +3642,17 @@ retry:
     }
     return 0;
 }
-
 int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid,
         int32_t target_memkb, int relative, int enforce)
 {
+    return libxl_set_memory_target_numa(ctx, domid, target_memkb, relative,
+                enforce, -1, 0);
+}
+
+int libxl_set_memory_target_numa(libxl_ctx *ctx, uint32_t domid,
+        int32_t target_memkb, int relative, int enforce,
+        int node_specify, bool nodeexact)
+{
     GC_INIT(ctx);
     int rc = 1, abort_transaction = 0;
     uint32_t memorykb = 0, videoram = 0;
@@ -3754,7 +3761,10 @@ retry_transaction:
         abort_transaction = 1;
         goto out;
     }
-
+    //lcc:
+    LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "target_nid = %d focus= %d", node_specify, (int) nodeexact);
+    libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target_nid",
+                dompath), "%"PRId32" %"PRId32, node_specify, (int)nodeexact);
     libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target",
                 dompath), "%"PRIu32, new_target_memkb);
     rc = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
tools/libxl/libxl.h +1 -0
index be19bf5..e21d8c3 100644
@@ -628,6 +628,7 @@ int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid,
 
 int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb);
 int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, int32_t target_memkb, int relative, int enforce);
+int libxl_set_memory_target_numa(libxl_ctx *ctx, uint32_t domid, int32_t target_memkb, int relative, int enforce, int node_specify, bool nodeexact);
 int libxl_get_memory_target(libxl_ctx *ctx, uint32_t domid, uint32_t *out_target);
 
 
tools/libxl/xl.h +1 -0
index e72a7d2..6e5873d 100644
@@ -62,6 +62,7 @@ int main_vcpupin(int argc, char **argv);
 int main_vcpuset(int argc, char **argv);
 int main_memmax(int argc, char **argv);
 int main_memset(int argc, char **argv);
+int main_memset_numa(int argc, char **argv);
 int main_sched_credit(int argc, char **argv);
 int main_sched_credit2(int argc, char **argv);
 int main_sched_sedf(int argc, char **argv);
tools/libxl/xl_cmdimpl.c +45 -0
index 884f050..ddfb0d5 100644
@@ -2523,6 +2523,51 @@ int main_memset(int argc, char **argv)
     return 0;
 }
 
+static void set_memory_target_numa(uint32_t domid, const char *mem, int mnid, bool nodeexact)
+{
+    long long int memorykb;
+
+    memorykb = parse_mem_size_kb(mem);
+    if (memorykb == -1)  {
+        fprintf(stderr, "invalid memory size: %s\n", mem);
+        exit(3);
+    }
+
+    libxl_set_memory_target_numa(ctx, domid, memorykb, 0, /* enforce */ 1, mnid, nodeexact);
+}
+
+int main_memset_numa(int argc, char **argv)
+{
+    uint32_t domid;
+    int opt = 0;
+    int mnid = -1;
+    const char *mem;
+    bool nodeexact = false;
+    static const struct option opts[] = {
+        {"exact", 0, 0, 'e'},
+        COMMON_LONG_OPTS,
+        {0, 0, 0, 0}
+    };
+
+    SWITCH_FOREACH_OPT(opt, "e", opts, "mem-set-numa", 1) {
+    case 'e':
+        nodeexact = true;
+        break;
+    }
+    if (argc < optind + 3){
+        help("mem-set-numa");
+        return 2;
+    }
+    domid = find_domain(argv[optind]);
+    mem = argv[optind + 1];
+    if (sscanf(argv[optind + 2], "%d", &mnid) != 1){
+        fprintf(stderr, "invalid node id");
+    }
+    fprintf(stderr, "nodeexact = %d domid = %d mem = %s mnid = %d\n", nodeexact, domid, mem, mnid);
+    set_memory_target_numa(domid, mem, mnid, nodeexact);
+    return 0;
+}
+
 static int cd_insert(uint32_t domid, const char *virtdev, char *phys)
 {
     libxl_device_disk disk; /* we don't free disk's contents */
tools/libxl/xl_cmdtable.c +7 -0
index 326a660..ab918c0 100644
@@ -199,6 +199,13 @@ struct cmd_spec cmd_table[] = {
       "Set the current memory usage for a domain",
       "<Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]>",
     },
+    { "mem-set-numa",
+        &main_memset_numa, 0, 1,
+        "Set the current memory usage for a domain, with numa node specified",
+        "[-e] <Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]> <nid>",
+        "-e, --exact: operatrion will force on this node exactly"
+        "nid: the machine(physical) node id\n"
+    },
     { "button-press",
       &main_button_press, 0, 1,
       "Indicate an ACPI button press to the domain",
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#13 lore raw
In reply to Yechen Li
Quoted 6 lines · Yechen Li

---

This small patch implements a numa support of memory operation for libxl The command is: xl mem-set-numa [-e] vmid memorysize nodeid
To pass the parameters to balloon driver in kernel, I add a file of xen-store
as /local/domain/(id)/memory/target_nid, hoping this is ok....

It might be OK if you document it in docs/misc/xenstore-paths.markdown.

Quoted 2 lines

It's my first time submitting a patch, please point out the problems so that
I could work better in future, thanks very much!

Please see http://wiki.xen.org/wiki/Submitting_Xen_Patches, in particular the bit about Signed-off-by.

Quoted 32 lines
 tools/libxl/libxl.c       | 14 ++++++++++++--
 tools/libxl/libxl.h       |  1 +
 tools/libxl/xl.h          |  1 +
 tools/libxl/xl_cmdimpl.c  | 45 +++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/xl_cmdtable.c |  7 +++++++
 5 files changed, 66 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +8 -1
index 81785df..f027d59 100644
@@ -3642,10 +3642,17 @@ retry:
     }
     return 0;
 }
-
 int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid,
         int32_t target_memkb, int relative, int enforce)
 {
+    return libxl_set_memory_target_numa(ctx, domid, target_memkb, relative,
+                enforce, -1, 0);
+}
+
+int libxl_set_memory_target_numa(libxl_ctx *ctx, uint32_t domid,
+        int32_t target_memkb, int relative, int enforce,
+        int node_specify, bool nodeexact)
+{
     GC_INIT(ctx);
     int rc = 1, abort_transaction = 0;
     uint32_t memorykb = 0, videoram = 0;

tools/libxl/libxl.c retry_transaction: · line 3764

Quoted 5 lines
tools/libxl/libxl.c +1 -1
@@ -3754,7 +3761,10 @@ retry_transaction:
         abort_transaction = 1;
         goto out;
     }
-
+    //lcc:

Please don't leave debug dropping in place.

Quoted 11 lines
tools/libxl/libxl.c +3 -0
+    LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "target_nid = %d focus= %d", node_specify, (int) nodeexact);
+    libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target_nid",
+                dompath), "%"PRId32" %"PRId32, node_specify, (int)nodeexact);
     libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target",
                 dompath), "%"PRIu32, new_target_memkb);
     rc = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
tools/libxl/libxl.h +0 -0
index be19bf5..e21d8c3 100644

tools/libxl/libxl.h int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid, · line 631

Quoted 4 lines
tools/libxl/libxl.h +1 -0
@@ -628,6 +628,7 @@ int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid,
 
 int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb);
 int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, int32_t target_memkb, int relative, int enforce);
+int libxl_set_memory_target_numa(libxl_ctx *ctx, uint32_t domid, int32_t target_memkb, int relative, int enforce, int node_specify, bool nodeexact);

This needs a LIBXL_HAVE style declaration. I'm unsure about adding another function as opposed to extending the current ABI using the LIBXL_API_VERSION compatibility provisions.

tools/libxl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 202

Quoted 9 lines
tools/libxl/xl_cmdtable.c +1 -0
index 326a660..ab918c0 100644
@@ -199,6 +199,13 @@ struct cmd_spec cmd_table[] = {
       "Set the current memory usage for a domain",
       "<Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]>",
     },
+    { "mem-set-numa",

Perhaps instead of adding a new function the existing mem-set should take a -n <node> parameter?

tools/libxl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 206

Quoted 4 lines
tools/libxl/xl_cmdtable.c +4 -0
+        &main_memset_numa, 0, 1,
+        "Set the current memory usage for a domain, with numa node specified",
+        "[-e] <Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]> <nid>",
+        "-e, --exact: operatrion will force on this node exactly"

"operation"

Quoted 5 lines
tools/libxl/xl_cmdtable.c +2 -0
+        "nid: the machine(physical) node id\n"
+    },
     { "button-press",
       &main_button_press, 0, 1,
       "Indicate an ACPI button press to the domain",
#8 lore raw
In reply to Dario Faggioli
Quoted 11 lines · Dario Faggioli

Hey, Yechen... Could you please switch to text-only e-mails? That would be much more respectful of the actual list etiquette, but most important it will all look a lot better looking when replying...

Quoted 6 lines · Li Yechen

But that kernel change is very bogus; first of all you need to clean it up to undo all the restoration of code that 3.11-rc
changed. And then you'll need to explain what the correlation between virtual and physical node IDs is.

Quoted 7 lines
Quoted 3 lines

The relation between virtual and physical node IDs is belong to another guy's work, I think we could see her email soon.

Well, although that's mostly true, I think it would not have harmed to have some sort of high level description of the overall design, trying to explain what the final goal is, who all the involved actors are, what role they play, etc.

Yechen,

If there are, as it sounds, several different patches from different people within the group needed to implement this feature then please could one of you take responsibility for combining them into a single (or at most two, one xen.git and one linux.git) coherent series which contains everything such that reviewers can get the whole picture.

Ian.

#9 lore raw
Quoted 10 lines · Ian Campbell
Quoted 8 lines · Dario Faggioli
Quoted 3 lines · Li Yechen

The relation between virtual and physical node IDs is belong to another guy's work, I think we could see her email soon.

Well, although that's mostly true, I think it would not have harmed to have some sort of high level description of the overall design, trying to explain what the final goal is, who all the involved actors are, what role they play, etc.

Quoted 8 lines

Yechen,

If there are, as it sounds, several different patches from different people within the group needed to implement this feature then please could one of you take responsibility for combining them into a single (or at most two, one xen.git and one linux.git) coherent series which contains everything such that reviewers can get the whole picture.

Yes, Ian, that is pretty much what is going on. Different people working on different features that are mostly independent but have some inter-dependencies.

We will definitely put things in such a way that the complete picture could be available and evident as soon as possible, however, that is not possible right now.

The reason why Yechen submitted this series, even if a fundamental building block of it (virtual NUMA topology for guests) is still missing, is that we thought that there was enough bits of _his_own_work_ --i.e., NUMA-aware ballooning-- in place already, for starting chasing a bit of feedback, at least on the design of NUMA-aware ballooning itself.

For instance, he has designed it in such a way that it is the higher toolstack layers (or the user, via xl) that are responsible for deciding on what physical NUMA node we want some free memory, is that a good approach? He is doing that by adding a new xenstore node, is that the right interface? And so on and so forth...

So, basically, we figured that it was worth to try getting an early enough answer for this kind of questions, especially considering that he also had some RFC level code that could well exemplify the design itself. Of course, as other are rightfully pointed out already, when submitting the RFCs, he failed at describing the complete design, the motivations and the intended usage of the code he was posting, and we are sorry and are already addressing this. :-)

To be really honest, I think this is the biggest issue with this patches, much more than the fact that some enabling feature/code for it is still missing. IOW, even if all the bit and pieces were there, it would be very hard to review the code without such an high level explanation of how it is intended to be used anyway, wouldn't it? And as I said, we're down to fix that.

I hope I clarified the situation at least a bit... In any case, thanks for having a look at it, and for your suggestion, that I personally commit to make happen, as soon as all the code will be there (and as soon as I come back from my summer vacations which are starting in two days :-P).

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel