Xen-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: xen-devel@lists.xen.org
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>, Jan Beulich <JBeulich@suse.com>
Subject: [PATCH v8 01/21] xen: make two memory hypercalls vNUMA-aware
Date: Mon, 16 Mar 2015 09:52:20 +0000	[thread overview]
Message-ID: <1426499560-28514-2-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1426499560-28514-1-git-send-email-wei.liu2@citrix.com>

Make XENMEM_increase_reservation and XENMEM_populate_physmap
vNUMA-aware.

That is, if guest requests Xen to allocate memory for specific vnode,
Xen can translate vnode to pnode using vNUMA information of that guest.

XENMEMF_vnode is introduced for the guest to mark the node number is in
fact virtual node number and should be translated by Xen.

XENFEAT_memory_op_vnode_supported is introduced to indicate that Xen is
able to translate virtual node to physical node.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
Changes in v8:
1. Move all "args.* = " after construct_memop_from_reservation.

Changes in v7:
1. Remove XEN_NUMA_NO_NODE.
2. Use nodeid_t for vnode and pnode variables.

Changes in v6:
1. Add logic in construct_memop_from_reservation.
---
 xen/common/kernel.c           |  2 +-
 xen/common/memory.c           | 60 +++++++++++++++++++++++++++++++++----------
 xen/include/public/features.h |  3 +++
 xen/include/public/memory.h   |  2 ++
 4 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 8a04d8b..6f359c1 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -307,7 +307,7 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         switch ( fi.submap_idx )
         {
         case 0:
-            fi.submap = 0;
+            fi.submap = (1U << XENFEAT_memory_op_vnode_supported);
             if ( VM_ASSIST(d, VMASST_TYPE_pae_extended_cr3) )
                 fi.submap |= (1U << XENFEAT_pae_pgdir_above_4gb);
             if ( paging_mode_translate(current->domain) )
diff --git a/xen/common/memory.c b/xen/common/memory.c
index 9d9d43c..0737811 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -692,11 +692,12 @@ out:
     return rc;
 }
 
-static int construct_memop_from_reservation(
+static int construct_memop_from_reservation(struct domain *d,
                const struct xen_memory_reservation *r,
                struct memop_args *a)
 {
     unsigned int address_bits;
+    int rc;
 
     a->extent_list  = r->extent_start;
     a->nr_extents   = r->nr_extents;
@@ -712,11 +713,41 @@ static int construct_memop_from_reservation(
         a->memflags = MEMF_bits(address_bits);
     }
 
-    a->memflags |= MEMF_node(XENMEMF_get_node(r->mem_flags));
-    if ( r->mem_flags & XENMEMF_exact_node_request )
-        a->memflags |= MEMF_exact_node;
+    if ( r->mem_flags & XENMEMF_vnode )
+    {
+        nodeid_t vnode, pnode;
 
-    return 0;
+        read_lock(&d->vnuma_rwlock);
+        if ( d->vnuma )
+        {
+            vnode = XENMEMF_get_node(r->mem_flags);
+            if ( vnode >= d->vnuma->nr_vnodes )
+            {
+                rc = -EINVAL;
+                read_unlock(&d->vnuma_rwlock);
+                goto out;
+            }
+
+            pnode = d->vnuma->vnode_to_pnode[vnode];
+            if ( pnode != NUMA_NO_NODE )
+            {
+                a->memflags |= MEMF_node(pnode);
+                if ( r->mem_flags & XENMEMF_exact_node_request )
+                    a->memflags |= MEMF_exact_node;
+            }
+        }
+        read_unlock(&d->vnuma_rwlock);
+    }
+    else
+    {
+        a->memflags |= MEMF_node(XENMEMF_get_node(r->mem_flags));
+        if ( r->mem_flags & XENMEMF_exact_node_request )
+            a->memflags |= MEMF_exact_node;
+    }
+
+    rc = 0;
+out:
+    return rc;
 }
 
 long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
@@ -744,21 +775,24 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( unlikely(start_extent >= reservation.nr_extents) )
             return start_extent;
 
-        if ( construct_memop_from_reservation(&reservation, &args) )
+        d = rcu_lock_domain_by_any_id(reservation.domid);
+        if ( d == NULL )
+            return start_extent;
+
+        if ( construct_memop_from_reservation(d, &reservation, &args) )
+        {
+            rcu_unlock_domain(d);
             return start_extent;
-        args.nr_done      = start_extent;
-        args.preempted    = 0;
+        }
 
+        args.domain    = d;
+        args.nr_done   = start_extent;
+        args.preempted = 0;
 
         if ( op == XENMEM_populate_physmap
              && (reservation.mem_flags & XENMEMF_populate_on_demand) )
             args.memflags |= MEMF_populate_on_demand;
 
-        d = rcu_lock_domain_by_any_id(reservation.domid);
-        if ( d == NULL )
-            return start_extent;
-        args.domain = d;
-
         if ( xsm_memory_adjust_reservation(XSM_TARGET, current->domain, d) )
         {
             rcu_unlock_domain(d);
diff --git a/xen/include/public/features.h b/xen/include/public/features.h
index 16d92aa..2110b04 100644
--- a/xen/include/public/features.h
+++ b/xen/include/public/features.h
@@ -99,6 +99,9 @@
 #define XENFEAT_grant_map_identity        12
  */
 
+/* Guest can use XENMEMF_vnode to specify virtual node for memory op. */
+#define XENFEAT_memory_op_vnode_supported 13
+
 #define XENFEAT_NR_SUBMAPS 1
 
 #endif /* __XEN_PUBLIC_FEATURES_H__ */
diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h
index 595f953..2b5206b 100644
--- a/xen/include/public/memory.h
+++ b/xen/include/public/memory.h
@@ -55,6 +55,8 @@
 /* Flag to request allocation only from the node specified */
 #define XENMEMF_exact_node_request  (1<<17)
 #define XENMEMF_exact_node(n) (XENMEMF_node(n) | XENMEMF_exact_node_request)
+/* Flag to indicate the node specified is virtual node */
+#define XENMEMF_vnode  (1<<18)
 #endif
 
 struct xen_memory_reservation {
-- 
1.9.1

  reply	other threads:[~2015-03-16  9:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-16  9:52 [PATCH v8 00/21] Virtual NUMA for PV and HVM Wei Liu
2015-03-16  9:52 ` Wei Liu [this message]
2015-03-16  9:52 ` [PATCH v8 02/21] libxc: duplicate snippet to allocate p2m_host array Wei Liu
2015-03-16  9:52 ` [PATCH v8 03/21] libxc: add p2m_size to xc_dom_image Wei Liu
2015-03-16  9:52 ` [PATCH v8 04/21] libxc: allocate memory with vNUMA information for PV guest Wei Liu
2015-03-16  9:52 ` [PATCH v8 05/21] libxl: introduce vNUMA types Wei Liu
2015-03-16  9:52 ` [PATCH v8 06/21] libxl: add vmemrange to libxl__domain_build_state Wei Liu
2015-03-16  9:52 ` [PATCH v8 07/21] libxl: introduce libxl__vnuma_config_check Wei Liu
2015-03-16  9:52 ` [PATCH v8 08/21] libxl: x86: factor out e820_host_sanitize Wei Liu
2015-03-16  9:52 ` [PATCH v8 09/21] libxl: functions to build vmemranges for PV guest Wei Liu
2015-03-16  9:52 ` [PATCH v8 10/21] libxl: build, check and pass vNUMA info to Xen " Wei Liu
2015-03-16  9:52 ` [PATCH v8 11/21] libxc: indentation change to xc_hvm_build_x86.c Wei Liu
2015-03-16  9:52 ` [PATCH v8 12/21] libxc: allocate memory with vNUMA information for HVM guest Wei Liu
2015-03-16  9:52 ` [PATCH v8 13/21] libxl: build, check and pass vNUMA info to Xen " Wei Liu
2015-03-16  9:52 ` [PATCH v8 14/21] libxl: disallow memory relocation when vNUMA is enabled Wei Liu
2015-03-16  9:52 ` [PATCH v8 15/21] libxl: define LIBXL_HAVE_VNUMA Wei Liu
2015-03-16  9:52 ` [PATCH v8 16/21] libxlu: rework internal representation of setting Wei Liu
2015-03-16  9:52 ` [PATCH v8 17/21] libxlu: nested list support Wei Liu
2015-03-16  9:52 ` [PATCH v8 18/21] libxlu: record location when parsing values Wei Liu
2015-03-18 11:49   ` Ian Campbell
2015-03-16  9:52 ` [PATCH v8 19/21] libxlu: introduce new APIs Wei Liu
2015-03-16  9:52 ` [PATCH v8 20/21] xl: introduce xcalloc Wei Liu
2015-03-16  9:52 ` [PATCH v8 21/21] xl: vNUMA support Wei Liu
2015-03-18 11:49   ` Ian Campbell
2015-03-18 12:31 ` [PATCH v8 00/21] Virtual NUMA for PV and HVM Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426499560-28514-2-git-send-email-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox