Skip to contentSkip to conversation

PATCH: Hugepage support for Domains booting with 4KB pages

PATCH Keshav Darak 2 participants 2 messages Mar 20, 2011 – Mar 22, 2011

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

We have implemented hugepage support for guests in following manner

In
our implementation we added a parameter hugepage_num which is specified
in the config file of the DomU. It is the number of hugepages that the
guest is guaranteed to receive whenever the kernel asks for hugepage by
using its boot time parameter or reserving after booting (eg. Using echo
XX > /proc/sys/vm/nr_hugepages). During creation of the domain we
reserve MFN's for these hugepages and store them in the list. The
listhead of this list is inside the domain structure with name "hugepage_list". When the domain is booting, at that time the memory
seen by the kernel is allocated memory  less the amount required for hugepages. The function reserve_hugepage_range is called as a initcall. Before this function the
xen_extra_mem_start points to this apparent end of the memory. In this
function we reserve the PFN range for the hugepages which are going to
be allocated by kernel by incrementing the xen_extra_mem_start. We
maintain these PFNs as pages in "xen_hugepfn_list" in the kernel.

Now
before the kernel requests for hugepages, it makes a hypercall
HYPERVISOR_memory_op  to get count of hugepages allocated to it and accordingly reserves the pfn range.
then whenever kernel requests for
hugepages it again make hypercall HYPERVISOR_memory_op to get the
preallocated hugepage and according makes the p2m mapping on both sides (xen as well as kernel side)

The approach can be better explained using the presentation attached.

--
Keshav Darak
Kaustubh Kabra
Ashwin Vasani
Aditya Gadre

tools/libxc/xc_dom.h +1 -0
diff -r 4e108cf56d07 tools/libxc/xc_dom.h
@@ -113,6 +113,7 @@
     domid_t guest_domid;
     int8_t vhpt_size_log2; /* for IA64 */
     int8_t superpages;
+    int hugepage_num;
     int shadow_enabled;
 
     int xen_version;
tools/libxc/xc_dom_core.c +14 -0
diff -r 4e108cf56d07 tools/libxc/xc_dom_core.c
@@ -699,6 +699,20 @@
 
     page_shift = XC_DOM_PAGE_SHIFT(dom);
     nr_pages = mem_mb << (20 - page_shift);
+    
+    
+    if(dom->hugepage_num && dom->superpages!=1)
+    {
+
+        nr_pages-=dom->hugepage_num*512;
+
+    }
+    if(nr_pages<=0)
+    {
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR, "%s: Allocated memory less than required for hugepages",
+                     __FUNCTION__);
+        return -1;
+    }
 
     DOMPRINTF("%s: mem %d MB, pages 0x%" PRIpfn " pages, %dk each",
                __FUNCTION__, mem_mb, nr_pages, 1 << (page_shift-10));
tools/libxc/xc_dom_x86.c +9 -0
diff -r 4e108cf56d07 tools/libxc/xc_dom_x86.c
@@ -747,9 +747,18 @@
             for ( j = 0; j < SUPERPAGE_NR_PFNS; j++, pfn++ )
                 dom->p2m_host[pfn] = mfn + j;
         }
+
     }
     else
     {
+        /*a2k2 setting up hugepages pool for domain in xen from its mem_size not allocated as free pages to domain. */
+        if(dom->hugepage_num)
+        {
+            rc = xc_domain_populate_hugemap(
+                dom->xch, dom->guest_domid, dom->hugepage_num,
+                9, 0, &dom->p2m_host[0]);
+
+        }
         /* setup initial p2m */
         for ( pfn = 0; pfn < dom->total_pages; pfn++ )
             dom->p2m_host[pfn] = pfn;
tools/libxc/xc_domain.c +28 -0
diff -r 4e108cf56d07 tools/libxc/xc_domain.c
@@ -729,6 +729,34 @@
     return do_memory_op(xch, XENMEM_add_to_physmap, &xatp, sizeof(xatp));
 }
 
+int xc_domain_populate_hugemap(xc_interface *xch,
+                               uint32_t domid,
+                               unsigned long nr_extents,
+                               unsigned int extent_order,
+                               unsigned int mem_flags,
+                               xen_pfn_t *extent_start)
+{
+    int err;
+    DECLARE_HYPERCALL_BOUNCE(extent_start, nr_extents * sizeof(*extent_start), XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
+    struct xen_memory_reservation reservation = {
+        .nr_extents   = nr_extents,
+        .extent_order = extent_order,
+        .mem_flags    = mem_flags,
+        .domid        = domid
+    };
+
+    if ( xc_hypercall_bounce_pre(xch, extent_start) )
+    {
+        PERROR("Could not bounce memory for XENMEM_populate_physmap hypercall");
+        return -1;
+    }
+    set_xen_guest_handle(reservation.extent_start, extent_start);
+
+    err = do_memory_op(xch, XENMEM_populate_hugemap, &reservation, sizeof(reservation));
+
+    xc_hypercall_bounce_post(xch, extent_start);
+    return err;
+}
 int xc_domain_populate_physmap(xc_interface *xch,
                                uint32_t domid,
                                unsigned long nr_extents,
tools/libxc/xenctrl.h +7 -0
diff -r 4e108cf56d07 tools/libxc/xenctrl.h
@@ -1006,6 +1006,13 @@
                                unsigned int mem_flags,
                                xen_pfn_t *extent_start);
 
+int xc_domain_populate_hugemap(xc_interface *xch,
+                               uint32_t domid,
+                               unsigned long nr_extents,
+                               unsigned int extent_order,
+                               unsigned int mem_flags,
+                               xen_pfn_t *extent_start);
+
 int xc_domain_populate_physmap_exact(xc_interface *xch,
                                      uint32_t domid,
                                      unsigned long nr_extents,
tools/python/xen/lowlevel/xc/xc.c +6 -4
diff -r 4e108cf56d07 tools/python/xen/lowlevel/xc/xc.c
@@ -455,6 +455,7 @@
     int store_evtchn, console_evtchn;
     int vhpt = 0;
     int superpages = 0;
+    int hugepage_num = 0;
     unsigned int mem_mb;
     unsigned long store_mfn = 0;
     unsigned long console_mfn = 0;
@@ -467,14 +468,14 @@
                                 "console_evtchn", "image",
                                 /* optional */
                                 "ramdisk", "cmdline", "flags",
-                                "features", "vhpt", "superpages", NULL };
-
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssisii", kwd_list,
+                                "features", "vhpt", "superpages","hugepage_num", NULL };
+
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssisiii", kwd_list,
                                       &domid, &store_evtchn, &mem_mb,
                                       &console_evtchn, &image,
                                       /* optional */
                                       &ramdisk, &cmdline, &flags,
-                                      &features, &vhpt, &superpages) )
+                                      &features, &vhpt, &superpages,&hugepage_num) )
         return NULL;
 
     xc_dom_loginit(self->xc_handle);
@@ -484,6 +485,7 @@
     /* for IA64 */
     dom->vhpt_size_log2 = vhpt;
 
+  dom->hugepage_num=hugepage_num;
     dom->superpages = superpages;
 
     if ( xc_dom_linux_build(self->xc_handle, dom, domid, mem_mb, image,
tools/python/xen/xend/XendConfig.py +7 -0
diff -r 4e108cf56d07 tools/python/xen/xend/XendConfig.py
@@ -244,6 +244,7 @@
     'memory_sharing': int,
     'pool_name' : str,
     'Description': str,
+    'hugepage_num':int,
 }
 
 # List of legacy configuration keys that have no equivalent in the
@@ -423,6 +424,7 @@
             'pool_name' : 'Pool-0',
             'superpages': 0,
             'description': '',
+            'hugepage_num':0,
         }
         
         return defaults
@@ -2135,6 +2137,8 @@
             image.append(['args', self['PV_args']])
         if self.has_key('superpages'):
             image.append(['superpages', self['superpages']])
+	if self.has_key('hugepage_num'):
+            image.append(['hugepage_num', self['hugepage_num']])
 
         for key in XENAPI_PLATFORM_CFG_TYPES.keys():
             if key in self['platform']:
@@ -2179,6 +2183,9 @@
         val = sxp.child_value(image_sxp, 'superpages')
         if val is not None:
             self['superpages'] = val
+        val = sxp.child_value(image_sxp, 'hugepage_num')
+        if val is not None:
+            self['hugepage_num'] = val
         
         val = sxp.child_value(image_sxp, 'memory_sharing')
         if val is not None:
tools/python/xen/xend/image.py +5 -1
diff -r 4e108cf56d07 tools/python/xen/xend/image.py
@@ -84,6 +84,7 @@
 
     ostype = None
     superpages = 0
+    hugepage_num = 0
     memory_sharing = 0
 
     def __init__(self, vm, vmConfig):
@@ -711,6 +712,7 @@
         self.vramsize = int(vmConfig['platform'].get('videoram',4)) * 1024
         self.is_stubdom = (self.kernel.find('stubdom') >= 0)
         self.superpages = int(vmConfig['superpages'])
+	 self.hugepage_num = int(vmConfig['hugepage_num'])
 
     def buildDomain(self):
         store_evtchn = self.vm.getStorePort()
@@ -729,6 +731,7 @@
         log.debug("features       = %s", self.vm.getFeatures())
         log.debug("flags          = %d", self.flags)
         log.debug("superpages     = %d", self.superpages)
+	 log.debug("hugepage_num   = %d", self.hugepage_num)
         if arch.type == "ia64":
             log.debug("vhpt          = %d", self.vhpt)
 
@@ -742,7 +745,8 @@
                               features       = self.vm.getFeatures(),
                               flags          = self.flags,
                               vhpt           = self.vhpt,
-                              superpages     = self.superpages)
+                              superpages     = self.superpages,
+			       hugepage_num   = self.hugepage_num)
 
     def getBitSize(self):
         return xc.getBitSize(image    = self.kernel,
tools/python/xen/xm/create.dtd +1 -0
diff -r 4e108cf56d07 tools/python/xen/xm/create.dtd
@@ -56,6 +56,7 @@
                  actions_after_crash    %CRASH_BEHAVIOUR; #REQUIRED
                  PCI_bus                CDATA #REQUIRED
                  superpages             CDATA #REQUIRED
+		  hugepage_num		 CDATA #REQUIRED
                  security_label         CDATA #IMPLIED>
 
 <!ELEMENT memory EMPTY> 
tools/python/xen/xm/create.py +8 -0
diff -r 4e108cf56d07 tools/python/xen/xm/create.py
@@ -680,6 +680,11 @@
            fn=set_int, default=0,
            use="Create domain with superpages")
 
+gopts.var('hugepage_num', val='NUM',
+           fn=set_int, default=0,
+           use="Domain with hugepages support")
+
+
 def err(msg):
     """Print an error to stderr and exit.
     """
@@ -770,6 +775,9 @@
         config_image.append(['args', vals.extra])
     if vals.superpages:
         config_image.append(['superpages', vals.superpages])
+    if vals.hugepage_num:
+        config_image.append(['hugepage_num', vals.hugepage_num])
+
 
     if vals.builder == 'hvm':
         configure_hvm(config_image, vals) 
tools/python/xen/xm/xenapi_create.py +4 -0
diff -r 4e108cf56d07 tools/python/xen/xm/xenapi_create.py
@@ -285,6 +285,8 @@
                 vm.attributes["s3_integrity"].value,
             "superpages":
                 vm.attributes["superpages"].value,
+ 	     "hugepage_num":
+                vm.attributes["hugepage_num"].value,
             "memory_static_max":
                 get_child_node_attribute(vm, "memory", "static_max"),
             "memory_static_min":
@@ -697,6 +699,8 @@
             = str(get_child_by_name(config, "s3_integrity", 0))
         vm.attributes["superpages"] \
             = str(get_child_by_name(config, "superpages", 0))
+	 vm.attributes["hugepage_num"] \
+            = str(get_child_by_name(config, "hugepage_num", 0))
         vm.attributes["pool_name"] \
             = str(get_child_by_name(config, "pool_name", "Pool-0"))
 
xen/arch/x86/setup.c +8 -2
diff -r 4e108cf56d07 xen/arch/x86/setup.c
@@ -60,7 +60,10 @@
 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
 static bool_t __initdata opt_watchdog;
 boolean_param("watchdog", opt_watchdog);
-
+//a2k2:
+static unsigned int __initdata dom0_hugepages=0;
+integer_param("dom0_hugepages", dom0_hugepages);
+int allocate_hugepages(struct domain *,int,int);
 /* **** Linux config option: propagated to domain0. */
 /* "acpi=off":    Sisables both ACPI table parsing and interpreter. */
 /* "acpi=force":  Override the disable blacklist.                   */
@@ -1259,7 +1262,10 @@
     
     if ( !tboot_protect_mem_regions() )
         panic("Could not protect TXT memory regions\n");
+    
 
+   
+    printk("a2k2:Dom0 hugepages are :%u\n",dom0_hugepages);
     /* Create initial domain 0. */
     dom0 = domain_create(0, DOMCRF_s3_integrity, DOM0_SSIDREF);
     if ( (dom0 == NULL) || (alloc_dom0_vcpu0() == NULL) )
@@ -1267,7 +1273,7 @@
 
     dom0->is_privileged = 1;
     dom0->target = NULL;
-
+    allocate_hugepages(dom0,dom0_hugepages,SUPERPAGE_ORDER);
     /* Grab the DOM0 command line. */
     cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
     if ( (cmdline != NULL) || (kextra != NULL) )
xen/common/domain.c +9 -3
diff -r 4e108cf56d07 xen/common/domain.c
@@ -240,9 +240,9 @@
     spin_lock_init(&d->hypercall_deadlock_mutex);
     INIT_PAGE_LIST_HEAD(&d->page_list);
     INIT_PAGE_LIST_HEAD(&d->xenpage_list);
-
+    INIT_PAGE_LIST_HEAD(&d->hugepage_list);
     spin_lock_init(&d->node_affinity_lock);
-
+    d->hugepage_num=0;
     spin_lock_init(&d->shutdown_lock);
     d->shutdown_code = -1;
 
@@ -441,7 +441,7 @@
 int domain_kill(struct domain *d)
 {
     int rc = 0;
-
+    struct page_info* page;
     if ( d == current->domain )
         return -EINVAL;
 
@@ -451,6 +451,12 @@
     case DOMDYING_alive:
         domain_pause(d);
         d->is_dying = DOMDYING_dying;
+         while(!page_list_empty(&(d->hugepage_list)))
+            {
+          
+                page=page_list_remove_head(&(d->hugepage_list));
+                free_domheap_pages(page,SUPERPAGE_ORDER);
+            }
         spin_barrier(&d->domain_lock);
         evtchn_destroy(d);
         gnttab_release_mappings(d);
xen/common/memory.c +71 -3

103 lines not on this page · raw message

xen/include/public/memory.h +3 -0
diff -r 4e108cf56d07 xen/include/public/memory.h
@@ -37,6 +37,9 @@
 #define XENMEM_increase_reservation 0
 #define XENMEM_decrease_reservation 1
 #define XENMEM_populate_physmap     6
+#define XENMEM_populate_hugepage    19
+#define XENMEM_hugepage_cnt         20
+#define XENMEM_populate_hugemap     21
 
 #if __XEN_INTERFACE_VERSION__ >= 0x00030209
 /*
xen/include/xen/sched.h +3 -0
diff -r 4e108cf56d07 xen/include/xen/sched.h
@@ -211,6 +211,9 @@
     spinlock_t       page_alloc_lock; /* protects all the following fields  */
     struct page_list_head page_list;  /* linked list, of size tot_pages     */
     struct page_list_head xenpage_list; /* linked list (size xenheap_pages) */
+    struct page_list_head hugepage_list; /* Free hugepage list*/
+    unsigned int     hugepage_num;    /* Free Hugepage Count  */
+
     unsigned int     tot_pages;       /* number of pages currently possesed */
     unsigned int     max_pages;       /* maximum value for tot_pages        */
     atomic_t         shr_pages;       /* number of shared pages             */
arch/x86/include/asm/hugetlb.h +8 -0
index bf88684..7707e21 100644
@@ -98,6 +98,14 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
 
 	return changed;
 }
+#ifdef CONFIG_XEN
+struct page* allocate_hugepage(int);
+#else
+static inline struct page * allocate_hugepage(int order)
+{
+        return NULL;
+}
+#endif
 
 static inline int arch_prepare_hugepage(struct page *page)
 {

index f46c340..00c489a 100644

arch/x86/mm/hugetlbpage.c +1 -2
@@ -147,8 +147,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
 			pte = (pte_t *) pmd_alloc(mm, pud, addr);
 		}
 	}
-	BUG_ON(pte && !pte_none(*pte) && !pte_huge(*pte));
-
+	BUG_ON(pte && !pte_none(*pte) && !((*pte).pte & (_AT(pteval_t, 1)<<7)));
 	return pte;
 }
 
arch/x86/xen/enlighten.c +4 -0
index 070f138..c1db610 100644
@@ -58,6 +58,7 @@
 #include <asm/reboot.h>
 #include <asm/stackprotector.h>
 #include <asm/hypervisor.h>
+#include <linux/list.h>
 
 #include "xen-ops.h"
 #include "mmu.h"
@@ -76,6 +77,9 @@ EXPORT_SYMBOL(machine_to_phys_mapping);
 unsigned int   machine_to_phys_order;
 EXPORT_SYMBOL(machine_to_phys_order);
 
+struct list_head xen_hugepfn_list;
+EXPORT_SYMBOL_GPL(xen_hugepfn_list);
+
 struct start_info *xen_start_info;
 EXPORT_SYMBOL_GPL(xen_start_info);
 
arch/x86/xen/mmu.c +75 -0

86 lines not on this page · raw message

arch/x86/xen/setup.c +34 -0
index 1a1934a..c1781e7 100644
@@ -138,6 +138,40 @@ static unsigned long __init xen_return_unused_memory(unsigned long max_pfn,
 	return released;
 }
 
+extern struct list_head xen_hugepfn_list;
+static int __init reserve_hugepage_range(void)
+{
+    phys_addr_t temp,hugemem_start;
+    unsigned long i,ret;
+    struct page *page;
+    static unsigned long frame_list[1];
+    struct xen_memory_reservation reservation = {
+        .address_bits = 0,
+	 .extent_order = 0,
+	 .nr_extents   = 1,
+	 .domid        = DOMID_SELF
+    };
+    if(!xen_pv_domain())
+	 return -ENODEV;
+    set_xen_guest_handle(reservation.extent_start, frame_list);
+    hugemem_start=PFN_UP(xen_extra_mem_start);
+    ret = HYPERVISOR_memory_op(20, &reservation);
+    printk("a2k2: num of hugepages found =%lu\n",ret);
+    temp=PFN_PHYS(PFN_UP(xen_extra_mem_start)+ret*512);
+
+    xen_extra_mem_start=temp;
+    xen_extra_mem_size-=ret*2*1024*1024;
+    INIT_LIST_HEAD(&xen_hugepfn_list);
+    for(i=0;i<ret;i++)
+    {
+        page=pfn_to_page(hugemem_start);
+        list_add_tail(&page->lru,&xen_hugepfn_list);
+        hugemem_start+=512;
+    }
+    return 0;
+}
+subsys_initcall(reserve_hugepage_range);
+
 /**
  * machine_specific_memory_setup - Hook for machine specific memory setup.
  **/
include/xen/interface/memory.h +1 -0
index aa4e368..168dd2b 100644
@@ -19,6 +19,7 @@
 #define XENMEM_increase_reservation 0
 #define XENMEM_decrease_reservation 1
 #define XENMEM_populate_physmap     6
+#define XENMEM_populate_hugepage    19
 struct xen_memory_reservation {
 
     /*
mm/hugetlb.c +9 -6
index f5a106e..7e38f73 100644
@@ -18,6 +18,7 @@
 #include <linux/mutex.h>
 #include <linux/bootmem.h>
 #include <linux/sysfs.h>
+#include <xen/xen.h>
 
 #include <asm/page.h>
 #include <asm/pgtable.h>
@@ -600,17 +620,19 @@ int PageHuge(struct page *page)
 	return dtor == free_huge_page;
 }
 
+ 
 static struct page *alloc_fresh_huge_page_node(struct hstate *h, int nid)
 {
 	struct page *page;
-
 	if (h->order >= MAX_ORDER)
 		return NULL;
-
-	page = alloc_pages_exact_node(nid,
-		htlb_alloc_mask|__GFP_COMP|__GFP_THISNODE|
-						__GFP_REPEAT|__GFP_NOWARN,
-		huge_page_order(h));
+       if(!xen_pv_domain())
+	        page = alloc_pages_exact_node(nid,
+		        htlb_alloc_mask|__GFP_COMP|__GFP_THISNODE|
+		                                        __GFP_REPEAT|__GFP_NOWARN,
+		        huge_page_order(h));
+	else
+	        page=allocate_hugepage(huge_page_order(h));
 	if (page) {
 		if (arch_prepare_hugepage(page)) {
 			__free_pages(page, huge_page_order(h));

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

#1 lore raw
Quoted 9 lines · Keshav Darak

We have implemented hugepage support for guests in following manner

In
our implementation we added a parameter hugepage_num which is specified in the config file of the DomU. It is the number of hugepages that the
guest is guaranteed to receive whenever the kernel asks for hugepage by using its boot time parameter or reserving after booting (eg. Using echo
XX > /proc/sys/vm/nr_hugepages). During creation of the domain we
reserve MFN's for these hugepages and store them in the list. The

There is bootup option for normal Linux kernels to set that up. Was that something you could use?

In regards to the patch, I've some questions..

Quoted 6 lines
arch/x86/include/asm/hugetlb.h +0 -0
index bf88684..7707e21 100644
@@ -98,6 +98,14 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
 

arch/x86/include/asm/hugetlb.h static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, · line 108

Quoted 10 lines
arch/x86/include/asm/hugetlb.h +8 -0
 	return changed;
 }
+#ifdef CONFIG_XEN
+struct page* allocate_hugepage(int);
+#else
+static inline struct page * allocate_hugepage(int order)
+{
+        return NULL;
+}
+#endif

So it looks like you are exposing the allocate_hugepage to be out of the hotplug memory. Could you do this via a pvops structure instead? You should also seperate this functionality as its own patch - ie, expose the allocate_hugepage.

arch/x86/mm/hugetlbpage.c pte_t *huge_pte_alloc(struct mm_struct *mm, · line 150

Quoted 13 lines
arch/x86/include/asm/hugetlb.h +0 -0
 static inline int arch_prepare_hugepage(struct page *page)
 {

index f46c340..00c489a 100644

arch/x86/mm/hugetlbpage.c +1 -2
@@ -147,8 +147,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
 			pte = (pte_t *) pmd_alloc(mm, pud, addr);
 		}
 	}
-	BUG_ON(pte && !pte_none(*pte) && !pte_huge(*pte));
-
+	BUG_ON(pte && !pte_none(*pte) && !((*pte).pte & (_AT(pteval_t, 1)<<7)));

Ugh. That is horrible.

why can't you use 'pte_huge' ? Is it b/c of this
* (We should never see kernel mappings with _PAGE_PSE set,
* but we could see hugetlbfs mappings, I think.). */
if (pat_enabled && !WARN_ON(pte & _PAGE_PAT)) { in xen/mmu.c?

If so, have you thought about removing the warnings and/or changing the logic there instead?

Quoted 16 lines
arch/x86/mm/hugetlbpage.c +0 -0
 	return pte;
 }
 
arch/x86/xen/enlighten.c +1 -0
index 070f138..c1db610 100644
@@ -58,6 +58,7 @@
 #include <asm/reboot.h>
 #include <asm/stackprotector.h>
 #include <asm/hypervisor.h>
+#include <linux/list.h>
 
 #include "xen-ops.h"
 #include "mmu.h"

arch/x86/xen/enlighten.c EXPORT_SYMBOL(machine_to_phys_mapping); · line 82

Quoted 6 lines
arch/x86/xen/enlighten.c +3 -0
@@ -76,6 +77,9 @@ EXPORT_SYMBOL(machine_to_phys_mapping);
 unsigned int   machine_to_phys_order;
 EXPORT_SYMBOL(machine_to_phys_order);
 
+struct list_head xen_hugepfn_list;
+EXPORT_SYMBOL_GPL(xen_hugepfn_list);
+

Hmm, a list, but no locking? There is no need for a spinlock?

Quoted 18 lines
arch/x86/xen/enlighten.c +0 -0
 struct start_info *xen_start_info;
 EXPORT_SYMBOL_GPL(xen_start_info);
 
arch/x86/xen/mmu.c +1 -0
index 32a1c65..fa9fa6c 100644
@@ -44,6 +44,7 @@
 #include <linux/bug.h>
 #include <linux/vmalloc.h>
 #include <linux/module.h>
+#include <linux/bootmem.h>
 
 #include <asm/pgtable.h>
 #include <asm/tlbflush.h>
@@ -2776,5 +2784,79 @@ static int __init xen_mmu_debugfs(void)
 	return 0;
 }

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2795

Quoted 10 lines
arch/x86/xen/mmu.c +9 -0
 fs_initcall(xen_mmu_debugfs);
+//a2k2
+extern struct list_head xen_hugepfn_list;
+static unsigned long frame_list[PAGE_SIZE / sizeof(unsigned long)];
+
+static void scrub_page(struct page *page)
+{
+#ifdef CONFIG_XEN_SCRUB_PAGES
+		clear_highpage(page);
+#endif

You don't seem to use this anywhere..

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2799

Quoted 4 lines
arch/x86/xen/mmu.c +4 -0
+}
+#ifdef CONFIG_HIGHMEM
+#define inc_totalhigh_pages() (totalhigh_pages++)
+#define dec_totalhigh_pages() (totalhigh_pages--)

so what do you do with those? I seem incremented, but nothing seems to use them.

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2806

Quoted 7 lines
arch/x86/xen/mmu.c +7 -0
+#else
+#define inc_totalhigh_pages() do {} while(0)
+#define dec_totalhigh_pages() do {} while(0)
+#endif
+
+struct page* allocate_hugepage(int order){
+    unsigned long  mfn, i, j;

You seem to be definiing 'i' but not using it?

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2808

Quoted 2 lines
arch/x86/xen/mmu.c +2 -0
+    struct page   *page;
+    long           rc,cnt;

You should be using 'int' for rc.

Quoted 5 lines
arch/x86/xen/mmu.c +5 -0
+    unsigned long pfn;
+    struct xen_memory_reservation reservation = {
+	.address_bits = 0,
+	.domid        = DOMID_SELF
+    };

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2823

Quoted 10 lines
arch/x86/xen/mmu.c +10 -0
+    if(list_empty(&xen_hugepfn_list)){
+        return NULL; 
+    } 
+    page = list_entry(xen_hugepfn_list.next, struct page, lru);
+    list_del(&page->lru);
+    frame_list[0] = page_to_pfn(page);
+
+    set_xen_guest_handle(reservation.extent_start, frame_list);
+    reservation.nr_extents = 1;
+    reservation.extent_order = 9;

shouldn't this 'order' instead of 9'?

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2828

Quoted 5 lines
arch/x86/xen/mmu.c +5 -0
+    cnt=1<<order;
+    rc = HYPERVISOR_memory_op(XENMEM_populate_hugepage, &reservation);
+    if (rc <= 0)
+    {
+	printk("a2k2: could not allocate hugepage\n"); 

Please run 'script/checkpatch.pl' before posting. It will show that this a not good.

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2837

Quoted 9 lines
arch/x86/xen/mmu.c +9 -0
+	goto out1;
+    }
+    pfn=page_to_pfn(page);
+    if(rc)
+    {
+	mfn = frame_list[0];
+	for (j = 0; j < cnt; j++, pfn++, mfn++) {
+	    set_phys_to_machine(pfn, mfn);
+	    if (pfn < max_low_pfn) {

... and what if 'pfn > max_low_pfn' ? What should we do then?

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2840

Quoted 3 lines
arch/x86/xen/mmu.c +3 -0
+	        int ret;
+		ret = HYPERVISOR_update_va_mapping(
+					       (unsigned long)__va(pfn << PAGE_SHIFT),

Use the PFN_DOWN macro please.

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2843

Quoted 3 lines
arch/x86/xen/mmu.c +3 -0
+					       mfn_pte(mfn, PAGE_KERNEL),
+					       0);
+		BUG_ON(ret);

Ugh. what if you just stopped the allocation and returned NULL instead?

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2848

Quoted 5 lines
arch/x86/xen/mmu.c +5 -0
+	    }
+	}
+
+	ClearPageReserved(page);
+	atomic_set(&page->_count,1);

Ugh.. Is that correct? Can you explain why you need to do that?

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2849

Quoted 1 line
arch/x86/xen/mmu.c +1 -0
+    }

What if rc is zero? Should we ocntinue on with page?

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2851

Quoted 2 lines
arch/x86/xen/mmu.c +2 -0
+    if (PageHighMem(page)) {
+        for(i=0;i<512;i++)

Shouldn't you determine the value 512 from the 'order'?

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2854

Quoted 3 lines
arch/x86/xen/mmu.c +3 -0
+	    inc_totalhigh_pages();
+    }
+    totalram_pages+=512;

Ditto.

arch/x86/xen/mmu.c static int __init xen_mmu_debugfs(void) · line 2858

Quoted 4 lines
arch/x86/xen/mmu.c +4 -0
+    __SetPageHead(page);
+    set_compound_order(page,order);
+    return page;
+ out1:

shouldn't you return the page back on the xen_hugepfn_list?

Quoted 9 lines
arch/x86/xen/mmu.c +2 -0
+    return NULL;
+}
 
 #endif	/* CONFIG_XEN_DEBUG_FS */
arch/x86/xen/setup.c +0 -0
index 1a1934a..c1781e7 100644

arch/x86/xen/setup.c static unsigned long __init xen_return_unused_memory(unsigned long max_pfn, · line 145

Quoted 8 lines
arch/x86/xen/setup.c +5 -0
@@ -138,6 +138,40 @@ static unsigned long __init xen_return_unused_memory(unsigned long max_pfn,
 	return released;
 }
 
+extern struct list_head xen_hugepfn_list;
+static int __init reserve_hugepage_range(void)
+{
+    phys_addr_t temp,hugemem_start;
+    unsigned long i,ret;

Is 'unsigned long' the right type for 'ret'?

arch/x86/xen/setup.c static unsigned long __init xen_return_unused_memory(unsigned long max_pfn, · line 158

Quoted 13 lines
arch/x86/xen/setup.c +13 -0
+    struct page *page;
+    static unsigned long frame_list[1];
+    struct xen_memory_reservation reservation = {
+        .address_bits = 0,
+	 .extent_order = 0,
+	 .nr_extents   = 1,
+	 .domid        = DOMID_SELF
+    };
+    if(!xen_pv_domain())
+	 return -ENODEV;
+    set_xen_guest_handle(reservation.extent_start, frame_list);
+    hugemem_start=PFN_UP(xen_extra_mem_start);
+    ret = HYPERVISOR_memory_op(20, &reservation);

20? There is no #define for this?
You are not checking to see if the hypercall failed.

arch/x86/xen/setup.c static unsigned long __init xen_return_unused_memory(unsigned long max_pfn, · line 160

Quoted 2 lines
arch/x86/xen/setup.c +2 -0
+    printk("a2k2: num of hugepages found =%lu\n",ret);
+    temp=PFN_PHYS(PFN_UP(xen_extra_mem_start)+ret*512);

There has to be a better way of doing this.

You are assuming that the hugepage is always 2MB. What if it is 16MB? Is there a way you can use any definitions of the architecture for this?

arch/x86/xen/setup.c static unsigned long __init xen_return_unused_memory(unsigned long max_pfn, · line 163

Quoted 3 lines
arch/x86/xen/setup.c +3 -0
+
+    xen_extra_mem_start=temp;
+    xen_extra_mem_size-=ret*2*1024*1024;

Ditto. You are assuming it is 2MB. I couldbe bigger (or smaller) depending on the architecture.

Quoted 45 lines
arch/x86/xen/setup.c +11 -0
+    INIT_LIST_HEAD(&xen_hugepfn_list);
+    for(i=0;i<ret;i++)
+    {
+        page=pfn_to_page(hugemem_start);
+        list_add_tail(&page->lru,&xen_hugepfn_list);
+        hugemem_start+=512;
+    }
+    return 0;
+}
+subsys_initcall(reserve_hugepage_range);
+
 /**
 * machine_specific_memory_setup - Hook for machine specific memory setup.
 **/
include/xen/interface/memory.h +1 -0
index aa4e368..168dd2b 100644
@@ -19,6 +19,7 @@
 #define XENMEM_increase_reservation 0
 #define XENMEM_decrease_reservation 1
 #define XENMEM_populate_physmap     6
+#define XENMEM_populate_hugepage    19
 struct xen_memory_reservation {
 
    /*
mm/hugetlb.c +2 -0
index f5a106e..7e38f73 100644
@@ -18,6 +18,7 @@
 #include <linux/mutex.h>
 #include <linux/bootmem.h>
 #include <linux/sysfs.h>
+#include <xen/xen.h>
 
 #include <asm/page.h>
 #include <asm/pgtable.h>
@@ -600,17 +620,19 @@ int PageHuge(struct page *page)
 	return dtor == free_huge_page;
 }
 
+ 
 static struct page *alloc_fresh_huge_page_node(struct hstate *h, int nid)
 {

mm/hugetlb.c int PageHuge(struct page *page) · line 629

Quoted 10 lines
mm/hugetlb.c +1 -6
 	struct page *page;
-
 	if (h->order >= MAX_ORDER)
 		return NULL;
-
-	page = alloc_pages_exact_node(nid,
-		htlb_alloc_mask|__GFP_COMP|__GFP_THISNODE|
-						__GFP_REPEAT|__GFP_NOWARN,
-		huge_page_order(h));
+       if(!xen_pv_domain())

Ugh. That is not the right way. You should be looking at using the pvops struct interface so that you can over-write the baremetal default implementation.

Quoted 10 lines
mm/hugetlb.c +6 -0
+	        page = alloc_pages_exact_node(nid,
+		        htlb_alloc_mask|__GFP_COMP|__GFP_THISNODE|
+		                                        __GFP_REPEAT|__GFP_NOWARN,
+		        huge_page_order(h));
+	else
+	        page=allocate_hugepage(huge_page_order(h));
 	if (page) {
 		if (arch_prepare_hugepage(page)) {
 			__free_pages(page, huge_page_order(h));