From: "Jan Beulich" Subject: [PATCH] x86: don't blindly create L3 tables for the direct map Date: Mon, 30 Sep 2013 13:34:51 +0100 Message-ID: <52498C0B02000078000F8020@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartE7D4F1FB.1__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VQcgi-0001zX-1g for xen-devel@lists.xenproject.org; Mon, 30 Sep 2013 12:34:56 +0000 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: Malcolm Crossley , Keir Fraser 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. --=__PartE7D4F1FB.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Now that the direct map area can extend all the way up to almost the end of address space, this is wasteful. Also fold two almost redundant messages in SRAT parsing into one. Signed-off-by: Jan Beulich Tested-by: Malcolm Crossley --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -137,7 +137,7 @@ l1_pgentry_t __attribute__ ((__section__ #define PTE_UPDATE_WITH_CMPXCHG #endif =20 -bool_t __read_mostly mem_hotplug =3D 0; +paddr_t __read_mostly mem_hotplug; =20 /* Private domain structs for DOMID_XEN and DOMID_IO. */ struct domain *dom_xen, *dom_io, *dom_cow; --- a/xen/arch/x86/srat.c +++ b/xen/arch/x86/srat.c @@ -113,6 +113,7 @@ static __init void bad_srat(void) apicid_to_node[i] =3D NUMA_NO_NODE; for (i =3D 0; i < ARRAY_SIZE(pxm2node); i++) pxm2node[i] =3D NUMA_NO_NODE; + mem_hotplug =3D 0; } =20 /* @@ -257,13 +258,6 @@ acpi_numa_memory_affinity_init(struct ac return; } /* It is fine to add this area to the nodes data it will be used = later*/ - if (ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) - { - printk(KERN_INFO "SRAT: hot plug zone found %"PRIx64" - = %"PRIx64" \n", - start, end); - mem_hotplug =3D 1; - } - i =3D conflicting_memblks(start, end); if (i =3D=3D node) { printk(KERN_WARNING @@ -287,8 +281,11 @@ acpi_numa_memory_affinity_init(struct ac if (nd->end < end) nd->end =3D end; } - printk(KERN_INFO "SRAT: Node %u PXM %u %"PRIx64"-%"PRIx64"\n", = node, pxm, - start, end); + if ((ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && end > mem_hotplug)= + mem_hotplug =3D end; + printk(KERN_INFO "SRAT: Node %u PXM %u %"PRIx64"-%"PRIx64"%s\n", + node, pxm, start, end, + ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE ? " (hotplug)" : = ""); =20 node_memblk_range[num_node_memblks].start =3D start; node_memblk_range[num_node_memblks].end =3D end; --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -559,25 +559,20 @@ void __init paging_init(void) * We setup the L3s for 1:1 mapping if host support memory hotplug * to avoid sync the 1:1 mapping on page fault handler */ - if ( mem_hotplug ) + for ( va =3D DIRECTMAP_VIRT_START; + va < DIRECTMAP_VIRT_END && (void *)va < __va(mem_hotplug); + va +=3D (1UL << L4_PAGETABLE_SHIFT) ) { - unsigned long va; - - for ( va =3D DIRECTMAP_VIRT_START; - va < DIRECTMAP_VIRT_END; - va +=3D (1UL << L4_PAGETABLE_SHIFT) ) + if ( !(l4e_get_flags(idle_pg_table[l4_table_offset(va)]) & + _PAGE_PRESENT) ) { - if ( !(l4e_get_flags(idle_pg_table[l4_table_offset(va)]) & - _PAGE_PRESENT) ) - { - l3_pg =3D alloc_domheap_page(NULL, 0); - if ( !l3_pg ) - goto nomem; - l3_ro_mpt =3D page_to_virt(l3_pg); - clear_page(l3_ro_mpt); - l4e_write(&idle_pg_table[l4_table_offset(va)], - l4e_from_page(l3_pg, __PAGE_HYPERVISOR)); - } + l3_pg =3D alloc_domheap_page(NULL, 0); + if ( !l3_pg ) + goto nomem; + l3_ro_mpt =3D page_to_virt(l3_pg); + clear_page(l3_ro_mpt); + l4e_write(&idle_pg_table[l4_table_offset(va)], + l4e_from_page(l3_pg, __PAGE_HYPERVISOR)); } } =20 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -399,7 +399,7 @@ static inline int get_page_and_type(stru int check_descriptor(const struct domain *, struct desc_struct *d); =20 extern bool_t opt_allow_superpage; -extern bool_t mem_hotplug; +extern paddr_t mem_hotplug; =20 /*************************************************************************= ***** * With shadow pagetables, the different kinds of address start=20 --=__PartE7D4F1FB.1__= Content-Type: text/plain; name="x86-mem-hotplug-boundary.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-mem-hotplug-boundary.patch" x86: don't blindly create L3 tables for the direct map=0A=0ANow that the = direct map area can extend all the way up to almost the=0Aend of address = space, this is wasteful.=0A=0AAlso fold two almost redundant messages in = SRAT parsing into one.=0A=0ASigned-off-by: Jan Beulich = =0ATested-by: Malcolm Crossley =0A=0A--- = a/xen/arch/x86/mm.c=0A+++ b/xen/arch/x86/mm.c=0A@@ -137,7 +137,7 @@ = l1_pgentry_t __attribute__ ((__section__=0A #define PTE_UPDATE_WITH_CMPXCHG= =0A #endif=0A =0A-bool_t __read_mostly mem_hotplug =3D 0;=0A+paddr_t = __read_mostly mem_hotplug;=0A =0A /* Private domain structs for DOMID_XEN = and DOMID_IO. */=0A struct domain *dom_xen, *dom_io, *dom_cow;=0A--- = a/xen/arch/x86/srat.c=0A+++ b/xen/arch/x86/srat.c=0A@@ -113,6 +113,7 @@ = static __init void bad_srat(void)=0A apicid_to_node[i] =3D = NUMA_NO_NODE;=0A for (i =3D 0; i < ARRAY_SIZE(pxm2node); i++)=0A = pxm2node[i] =3D NUMA_NO_NODE;=0A+ mem_hotplug =3D 0;=0A }=0A = =0A /*=0A@@ -257,13 +258,6 @@ acpi_numa_memory_affinity_init(struct ac=0A = return;=0A }=0A /* It is fine to add this area to the = nodes data it will be used later*/=0A- if (ma->flags & ACPI_SRAT_MEM_HOT_P= LUGGABLE)=0A- {=0A- printk(KERN_INFO "SRAT: hot plug zone = found %"PRIx64" - %"PRIx64" \n",=0A- start, = end);=0A- mem_hotplug =3D 1;=0A- }=0A-=0A i =3D = conflicting_memblks(start, end);=0A if (i =3D=3D node) {=0A = printk(KERN_WARNING=0A@@ -287,8 +281,11 @@ acpi_numa_memory_affinity_init(s= truct ac=0A if (nd->end < end)=0A nd->end = =3D end;=0A }=0A- printk(KERN_INFO "SRAT: Node %u PXM %u %"PRIx64"-%"= PRIx64"\n", node, pxm,=0A- start, end);=0A+ if ((ma->flags & = ACPI_SRAT_MEM_HOT_PLUGGABLE) && end > mem_hotplug)=0A+ mem_hotplug= =3D end;=0A+ printk(KERN_INFO "SRAT: Node %u PXM %u %"PRIx64"-%"PRIx64"%= s\n",=0A+ node, pxm, start, end,=0A+ ma->flags & = ACPI_SRAT_MEM_HOT_PLUGGABLE ? " (hotplug)" : "");=0A =0A node_memblk= _range[num_node_memblks].start =3D start;=0A node_memblk_range[num_node_= memblks].end =3D end;=0A--- a/xen/arch/x86/x86_64/mm.c=0A+++ b/xen/arch/x86= /x86_64/mm.c=0A@@ -559,25 +559,20 @@ void __init paging_init(void)=0A = * We setup the L3s for 1:1 mapping if host support memory hotplug=0A = * to avoid sync the 1:1 mapping on page fault handler=0A */=0A- if = ( mem_hotplug )=0A+ for ( va =3D DIRECTMAP_VIRT_START;=0A+ va = < DIRECTMAP_VIRT_END && (void *)va < __va(mem_hotplug);=0A+ va = +=3D (1UL << L4_PAGETABLE_SHIFT) )=0A {=0A- unsigned long = va;=0A-=0A- for ( va =3D DIRECTMAP_VIRT_START;=0A- va = < DIRECTMAP_VIRT_END;=0A- va +=3D (1UL << L4_PAGETABLE_SHIFT) = )=0A+ if ( !(l4e_get_flags(idle_pg_table[l4_table_offset(va)]) = &=0A+ _PAGE_PRESENT) )=0A {=0A- if ( = !(l4e_get_flags(idle_pg_table[l4_table_offset(va)]) &=0A- = _PAGE_PRESENT) )=0A- {=0A- l3_pg =3D alloc_domhea= p_page(NULL, 0);=0A- if ( !l3_pg )=0A- = goto nomem;=0A- l3_ro_mpt =3D page_to_virt(l3_pg);=0A- = clear_page(l3_ro_mpt);=0A- l4e_write(&idle_pg_tabl= e[l4_table_offset(va)],=0A- l4e_from_page(l3_pg, = __PAGE_HYPERVISOR));=0A- }=0A+ l3_pg =3D alloc_domhea= p_page(NULL, 0);=0A+ if ( !l3_pg )=0A+ goto = nomem;=0A+ l3_ro_mpt =3D page_to_virt(l3_pg);=0A+ = clear_page(l3_ro_mpt);=0A+ l4e_write(&idle_pg_table[l4_table_off= set(va)],=0A+ l4e_from_page(l3_pg, __PAGE_HYPERVISOR))= ;=0A }=0A }=0A =0A--- a/xen/include/asm-x86/mm.h=0A+++ = b/xen/include/asm-x86/mm.h=0A@@ -399,7 +399,7 @@ static inline int = get_page_and_type(stru=0A int check_descriptor(const struct domain *, = struct desc_struct *d);=0A =0A extern bool_t opt_allow_superpage;=0A-extern= bool_t mem_hotplug;=0A+extern paddr_t mem_hotplug;=0A =0A /***************= ***************************************************************=0A * With = shadow pagetables, the different kinds of address start =0A --=__PartE7D4F1FB.1__= 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 --=__PartE7D4F1FB.1__=--