[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v3 3/3] mm: MEMF_node should handle changes in nodeid_t size



Instead of using a hardcoded constant to extract nodeID from
memflags use a macro whose value is based on nodeid_t size.

Also provide a macro for extracting nodeID from memflags so that
users don't need to remember to decrement the value.

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
---

Changes in v3:
* Fixed shift for MEMF_node_mask and moved it a few lines down
* Added BUILD_BUG_ON((_MEMF_bits - _MEMF_node) >= (8 * sizeof(nodeid_t))) to
  alloc_heap_pages() (Not sure it's the best place).

 xen/common/page_alloc.c |    5 ++++-
 xen/include/xen/mm.h    |    5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 124fa88..08d8ed6 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -581,13 +581,16 @@ static struct page_info *alloc_heap_pages(
     struct domain *d)
 {
     unsigned int first_node, i, j, zone = 0, nodemask_retry = 0;
-    nodeid_t node = (nodeid_t)((memflags >> _MEMF_node) - 1);
+    nodeid_t node = MEMF2NODE(memflags);
     unsigned long request = 1UL << order;
     struct page_info *pg;
     nodemask_t nodemask = (d != NULL ) ? d->node_affinity : node_online_map;
     bool_t need_tlbflush = 0;
     uint32_t tlbflush_timestamp = 0;
 
+    /* Make sure there are enough bits in memflags for nodeID */
+    BUILD_BUG_ON((_MEMF_bits - _MEMF_node) < (8 * sizeof(nodeid_t)));
+
     if ( node == NUMA_NO_NODE )
     {
         memflags &= ~MEMF_exact_node;
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 74a65a6..788fbdd 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -121,10 +121,13 @@ struct npfec {
 #define _MEMF_exact_node  4
 #define  MEMF_exact_node  (1U<<_MEMF_exact_node)
 #define _MEMF_node        8
-#define  MEMF_node(n)     ((((n)+1)&0xff)<<_MEMF_node)
+#define  MEMF_node_mask   ((1U<<(8*sizeof(nodeid_t)))-1)
+#define  MEMF_node(n)     ((((n)+1)&MEMF_node_mask)<<_MEMF_node)
 #define _MEMF_bits        24
 #define  MEMF_bits(n)     ((n)<<_MEMF_bits)
 
+#define MEMF2NODE(memflags) (MASK_EXTR(memflags,MEMF_node_mask)-1)
+
 #ifdef CONFIG_PAGEALLOC_MAX_ORDER
 #define MAX_ORDER CONFIG_PAGEALLOC_MAX_ORDER
 #else
-- 
1.7.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.