From: "Jan Beulich" Subject: [PATCH 1/5] x86: allow specifying the NUMA nodes Dom0 should run on Date: Thu, 26 Feb 2015 13:52:56 +0000 Message-ID: <54EF3348020000780006413C@mail.emea.novell.com> References: <54EF315902000078000640FF@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartDEEB6828.2__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YQys8-0005Ep-1g for xen-devel@lists.xenproject.org; Thu, 26 Feb 2015 13:53:00 +0000 In-Reply-To: <54EF315902000078000640FF@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Keir Fraser , Andrew Cooper , Dario Faggioli , Ian Jackson , Tim Deegan , Ian Campbell List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartDEEB6828.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... by introducing a "dom0_nodes" option augmenting the "dom0_mem" and "dom0_max_vcpus" ones. Note that this gives meaning to MEMF_exact_node specified alone (i.e. implicitly combined with NUMA_NO_NODE): In such a case any node inside the domain's node mask is acceptable, but no other node. This changed behavior is (implicitly) being exposed through the memop hypercalls. Note further that this change doesn't take care of moving the initrd image into memory matching Dom0's affinity when the initrd doesn't get copied (because of being part of the initial mapping) anyway. Signed-off-by: Jan Beulich --- I'm uncertain whether range restricting the PXMs permitted for Dom0 is the right approach (matching what other NUMA code did until recently), or whether we would instead want to simply limit the number of PXMs we can handler there (i.e. using a static array instead of a static bitmap). --- a/docs/misc/xen-command-line.markdown +++ b/docs/misc/xen-command-line.markdown @@ -540,6 +540,15 @@ any dom0 autoballooning feature present=20 _xl.conf(5)_ man page or [Xen Best Practices](http://wiki.xen.org/wiki/Xen_Best_Practices#Xen_dom0_dedicated_= memory_and_preventing_dom0_memory_ballooning). =20 +### dom0\_nodes + +> `=3D [,...]` + +Specify the NUMA nodes to place Dom0 on. Defaults for vCPU-s created +and memory assigned to Dom0 will be adjusted to match the node +restrictions set up here. Note that the values to be specified here are +ACPI PXM ones, not Xen internal node numbers. + ### dom0\_shadow > `=3D ` =20 --- a/xen/arch/x86/domain_build.c +++ b/xen/arch/x86/domain_build.c @@ -100,11 +100,58 @@ static void __init parse_dom0_max_vcpus( } custom_param("dom0_max_vcpus", parse_dom0_max_vcpus); =20 +#define MAX_DOM0_PXM 255 +static __initdata DECLARE_BITMAP(dom0_pxms, MAX_DOM0_PXM + 1); + +static void __init parse_dom0_nodes(const char *s) +{ + do { + unsigned int pxm =3D simple_strtoul(s, &s, 0); + + if ( pxm <=3D MAX_DOM0_PXM ) + __set_bit(pxm, dom0_pxms); + } while ( *s++ =3D=3D ',' ); +} +custom_param("dom0_nodes", parse_dom0_nodes); + +static cpumask_t __initdata dom0_cpus; + +static struct vcpu *__init setup_vcpu(struct domain *d, unsigned int = vcpu_id, + unsigned int cpu) +{ + struct vcpu *v =3D alloc_vcpu(d, vcpu_id, cpu); + + if ( v ) + { + if ( !d->is_pinned ) + cpumask_copy(v->cpu_hard_affinity, &dom0_cpus); + cpumask_copy(v->cpu_soft_affinity, &dom0_cpus); + } + + return v; +} + +static nodemask_t __initdata dom0_nodes; + unsigned int __init dom0_max_vcpus(void) { - unsigned max_vcpus; + unsigned int pxm, max_vcpus; + nodeid_t node; + + for ( pxm =3D 0; pxm <=3D MAX_DOM0_PXM; ++pxm ) + if ( test_bit(pxm, dom0_pxms) && + (node =3D pxm_to_node(pxm)) !=3D NUMA_NO_NODE ) + node_set(node, dom0_nodes); + nodes_and(dom0_nodes, dom0_nodes, node_online_map); + if ( nodes_empty(dom0_nodes) ) + dom0_nodes =3D node_online_map; + for_each_node_mask ( node, dom0_nodes ) + cpumask_or(&dom0_cpus, &dom0_cpus, &node_to_cpumask(node)); + cpumask_and(&dom0_cpus, &dom0_cpus, cpupool0->cpu_valid); + if ( cpumask_empty(&dom0_cpus) ) + cpumask_copy(&dom0_cpus, cpupool0->cpu_valid); =20 - max_vcpus =3D num_cpupool_cpus(cpupool0); + max_vcpus =3D cpumask_weight(&dom0_cpus); if ( opt_dom0_max_vcpus_min > max_vcpus ) max_vcpus =3D opt_dom0_max_vcpus_min; if ( opt_dom0_max_vcpus_max < max_vcpus ) @@ -119,12 +166,15 @@ struct vcpu *__init alloc_dom0_vcpu0(str { unsigned int max_vcpus =3D dom0_max_vcpus(); =20 + dom0->node_affinity =3D dom0_nodes; + dom0->auto_node_affinity =3D !!bitmap_empty(dom0_pxms, MAX_DOM0_PXM + = 1); + dom0->vcpu =3D xzalloc_array(struct vcpu *, max_vcpus); if ( !dom0->vcpu ) return NULL; dom0->max_vcpus =3D max_vcpus; =20 - return alloc_vcpu(dom0, 0, 0); + return setup_vcpu(dom0, 0, cpumask_first(&dom0_cpus)); } =20 #ifdef CONFIG_SHADOW_PAGING @@ -156,7 +206,7 @@ static struct page_info * __init alloc_c struct domain *d, unsigned long max_pages) { static unsigned int __initdata last_order =3D MAX_ORDER; - static unsigned int __initdata memflags =3D MEMF_no_dma; + static unsigned int __initdata memflags =3D MEMF_no_dma|MEMF_exact_nod= e; struct page_info *page; unsigned int order =3D get_order_from_pages(max_pages), free_order; =20 @@ -190,7 +240,7 @@ static struct page_info * __init alloc_c =20 if ( d->tot_pages + (1 << order) > d->max_pages ) continue; - pg2 =3D alloc_domheap_pages(d, order, 0); + pg2 =3D alloc_domheap_pages(d, order, MEMF_exact_node); if ( pg2 > page ) { free_domheap_pages(page, free_order); @@ -217,10 +267,14 @@ static unsigned long __init dom0_paging_ static unsigned long __init compute_dom0_nr_pages( struct domain *d, struct elf_dom_parms *parms, unsigned long = initrd_len) { - unsigned long avail =3D avail_domheap_pages() + initial_images_nrpages= (); - unsigned long nr_pages, min_pages, max_pages; + nodeid_t node; + unsigned long avail =3D 0, nr_pages, min_pages, max_pages; bool_t need_paging; =20 + for_each_node_mask ( node, dom0_nodes ) + avail +=3D avail_domheap_pages_region(node, 0, 0) + + initial_images_nrpages(node); + /* Reserve memory for further dom0 vcpu-struct allocations... */ avail -=3D (d->max_vcpus - 1UL) << get_order_from_bytes(sizeof(struct vcpu)); @@ -1230,11 +1284,11 @@ int __init construct_dom0( =20 printk("Dom0 has maximum %u VCPUs\n", d->max_vcpus); =20 - cpu =3D cpumask_first(cpupool0->cpu_valid); + cpu =3D v->processor; for ( i =3D 1; i < d->max_vcpus; i++ ) { - cpu =3D cpumask_cycle(cpu, cpupool0->cpu_valid); - (void)alloc_vcpu(d, i, cpu); + cpu =3D cpumask_cycle(cpu, &dom0_cpus); + setup_vcpu(d, i, cpu); } =20 /* --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -140,13 +140,21 @@ static void __init parse_acpi_param(char static const module_t *__initdata initial_images; static unsigned int __initdata nr_initial_images; =20 -unsigned long __init initial_images_nrpages(void) +unsigned long __init initial_images_nrpages(nodeid_t node) { + unsigned long node_start =3D node_start_pfn(node); + unsigned long node_end =3D node_end_pfn(node); unsigned long nr; unsigned int i; =20 for ( nr =3D i =3D 0; i < nr_initial_images; ++i ) - nr +=3D PFN_UP(initial_images[i].mod_end); + { + unsigned long start =3D initial_images[i].mod_start; + unsigned long end =3D start + PFN_UP(initial_images[i].mod_end); + + if ( end > node_start && node_end > start ) + nr +=3D min(node_end, end) - max(node_start, start); + } =20 return nr; } --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -581,7 +581,7 @@ static struct page_info *alloc_heap_page struct domain *d) { unsigned int i, j, zone =3D 0, nodemask_retry =3D 0; - nodeid_t first_node, node =3D MEMF_get_node(memflags); + nodeid_t first_node, node =3D MEMF_get_node(memflags), req_node =3D = node; unsigned long request =3D 1UL << order; struct page_info *pg; nodemask_t nodemask =3D (d !=3D NULL ) ? d->node_affinity : node_onlin= e_map; @@ -593,7 +593,6 @@ static struct page_info *alloc_heap_page =20 if ( node =3D=3D NUMA_NO_NODE ) { - memflags &=3D ~MEMF_exact_node; if ( d !=3D NULL ) { node =3D next_node(d->last_alloc_node, nodemask); @@ -654,7 +653,7 @@ static struct page_info *alloc_heap_page goto found; } while ( zone-- > zone_lo ); /* careful: unsigned zone may wrap = */ =20 - if ( memflags & MEMF_exact_node ) + if ( (memflags & MEMF_exact_node) && req_node !=3D NUMA_NO_NODE ) goto not_found; =20 /* Pick next node. */ @@ -671,7 +670,7 @@ static struct page_info *alloc_heap_page if ( node =3D=3D first_node ) { /* When we have tried all in nodemask, we fall back to = others. */ - if ( nodemask_retry++ ) + if ( (memflags & MEMF_exact_node) || nodemask_retry++ ) goto not_found; nodes_andnot(nodemask, node_online_map, nodemask); first_node =3D node =3D first_node(nodemask); --- a/xen/include/asm-x86/setup.h +++ b/xen/include/asm-x86/setup.h @@ -2,6 +2,7 @@ #define __X86_SETUP_H_ =20 #include +#include =20 extern unsigned long xenheap_initial_phys_start; =20 @@ -32,7 +33,7 @@ int construct_dom0( void *(*bootstrap_map)(const module_t *), char *cmdline); =20 -unsigned long initial_images_nrpages(void); +unsigned long initial_images_nrpages(nodeid_t node); void discard_initial_images(void); =20 unsigned int dom0_max_vcpus(void); --=__PartDEEB6828.2__= Content-Type: text/plain; name="x86-Dom0-nodes.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-Dom0-nodes.patch" x86: allow specifying the NUMA nodes Dom0 should run on=0A=0A... by = introducing a "dom0_nodes" option augmenting the "dom0_mem" and=0A"dom0_max= _vcpus" ones.=0A=0ANote that this gives meaning to MEMF_exact_node = specified alone (i.e.=0Aimplicitly combined with NUMA_NO_NODE): In such a = case any node inside=0Athe domain's node mask is acceptable, but no other = node. This changed=0Abehavior is (implicitly) being exposed through the = memop hypercalls.=0A=0ANote further that this change doesn't take care of = moving the initrd=0Aimage into memory matching Dom0's affinity when the = initrd doesn't get=0Acopied (because of being part of the initial mapping) = anyway.=0A=0ASigned-off-by: Jan Beulich =0A---=0AI'm = uncertain whether range restricting the PXMs permitted for Dom0 is=0Athe = right approach (matching what other NUMA code did until recently),=0Aor = whether we would instead want to simply limit the number of PXMs we=0Acan = handler there (i.e. using a static array instead of a static=0Abitmap).=0A= =0A--- a/docs/misc/xen-command-line.markdown=0A+++ b/docs/misc/xen-command-= line.markdown=0A@@ -540,6 +540,15 @@ any dom0 autoballooning feature = present =0A _xl.conf(5)_ man page or [Xen Best=0A Practices](http://wiki.xe= n.org/wiki/Xen_Best_Practices#Xen_dom0_dedicated_memory_and_preventing_dom0= _memory_ballooning).=0A =0A+### dom0\_nodes=0A+=0A+> `=3D [,...]`= =0A+=0A+Specify the NUMA nodes to place Dom0 on. Defaults for vCPU-s = created=0A+and memory assigned to Dom0 will be adjusted to match the = node=0A+restrictions set up here. Note that the values to be specified = here are=0A+ACPI PXM ones, not Xen internal node numbers.=0A+=0A ### = dom0\_shadow=0A > `=3D `=0A =0A--- a/xen/arch/x86/domain_build.c= =0A+++ b/xen/arch/x86/domain_build.c=0A@@ -100,11 +100,58 @@ static void = __init parse_dom0_max_vcpus(=0A }=0A custom_param("dom0_max_vcpus", = parse_dom0_max_vcpus);=0A =0A+#define MAX_DOM0_PXM 255=0A+static __initdata= DECLARE_BITMAP(dom0_pxms, MAX_DOM0_PXM + 1);=0A+=0A+static void __init = parse_dom0_nodes(const char *s)=0A+{=0A+ do {=0A+ unsigned int = pxm =3D simple_strtoul(s, &s, 0);=0A+=0A+ if ( pxm <=3D MAX_DOM0_PXM= )=0A+ __set_bit(pxm, dom0_pxms);=0A+ } while ( *s++ =3D=3D = ',' );=0A+}=0A+custom_param("dom0_nodes", parse_dom0_nodes);=0A+=0A+static = cpumask_t __initdata dom0_cpus;=0A+=0A+static struct vcpu *__init = setup_vcpu(struct domain *d, unsigned int vcpu_id,=0A+ = unsigned int cpu)=0A+{=0A+ struct vcpu *v =3D = alloc_vcpu(d, vcpu_id, cpu);=0A+=0A+ if ( v )=0A+ {=0A+ if ( = !d->is_pinned )=0A+ cpumask_copy(v->cpu_hard_affinity, = &dom0_cpus);=0A+ cpumask_copy(v->cpu_soft_affinity, &dom0_cpus);=0A+= }=0A+=0A+ return v;=0A+}=0A+=0A+static nodemask_t __initdata = dom0_nodes;=0A+=0A unsigned int __init dom0_max_vcpus(void)=0A {=0A- = unsigned max_vcpus;=0A+ unsigned int pxm, max_vcpus;=0A+ nodeid_t = node;=0A+=0A+ for ( pxm =3D 0; pxm <=3D MAX_DOM0_PXM; ++pxm )=0A+ = if ( test_bit(pxm, dom0_pxms) &&=0A+ (node =3D pxm_to_node(pxm= )) !=3D NUMA_NO_NODE )=0A+ node_set(node, dom0_nodes);=0A+ = nodes_and(dom0_nodes, dom0_nodes, node_online_map);=0A+ if ( nodes_empty= (dom0_nodes) )=0A+ dom0_nodes =3D node_online_map;=0A+ for_each_n= ode_mask ( node, dom0_nodes )=0A+ cpumask_or(&dom0_cpus, &dom0_cpus,= &node_to_cpumask(node));=0A+ cpumask_and(&dom0_cpus, &dom0_cpus, = cpupool0->cpu_valid);=0A+ if ( cpumask_empty(&dom0_cpus) )=0A+ = cpumask_copy(&dom0_cpus, cpupool0->cpu_valid);=0A =0A- max_vcpus =3D = num_cpupool_cpus(cpupool0);=0A+ max_vcpus =3D cpumask_weight(&dom0_cpus)= ;=0A if ( opt_dom0_max_vcpus_min > max_vcpus )=0A max_vcpus = =3D opt_dom0_max_vcpus_min;=0A if ( opt_dom0_max_vcpus_max < max_vcpus = )=0A@@ -119,12 +166,15 @@ struct vcpu *__init alloc_dom0_vcpu0(str=0A {=0A = unsigned int max_vcpus =3D dom0_max_vcpus();=0A =0A+ dom0->node_affi= nity =3D dom0_nodes;=0A+ dom0->auto_node_affinity =3D !!bitmap_empty(dom= 0_pxms, MAX_DOM0_PXM + 1);=0A+=0A dom0->vcpu =3D xzalloc_array(struct = vcpu *, max_vcpus);=0A if ( !dom0->vcpu )=0A return NULL;=0A = dom0->max_vcpus =3D max_vcpus;=0A =0A- return alloc_vcpu(dom0, 0, = 0);=0A+ return setup_vcpu(dom0, 0, cpumask_first(&dom0_cpus));=0A }=0A = =0A #ifdef CONFIG_SHADOW_PAGING=0A@@ -156,7 +206,7 @@ static struct = page_info * __init alloc_c=0A struct domain *d, unsigned long = max_pages)=0A {=0A static unsigned int __initdata last_order =3D = MAX_ORDER;=0A- static unsigned int __initdata memflags =3D MEMF_no_dma;= =0A+ static unsigned int __initdata memflags =3D MEMF_no_dma|MEMF_exact_= node;=0A struct page_info *page;=0A unsigned int order =3D = get_order_from_pages(max_pages), free_order;=0A =0A@@ -190,7 +240,7 @@ = static struct page_info * __init alloc_c=0A =0A if ( d->tot_pages = + (1 << order) > d->max_pages )=0A continue;=0A- pg2 = =3D alloc_domheap_pages(d, order, 0);=0A+ pg2 =3D alloc_domheap_page= s(d, order, MEMF_exact_node);=0A if ( pg2 > page )=0A {=0A = free_domheap_pages(page, free_order);=0A@@ -217,10 +267,14 @@ = static unsigned long __init dom0_paging_=0A static unsigned long __init = compute_dom0_nr_pages(=0A struct domain *d, struct elf_dom_parms = *parms, unsigned long initrd_len)=0A {=0A- unsigned long avail =3D = avail_domheap_pages() + initial_images_nrpages();=0A- unsigned long = nr_pages, min_pages, max_pages;=0A+ nodeid_t node;=0A+ unsigned long = avail =3D 0, nr_pages, min_pages, max_pages;=0A bool_t need_paging;=0A = =0A+ for_each_node_mask ( node, dom0_nodes )=0A+ avail +=3D = avail_domheap_pages_region(node, 0, 0) +=0A+ initial_images= _nrpages(node);=0A+=0A /* Reserve memory for further dom0 vcpu-struct = allocations... */=0A avail -=3D (d->max_vcpus - 1UL)=0A = << get_order_from_bytes(sizeof(struct vcpu));=0A@@ -1230,11 +1284,11 @@ = int __init construct_dom0(=0A =0A printk("Dom0 has maximum %u = VCPUs\n", d->max_vcpus);=0A =0A- cpu =3D cpumask_first(cpupool0->cpu_val= id);=0A+ cpu =3D v->processor;=0A for ( i =3D 1; i < d->max_vcpus; = i++ )=0A {=0A- cpu =3D cpumask_cycle(cpu, cpupool0->cpu_valid);= =0A- (void)alloc_vcpu(d, i, cpu);=0A+ cpu =3D cpumask_cycle(c= pu, &dom0_cpus);=0A+ setup_vcpu(d, i, cpu);=0A }=0A =0A = /*=0A--- a/xen/arch/x86/setup.c=0A+++ b/xen/arch/x86/setup.c=0A@@ -140,13 = +140,21 @@ static void __init parse_acpi_param(char=0A static const = module_t *__initdata initial_images;=0A static unsigned int __initdata = nr_initial_images;=0A =0A-unsigned long __init initial_images_nrpages(void)= =0A+unsigned long __init initial_images_nrpages(nodeid_t node)=0A {=0A+ = unsigned long node_start =3D node_start_pfn(node);=0A+ unsigned long = node_end =3D node_end_pfn(node);=0A unsigned long nr;=0A unsigned = int i;=0A =0A for ( nr =3D i =3D 0; i < nr_initial_images; ++i )=0A- = nr +=3D PFN_UP(initial_images[i].mod_end);=0A+ {=0A+ = unsigned long start =3D initial_images[i].mod_start;=0A+ unsigned = long end =3D start + PFN_UP(initial_images[i].mod_end);=0A+=0A+ if = ( end > node_start && node_end > start )=0A+ nr +=3D min(node_en= d, end) - max(node_start, start);=0A+ }=0A =0A return nr;=0A = }=0A--- a/xen/common/page_alloc.c=0A+++ b/xen/common/page_alloc.c=0A@@ = -581,7 +581,7 @@ static struct page_info *alloc_heap_page=0A struct = domain *d)=0A {=0A unsigned int i, j, zone =3D 0, nodemask_retry =3D = 0;=0A- nodeid_t first_node, node =3D MEMF_get_node(memflags);=0A+ = nodeid_t first_node, node =3D MEMF_get_node(memflags), req_node =3D = node;=0A unsigned long request =3D 1UL << order;=0A struct = page_info *pg;=0A nodemask_t nodemask =3D (d !=3D NULL ) ? d->node_affi= nity : node_online_map;=0A@@ -593,7 +593,6 @@ static struct page_info = *alloc_heap_page=0A =0A if ( node =3D=3D NUMA_NO_NODE )=0A {=0A- = memflags &=3D ~MEMF_exact_node;=0A if ( d !=3D NULL )=0A = {=0A node =3D next_node(d->last_alloc_node, nodemask);=0A@@ = -654,7 +653,7 @@ static struct page_info *alloc_heap_page=0A = goto found;=0A } while ( zone-- > zone_lo ); /* careful: = unsigned zone may wrap */=0A =0A- if ( memflags & MEMF_exact_node = )=0A+ if ( (memflags & MEMF_exact_node) && req_node !=3D NUMA_NO_NOD= E )=0A goto not_found;=0A =0A /* Pick next node. = */=0A@@ -671,7 +670,7 @@ static struct page_info *alloc_heap_page=0A = if ( node =3D=3D first_node )=0A {=0A /* When we = have tried all in nodemask, we fall back to others. */=0A- if ( = nodemask_retry++ )=0A+ if ( (memflags & MEMF_exact_node) || = nodemask_retry++ )=0A goto not_found;=0A = nodes_andnot(nodemask, node_online_map, nodemask);=0A = first_node =3D node =3D first_node(nodemask);=0A--- a/xen/include/asm-x86/s= etup.h=0A+++ b/xen/include/asm-x86/setup.h=0A@@ -2,6 +2,7 @@=0A #define = __X86_SETUP_H_=0A =0A #include =0A+#include = =0A =0A extern unsigned long xenheap_initial_phys_start;=0A =0A@@ -32,7 = +33,7 @@ int construct_dom0(=0A void *(*bootstrap_map)(const module_t = *),=0A char *cmdline);=0A =0A-unsigned long initial_images_nrpages(void= );=0A+unsigned long initial_images_nrpages(nodeid_t node);=0A void = discard_initial_images(void);=0A =0A unsigned int dom0_max_vcpus(void);=0A --=__PartDEEB6828.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartDEEB6828.2__=--